ParserModel.php 28 KB

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