// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\AcceptorModel; 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 GoodsService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new GoodsModel(); } /** * 获取列表_de * @param $params 参数 * @param int $pageSize 分页大小:默认 15 * @return array */ public function getDataList($params, $pageSize = 10, $field = []) { $where = ['a.mark' => 1]; $query = $this->model->with(['category']) ->from('goods as a') ->where($where) ->select($field ? $field : ['a.*']); if (isset($params['goods_name']) && $params['goods_name'] != '') { $query->where('a.goods_name','like',"%{$params['goods_name']}%"); } if (isset($params['spu_name']) && $params['spu_name'] != '') { $query->where('a.spu_name','like',"%{$params['spu_name']}%"); } if (isset($params['spu_sn']) && $params['spu_sn'] != '') { $query->where('a.spu_sn','like',"%{$params['spu_sn']}%"); } if (isset($params['brand_name']) && $params['brand_name'] != '') { $query->where('a.brand_name','like',"%{$params['brand_name']}%"); } if (isset($params['supply_type'])) { if(is_array($params['supply_type'])){ $query->whereIn('a.supply_type',$params['supply_type']); }else{ if($params['supply_type'] != ''){ $query->where('a.supply_type',$params['supply_type']); } } } if (isset($params['is_recommend'])) { if(is_array($params['is_recommend'])){ $query->whereIn('a.is_recommend',$params['is_recommend']); }else{ if($params['is_recommend'] != ''){ $query->where('a.is_recommend',$params['is_recommend']); } } } 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']); } } } $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list ? $list->toArray() : []; if ($list) { foreach ($list['data'] as &$item) { $item['detail_img'] = !empty($item['detail_img']) ? json_decode($item['detail_img']) : ''; } } 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(isset($data['detail_img']) && is_array($data['detail_img'])){ $data['detail_img'] = json_encode($data['detail_img']); } return parent::edit($data); // TODO: Change the autogenerated stub } }