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

CmsModel.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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\api\model;
  10. use core\basic\Model;
  11. class CmsModel extends Model
  12. {
  13. // 存储分类及子编码
  14. protected $scodes = array();
  15. // 存储分类查询数据
  16. protected $sorts;
  17. // 存储栏目位置
  18. protected $position = array();
  19. // 单个站点配置信息
  20. public function getSite($acode, $name)
  21. {
  22. return parent::table('ay_site')->where("acode='" . $acode . "'")->value($name);
  23. }
  24. // 站点配置信息
  25. public function getSiteAll($acode)
  26. {
  27. return parent::table('ay_site')->where("acode='" . $acode . "'")->find();
  28. }
  29. // 单个公司信息
  30. public function getCompany($acode, $name)
  31. {
  32. return parent::table('ay_company')->where("acode='" . $acode . "'")->value($name);
  33. }
  34. // 公司信息
  35. public function getCompanyAll($acode)
  36. {
  37. return parent::table('ay_company')->where("acode='" . $acode . "'")->find();
  38. }
  39. // 自定义标签
  40. public function getLabel($name)
  41. {
  42. return parent::table('ay_label')->where("name='$name'")
  43. ->decode()
  44. ->value('value');
  45. }
  46. // 所有自定义标签
  47. public function getLabelAll()
  48. {
  49. return parent::table('ay_label')->decode()->column('value', 'name');
  50. }
  51. // 分类信息
  52. public function getSort($acode, $scode)
  53. {
  54. $field = array(
  55. 'a.*',
  56. 'b.type'
  57. );
  58. $join = array(
  59. 'ay_model b',
  60. 'a.mcode=b.mcode',
  61. 'LEFT'
  62. );
  63. return parent::table('ay_content_sort a')->field($field)
  64. ->where("a.acode='" . $acode . "'")
  65. ->where("a.scode='$scode'")
  66. ->join($join)
  67. ->find();
  68. }
  69. // 分类栏目列表
  70. public function getSorts($acode)
  71. {
  72. $fields = array(
  73. 'a.*',
  74. 'b.type'
  75. );
  76. $join = array(
  77. 'ay_model b',
  78. 'a.mcode=b.mcode',
  79. 'LEFT'
  80. );
  81. $result = parent::table('ay_content_sort a')->field($fields)
  82. ->where("a.acode='" . $acode . "'")
  83. ->where('a.status=1')
  84. ->join($join)
  85. ->order('a.pcode,a.sorting,a.id')
  86. ->select();
  87. return get_tree($result, 0, 'scode', 'pcode');
  88. }
  89. // 获取分类的子类
  90. public function getSortsSon($acode, $scode)
  91. {
  92. $fields = array(
  93. 'a.*',
  94. 'b.type'
  95. );
  96. $join = array(
  97. 'ay_model b',
  98. 'a.mcode=b.mcode',
  99. 'LEFT'
  100. );
  101. $result = parent::table('ay_content_sort a')->field($fields)
  102. ->where("a.pcode='" . $scode . "'")
  103. ->where("a.acode='" . $acode . "'")
  104. ->where('a.status=1')
  105. ->join($join)
  106. ->order('a.sorting,a.id')
  107. ->select();
  108. return $result;
  109. }
  110. // 分类顶级编码
  111. public function getSortTopScode($acode, $scode)
  112. {
  113. if (! isset($this->sorts)) {
  114. $fields = array(
  115. 'a.id',
  116. 'a.pcode',
  117. 'a.scode',
  118. 'a.name',
  119. 'b.type'
  120. );
  121. $join = array(
  122. 'ay_model b',
  123. 'a.mcode=b.mcode',
  124. 'LEFT'
  125. );
  126. $this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . $acode . "'")
  127. ->join($join)
  128. ->column($fields, 'scode');
  129. }
  130. $result = $this->sorts;
  131. return $this->getTopParent($scode, $result);
  132. }
  133. // 获取位置
  134. public function getPosition($acode, $scode)
  135. {
  136. if (! isset($this->sorts)) {
  137. $fields = array(
  138. 'a.id',
  139. 'a.pcode',
  140. 'a.scode',
  141. 'a.name',
  142. 'a.outlink',
  143. 'b.type'
  144. );
  145. $join = array(
  146. 'ay_model b',
  147. 'a.mcode=b.mcode',
  148. 'LEFT'
  149. );
  150. $this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . $acode . "'")
  151. ->join($join)
  152. ->column($fields, 'scode');
  153. }
  154. $result = $this->sorts;
  155. $this->position = array();
  156. $this->getTopParent($scode, $result);
  157. return array_reverse($this->position);
  158. }
  159. // 分类顶级编码及栏目树
  160. private function getTopParent($scode, $sorts)
  161. {
  162. if (! $scode || ! $sorts) {
  163. return;
  164. }
  165. $this->position[] = $sorts[$scode];
  166. if ($sorts[$scode]['pcode']) {
  167. return $this->getTopParent($sorts[$scode]['pcode'], $sorts);
  168. } else {
  169. return $sorts[$scode]['scode'];
  170. }
  171. }
  172. // 分类子类集
  173. private function getSubScodes($scode)
  174. {
  175. if (! $scode) {
  176. return;
  177. }
  178. $this->scodes[] = $scode;
  179. $subs = parent::table('ay_content_sort')->where("pcode='$scode'")->column('scode');
  180. if ($subs) {
  181. foreach ($subs as $value) {
  182. $this->getSubScodes($value);
  183. }
  184. }
  185. return $this->scodes;
  186. }
  187. // 列表内容,带分页
  188. public function getLists($acode, $scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true)
  189. {
  190. $fields = array(
  191. 'a.*',
  192. 'b.name as sortname',
  193. 'b.filename as sortfilename',
  194. 'c.name as subsortname',
  195. 'd.type',
  196. 'd.name as modelname',
  197. 'd.urlname',
  198. 'e.*'
  199. );
  200. $join = array(
  201. array(
  202. 'ay_content_sort b',
  203. 'a.scode=b.scode',
  204. 'LEFT'
  205. ),
  206. array(
  207. 'ay_content_sort c',
  208. 'a.subscode=c.scode',
  209. 'LEFT'
  210. ),
  211. array(
  212. 'ay_model d',
  213. 'b.mcode=d.mcode',
  214. 'LEFT'
  215. ),
  216. array(
  217. 'ay_content_ext e',
  218. 'a.id=e.contentid',
  219. 'LEFT'
  220. )
  221. );
  222. $scode_arr = array();
  223. if ($scode) {
  224. // 获取所有子类分类编码
  225. $this->scodes = array(); // 先清空
  226. $arr = explode(',', $scode); // 传递有多个分类时进行遍历
  227. foreach ($arr as $value) {
  228. $scodes = $this->getSubScodes(trim($value));
  229. }
  230. // 拼接条件
  231. $scode_arr = array(
  232. "a.scode in (" . implode_quot(',', $scodes) . ")",
  233. "a.subscode='$scode'"
  234. );
  235. }
  236. $where = array(
  237. "a.acode='" . $acode . "'",
  238. 'a.status=1',
  239. 'd.type=2',
  240. "a.date<'" . date('Y-m-d H:i:s') . "'"
  241. );
  242. // 筛选条件支持模糊匹配
  243. return parent::table('ay_content a')->field($fields)
  244. ->where($scode_arr, 'OR')
  245. ->where($where)
  246. ->where($select, 'AND', 'AND', $fuzzy)
  247. ->where($filter, 'OR')
  248. ->where($tags, 'OR')
  249. ->join($join)
  250. ->order($order)
  251. ->page(1, $num)
  252. ->decode()
  253. ->select();
  254. }
  255. // 列表内容,不带分页
  256. public function getList($acode, $scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true)
  257. {
  258. $fields = array(
  259. 'a.*',
  260. 'b.name as sortname',
  261. 'b.filename as sortfilename',
  262. 'c.name as subsortname',
  263. 'd.type',
  264. 'd.name as modelname',
  265. 'd.urlname',
  266. 'e.*'
  267. );
  268. $join = array(
  269. array(
  270. 'ay_content_sort b',
  271. 'a.scode=b.scode',
  272. 'LEFT'
  273. ),
  274. array(
  275. 'ay_content_sort c',
  276. 'a.subscode=c.scode',
  277. 'LEFT'
  278. ),
  279. array(
  280. 'ay_model d',
  281. 'b.mcode=d.mcode',
  282. 'LEFT'
  283. ),
  284. array(
  285. 'ay_content_ext e',
  286. 'a.id=e.contentid',
  287. 'LEFT'
  288. )
  289. );
  290. $scode_arr = array();
  291. if ($scode) {
  292. // 获取所有子类分类编码
  293. $this->scodes = array(); // 先清空
  294. $arr = explode(',', $scode); // 传递有多个分类时进行遍历
  295. foreach ($arr as $value) {
  296. $scodes = $this->getSubScodes(trim($value));
  297. }
  298. // 拼接条件
  299. $scode_arr = array(
  300. "a.scode in (" . implode_quot(',', $scodes) . ")",
  301. "a.subscode='$scode'"
  302. );
  303. }
  304. $where = array(
  305. "a.acode='" . $acode . "'",
  306. 'a.status=1',
  307. 'd.type=2',
  308. "a.date<'" . date('Y-m-d H:i:s') . "'"
  309. );
  310. // 筛选条件支持模糊匹配
  311. return parent::table('ay_content a')->field($fields)
  312. ->where($scode_arr, 'OR')
  313. ->where($where)
  314. ->where($select, 'AND', 'AND', $fuzzy)
  315. ->where($filter, 'OR')
  316. ->where($tags, 'OR')
  317. ->join($join)
  318. ->order($order)
  319. ->limit($num)
  320. ->decode()
  321. ->select();
  322. }
  323. // 内容详情
  324. public function getContent($acode, $id)
  325. {
  326. $field = array(
  327. 'a.*',
  328. 'b.name as sortname',
  329. 'b.filename as sortfilename',
  330. 'c.name as subsortname',
  331. 'd.type',
  332. 'd.name as modelname',
  333. 'd.urlname',
  334. 'e.*'
  335. );
  336. $join = array(
  337. array(
  338. 'ay_content_sort b',
  339. 'a.scode=b.scode',
  340. 'LEFT'
  341. ),
  342. array(
  343. 'ay_content_sort c',
  344. 'a.subscode=c.scode',
  345. 'LEFT'
  346. ),
  347. array(
  348. 'ay_model d',
  349. 'b.mcode=d.mcode',
  350. 'LEFT'
  351. ),
  352. array(
  353. 'ay_content_ext e',
  354. 'a.id=e.contentid',
  355. 'LEFT'
  356. )
  357. );
  358. $result = parent::table('ay_content a')->field($field)
  359. ->where("a.id='$id'")
  360. ->where("a.acode='" . $acode . "'")
  361. ->where('a.status=1')
  362. ->join($join)
  363. ->decode()
  364. ->find();
  365. if ($result) {
  366. $data2 = array(
  367. 'visits' => '+=1'
  368. );
  369. parent::table('ay_content')->where("id={$result->id}")->update($data2);
  370. }
  371. return $result;
  372. }
  373. // 单页详情
  374. public function getAbout($acode, $scode)
  375. {
  376. $field = array(
  377. 'a.*',
  378. 'b.name as sortname',
  379. 'b.filename as sortfilename',
  380. 'c.name as subsortname',
  381. 'd.type',
  382. 'd.name as modelname',
  383. 'd.urlname',
  384. 'e.*'
  385. );
  386. $join = array(
  387. array(
  388. 'ay_content_sort b',
  389. 'a.scode=b.scode',
  390. 'LEFT'
  391. ),
  392. array(
  393. 'ay_content_sort c',
  394. 'a.subscode=c.scode',
  395. 'LEFT'
  396. ),
  397. array(
  398. 'ay_model d',
  399. 'b.mcode=d.mcode',
  400. 'LEFT'
  401. ),
  402. array(
  403. 'ay_content_ext e',
  404. 'a.id=e.contentid',
  405. 'LEFT'
  406. )
  407. );
  408. $result = parent::table('ay_content a')->field($field)
  409. ->where("a.scode='$scode' OR b.filename='$scode'")
  410. ->where("a.acode='" . $acode . "'")
  411. ->where('a.status=1')
  412. ->join($join)
  413. ->order('id DESC')
  414. ->decode()
  415. ->find();
  416. if ($result) {
  417. $data2 = array(
  418. 'visits' => '+=1'
  419. );
  420. parent::table('ay_content')->where("id={$result->id}")->update($data2);
  421. }
  422. return $result;
  423. }
  424. // 指定内容多图
  425. public function getContentPics($acode, $id)
  426. {
  427. $result = parent::table('ay_content')->where("id='$id'")
  428. ->where("acode='" . $acode . "'")
  429. ->where('status=1')
  430. ->value('pics');
  431. return $result;
  432. }
  433. // 幻灯片
  434. public function getSlides($acode, $gid, $num)
  435. {
  436. $result = parent::table('ay_slide')->where("gid='$gid'")
  437. ->where("acode='" . $acode . "'")
  438. ->order('sorting asc,id asc')
  439. ->limit($num)
  440. ->select();
  441. return $result;
  442. }
  443. // 友情链接
  444. public function getLinks($acode, $gid, $num)
  445. {
  446. $result = parent::table('ay_link')->where("gid='$gid'")
  447. ->where("acode='" . $acode . "'")
  448. ->order('sorting asc,id asc')
  449. ->limit($num)
  450. ->select();
  451. return $result;
  452. }
  453. // 获取留言
  454. public function getMessage($acode, $num)
  455. {
  456. return parent::table('ay_message')->where("status=1")
  457. ->where("acode='" . $acode . "'")
  458. ->order('id DESC')
  459. ->decode(false)
  460. ->page(1, $num)
  461. ->select();
  462. }
  463. // 新增留言
  464. public function addMessage($table, $data)
  465. {
  466. return parent::table('ay_message')->autoTime()->insert($data);
  467. }
  468. // 获取表单字段
  469. public function getFormField($fcode)
  470. {
  471. $field = array(
  472. 'a.table_name',
  473. 'a.form_name',
  474. 'b.name',
  475. 'b.required',
  476. 'b.description'
  477. );
  478. $join = array(
  479. 'ay_form_field b',
  480. 'a.fcode=b.fcode',
  481. 'LEFT'
  482. );
  483. return parent::table('ay_form a')->field($field)
  484. ->where("a.fcode='$fcode'")
  485. ->join($join)
  486. ->order('b.sorting ASC,b.id ASC')
  487. ->select();
  488. }
  489. // 获取表单表名称
  490. public function getFormTable($fcode)
  491. {
  492. return parent::table('ay_form')->where("fcode='$fcode'")->value('table_name');
  493. }
  494. // 获取表单数据
  495. public function getForm($table, $num)
  496. {
  497. return parent::table($table)->order('id DESC')
  498. ->decode(false)
  499. ->page(1, $num)
  500. ->select();
  501. }
  502. // 新增表单数据
  503. public function addForm($table, $data)
  504. {
  505. return parent::table($table)->insert($data);
  506. }
  507. }