model = (new ResourceSharing()); } //获取列表 public function getList(array $where) { $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 $page = $page_params['page']; $limit = $page_params['limit']; $person_id = $this->member_id;//当前登录的员工id $campus_where = []; $campus_where[] = ['person_id','=',$person_id]; if (!empty($where['campus_name'])) { $campus_where[] = ['campus_name','like','%'.$where['campus_name'].'%']; } //查当前用户的归属校区 $campus_id = CampusPersonRole::where($campus_where) ->distinct(true) ->column('campus_id'); if ($campus_id) { //查当前用户校区下的全部员工id $person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id) ->distinct(true) ->column('person_id'); } $resource_id_arr = [];//客户资源表id //客户资源表名字 if (!empty($where['name'])) { $resource_id = (new CustomerResources())->where('name', 'like', "%{$where['name']}%")->column('id'); $resource_id_arr = array_merge($resource_id_arr, $resource_id); } //客户资源表手机号 if (!empty($where['phone_number'])) { $resource_id = (new CustomerResources())->where('phone_number', 'like', "%{$where['phone_number']}%")->column('id'); $resource_id_arr = array_merge($resource_id_arr, $resource_id); } //去重 $resource_id_arr = array_unique($resource_id_arr); $model = $this->model; if ($resource_id_arr) { $model = $model->whereIn('resource_id', $resource_id_arr); } if (!empty($where['shared_at_arr'])) { $model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]); } $model = $model->when(!empty($person_id_arr), function ($query) use ($person_id_arr) { $query->whereIn('user_id', $person_id_arr); }); if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') { $model = $model->whereOr('shared_by', $where['shared_by']); } //分页查询 $res = $model->with([ 'customerResource' => function ($query) { $query->append(['initial_intent_name']); } ]) ->withJoin(['customerResource']) ->order('customerResource.updated_at', 'desc') ->paginate([ 'list_rows' => $limit, 'page' => $page, ])->toArray(); foreach ($res['data'] as &$item){ $item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']); } return $res; } //查询资源共享详情 public function info(array $where, string $field = '*') { $res = [ 'code' => 0, 'msg' => '操作失败', 'data' => [] ]; if (!$where) { $res['msg'] = '缺少查询条件'; return $res; } $model = $this->model; if (!empty($where['id'])) { $model = $model->where('id', $where['id']); } $data = $model->with([ 'customerResource' => function ($query) { $query->with([ 'sixSpeed' => function ($query_2) { $query_2->append([ 'purchase_power_name',//购买力 'concept_awareness_name',//认知理念 ]); }, 'personnel' => function ($query_2) { } ])->append([ 'source_channel_name',//来源渠道 'source_name',//来源 'gender_name',//性别 'purchasing_power_name',//购买力 'cognitive_idea_name',//认知理念 'initial_intent_name',//客户初步意向度 'status_name',//客户状态 ]); } ])->field($field)->find(); if ($data) { $data = $data->toArray(); } if (!empty($data['customerResource'])) { $data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id']) ->where('order_status', 'paid') ->count();//成交次数 } // dd(123123,$data); if ($data) { $res['code'] = 1; $res['msg'] = '操作成功'; $res['data'] = $data; } else { $res['code'] = 0; $res['msg'] = '未找到数据'; $res['data'] = []; } return $res; } //更新资源共享表 public function editData(array $where, array $data) { $res = [ 'code' => 0, 'msg' => '操作失败', 'data' => [] ]; if (!$where) { $res['msg'] = '查询条件不能为空'; return $res; } $model = $this->model; if ($where['id']) { $model = $model->where('id', $where['id']); } $data = $model->update($data); if ($data) { $res = [ 'code' => 1, 'msg' => '操作成功', 'data' => [] ]; } return $res; } }