123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\models\article;
- use app\models\store\StoreProduct;
- use crmeb\services\SystemConfigService;
- use think\facade\Db;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- class Article extends BaseModel
- {
-
- protected $pk = 'id';
-
- protected $name = 'article';
- use ModelTrait;
- public function profile()
- {
- return $this->hasOne(StoreProduct::class, 'id', 'product_id')->field('store_name,image,price,id,ot_price');
- }
- protected function getImageInputAttr($value)
- {
- return explode(',', $value) ?: [];
- }
-
- public static function getArticleOne($id = 0)
- {
- if (!$id) return [];
- $list = self::where('status', 1)->where('hide', 0)->where('id', $id)->order('id desc')->find();
- if ($list) {
- $list->store_info = $list->profile ? $list->profile->toArray() : null;
- $list = $list->hidden(['hide', 'status', 'admin_id', 'mer_id'])->toArray();
- $list["content"] = Db::name('articleContent')->where('nid', $id)->value('content');
- $list["content"] = htmlspecialchars_decode($list["content"]);
- return $list;
- } else return [];
- }
-
- public static function cidByArticleList($cid, $page, $limit, $field = 'id,title,image_input,visit,add_time,synopsis,url')
- {
- $model = new self();
- if ((int)$cid) $model = $model->where("CONCAT(',',cid,',') LIKE '%,$cid,%'");
- $model = $model->field($field);
- $model = $model->where('status', 1);
- $model = $model->where('hide', 0);
- $model = $model->order('sort DESC,add_time DESC');
- if ($page) $model = $model->page($page, $limit);
- return $model->select();
- }
-
- public static function getArticleListHot($field = 'id,title,image_input,visit,add_time,synopsis,url')
- {
- $model = new self();
- $model = $model->field($field);
- $model = $model->where('status', 1);
- $model = $model->where('hide', 0);
- $model = $model->where('is_hot', 1);
- $model = $model->order('sort DESC,add_time DESC');
- return $model->select();
- }
-
- public static function getArticleListBanner($field = 'id,title,image_input,visit,add_time,synopsis,url')
- {
- $model = new self();
- $model = $model->field($field);
- $model = $model->where('status', 1);
- $model = $model->where('hide', 0);
- $model = $model->where('is_banner', 1);
- $model = $model->order('sort DESC,add_time DESC');
- $model = $model->limit(sys_config('news_slides_limit') ?? 3);
- return $model->select();
- }
- }
|