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]; } }