心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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