// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\ComplaintModel; use App\Models\FreightPackageModel; use App\Models\TicketModel; use App\Services\BaseService; use App\Services\RedisService; /** * 意见反馈管理-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Common */ class ComplaintService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new ComplaintModel(); } /** * 静态入口 */ 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]; $list = $this->model->from('complaint as a') ->leftJoin('member as b','b.id','=','a.user_id') ->leftJoin('driver as c','c.id','=','a.user_id') ->where($where) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.title','like',"%{$keyword}%")->orWhere('a.content','like',"%{$keyword}%")->orWhere('a.mobile','like',"%{$keyword}%"); } }) ->where(function ($query) use($params){ $status = isset($params['status'])? $params['status'] : 0; if($status>0 && is_array($status)){ $query->whereIn('a.status', $status); }else if($status){ $query->where('a.status', $status); } $type = isset($params['type'])? $params['type'] : 0; if($type>0){ $query->where('a.type', $type); } $userType = isset($params['user_type'])? $params['user_type'] : 0; if($userType>0){ $query->where('a.user_type', $userType); } }) ->select(['a.*','b.nickname as username','c.realname as driver_name']) ->orderBy('a.create_time','desc') ->orderBy('a.id','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ $typeArr = [1=>'功能BUG',2=>'产品优化',3=>'客服功能',4=>'规则制度',5=>'费用相关',99=>'其他']; foreach($list['data'] as &$item){ $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : ''; $item['albums'] = $item['albums']? get_images_preview($item['albums']) : []; if($item['user_type'] == 2){ $item['username'] = $item['driver_name']? $item['driver_name'] : ''; } $item['type_name'] = isset($typeArr[$item['type']]) && $typeArr[$item['type']]? $typeArr[$item['type']] : '其他'; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 编辑 * @return array */ public function edit() { $data = request()->post(); if(isset($data['albums'])){ $data['albums'] = $data['albums']? get_format_images($data['albums']) : ''; } return parent::edit($data); } }