// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\AccountModel; use App\Models\ArticleModel; use App\Services\BaseService; /** * 文章管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class ArticleService * @package App\Services\Common */ class ArticleService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * ArticleService constructor. */ public function __construct() { $this->model = new ArticleModel(); } /** * 静态入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = (new static()); } return self::$instance; } /** * @param $params * @param int $pageSize * @return array */ public function getDataList($params, $pageSize = 15) { $where = ['a.mark' => 1]; $status = isset($params['status'])? $params['status'] : 0; $type = isset($params['type'])? $params['type'] : 0; $cateId = isset($params['cate_id'])? $params['cate_id'] : 0; if($status>0){ $where['a.status'] = $status; } if($type>0){ $where['a.type'] = $type; } if($cateId>0){ $where['a.cate_id'] = $cateId; } $list = $this->model->from('article as a') ->leftJoin('article_cate as b', 'b.id', '=', 'a.cate_id') ->where($where) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.title','like',"%{$keyword}%")->orWhere('b.name','like',"%{$keyword}%"); } }) ->select(['a.*','b.name as cate_name']) ->orderBy('a.create_time','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ foreach($list['data'] as &$item){ $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : ''; $item['cover'] = $item['cover']? get_image_url($item['cover']) : ''; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 添加或编辑 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { $data = request()->all(); return parent::edit($data); // TODO: Change the autogenerated stub } /** * 获取店铺交易统计 * @param $shopId * @param int $type * @param int $coinType * @return mixed */ public function getInfoByCate($cateId) { return $this->model->where(['cate_id'=> $cateId,'status'=>1,'mark'=>1]) ->orderBy('create_time','desc') ->first(); } }