diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index cb3e3992..e87b153c 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -47,6 +47,26 @@ class ResourceSharing extends BaseApiService return success($res); } + //资源共享-详情 + public function info(Request $request) + { + $resource_sharing_id = $request->param('resource_sharing_id','');//资源共享表id + + if(!$resource_sharing_id){ + return fail('缺少参数'); + } + + $where = [ + 'id' => $resource_sharing_id + ]; + + $res = (new ResourceSharingService())->info($where); + if (!$res['code']) { + return fail($res['msg']); + } + return success($res['data']); + } + //把资源分配给指定员工 public function assign(Request $request) { diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 624df44a..a8cec341 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -209,6 +209,8 @@ Route::group(function () { //资源共享-列表 Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); + //资源共享-详情(客户详情) + Route::get('resourceSharing/info', 'apiController.ResourceSharing/info'); //资源共享-分配员工 Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign'); diff --git a/niucloud/app/model/customer_resources/CustomerResources.php b/niucloud/app/model/customer_resources/CustomerResources.php index 7e90527f..b3c0aae6 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -13,6 +13,7 @@ namespace app\model\customer_resources; use app\model\dict\Dict; use app\model\resource_sharing\ResourceSharing; +use app\model\six_speed\SixSpeed; use core\base\BaseModel; use think\model\concern\SoftDelete; use think\model\relation\HasMany; @@ -85,6 +86,7 @@ class CustomerResources extends BaseModel + //获取顾问名字 public function personnel(){ return $this->hasOne(Personnel::class, 'id', 'consultant')->joinType('left')->withField('name,id')->bind(['consultant_name'=>'name']); } @@ -100,6 +102,12 @@ class CustomerResources extends BaseModel } + //一对一关联six_speed模型 + public function sixSpeed() + { + return $this->hasOne(SixSpeed::class, 'resource_id', 'id'); + } + /** * 获取客户初步意向度类型名称 * @param $value @@ -108,13 +116,15 @@ class CustomerResources extends BaseModel */ public function getInitialIntentNameAttr($value, $data) { - if (isset($data['initial_intent']) && $data['initial_intent'] !== '') { - $dict = Dict::where('key','preliminarycustomerintention')->find(); + $key = 'preliminarycustomerintention'; + $val = (String)$data['initial_intent']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); $dictionary = $dict['dictionary'] ?? []; // 查找匹配的 name $res = ''; foreach ($dictionary as $item) { - if ($item['value'] === $data['initial_intent']) { + if ($item['value'] == $val) { $res = $item['name']; break; } @@ -125,4 +135,148 @@ class CustomerResources extends BaseModel } } + /** + * 获取来源渠道类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getSourceChannelNameAttr($value, $data) + { + $key = 'SourceChannel'; + $val = (String)$data['source_channel']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + $arr = [ + "name" => "线下", + "value" => "0", + "sort" => 0, + "memo" => "", + ]; + array_unshift($dictionary, $arr); + foreach ($dictionary as $item) { + if ($item['value'] == $val) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + + /** + * 获取来源类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getSourceNameAttr($value, $data) + { + $key = 'source'; + $val = (String)$data['source']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + foreach ($dictionary as $item) { + if ($item['value'] == $val) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + + /** + * 获取性别类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getGenderNameAttr($value, $data) + { + $key = 'zy_sex'; + $val = (String)$data['gender']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + foreach ($dictionary as $item) { + if ($item['value'] == $val) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + + /** + * 获取购买力类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getPurchasingPowerNameAttr($value, $data) + { + $key = 'customer_purchasing_power'; + $val = (String)$data['purchasing_power']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + foreach ($dictionary as $item) { + if ($item['value'] == $val) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + + /** + * 获取客户状态类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getStatusNameAttr($value, $data) + { + $key = 'kh_status'; + $val = (String)$data['status']; + if ((!empty($val) || isset($val)) && $val !== '') { + $dict = Dict::where('key',$key)->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + foreach ($dictionary as $item) { + if ($item['value'] == $val) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + + + } diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 87755e09..9eac3a88 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -12,6 +12,7 @@ namespace app\service\api\apiService; use app\model\campus_person_role\CampusPersonRole; +use app\model\order_table\OrderTable; use app\model\resource_sharing\ResourceSharing; use core\base\BaseApiService; @@ -93,11 +94,32 @@ class ResourceSharingService extends BaseApiService $model = $model->where('id', $where['id']); } - $data = $model->field($field)->find(); + $data = $model->with([ + 'customerResource'=>function($query){ + $query->with([ + 'sixSpeed'=>function($query_2){}, + '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 (!empty($data['customerResource'])) { + $data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id']) + ->where('order_status', 'paid') + ->count();//成交次数 + } if ($data) { $res['code'] = 1; $res['msg'] = '操作成功'; $res['data'] = $data->toArray(); + } else { $res['code'] = 0; $res['msg'] = '未找到数据';