// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\AcceptorModel; use App\Models\AccountLogModel; use App\Models\ArticleModel; use App\Models\GoodsCategoryModel; use App\Models\GoodsModel; use App\Models\TradeModel; use App\Services\BaseService; use Illuminate\Support\Facades\DB; /** * 承兑商管理-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Common */ class ArticleService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new ArticleModel(); } /** * 获取列表 * @param $params 参数 * @param int $pageSize 分页大小:默认 15 * @return array */ public function getDataList($params, $pageSize = 10, $field=[]) { $where = ['a.mark' => 1]; $query = $this->model->with(['articleCate']) ->from('article as a') ->leftJoin('article_cate as b','b.id','a.cate_id') ->where($where) ->select($field ? $field : ['a.*']); if (isset($params['cate_id']) && $params['cate_id'] != '') { $query->where(function($query) use($params){ if(!empty($params['cate_id']) && $params['cate_id']!=''){ $query->where('b.name','like',"%{$params['cate_id']}%") ->orWhere('b.id','like',"%{$params['cate_id']}%"); } }); } if (isset($params['title']) && $params['title'] != '') { $query->where('a.title','like',"%{$params['title']}%"); } if (isset($params['status'])) { if(is_array($params['status'])){ $query->whereIn('a.status',$params['status']); }else{ if($params['status'] != ''){ $query->where('a.status',$params['status']); } } } if (isset($params['type'])) { if(is_array($params['type'])){ $query->whereIn('a.type',$params['type']); }else{ if($params['type'] != ''){ $query->where('a.type',$params['type']); } } } $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list ? $list->toArray() : []; if ($list) { foreach ($list['data'] as &$item) { $item['cover'] = $item['cover'] ? get_image_url($item['cover']) : $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(); if(!empty($data['cover'])){ $data['cover'] = $data['cover'] ? remove_image_url($data['cover']) : $data['cover']; } return parent::edit($data); // TODO: Change the autogenerated stub } }