123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace app\models\article;
- use app\models\user\EnterpriseUser as iseUser;
- use app\models\store\StoreProduct;
- use app\models\article\ArticleReply;
- use crmeb\services\SystemConfigService;
- use think\facade\Db;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- /**
- * TODO 文章Model
- * Class Article
- * @package app\models\article
- */
- class Article extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- 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) ?: [];
- }
- /**
- * TODO 获取一条新闻
- * @param int $id
- * @return array|null|\think\Model
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- 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 = $list->hidden(['hide', 'status', 'admin_id'])->toArray();
- $list["content"] = Db::name('articleContent')->where('nid', $id)->value('content');
- $list["content"] = htmlspecialchars_decode($list["content"]);
- return $list;
- } else return [];
- }
- /**
- * TODO 获取某个分类底下的文章
- * @param $cid
- * @param $page
- * @param $limit
- * @param string $field
- * @return mixed
- */
- public static function cidByArticleList($cid, $page, $limit, $field = 'id,title,image_input,visit,add_time,synopsis,url')
- {
- $model = new self();
- // if ($cid) $model->where("`cid` LIKE '$cid,%' OR `cid` LIKE '%,$cid,%' OR `cid` LIKE '%,$cid' OR `cid`=$cid ");
- 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();
- }
- /**
- * TODO 获取首页推文章
- * @param string $field
- * @return mixed]
- */
- public static function getArticleListHot($field = 'id,title,image_input,visit,add_time,synopsis,url,mer_id,is_hot,is_top',$type)
- {
- $model = new self();
- $model = $model->field($field);
- $model = $model->where('status', 1);
- $model = $model->where('is_check', 1);
- $model = $model->where('hide', 0);
- if(isset($type['type'])&&$type['type']>0){
- $model = $model->where('cid',$type['type']);
- }elseif (isset($type['type'])&&$type['type']==0) {
- $model = $model->where('is_top',1);
- }else{
- $model = $model->where('is_hot', 1);
-
- }
- $model =$model->page($type['page'],$type['rows']);
- $model = $model->order('sort DESC,add_time DESC');
- $data=[];
- foreach($model->select() as $k=>$v){
- $mser=iseUser::where('id',$v['mer_id'])->find();
- $plays = new ArticleReply();
- $play=$plays->counts($v['id']);
- $data[]=[
- 'id'=>$v['id'],
- 'title'=>$v['title'],
- 'is_hot'=>$v['is_hot'],
- 'image_input'=>$v['image_input'],
- 'comment'=>$play,
- 'add_time'=>$v['add_time'],
- 'mername'=>$mser['name'],
- 'is_top'=>$v['is_top'],
- ];
-
- }
- $count=count($data);
- $list=['count'=>$count,'list'=>$data];
- return $list;
- }
- /**
- * TODO 获取轮播文章
- * @param string $field
- * @return mixed
- */
- 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();
- }
- public function search($data){
- $model = new self();
- $res=$model->alias('a')
- ->join(['eb_enterprise_user'=>'e'],'a.mer_id=e.id')
- ->where('status',1)
- ->where('is_check',1)
- ->where('synopsis|title','like','%'.$data['search'].'%')
- ->page($data['page'],$data['rows'])
- ->field('a.id,title,image_input,name,add_time')
- ->order('add_time', 'desc')
- ->select();
- $count=count($res);
- // 查询评论数
- $list=[];
- foreach($res as $v){
- $plays = new ArticleReply();
- $play=$plays->counts($v['id']);
- $list[]=[
- 'id'=>$v['id'],
- 'title'=>$v['title'],
- 'image_input'=>$v['image_input'],
- 'comment'=>$play,
- 'add_time'=>$v['add_time'],
- 'mername'=>$v['name']
- ];
- }
- return $lists=['count'=> $count, 'list'=>$list];
-
-
- }
- }
|