Archives.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. namespace addons\cms\model;
  3. use addons\cms\library\Service;
  4. use app\common\library\Auth;
  5. use think\Cache;
  6. use think\Db;
  7. use think\Model;
  8. use traits\model\SoftDelete;
  9. /**
  10. * 文章模型
  11. */
  12. class Archives extends Model
  13. {
  14. protected $name = "cms_archives";
  15. // 开启自动写入时间戳字段
  16. protected $autoWriteTimestamp = 'int';
  17. // 定义时间戳字段名
  18. protected $createTime = 'createtime';
  19. protected $updateTime = 'updatetime';
  20. protected $deleteTime = 'deletetime';
  21. // 追加属性
  22. protected $append = [
  23. 'url',
  24. 'fullurl',
  25. 'likeratio',
  26. 'taglist',
  27. 'create_date',
  28. ];
  29. protected static $config = [];
  30. protected static $tagCount = 0;
  31. use SoftDelete;
  32. /**
  33. * 批量设置数据
  34. * @param $data
  35. * @return $this
  36. */
  37. public function setData($data)
  38. {
  39. if (is_object($data)) {
  40. $data = get_object_vars($data);
  41. }
  42. //替换付费内容标签
  43. if (isset($data['content'])) {
  44. $data['content'] = str_replace(['##paidbegin##', '##paidend##'], ['<paid>', '</paid>'], $data['content']);
  45. $data['content'] = str_replace(['$$paidbegin$$', '$$paidend$$'], ['<paid>', '</paid>'], $data['content']);
  46. }
  47. $this->data = array_merge($this->data, $data);
  48. $this->origin = $this->data;
  49. return $this;
  50. }
  51. protected static function init()
  52. {
  53. $config = get_addon_config('cms');
  54. self::$config = $config;
  55. }
  56. public function getCreateDateAttr($value, $data)
  57. {
  58. return human_date($data['createtime']);
  59. }
  60. public function getHasimageAttr($value, $data)
  61. {
  62. return $this->getData("image") ? true : false;
  63. }
  64. public function getIscommentAttr($value, $data)
  65. {
  66. //优先判断全局评论开关
  67. $iscomment = self::$config['iscomment'] ?? 1;
  68. if ($iscomment) {
  69. $iscomment = $value ? $value : self::$config['iscomment'];
  70. }
  71. return $iscomment;
  72. }
  73. public function getImageAttr($value, $data)
  74. {
  75. $value = $value ? $value : self::$config['default_archives_img'];
  76. return cdnurl($value, true);
  77. }
  78. public function getImagesAttr($value, $data)
  79. {
  80. if (!$data['images']) {
  81. return '';
  82. }
  83. $images = explode(',', $data['images']);
  84. foreach ($images as $index => &$image) {
  85. $image = cdnurl($image, true);
  86. }
  87. return implode(',', $images);
  88. }
  89. public function getImagesListAttr($value, $data)
  90. {
  91. $images = $this->getAttr("images");
  92. return $images ? array_filter(explode(',', $images)) : [];
  93. }
  94. /**
  95. * 获取格式化的内容
  96. */
  97. public function getContentAttr($value, $data)
  98. {
  99. //如果内容中包含有付费标签
  100. $value = $data['content'];
  101. $pattern = '/<paid>(.*?)<\/paid>/is';
  102. if (preg_match($pattern, $value) && !$this->getAttr('ispaid')) {
  103. $paytype = static::$config['defaultpaytype'];
  104. $payurl = addon_url('cms/order/submit', ['id' => $data['id'], 'paytype' => $paytype]);
  105. if (!isset($data['price']) || $data['price'] <= 0) {
  106. $value = preg_replace($pattern, "<div class='alert alert-warning alert-paid'><a href='javascript:' class=''>内容已经隐藏</a></div>", $value);
  107. } else {
  108. $value = preg_replace($pattern, "<div class='alert alert-warning alert-paid'><a href='{$payurl}' class='btn-paynow' data-price='{$data['price']}' data-paytype='{$paytype}'>内容已经隐藏,点击付费后查看</a></div>", $value);
  109. }
  110. }
  111. return $value;
  112. }
  113. /**
  114. * 获取金额
  115. */
  116. public function getPriceAttr($value, &$data)
  117. {
  118. if (isset($data['price'])) {
  119. return $data['price'];
  120. }
  121. $price = 0;
  122. if (isset($data['model_id'])) {
  123. $model = Modelx::get($data['model_id']);
  124. if ($model && in_array('price', $model['fields'])) {
  125. $price = Db::name($model['table'])->where('id', $data['id'])->value('price');
  126. }
  127. }
  128. $data['price'] = $price;
  129. return $price;
  130. }
  131. /**
  132. * 判断是否支付
  133. */
  134. public function getIspayAttr($value, &$data)
  135. {
  136. return $this->getAttr('ispaid');
  137. }
  138. /**
  139. * 判断是否支付
  140. */
  141. public function getIspaidAttr($value, &$data)
  142. {
  143. if (isset($data['ispaid'])) {
  144. return $data['ispaid'];
  145. }
  146. $channel = isset($this->channel) ? $this->channel : null;
  147. //只有当未设定VIP时才判断付费字段
  148. if ($channel && !$channel->vip) {
  149. //如果未定义price字段或price字段值为0
  150. if (!isset($data['price']) || $data['price'] == 0) {
  151. return true;
  152. }
  153. }
  154. $isvip = $channel && isset($channel['vip']) && $channel['vip'] && Auth::instance()->vip >= $channel->vip ? true : false;
  155. $data['ispaid'] = $isvip || \addons\cms\library\Order::check($data['id']);
  156. return $data['ispaid'];
  157. }
  158. /**
  159. * 判断是否是部分内容付费
  160. */
  161. public function getIsPaidPartOfContentAttr($value, $data)
  162. {
  163. if (isset($data['is_paid_part_of_content'])) {
  164. return $data['is_paid_part_of_content'];
  165. }
  166. $value = isset($this->origin['content']) ? $this->origin['content'] : '';
  167. $result = preg_match('/<paid>(.*?)<\/paid>/is', $value);
  168. $data['is_paid_part_of_content'] = $result;
  169. return $result;
  170. }
  171. /**
  172. * 获取下载地址列表
  173. */
  174. public function getDownloadurlListAttr($value, $data)
  175. {
  176. $titleArr = isset(self::$config['downloadtype']) ? self::$config['downloadtype'] : [];
  177. $downloadurl = (array)json_decode($data['downloadurl'], true);
  178. $downloadurl = array_filter($downloadurl);
  179. $list = [];
  180. foreach ($downloadurl as $index => $item) {
  181. if (!is_array($item)) {
  182. $urlArr = explode(' ', $item);
  183. $result['name'] = $index;
  184. $result['title'] = isset($titleArr[$index]) ? $titleArr[$index] : '其它';
  185. $result['url'] = cdnurl($urlArr[0], true);
  186. $result['password'] = isset($urlArr[1]) ? $urlArr[1] : '';
  187. $list[] = $result;
  188. } elseif (is_array($item) && isset($item['name']) && isset($item['url']) && $item['url']) {
  189. $item['url'] = cdnurl($item['url'], true);
  190. $result = $item;
  191. $result['title'] = isset($titleArr[$item['name']]) ? $titleArr[$item['name']] : '其它';
  192. $list[] = $result;
  193. }
  194. }
  195. return $list;
  196. }
  197. public function getTaglistAttr($value, &$data)
  198. {
  199. if (isset($data['taglist'])) {
  200. return $data['taglist'];
  201. }
  202. $tags = array_filter(explode(",", $data['tags']));
  203. $tagList = [];
  204. if (stripos(self::$config['rewrite']['tag/index'], ":id") !== false) {
  205. $tagList = Tag::where('name', 'in', $tags)->column('name,id');
  206. }
  207. $time = $data['createtime'] ?? time();
  208. $list = [];
  209. foreach ($tags as $k => $v) {
  210. $vars = [':name' => $v, ':diyname' => $v, ':id' => isset($tagList[$v]) ? $tagList[$v] : '0', ':year' => date("Y", $time), ':month' => date("m", $time), ':day' => date("d", $time)];
  211. $list[] = ['name' => $v, 'url' => addon_url('cms/tag/index', $vars)];
  212. }
  213. $data['taglist'] = $list;
  214. return $list;
  215. }
  216. public function getUrlAttr($value, $data)
  217. {
  218. return $this->buildUrl($value, $data);
  219. }
  220. public function getFullurlAttr($value, $data)
  221. {
  222. return $this->buildUrl($value, $data, true);
  223. }
  224. private function buildUrl($value, $data, $domain = false)
  225. {
  226. $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id'];
  227. $catename = isset($this->channel) && $this->channel ? $this->channel->diyname : 'all';
  228. $cateid = isset($this->channel) && $this->channel ? $this->channel->id : 0;
  229. $time = $data['publishtime'] ?? time();
  230. $vars = [
  231. ':id' => $data['id'],
  232. ':diyname' => $diyname,
  233. ':channel' => $data['channel_id'],
  234. ':catename' => $catename,
  235. ':cateid' => $cateid,
  236. ':year' => date("Y", $time),
  237. ':month' => date("m", $time),
  238. ':day' => date("d", $time),
  239. ];
  240. $suffix = static::$config['moduleurlsuffix']['archives'] ?? static::$config['urlsuffix'];
  241. return addon_url('cms/archives/index', $vars, $suffix, $domain);
  242. }
  243. public function getLikeratioAttr($value, $data)
  244. {
  245. return ($data['dislikes'] > 0 ? min(1, $data['likes'] / ($data['dislikes'] + $data['likes'])) : ($data['likes'] ? 1 : 0.5)) * 100;
  246. }
  247. public function getStyleTextAttr($value, $data)
  248. {
  249. $color = $this->getAttr("style_color");
  250. $color = $color ? $color : "inherit";
  251. $color = str_replace(['#', ' '], '', $color);
  252. $bold = $this->getAttr("style_bold") ? "bold" : "normal";
  253. $attr = ["font-weight:{$bold};"];
  254. if (stripos($color, ',') !== false) {
  255. list($first, $second) = explode(',', $color);
  256. $attr[] = "background-image: -webkit-linear-gradient(0deg, #{$first} 0%, #{$second} 100%);background-image: linear-gradient(90deg, #{$first} 0%, #{$second} 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;";
  257. } else {
  258. $attr[] = "color:#{$color};";
  259. }
  260. return implode('', $attr);
  261. }
  262. public function getStyleBoldAttr($value, $data)
  263. {
  264. return in_array('b', explode('|', $data['style']));
  265. }
  266. public function getStyleColorAttr($value, $data)
  267. {
  268. $styleArr = explode('|', $data['style']);
  269. foreach ($styleArr as $index => $item) {
  270. if (preg_match('/\,|#/', $item)) {
  271. return $item;
  272. }
  273. }
  274. return '';
  275. }
  276. /**
  277. * 获取内容页分页HTML
  278. */
  279. public function getPagerHTML($page, $total, $simple = false)
  280. {
  281. if ($total <= 1) {
  282. return '';
  283. }
  284. $result = \addons\cms\library\Bootstrap::make([], 1, $page, $total, $simple, ['path' => $this->url, 'simple' => $simple]);
  285. return "<div class='pager'>" . $result->render() . "</div>";
  286. }
  287. /**
  288. * 获取文档列表
  289. * @param $tag
  290. * @return array|false|\PDOStatement|string|\think\Collection
  291. */
  292. public static function getArchivesList($tag)
  293. {
  294. $config = get_addon_config('cms');
  295. $type = empty($tag['type']) ? '' : $tag['type'];
  296. $model = !isset($tag['model']) ? '' : $tag['model'];
  297. $channel = !isset($tag['channel']) ? '' : $tag['channel'];
  298. $special = !isset($tag['special']) ? '' : $tag['special'];
  299. $tags = empty($tag['tags']) ? '' : $tag['tags'];
  300. $condition = empty($tag['condition']) ? '' : $tag['condition'];
  301. $field = empty($tag['field']) ? '*' : $tag['field'];
  302. $flag = empty($tag['flag']) ? '' : $tag['flag'];
  303. $row = empty($tag['row']) ? 10 : (int)$tag['row'];
  304. $orderby = empty($tag['orderby']) ? 'createtime' : $tag['orderby'];
  305. $orderway = empty($tag['orderway']) ? 'desc' : strtolower($tag['orderway']);
  306. $limit = empty($tag['limit']) ? $row : $tag['limit'];
  307. $cache = !isset($tag['cache']) ? $config['cachelifetime'] === 'true' ? true : (int)$config['cachelifetime'] : (int)$tag['cache'];
  308. $imgwidth = empty($tag['imgwidth']) ? '' : $tag['imgwidth'];
  309. $imgheight = empty($tag['imgheight']) ? '' : $tag['imgheight'];
  310. $addon = empty($tag['addon']) ? false : $tag['addon'];
  311. $orderway = in_array($orderway, ['asc', 'desc']) ? $orderway : 'desc';
  312. $paginate = !isset($tag['paginate']) ? false : $tag['paginate'];
  313. $with = !isset($tag['with']) ? 'channel' : $tag['with'];
  314. $cache = !$cache ? false : $cache;
  315. $where = ['status' => 'normal'];
  316. $where['deletetime'] = ['exp', Db::raw('IS NULL')]; //by erastudio
  317. if ($model !== '') {
  318. $where['model_id'] = ['in', $model];
  319. }
  320. self::$tagCount++;
  321. $archivesModel = self::with($with)->alias('a');
  322. if ($channel !== '') {
  323. if ($type === 'son') {
  324. $subQuery = Channel::where('parent_id', 'in', $channel)->field('id')->buildSql();
  325. //子级
  326. $where['channel_id'] = ['exp', Db::raw(' IN ' . '(' . $subQuery . ')')];
  327. } elseif ($type === 'sons') {
  328. //所有子级
  329. $where['channel_id'] = ['in', Channel::getChannelChildrenIds($channel)];
  330. } else {
  331. $where['channel_id'] = ['in', $channel];
  332. }
  333. }
  334. //如果有设置标志,则拆分标志信息并构造condition条件
  335. if ($flag !== '') {
  336. if (stripos($flag, '&') !== false) {
  337. $arr = [];
  338. foreach (explode('&', $flag) as $k => $v) {
  339. $arr[] = "FIND_IN_SET('{$v}', flag)";
  340. }
  341. if ($arr) {
  342. $condition .= "(" . implode(' AND ', $arr) . ")";
  343. }
  344. } else {
  345. $condition .= ($condition ? ' AND ' : '');
  346. $arr = [];
  347. foreach (explode(',', str_replace('|', ',', $flag)) as $k => $v) {
  348. $arr[] = "FIND_IN_SET('{$v}', flag)";
  349. }
  350. if ($arr) {
  351. $condition .= "(" . implode(' OR ', $arr) . ")";
  352. }
  353. }
  354. }
  355. if ($special) {
  356. $specialModel = Special::get($special, [], true);
  357. if ($specialModel && $specialModel['tag_ids']) {
  358. $archivesModel->where("a.id", "in", function ($query) use ($specialModel) {
  359. return $query->name("cms_taggable")->where("tag_id", "in", $specialModel['tag_ids'])->field("archives_id");
  360. });
  361. $cache = false;
  362. }
  363. }
  364. $order = $orderby == 'rand' ? Db::raw('rand()') : (preg_match("/\,|\s/", $orderby) ? $orderby : "{$orderby} {$orderway}");
  365. $order = $orderby == 'weigh' ? $order . ',id DESC' : $order;
  366. // 如果有筛选标签,则采用子查询
  367. if ($tags) {
  368. $tagIds = Tag::where('name', 'in', explode(',', $tags))->cache($cache)->limit($limit)->column("id");
  369. $archivesModel->where("a.id", "in", function ($query) use ($tagIds) {
  370. return $query->name("cms_taggable")->where("tag_id", "in", $tagIds)->field("archives_id");
  371. });
  372. $cache = false;
  373. }
  374. $modelInfo = null;
  375. $prefix = config('database.prefix');
  376. $archivesModel
  377. ->where($where)
  378. ->where($condition)
  379. ->field($field, false, $prefix . "cms_archives", "a")
  380. ->orderRaw($order);
  381. if ($addon && (is_numeric($model) || $channel)) {
  382. if ($channel) {
  383. //如果channel设置了多个值则只取第一个作为判断
  384. $channelArr = explode(',', $channel);
  385. $channelinfo = Channel::get($channelArr[0], [], true);
  386. $model = $channelinfo ? $channelinfo['model_id'] : $model;
  387. }
  388. // 查询相关联的模型信息
  389. $modelInfo = Modelx::get($model, [], true);
  390. if ($modelInfo) {
  391. $archivesModel->join($modelInfo['table'] . ' n', 'a.id=n.id', 'LEFT');
  392. if ($addon == 'true') {
  393. $archivesModel->field('id,content', true, $prefix . $modelInfo['table'], 'n');
  394. } else {
  395. $archivesModel->field($addon, false, $prefix . $modelInfo['table'], 'n');
  396. }
  397. }
  398. }
  399. if ($paginate) {
  400. $paginateArr = explode(',', $paginate);
  401. $listRows = is_numeric($paginate) ? $paginate : (is_numeric($paginateArr[0]) ? $paginateArr[0] : $row);
  402. $config = [];
  403. $config['var_page'] = isset($paginateArr[2]) ? $paginateArr[2] : 'apage' . self::$tagCount;
  404. $config['path'] = isset($paginateArr[3]) ? $paginateArr[3] : '';
  405. $config['fragment'] = isset($paginateArr[4]) ? $paginateArr[4] : '';
  406. $config['query'] = request()->get();
  407. $list = $archivesModel->paginate($listRows, (isset($paginateArr[1]) ? $paginateArr[1] : false), $config);
  408. } else {
  409. $list = $archivesModel->limit($limit)->cache($cache)->select();
  410. }
  411. if ($modelInfo) {
  412. $fieldsContentList = [];
  413. if ($modelInfo->fields) {
  414. $fieldsContentList = Fields::getFieldsContentList('model', $modelInfo->id);
  415. }
  416. foreach ($list as $index => &$item) {
  417. Service::appendTextAttr($fieldsContentList, $item);
  418. }
  419. }
  420. self::render($list, $imgwidth, $imgheight);
  421. return $list;
  422. }
  423. /**
  424. * 追加_text属性值
  425. * @param $fieldsContentList
  426. * @param $row
  427. */
  428. public static function appendTextAttr(&$fieldsContentList, &$row)
  429. {
  430. //附加列表字段
  431. array_walk($fieldsContentList, function ($content, $field) use (&$row) {
  432. if (isset($row[$field])) {
  433. if (isset($content[$row[$field]])) {
  434. $list = [$row[$field] => $content[$row[$field]]];
  435. } else {
  436. $keys = $values = explode(',', $row[$field]);
  437. foreach ($values as $index => &$item) {
  438. $item = isset($content[$item]) ? $content[$item] : $item;
  439. }
  440. $list = array_combine($keys, $values);
  441. }
  442. } else {
  443. $list = [];
  444. }
  445. $list = array_filter($list);
  446. $row[$field . '_text'] = implode(',', $list);
  447. $row[$field . '_list'] = $list;
  448. });
  449. }
  450. /**
  451. * 渲染数据
  452. * @param array $list
  453. * @param int $imgwidth
  454. * @param int $imgheight
  455. * @return array
  456. */
  457. public static function render(&$list, $imgwidth, $imgheight)
  458. {
  459. $width = $imgwidth ? 'width="' . $imgwidth . '"' : '';
  460. $height = $imgheight ? 'height="' . $imgheight . '"' : '';
  461. foreach ($list as $k => &$v) {
  462. $v['textlink'] = '<a href="' . $v['url'] . '">' . $v['title'] . '</a>';
  463. $v['channellink'] = '<a href="' . $v['channel']['url'] . '">' . $v['channel']['name'] . '</a>';
  464. $v['imglink'] = '<a href="' . $v['url'] . '"><img src="' . $v['image'] . '" border="" ' . $width . ' ' . $height . ' /></a>';
  465. $v['img'] = '<img src="' . $v['image'] . '" border="" ' . $width . ' ' . $height . ' />';
  466. }
  467. return $list;
  468. }
  469. /**
  470. * 获取分页列表
  471. * @param array $list
  472. * @param array $tag
  473. * @return array
  474. */
  475. public static function getPageList($list, $tag)
  476. {
  477. $imgwidth = empty($tag['imgwidth']) ? '' : $tag['imgwidth'];
  478. $imgheight = empty($tag['imgheight']) ? '' : $tag['imgheight'];
  479. return self::render($list, $imgwidth, $imgheight);
  480. }
  481. /**
  482. * 获取分页过滤
  483. * @param array $list
  484. * @param array $tag
  485. * @return array
  486. */
  487. public static function getPageFilter($list, $tag)
  488. {
  489. $exclude = empty($tag['exclude']) ? '' : $tag['exclude'];
  490. return $list;
  491. }
  492. /**
  493. * 获取分页排序
  494. * @param array $list
  495. * @param array $tag
  496. * @return array
  497. */
  498. public static function getPageOrder($list, $tag)
  499. {
  500. $exclude = empty($tag['exclude']) ? '' : $tag['exclude'];
  501. return $list;
  502. }
  503. /**
  504. * 获取上一页下一页
  505. * @param string $type
  506. * @param string $archives
  507. * @param string $channel
  508. * @param array $tag
  509. * @return array
  510. */
  511. public static function getPrevNext($tag = [])
  512. {
  513. $type = isset($tag['type']) ? $tag['type'] : 'prev';
  514. $channel = isset($tag['channel']) ? $tag['channel'] : '';
  515. $archives = isset($tag['archives']) ? $tag['archives'] : '';
  516. $condition = isset($tag['condition']) ? $tag['condition'] : '';
  517. $model = self::where('id', $type === 'prev' ? '<' : '>', $archives)->where('status', 'normal');
  518. if ($channel !== '') {
  519. $model->where('channel_id', 'in', $channel);
  520. }
  521. if (isset($condition)) {
  522. $model->where($condition);
  523. }
  524. $model->order($type === 'prev' ? 'id desc' : 'id asc');
  525. $row = $model->find();
  526. return $row;
  527. }
  528. /**
  529. * 获取SQL查询结果
  530. */
  531. public static function getQueryList($tag)
  532. {
  533. $config = get_addon_config('cms');
  534. $sql = isset($tag['sql']) ? $tag['sql'] : '';
  535. $bind = isset($tag['bind']) ? explode(',', $tag['bind']) : [];
  536. $cache = !isset($tag['cache']) ? $config['cachelifetime'] === 'true' ? true : (int)$config['cachelifetime'] : (int)$tag['cache'];
  537. $cache = !$cache ? false : $cache;
  538. $name = md5("sql-" . $tag['sql']);
  539. $list = Cache::get($name);
  540. if (!$list) {
  541. $list = Db::query($sql, $bind);
  542. Cache::set($name, $list, $cache);
  543. }
  544. return $list;
  545. }
  546. /**
  547. * 关联模型
  548. */
  549. public function user()
  550. {
  551. return $this->belongsTo("\app\common\model\User", 'user_id', 'id', [], 'LEFT')->setEagerlyType(1);
  552. }
  553. /**
  554. * 关联模型
  555. */
  556. public function model()
  557. {
  558. return $this->belongsTo("Modelx", 'model_id')->setEagerlyType(1);
  559. }
  560. /**
  561. * 关联栏目模型
  562. */
  563. public function channel()
  564. {
  565. return $this->belongsTo("Channel", 'channel_id', 'id', [], 'LEFT')->setEagerlyType(1);
  566. }
  567. }