心理咨询网
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.

ParserModelgaosu.php 32KB

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