field(['id', 'name']) ->where([ ['del', '=', 0], ['is_show', '=', 1] ])->select()->toArray(); } catch (\Exception $e) { return ['error'=>$e->getMessage()]; } } /** * @Notes: 文章列表 * @Author: 张无忌 * @param $get * @return array */ public static function lists($get) { try { $where = [ ['a.del', '=', 0], ['a.is_show', '=', 1], ['c.del', '=', 0], ['c.is_show', '=', 1], ]; if(isset($get['cid']) && !empty($get['cid']) && $get['cid']>0 && !strstr($get['cid'],"city_")) { $where[] = ['cid', '=', $get['cid']]; } if(isset($get['cid']) && !empty($get['cid']) && strstr($get['cid'],"city_") ) { $where[] = ['a.city_id', '=', str_replace("city_","",$get['cid'])]; } $order = [ 'sort' => 'asc', 'id' => 'desc' ]; $model = new Resource(); $count = $model->alias('a')->join('resource_category c', 'c.id = a.cid')->where($where)->count(); $list = $model->alias('a') ->join('resource_category c', 'c.id = a.cid') ->field(['a.id', 'a.title', 'a.image', 'a.visit', 'a.likes','a.intro', 'a.content', 'a.create_time','a.price','a.type','a.province_id','a.city_id','a.district_id']) ->where($where) ->order($order) ->page($get['page_no'], $get['page_size']) ->select() ->toArray(); foreach ($list as &$item){ $item['price_str'] = $item['type']==0? "免费":($item['type']==1?"VIP会员免费":round($item['price'],2)); } $more = is_more($count, $get['page_no'], $get['page_size']); $data = [ 'list' => $list, 'page_no' => $get['page_no'], 'page_size' => $get['page_size'], 'count' => $count, 'more' => $more ]; return $data; } catch (\Exception $e) { return ['error'=>$e->getMessage()]; } } /** * @Notes: 文章详细 * @Author: 张无忌 * @param $id * @return array */ public static function detail($id) { $article = Resource::field('*')->where('id', $id)->findOrEmpty(); if($article->isEmpty()) { $article = []; }else{ $article->visit = $article->visit + 1; $article->save(); $article = $article->toArray(); } return $article; } }