ParserModel.php 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年2月14日
  7. * 标签解析引擎模型
  8. */
  9. namespace app\home\model;
  10. use core\basic\Model;
  11. class ParserModel extends Model
  12. {
  13. // 存储分类及子编码
  14. protected $scodes = array();
  15. // 存储分类查询数据
  16. protected $sorts;
  17. // 存储栏目位置
  18. protected $position = array();
  19. // 上一篇
  20. protected $pre;
  21. // 下一篇
  22. protected $next;
  23. // 获取模型数据
  24. public function checkModelUrlname($urlname)
  25. {
  26. if ($urlname == 'list' || $urlname == 'about') {
  27. return true;
  28. }
  29. return parent::table('ay_model')->where("urlname='$urlname'")->find();
  30. }
  31. // 站点配置信息
  32. public function getSite()
  33. {
  34. return parent::table('ay_site')->where("acode='" . get_lg() . "'")->find();
  35. }
  36. // 公司信息
  37. public function getCompany()
  38. {
  39. return parent::table('ay_company')->where("acode='" . get_lg() . "'")->find();
  40. }
  41. // 自定义标签,不区分语言,兼容跨语言
  42. public function getLabel()
  43. {
  44. return parent::table('ay_label')->decode()->column('value,type', 'name');
  45. }
  46. // 单个分类信息,不区分语言,兼容跨语言
  47. public function getSort($scode)
  48. {
  49. $scode = escape_string($scode);
  50. $field = array(
  51. 'a.*',
  52. 'c.name AS parentname',
  53. 'b.type',
  54. 'b.urlname',
  55. 'd.gcode'
  56. );
  57. $join = array(
  58. array(
  59. 'ay_model b',
  60. 'a.mcode=b.mcode',
  61. 'LEFT'
  62. ),
  63. array(
  64. 'ay_content_sort c',
  65. 'a.pcode=c.scode',
  66. 'LEFT'
  67. ),
  68. array(
  69. 'ay_member_group d',
  70. 'a.gid=d.id',
  71. 'LEFT'
  72. )
  73. );
  74. return parent::table('ay_content_sort a')->field($field)
  75. ->where("a.scode='$scode' OR a.filename='$scode'")
  76. ->join($join)
  77. ->find();
  78. }
  79. // 多个分类信息,不区分语言,兼容跨语言
  80. public function getMultSort($scodes)
  81. {
  82. $field = array(
  83. 'a.*',
  84. 'c.name AS parentname',
  85. 'b.type',
  86. 'b.urlname'
  87. );
  88. $join = array(
  89. array(
  90. 'ay_model b',
  91. 'a.mcode=b.mcode',
  92. 'LEFT'
  93. ),
  94. array(
  95. 'ay_content_sort c',
  96. 'a.pcode=c.scode',
  97. 'LEFT'
  98. )
  99. );
  100. return parent::table('ay_content_sort a')->field($field)
  101. ->in('a.scode', $scodes)
  102. ->join($join)
  103. ->order('a.sorting,a.id')
  104. ->select();
  105. }
  106. // 指定分类数量
  107. public function getSortRows($scode)
  108. {
  109. $this->scodes = array(); // 先清空
  110. // 获取多分类子类
  111. $arr = explode(',', $scode);
  112. foreach ($arr as $value) {
  113. $scodes = $this->getSubScodes(trim($value));
  114. }
  115. // 拼接条件
  116. $where1 = array(
  117. "scode in (" . implode_quot(',', $scodes) . ")",
  118. "subscode='$scode'"
  119. );
  120. $where2 = array(
  121. "acode='" . get_lg() . "'",
  122. 'status=1',
  123. "date<'" . date('Y-m-d H:i:s') . "'"
  124. );
  125. $result = parent::table('ay_content')->where($where1, 'OR')
  126. ->where($where2)
  127. ->column('id');
  128. return count($result);
  129. }
  130. // 分类栏目列表关系树
  131. public function getSortsTree()
  132. {
  133. $fields = array(
  134. 'a.*',
  135. 'b.type',
  136. 'b.urlname'
  137. );
  138. $join = array(
  139. 'ay_model b',
  140. 'a.mcode=b.mcode',
  141. 'LEFT'
  142. );
  143. $result = parent::table('ay_content_sort a')->where("a.acode='" . get_lg() . "'")
  144. ->where('a.status=1')
  145. ->join($join)
  146. ->order('a.pcode,a.sorting,a.id')
  147. ->column($fields, 'scode');
  148. foreach ($result as $key => $value) {
  149. if ($value['pcode']) {
  150. $result[$value['pcode']]['son'][] = $value; // 记录到关系树
  151. } else {
  152. $data['top'][] = $value; // 记录顶级菜单
  153. }
  154. }
  155. $data['tree'] = $result;
  156. return $data;
  157. }
  158. // 获取分类名称
  159. public function getSortName($scode)
  160. {
  161. $result = $this->getSortList();
  162. return $result[$scode]['name'];
  163. }
  164. // 分类顶级编码
  165. public function getSortTopScode($scode)
  166. {
  167. $result = $this->getSortList();
  168. return $this->getTopParent($scode, $result);
  169. }
  170. // 获取位置
  171. public function getPosition($scode)
  172. {
  173. $result = $this->getSortList();
  174. $this->position = array(); // 重置
  175. $this->getTopParent($scode, $result);
  176. return array_reverse($this->position);
  177. }
  178. // 分类顶级编码
  179. private function getTopParent($scode, $sorts)
  180. {
  181. if (! $scode || ! $sorts) {
  182. return;
  183. }
  184. $this->position[] = $sorts[$scode];
  185. if ($sorts[$scode]['pcode']) {
  186. return $this->getTopParent($sorts[$scode]['pcode'], $sorts);
  187. } else {
  188. return $sorts[$scode]['scode'];
  189. }
  190. }
  191. /* // 分类子类集
  192. private function getSubScodes($scode)
  193. {
  194. if (! $scode) {
  195. return;
  196. }
  197. $this->scodes[] = $scode;
  198. $subs = parent::table('ay_content_sort')->where("pcode='$scode'")->column('scode');
  199. if ($subs) {
  200. foreach ($subs as $value) {
  201. $this->getSubScodes($value);
  202. }
  203. }
  204. return $this->scodes;
  205. } */
  206. // 分类子类集
  207. public function getSubScodes($scode)
  208. {
  209. if (! $scode) {
  210. return;
  211. }
  212. $this->scodes[] = $scode;
  213. $subs = parent::table('ay_content_sort')->where("pcode='$scode'")
  214. ->where("outlink=''")
  215. ->column('scode');
  216. if ($subs) {
  217. foreach ($subs as $value) {
  218. $this->getSubScodes($value);
  219. }
  220. }
  221. return $this->scodes;
  222. }
  223. // 清除静态缓存时,获取全部栏目编码
  224. public function getScodes($type)
  225. {
  226. $join = array(
  227. 'ay_model b',
  228. 'a.mcode=b.mcode',
  229. 'LEFT'
  230. );
  231. // 不包括外链
  232. return parent::table('ay_content_sort a')->join($join)
  233. ->in('b.type', $type)
  234. ->where("outlink=''")
  235. ->column('scode');
  236. }
  237. // 生成静态时,获取栏目全部内容ID
  238. public function getContentIds($scodes, $where = array())
  239. {
  240. return parent::table('ay_content')->in('scode', $scodes)
  241. ->where("outlink=''")
  242. ->where($where)
  243. ->column('id');
  244. }
  245. // 获取栏目清单
  246. private function getSortList()
  247. {
  248. if (! isset($this->sorts)) {
  249. $fields = array(
  250. 'a.id',
  251. 'a.pcode',
  252. 'a.scode',
  253. 'a.name',
  254. 'a.filename',
  255. 'a.outlink',
  256. 'b.type',
  257. 'b.urlname'
  258. );
  259. $join = array(
  260. 'ay_model b',
  261. 'a.mcode=b.mcode',
  262. 'LEFT'
  263. );
  264. $this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . get_lg() . "'")
  265. ->join($join)
  266. ->column($fields, 'scode');
  267. }
  268. return $this->sorts;
  269. }
  270. // 获取筛选字段数据
  271. public function getSelect($field)
  272. {
  273. return parent::table('ay_extfield')->where("name='$field'")->value('value');
  274. }
  275. // 列表内容,带分页,不区分语言,兼容跨语言
  276. public function getLists($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)
  277. {
  278. $scode = escape_string($scode);
  279. $ext_table = false;
  280. if ($lfield) {
  281. $lfield .= ',id,outlink,type,scode,sortfilename,filename,urlname'; // 附加必须字段
  282. $fields = explode(',', $lfield);
  283. $fields = array_unique($fields); // 去重
  284. foreach ($fields as $key => $value) {
  285. if (strpos($value, 'ext_') === 0) {
  286. $ext_table = true;
  287. $fields[$key] = 'e.' . $value;
  288. } elseif ($value == 'sortname') {
  289. $fields[$key] = 'b.name as sortname';
  290. } elseif ($value == 'sortfilename') {
  291. $fields[$key] = 'b.filename as sortfilename';
  292. } elseif ($value == 'subsortname') {
  293. $fields[$key] = 'c.name as subsortname';
  294. } elseif ($value == 'subfilename') {
  295. $fields[$key] = 'c.filename as subfilename';
  296. } elseif ($value == 'type' || $value == 'urlname') {
  297. $fields[$key] = 'd.' . $value;
  298. } elseif ($value == 'modelname') {
  299. $fields[$key] = 'd.name as modelname';
  300. } else {
  301. $fields[$key] = 'a.' . $value;
  302. }
  303. }
  304. } else {
  305. $ext_table = true;
  306. $fields = array(
  307. 'a.*',
  308. 'b.name as sortname',
  309. 'b.filename as sortfilename',
  310. 'c.name as subsortname',
  311. 'c.filename as subfilename',
  312. 'd.type',
  313. 'd.name as modelname',
  314. 'd.urlname',
  315. 'e.*',
  316. 'f.gcode'
  317. );
  318. }
  319. $join = array(
  320. array(
  321. 'ay_content_sort b',
  322. 'a.scode=b.scode',
  323. 'LEFT'
  324. ),
  325. array(
  326. 'ay_content_sort c',
  327. 'a.subscode=c.scode',
  328. 'LEFT'
  329. ),
  330. array(
  331. 'ay_model d',
  332. 'b.mcode=d.mcode',
  333. 'LEFT'
  334. ),
  335. array(
  336. 'ay_member_group f',
  337. 'a.gid=f.id',
  338. 'LEFT'
  339. )
  340. );
  341. // 加载扩展字段表
  342. if ($ext_table) {
  343. $join[] = array(
  344. 'ay_content_ext e',
  345. 'a.id=e.contentid',
  346. 'LEFT'
  347. );
  348. }
  349. $scode_arr = array();
  350. if ($scode) {
  351. // 获取所有子类分类编码
  352. $this->scodes = array(); // 先清空
  353. $arr = explode(',', $scode); // 传递有多个分类时进行遍历
  354. foreach ($arr as $value) {
  355. $scodes = $this->getSubScodes(trim($value));
  356. }
  357. // 拼接条件
  358. $scode_arr = array(
  359. "a.scode in (" . implode_quot(',', $scodes) . ")",
  360. "a.subscode='$scode'"
  361. );
  362. }
  363. $where = array(
  364. 'a.status=1',
  365. 'd.type=2',
  366. "a.date<'" . date('Y-m-d H:i:s') . "'"
  367. );
  368. if ($lg) {
  369. $where['a.acode'] = $lg;
  370. }
  371. $indexSql = '';
  372. //todo:V3.1.5判断mysql是否设置了索引
  373. if (get_db_type() == 'mysql') {
  374. $checkIndex = parent::table('ay_content')->checkIndexSql();
  375. foreach ($checkIndex as $item){
  376. if($item[2] == 'ay_content_unique'){
  377. $indexSql = 'FORCE INDEX ( ay_content_unique )';
  378. break;
  379. }
  380. }
  381. }
  382. // 筛选条件支持模糊匹配
  383. return parent::table('ay_content a ' . $indexSql)->field($fields)
  384. ->where($scode_arr, 'OR')
  385. ->where($where)
  386. ->where($select, 'AND', 'AND', $fuzzy)
  387. ->where($filter, 'OR')
  388. ->where($tags, 'OR')
  389. ->join($join)
  390. ->order($order)
  391. ->page(1, $num, $start)
  392. ->decode()
  393. ->select();
  394. }
  395. // 列表内容,不带分页,不区分语言,兼容跨语言
  396. public function getList($scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true, $start = 1, $lfield = null, $lg = null)
  397. {
  398. $scode = escape_string($scode);
  399. $ext_table = false;
  400. if ($lfield) {
  401. $lfield .= ',id,outlink,type,scode,sortfilename,filename,urlname'; // 附加必须字段
  402. $fields = explode(',', $lfield);
  403. $fields = array_unique($fields); // 去重
  404. foreach ($fields as $key => $value) {
  405. if (strpos($value, 'ext_') === 0) {
  406. $ext_table = true;
  407. $fields[$key] = 'e.' . $value;
  408. } elseif ($value == 'sortname') {
  409. $fields[$key] = 'b.name as sortname';
  410. } elseif ($value == 'sortfilename') {
  411. $fields[$key] = 'b.filename as sortfilename';
  412. } elseif ($value == 'subsortname') {
  413. $fields[$key] = 'c.name as subsortname';
  414. } elseif ($value == 'subfilename') {
  415. $fields[$key] = 'c.filename as subfilename';
  416. } elseif ($value == 'type' || $value == 'urlname') {
  417. $fields[$key] = 'd.' . $value;
  418. } elseif ($value == 'modelname') {
  419. $fields[$key] = 'd.name as modelname';
  420. } else {
  421. $fields[$key] = 'a.' . $value;
  422. }
  423. }
  424. } else {
  425. $ext_table = true;
  426. $fields = array(
  427. 'a.*',
  428. 'b.name as sortname',
  429. 'b.filename as sortfilename',
  430. 'c.name as subsortname',
  431. 'c.filename as subfilename',
  432. 'd.type',
  433. 'd.name as modelname',
  434. 'd.urlname',
  435. 'e.*',
  436. 'f.gcode'
  437. );
  438. }
  439. $join = array(
  440. array(
  441. 'ay_content_sort b',
  442. 'a.scode=b.scode',
  443. 'LEFT'
  444. ),
  445. array(
  446. 'ay_content_sort c',
  447. 'a.subscode=c.scode',
  448. 'LEFT'
  449. ),
  450. array(
  451. 'ay_model d',
  452. 'b.mcode=d.mcode',
  453. 'LEFT'
  454. ),
  455. array(
  456. 'ay_member_group f',
  457. 'a.gid=f.id',
  458. 'LEFT'
  459. )
  460. );
  461. // 加载扩展字段表
  462. if ($ext_table) {
  463. $join[] = array(
  464. 'ay_content_ext e',
  465. 'a.id=e.contentid',
  466. 'LEFT'
  467. );
  468. }
  469. $scode_arr = array();
  470. if ($scode) {
  471. // 获取所有子类分类编码
  472. $this->scodes = array(); // 先清空
  473. $arr = explode(',', $scode); // 传递有多个分类时进行遍历
  474. foreach ($arr as $value) {
  475. $scodes = $this->getSubScodes(trim($value));
  476. }
  477. // 拼接条件
  478. $scode_arr = array(
  479. "a.scode in (" . implode_quot(',', $scodes) . ")",
  480. "a.subscode='$scode'"
  481. );
  482. }
  483. $where = array(
  484. 'a.status=1',
  485. 'd.type=2',
  486. "a.date<'" . date('Y-m-d H:i:s') . "'"
  487. );
  488. if ($lg) {
  489. $where['a.acode'] = $lg;
  490. }
  491. $indexSql = '';
  492. //todo:V3.1.5判断mysql是否设置了索引
  493. if (get_db_type() == 'mysql') {
  494. $checkIndex = parent::table('ay_content')->checkIndexSql();
  495. foreach ($checkIndex as $item){
  496. if($item[2] == 'ay_content_unique'){
  497. $indexSql = 'FORCE INDEX ( ay_content_unique )';
  498. break;
  499. }
  500. }
  501. }
  502. // 筛选条件支持模糊匹配
  503. return parent::table('ay_content a ' . $indexSql)->field($fields)
  504. ->where($scode_arr, 'OR')
  505. ->where($where)
  506. ->where($select, 'AND', 'AND', $fuzzy)
  507. ->where($filter, 'OR')
  508. ->where($tags, 'OR')
  509. ->join($join)
  510. ->order($order)
  511. ->limit($start - 1, $num)
  512. ->decode()
  513. ->select();
  514. }
  515. // 内容详情,不区分语言,兼容跨语言
  516. public function getContent($id)
  517. {
  518. $id = escape_string($id);
  519. $field = array(
  520. 'a.*',
  521. 'b.name as sortname',
  522. 'b.filename as sortfilename',
  523. 'b.outlink as sortoutlink',
  524. 'c.name as subsortname',
  525. 'c.filename as subfilename',
  526. 'd.type',
  527. 'd.name as modelname',
  528. 'd.urlname',
  529. 'e.*',
  530. 'f.gcode'
  531. );
  532. $join = array(
  533. array(
  534. 'ay_content_sort b',
  535. 'a.scode=b.scode',
  536. 'LEFT'
  537. ),
  538. array(
  539. 'ay_content_sort c',
  540. 'a.subscode=c.scode',
  541. 'LEFT'
  542. ),
  543. array(
  544. 'ay_model d',
  545. 'b.mcode=d.mcode',
  546. 'LEFT'
  547. ),
  548. array(
  549. 'ay_content_ext e',
  550. 'a.id=e.contentid',
  551. 'LEFT'
  552. ),
  553. array(
  554. 'ay_member_group f',
  555. 'a.gid=f.id',
  556. 'LEFT'
  557. )
  558. );
  559. $result = parent::table('ay_content a')->field($field)
  560. ->where("a.id='$id' OR a.filename='$id'")
  561. ->where('a.status=1')
  562. ->where("a.date<'" . date('Y-m-d H:i:s') . "'")
  563. ->join($join)
  564. ->decode()
  565. ->find();
  566. return $result;
  567. }
  568. // 单篇详情,不区分语言,兼容跨语言
  569. public function getAbout($scode)
  570. {
  571. $scode = escape_string($scode);
  572. $field = array(
  573. 'a.*',
  574. 'b.name as sortname',
  575. 'b.filename as sortfilename',
  576. 'c.name as subsortname',
  577. 'c.filename as subfilename',
  578. 'd.type',
  579. 'd.name as modelname',
  580. 'd.urlname',
  581. 'e.*',
  582. 'f.gcode'
  583. );
  584. $join = array(
  585. array(
  586. 'ay_content_sort b',
  587. 'a.scode=b.scode',
  588. 'LEFT'
  589. ),
  590. array(
  591. 'ay_content_sort c',
  592. 'a.subscode=c.scode',
  593. 'LEFT'
  594. ),
  595. array(
  596. 'ay_model d',
  597. 'b.mcode=d.mcode',
  598. 'LEFT'
  599. ),
  600. array(
  601. 'ay_content_ext e',
  602. 'a.id=e.contentid',
  603. 'LEFT'
  604. ),
  605. array(
  606. 'ay_member_group f',
  607. 'a.gid=f.id',
  608. 'LEFT'
  609. )
  610. );
  611. $result = parent::table('ay_content a')->field($field)
  612. ->where("a.scode='$scode' OR b.filename='$scode'")
  613. ->where('a.status=1')
  614. ->join($join)
  615. ->decode()
  616. ->order('id DESC')
  617. ->find();
  618. return $result;
  619. }
  620. // 指定内容多图
  621. public function getContentPics($id, $field)
  622. {
  623. $join = array(
  624. 'ay_content_ext b',
  625. 'a.id=b.contentid',
  626. 'LEFT'
  627. );
  628. $result = parent::table('ay_content a')->field($field . ',picstitle')
  629. ->join($join)
  630. ->where("a.id='$id'")
  631. ->where('a.status=1')
  632. ->where("a.date<'" . date('Y-m-d H:i:s') . "'")
  633. ->find();
  634. return $result;
  635. }
  636. // 指定内容多选调用
  637. public function getContentCheckbox($id, $field)
  638. {
  639. $result = parent::table('ay_content_ext')->where("contentid='$id'")->value($field);
  640. return $result;
  641. }
  642. // 指定内容标签调用
  643. public function getContentTags($id)
  644. {
  645. $result = parent::table('ay_content')->field('scode,tags')
  646. ->where("id='$id'")
  647. ->where('status=1')
  648. ->where("date<'" . date('Y-m-d H:i:s') . "'")
  649. ->find();
  650. return $result;
  651. }
  652. // 指定分类标签调用
  653. public function getSortTags($scode)
  654. {
  655. $join = array(
  656. array(
  657. 'ay_content_sort b',
  658. 'a.scode=b.scode',
  659. 'LEFT'
  660. ),
  661. array(
  662. 'ay_model c',
  663. 'b.mcode=c.mcode',
  664. 'LEFT'
  665. )
  666. );
  667. $scode_arr = array();
  668. if ($scode) {
  669. // 获取所有子类分类编码
  670. $this->scodes = array(); // 先清空
  671. $scodes = $this->getSubScodes(trim($scode)); // 获取子类
  672. // 拼接条件
  673. $scode_arr = array(
  674. "a.scode in (" . implode_quot(',', $scodes) . ")",
  675. "a.subscode='$scode'"
  676. );
  677. }
  678. $result = parent::table('ay_content a')->where("c.type=2 AND a.tags<>''")
  679. ->where($scode_arr, 'OR')
  680. ->join($join)
  681. ->where('a.status=1')
  682. ->order('a.visits DESC')
  683. ->column('a.tags');
  684. return $result;
  685. }
  686. // 上一篇内容
  687. public function getContentPre($scode, $id)
  688. {
  689. if (! $this->pre) {
  690. $this->scodes = array();
  691. $scodes = $this->getSubScodes($scode);
  692. $field = array(
  693. 'a.id',
  694. 'a.title',
  695. 'a.filename',
  696. 'a.ico',
  697. 'a.scode',
  698. 'b.filename as sortfilename',
  699. 'c.type',
  700. 'c.urlname'
  701. );
  702. $join = array(
  703. array(
  704. 'ay_content_sort b',
  705. 'a.scode=b.scode',
  706. 'LEFT'
  707. ),
  708. array(
  709. 'ay_model c',
  710. 'b.mcode=c.mcode',
  711. 'LEFT'
  712. )
  713. );
  714. $this->pre = parent::table('ay_content a')->field($field)
  715. ->where("a.id<$id")
  716. ->join($join)
  717. ->in('a.scode', $scodes)
  718. ->where("a.acode='" . get_lg() . "'")
  719. ->where('a.status=1')
  720. ->where("a.date<'" . date('Y-m-d H:i:s') . "'")
  721. ->order('a.id DESC')
  722. ->find();
  723. }
  724. return $this->pre;
  725. }
  726. // 下一篇内容
  727. public function getContentNext($scode, $id)
  728. {
  729. if (! $this->next) {
  730. $this->scodes = array();
  731. $scodes = $this->getSubScodes($scode);
  732. $field = array(
  733. 'a.id',
  734. 'a.title',
  735. 'a.filename',
  736. 'a.ico',
  737. 'a.scode',
  738. 'b.filename as sortfilename',
  739. 'c.type',
  740. 'c.urlname'
  741. );
  742. $join = array(
  743. array(
  744. 'ay_content_sort b',
  745. 'a.scode=b.scode',
  746. 'LEFT'
  747. ),
  748. array(
  749. 'ay_model c',
  750. 'b.mcode=c.mcode',
  751. 'LEFT'
  752. )
  753. );
  754. $this->next = parent::table('ay_content a')->field($field)
  755. ->where("a.id>$id")
  756. ->join($join)
  757. ->in('a.scode', $scodes)
  758. ->where("a.acode='" . get_lg() . "'")
  759. ->where('a.status=1')
  760. ->where("a.date<'" . date('Y-m-d H:i:s') . "'")
  761. ->order('a.id ASC')
  762. ->find();
  763. }
  764. return $this->next;
  765. }
  766. // 幻灯片
  767. public function getSlides($gid, $num, $start = 1)
  768. {
  769. $result = parent::table('ay_slide')->where("gid='$gid'")
  770. ->order('sorting ASC,id ASC')
  771. ->limit($start - 1, $num)
  772. ->select();
  773. return $result;
  774. }
  775. // 友情链接
  776. public function getLinks($gid, $num, $start = 1)
  777. {
  778. $result = parent::table('ay_link')->where("gid='$gid'")
  779. ->order('sorting ASC,id ASC')
  780. ->limit($start - 1, $num)
  781. ->select();
  782. return $result;
  783. }
  784. // 获取留言
  785. public function getMessage($num, $page = true, $start = 1, $lg = null)
  786. {
  787. if ($lg == 'all') {
  788. $where = array();
  789. } elseif ($lg) {
  790. $where = array(
  791. 'a.acode' => $lg
  792. );
  793. } else {
  794. $where = array(
  795. 'a.acode' => get_lg()
  796. );
  797. }
  798. $field = array(
  799. 'a.*',
  800. 'b.username',
  801. 'b.nickname',
  802. 'b.headpic'
  803. );
  804. $join = array(
  805. 'ay_member b',
  806. 'a.uid=b.id',
  807. 'LEFT'
  808. );
  809. if ($page) {
  810. return parent::table('ay_message a')->field($field)
  811. ->join($join)
  812. ->where("a.status=1")
  813. ->where($where)
  814. ->order('a.id DESC')
  815. ->decode(false)
  816. ->page(1, $num, $start)
  817. ->select();
  818. } else {
  819. return parent::table('ay_message a')->field($field)
  820. ->join($join)
  821. ->where("a.status=1")
  822. ->where($where)
  823. ->order('a.id DESC')
  824. ->decode(false)
  825. ->limit($start - 1, $num)
  826. ->select();
  827. }
  828. }
  829. // 新增留言
  830. public function addMessage($data)
  831. {
  832. return parent::table('ay_message')->autoTime()->insert($data);
  833. }
  834. // 获取表单字段
  835. public function getFormField($fcode)
  836. {
  837. $field = array(
  838. 'a.table_name',
  839. 'a.form_name',
  840. 'b.name',
  841. 'b.required',
  842. 'b.description'
  843. );
  844. $join = array(
  845. 'ay_form_field b',
  846. 'a.fcode=b.fcode',
  847. 'LEFT'
  848. );
  849. return parent::table('ay_form a')->field($field)
  850. ->where("a.fcode='$fcode'")
  851. ->join($join)
  852. ->order('b.sorting ASC,b.id ASC')
  853. ->select();
  854. }
  855. // 获取表单表名称
  856. public function getFormTable($fcode)
  857. {
  858. return parent::table('ay_form')->where("fcode='$fcode'")->value('table_name');
  859. }
  860. // 获取表单数据
  861. public function getForm($table, $num, $page = true, $start = 1)
  862. {
  863. if ($page) {
  864. return parent::table($table)->order('id DESC')
  865. ->decode(false)
  866. ->page(1, $num, $start)
  867. ->select();
  868. } else {
  869. return parent::table($table)->order('id DESC')
  870. ->decode(false)
  871. ->limit($start - 1, $num)
  872. ->select();
  873. }
  874. }
  875. // 新增表单数据
  876. public function addForm($table, $data)
  877. {
  878. return parent::table($table)->insert($data);
  879. }
  880. // 文章内链
  881. public function getTags()
  882. {
  883. return parent::table('ay_tags')->field('name,link')
  884. ->where("acode='" . get_lg() . "'")
  885. ->order('length(name) desc')
  886. ->select();
  887. }
  888. // 新增评论
  889. public function addComment($data)
  890. {
  891. return parent::table('ay_member_comment')->insert($data);
  892. }
  893. // 文章评论
  894. public function getComment($contentid, $pid, $num, $order, $page = false, $start = 1)
  895. {
  896. $field = array(
  897. 'a.*',
  898. 'b.username',
  899. 'b.nickname',
  900. 'b.headpic',
  901. 'c.username as pusername',
  902. 'c.nickname as pnickname',
  903. 'c.headpic as pheadpic'
  904. );
  905. $join = array(
  906. array(
  907. 'ay_member b',
  908. 'a.uid=b.id',
  909. 'LEFT'
  910. ),
  911. array(
  912. 'ay_member c',
  913. 'a.puid=c.id',
  914. 'LEFT'
  915. )
  916. );
  917. if ($page) {
  918. return parent::table('ay_member_comment a')->field($field)
  919. ->join($join)
  920. ->where("a.contentid='$contentid'")
  921. ->where('a.pid=' . $pid)
  922. ->where("a.status=1")
  923. ->order($order)
  924. ->page(1, $num, $start)
  925. ->select();
  926. } else {
  927. return parent::table('ay_member_comment a')->field($field)
  928. ->join($join)
  929. ->where("a.contentid='$contentid'")
  930. ->where('a.pid=' . $pid)
  931. ->where("a.status=1")
  932. ->order($order)
  933. ->limit($start - 1, $num)
  934. ->select();
  935. }
  936. }
  937. // 我的评论
  938. public function getMyComment($num, $order, $page = false, $start = 1)
  939. {
  940. $field = array(
  941. 'a.*',
  942. 'b.username',
  943. 'b.nickname',
  944. 'b.headpic',
  945. 'c.username as pusername',
  946. 'c.nickname as pnickname',
  947. 'c.headpic as pheadpic',
  948. 'd.title'
  949. );
  950. $join = array(
  951. array(
  952. 'ay_member b',
  953. 'a.uid=b.id',
  954. 'LEFT'
  955. ),
  956. array(
  957. 'ay_member c',
  958. 'a.puid=c.id',
  959. 'LEFT'
  960. ),
  961. array(
  962. 'ay_content d',
  963. 'a.contentid=d.id',
  964. 'LEFT'
  965. )
  966. );
  967. if ($page) {
  968. return parent::table('ay_member_comment a')->field($field)
  969. ->join($join)
  970. ->where("uid='" . session('pboot_uid') . "'")
  971. ->order($order)
  972. ->page(1, $num, $start)
  973. ->select();
  974. } else {
  975. return parent::table('ay_member_comment a')->field($field)
  976. ->join($join)
  977. ->where("uid='" . session('pboot_uid') . "'")
  978. ->order($order)
  979. ->limit($start - 1, $num)
  980. ->select();
  981. }
  982. }
  983. // 删除评论
  984. public function delComment($id)
  985. {
  986. return parent::table('ay_member_comment')->where("uid='" . session('pboot_uid') . "'")
  987. ->where("id=$id")
  988. ->delete();
  989. }
  990. }