From fb2d2f4dd27d4e773862914a39f4c42becebf667 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Mon, 19 May 2025 17:42:54 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat(api):=20=E6=96=B0=E5=A2=9E=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E5=92=8C=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=85=B1=E4=BA=AB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增获取全部员工信息接口和功能 - 新增资源共享分配员工功能 - 优化资源共享列表查询,增加时间筛选条件 - 修复和完善人员信息获取接口返回结构 --- .../controller/apiController/Personnel.php | 124 +++--------------- .../apiController/ResourceSharing.php | 43 ++++++ niucloud/app/api/route/route.php | 5 +- .../customer_resources/CustomerResources.php | 26 ++++ .../api/apiService/PersonnelService.php | 72 ++++++++-- .../api/apiService/ResourceSharingService.php | 81 +++++++++++- 6 files changed, 229 insertions(+), 122 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index fc0ed492..b5f63cdf 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -36,10 +36,10 @@ class Personnel extends BaseApiService 'id'=>$this->member_id, ]; $res = (new PersonnelService())->info($where); - if(!$res){ - return fail('账户信息有误'); + if(!$res['code']){ + return fail($res['msg']); } - return success($res); + return success($res['data']); } //员工修改 @@ -66,114 +66,20 @@ class Personnel extends BaseApiService return success([]); } - /** - * 登录 - * @return Response - */ - public function login() - { - $data = $this->request->params([ - ['username', ''], - ['password', ''], - ]); - //校验登录注册配置 - (new ConfigService())->checkLoginConfig(MemberLoginTypeDict::USERNAME); - //参数验证 - //验证码验证 - $result = (new LoginService())->account($data['username'], $data['password']); - if (!$result) { - //账号密码错误, 重置验证码 - return fail('ACCOUNT_OR_PASSWORD_ERROR'); + //人力资源-人员表 + public function getPersonnelAll(Request $request){ + //获取员工信息 + $where = [ + 'account_type' => $request->param('account_type', ''),//账号类型|teacher=老师,market=销售 + 'personnel_id' => $request->param('personnel_id', ''),//员工id + ]; + $field = 'id,name'; + $res = (new PersonnelService())->getAll($where,$field); + if(!$res){ + return fail('账户信息有误'); } - return success($result); - } - - /** - * 登出 - * @return Response - */ - public function logout() - { - (new LoginService)->logout(); - return success('MEMBER_LOGOUT'); - } - - /** - * 创建验证码 - * @return Response - */ - public function captcha() - { - return success((new CaptchaService())->create()); - } - - /** - * 发送手机验证码 - * @param $type - * @return Response - * @throws Exception - */ - public function sendMobileCode($type) - { - $data = $this->request->params([ - ['mobile', ''], - ]); - return success((new LoginService())->sendMobileCode($data['mobile'], $type)); - } - - /** - * 手机号登录 - * @return Response - */ - public function mobile() - { - $data = $this->request->params([ - ['mobile', ''], - ['nickname', ''], - ['headimg', ''], - ['mobile', ''] - ]); - //校验登录注册配置 - (new ConfigService())->checkLoginConfig(MemberLoginTypeDict::MOBILE); - return success((new LoginService())->mobile($data)); - } - - /** - * 重置密码 - * @return Response - */ - public function resetPassword() - { - $data = $this->request->params([ - ['mobile', ''], - ['password', ''] - ]); - //参数验证 - $this->validate($data, 'app\validate\member\Member.reset_password'); - (new LoginService())->resetPassword($data['mobile'], $data['password']); - return success('PASSWORD_RESET_SUCCESS'); + return success($res); } - //销售教师人员登陆 - public function personnelLogin() - { - $data = $this->request->params([ - ['phone', ''], - ['password', ''], - ['login_type', ''],//登陆类型|1=教练,2=销售 - ]); - //验证码验证 - $result = (new LoginService())->loginByPersonnel($data); - if(!$result['user_type']){ - if($data['login_type'] == 1){ - $msg = '暂无教练权限'; - }else{ - $msg = '暂无销售权限'; - } - return fail($msg);//code|0错误 - } - - return success($result);//code|1正确 - } } diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index a46719c4..97aecf2f 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -31,12 +31,55 @@ class ResourceSharing extends BaseApiService $page = $request->param('page','1');// $limit = $request->param('limit','10');// $shared_by = $request->param('shared_by','');//共享人ID + $shared_at_arr = $request->param('shared_at_arr',[]);//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)] + $where = [ 'shared_by'=>$shared_by, + 'shared_at_arr'=>$shared_at_arr, ]; $res= (new ResourceSharingService())->getList($where); return success($res); } + //把资源分配给指定员工 + public function assign(Request $request) + { + $id = $request->param('resource_sharing_id', '');//资源共享表 + $shared_by = $request->param('shared_by', '');//共享人ID + + if (empty($id) || empty($shared_by)) { + return fail('缺少必要参数'); + } + + $where = [ + 'id' => $id, + ]; + + $data = [ + 'shared_by' => $shared_by + ]; + + $info = (new ResourceSharingService())->info($where);//获取详情 + + if (!$info['code']) { + return fail($info['msg']); + } else { + if ($info['data']['shared_by'] > 0) { + if ($info['data']['shared_by'] == $shared_by) { + return success('当前资源已分享给该用户'); + } else { + return fail('该资源已被分享给其他用户'); + } + } + } + + + $res = (new ResourceSharingService())->editData($where, $data);//更新 + if (!$res['code']) { + return fail('操作失败'); + } + return success('操作成功'); + } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index ae0c7af3..624df44a 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -202,12 +202,15 @@ Route::group(function () { Route::get('personnel/info', 'apiController.Personnel/info'); //员工端-修改 Route::post('personnel/edit', 'apiController.Personnel/edit'); - + //员工端-获取全部人员列表 + Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add'); //资源共享-列表 Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); + //资源共享-分配员工 + 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 64520bfd..7e90527f 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -11,6 +11,7 @@ namespace app\model\customer_resources; +use app\model\dict\Dict; use app\model\resource_sharing\ResourceSharing; use core\base\BaseModel; use think\model\concern\SoftDelete; @@ -99,4 +100,29 @@ class CustomerResources extends BaseModel } + /** + * 获取客户初步意向度类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getInitialIntentNameAttr($value, $data) + { + if (isset($data['initial_intent']) && $data['initial_intent'] !== '') { + $dict = Dict::where('key','preliminarycustomerintention')->find(); + $dictionary = $dict['dictionary'] ?? []; + // 查找匹配的 name + $res = ''; + foreach ($dictionary as $item) { + if ($item['value'] === $data['initial_intent']) { + $res = $item['name']; + break; + } + } + return $res; + } else { + return ''; + } + } + } diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index 1dbde67c..be3833b4 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -38,10 +38,20 @@ class PersonnelService extends BaseApiService //获取员工信息 public function info(array $where,string $field = '*'){ $model = $this->model; + + $res = [ + 'code'=>0, + 'msg'=>'请添加检索条件', + 'data'=>[] + ]; + if(!$where){ + return $res; + } + if(!empty($where['id'])){ $model = $model->where('id',$where['id']); } - $res = $model->field($field)->find();//员工信息 + $data = $model->field($field)->find();//员工信息 //查询部门信息 $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); @@ -63,16 +73,23 @@ class PersonnelService extends BaseApiService $department_name_str = implode(',',$department_name_arr); - if($res){ - $res = $res->toArray(); - $res['role']=$role; - $res['role_name_str'] = $role_name_str; - $res['role_key_arr'] = $role_key_arr; - $res['department_name_str'] = $department_name_str; + if($data){ + $data = $data->toArray(); + $data['role']=$role; + $data['role_name_str'] = $role_name_str; + $data['role_key_arr'] = $role_key_arr; + $data['department_name_str'] = $department_name_str; + $res['code'] = 1; + $res['msg'] = '操作成功'; + $res['data'] = $data; }else{ - $res = []; + $data = []; + $res['code'] = 0; + $res['msg'] = '为找到数据'; + $res['data'] = $data; } + return $res; } @@ -109,6 +126,45 @@ class PersonnelService extends BaseApiService } + //员工信息-获取全部用户 + public function getAll(array $where,string $field = '*') + { + if (!$where) { + return [ + 'code' => 0, + 'msg' => '查询条件不能为空' + ]; + } + + $model = $this->model; + + //存在员工id的时候 + if ((!empty($where['personnel_id']) || isset($where['personnel_id'])) && $where['personnel_id'] !== '') { + //查询这个员工的校区id + $campus_id = CampusPersonRole::where('person_id', $where['personnel_id']) + ->distinct(true) + ->column('campus_id'); + if ($campus_id) { + $person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id) + ->distinct(true) + ->column('person_id'); + if ($person_id_arr) { + //根据校区id获取校区下的全部员工 + $model = $model->whereIn('id', $person_id_arr); + } + } + } + + if (empty($where['account_type'])) { + $model = $model->where('account_type', $where['account_type']); + } + + $res = $model->field($field) + ->select() + ->toArray();//员工信息 + return $res; + } + diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index b9e63881..87755e09 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -38,20 +38,32 @@ class ResourceSharingService extends BaseApiService $person_id = $this->member_id;//当前登录的员工id //查当前用户的归属校区 - $campus_id = CampusPersonRole::where('person_id',$person_id)->value('campus_id'); + $campus_id = CampusPersonRole::where('person_id',$person_id) + ->distinct(true) + ->column('campus_id'); //查当前用户校区下的全部员工id - $person_id_arr = CampusPersonRole::where('campus_id',$campus_id) ->distinct(true) + $person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id) + ->distinct(true) ->column('person_id'); $model = $this->model; - if (!isset($where['shared_by']) && $where['shared_by'] !== '') { + + if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') { $model = $model->where('shared_by', $where['shared_by']); } + + 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->whereIn('user_id', $person_id_arr); //分页查询 $res = $model->with([ - 'customerResource'=>function($query){} + 'customerResource'=>function($query){ + $query->append(['initial_intent_name']); + } ])->paginate([ 'list_rows' => $limit, 'page' => $page, @@ -61,4 +73,65 @@ class ResourceSharingService extends BaseApiService } + //查询资源共享详情 + 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->field($field)->find(); + if ($data) { + $res['code'] = 1; + $res['msg'] = '操作成功'; + $res['data'] = $data->toArray(); + } 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; + } + } From 5970cfeda37125a38d91e6caf936c1d7dbd16554 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Mon, 19 May 2025 18:39:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor(ResourceSharing):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=B5=84=E6=BA=90=E5=88=86=E4=BA=AB=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E5=85=B1=E4=BA=AB=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 shared_at_arr 参数名改为 shared_at_str,以更准确地反映其为字符串类型 - 添加逻辑将 shared_at_str 解析为开始和结束时间,格式化为 YYYY-MM-DD HH:MM:SS - 优化了共享时间的处理,确保查询结果包含完整的开始和结束日期 --- .../app/api/controller/apiController/ResourceSharing.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index 97aecf2f..cb3e3992 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -31,8 +31,13 @@ class ResourceSharing extends BaseApiService $page = $request->param('page','1');// $limit = $request->param('limit','10');// $shared_by = $request->param('shared_by','');//共享人ID - $shared_at_arr = $request->param('shared_at_arr',[]);//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)] - + $shared_at_str = $request->param('shared_at_str','');//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)] + $shared_at_arr = []; + if(!empty($shared_at_str)){ + $shared_at_arr = explode(' ~ ',$shared_at_str); + $shared_at_arr[0] = "{$shared_at_arr[0]} 00:00:00"; + $shared_at_arr[1] = "{$shared_at_arr[1]} 23:59:59"; + } $where = [ 'shared_by'=>$shared_by, From 93e7e7769a34e7c41d8ed054b9ae20378086160c Mon Sep 17 00:00:00 2001 From: wangzeyan <258785420@qq.com> Date: Mon, 19 May 2025 19:21:44 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=8E=92=E8=AF=BE=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/app/lang/zh-cn/course.course.json | 4 +- .../views/course/components/course-edit.vue | 22 +- admin/src/app/views/course/course.vue | 13 +- admin/src/app/views/timetables/timetables.vue | 269 +++++++++++------- .../app/adminapi/controller/course/Course.php | 1 - niucloud/app/model/course/Course.php | 116 ++++++-- 6 files changed, 300 insertions(+), 125 deletions(-) diff --git a/admin/src/app/lang/zh-cn/course.course.json b/admin/src/app/lang/zh-cn/course.course.json index 87e24f74..ee23f55d 100644 --- a/admin/src/app/lang/zh-cn/course.course.json +++ b/admin/src/app/lang/zh-cn/course.course.json @@ -9,8 +9,8 @@ "durationPlaceholder": "请输入课程时长", "sessionCount": "课时数量", "sessionCountPlaceholder": "请输入课时数量", - "singleSessionCount": "单次逍客数量", - "singleSessionCountPlaceholder": "请输入单次逍客数量", + "singleSessionCount": "单次消课数量", + "singleSessionCountPlaceholder": "请输入单次消课数量", "price": "课程价格", "pricePlaceholder": "请输入课程价格", "internalReminder": "内部提醒课时", diff --git a/admin/src/app/views/course/components/course-edit.vue b/admin/src/app/views/course/components/course-edit.vue index b1d3d780..07e8534e 100644 --- a/admin/src/app/views/course/components/course-edit.vue +++ b/admin/src/app/views/course/components/course-edit.vue @@ -24,14 +24,19 @@ - + > + + - { const emit = defineEmits(['complete']) +const courseTypeList = ref([]) +const getcourseTypeList = async () => { + courseTypeList.value = await ( + await useDictionary('course_type') + ).data.dictionary +} +getcourseTypeList() /** * 确认 * @param formEl diff --git a/admin/src/app/views/course/course.vue b/admin/src/app/views/course/course.vue index 6ce6185c..aed2b754 100644 --- a/admin/src/app/views/course/course.vue +++ b/admin/src/app/views/course/course.vue @@ -24,10 +24,17 @@ /> - + > + + () // 选中数据 diff --git a/admin/src/app/views/timetables/timetables.vue b/admin/src/app/views/timetables/timetables.vue index 33d5d982..07c18c89 100644 --- a/admin/src/app/views/timetables/timetables.vue +++ b/admin/src/app/views/timetables/timetables.vue @@ -1,125 +1,198 @@ - diff --git a/niucloud/app/adminapi/controller/course/Course.php b/niucloud/app/adminapi/controller/course/Course.php index d8634497..6385816d 100644 --- a/niucloud/app/adminapi/controller/course/Course.php +++ b/niucloud/app/adminapi/controller/course/Course.php @@ -105,5 +105,4 @@ class Course extends BaseAdminController return success('DELETE_SUCCESS'); } - } diff --git a/niucloud/app/model/course/Course.php b/niucloud/app/model/course/Course.php index 0f5e48e3..ace8ac7d 100644 --- a/niucloud/app/model/course/Course.php +++ b/niucloud/app/model/course/Course.php @@ -9,7 +9,7 @@ // | Author: Niucloud Team // +---------------------------------------------------------------------- -namespace app\model\campus; +namespace app\model\course; use core\base\BaseModel; use think\model\concern\SoftDelete; @@ -17,11 +17,11 @@ use think\model\relation\HasMany; use think\model\relation\HasOne; /** - * 校区模型 - * Class Campus - * @package app\model\campus + * 课程模型 + * Class Course + * @package app\model\course */ -class Campus extends BaseModel +class Course extends BaseModel { use SoftDelete; @@ -36,13 +36,13 @@ class Campus extends BaseModel * 模型名称 * @var string */ - protected $name = 'campus'; + protected $name = 'course'; /** * 定义软删除标记字段. * @var string */ - protected $deleteTime = 'delete_time'; + protected $deleteTime = 'deleted_at'; /** * 定义软删除字段的默认值. @@ -51,38 +51,122 @@ class Campus extends BaseModel protected $defaultSoftDelete = 0; /** - * 搜索器:校区校区名称 + * 搜索器:课程课程编号 * @param $value * @param $data */ - public function searchCampusNameAttr($query, $value, $data) + public function searchIdAttr($query, $value, $data) { if ($value) { - $query->where("campus_name", "like", "%".$value."%"); + $query->where("id", $value); } } /** - * 搜索器:校区校区地址 + * 搜索器:课程课程名称 * @param $value * @param $data */ - public function searchCampusAddressAttr($query, $value, $data) + public function searchCourseNameAttr($query, $value, $data) { if ($value) { - $query->where("campus_address", $value); + $query->where("course_name", $value); } } /** - * 搜索器:校区校区状态 + * 搜索器:课程课程类型 * @param $value * @param $data */ - public function searchCampusStatusAttr($query, $value, $data) + public function searchCourseTypeAttr($query, $value, $data) { if ($value) { - $query->where("campus_status", $value); + $query->where("course_type", $value); + } + } + + /** + * 搜索器:课程课程时长 + * @param $value + * @param $data + */ + public function searchDurationAttr($query, $value, $data) + { + if ($value) { + $query->where("duration", $value); + } + } + + /** + * 搜索器:课程课时数量 + * @param $value + * @param $data + */ + public function searchSessionCountAttr($query, $value, $data) + { + if ($value) { + $query->where("session_count", $value); + } + } + + /** + * 搜索器:课程单次逍客数量 + * @param $value + * @param $data + */ + public function searchSingleSessionCountAttr($query, $value, $data) + { + if ($value) { + $query->where("single_session_count", $value); + } + } + + /** + * 搜索器:课程课程价格 + * @param $value + * @param $data + */ + public function searchPriceAttr($query, $value, $data) + { + if ($value) { + $query->where("price", $value); + } + } + + /** + * 搜索器:课程内部提醒课时 + * @param $value + * @param $data + */ + public function searchInternalReminderAttr($query, $value, $data) + { + if ($value) { + $query->where("internal_reminder", $value); + } + } + + /** + * 搜索器:课程客户提醒课时 + * @param $value + * @param $data + */ + public function searchCustomerReminderAttr($query, $value, $data) + { + if ($value) { + $query->where("customer_reminder", $value); + } + } + + /** + * 搜索器:课程课程备注 + * @param $value + * @param $data + */ + public function searchRemarksAttr($query, $value, $data) + { + if ($value) { + $query->where("remarks", $value); } } From df7a0a83ea6de9dd54d249f970d10bed4f767bb1 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Tue, 20 May 2025 12:38:49 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat(resource-sharing):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=B5=84=E6=BA=90=E5=85=B1=E4=BA=AB=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=B9=B6=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增资源共享详情接口,用于获取客户详情信息 - 在客户信息中添加多个属性的自定义获取器,用于展示字典值对应的名称 - 在资源共享详情中加入客户成交次数的统计 - 更新路由配置,添加新的资源共享详情接口路由 --- .../apiController/ResourceSharing.php | 20 +++ niucloud/app/api/route/route.php | 2 + .../customer_resources/CustomerResources.php | 160 +++++++++++++++++- .../api/apiService/ResourceSharingService.php | 24 ++- 4 files changed, 202 insertions(+), 4 deletions(-) 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'] = '未找到数据'; From a956a43db3e622dd10c5bff626c8818527b8a44a Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Tue, 20 May 2025 16:41:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feat(customerResources):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AE=A2=E6=88=B7=E8=B5=84=E6=BA=90=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增客户资源编辑接口和相关逻辑 - 实现客户资源数据和六要素数据的更新 - 添加数据变更日志记录功能 - 优化数据验证和错误处理 --- .../apiController/CustomerResources.php | 75 +++++++++++ niucloud/app/api/route/route.php | 2 + niucloud/app/model/six_speed/SixSpeed.php | 56 ++++++++ .../service/api/apiService/CommonService.php | 37 ++++++ .../apiService/CustomerResourcesService.php | 122 ++++++++++++++++++ .../api/apiService/ResourceSharingService.php | 7 +- 6 files changed, 298 insertions(+), 1 deletion(-) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 031558ac..29f2cf13 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -77,5 +77,80 @@ class CustomerResources extends BaseApiService return success([]); } + //客户资源-编辑 + public function edit(Request $request){ + + $resource_sharing_id = $request->param('resource_sharing_id', '');//资源共享id + + $customer_resources_id = $request->param('id', '');//客户资源表id + + $promised_visit_time = $request->param('promised_visit_time', ''); + if($promised_visit_time){ + $promised_visit_time = date('Y-m-d H:i:s',strtotime($promised_visit_time)); + } + + + $optional_class_time = $request->param('optional_class_time', ''); + if($optional_class_time){ + $optional_class_time = date('Y-m-d H:i:s',strtotime($optional_class_time)); + } + + + if(empty($customer_resources_id)){ + return fail("缺少客户id"); + } + + $where=[ + 'id'=>$customer_resources_id + ]; + + //客户资源数据 + $customer_resources_data = [ + "source_channel" => $request->param('source_channel', ''),//来源渠道 + "source" => $request->param('source', ''),//来源 + "name" => $request->param('name', ''),//姓名 + "age" => $request->param('age', ''),//年龄 + "gender" => $request->param('gender', ''),//性别 + "phone_number" => $request->param('phone_number', ''),//联系电话 + "demand" => $request->param('demand', ''),//需求 + "decision_maker" => $request->param('decision_maker', ''),//决策人 + "initial_intent" => $request->param('initial_intent', ''),//客户初步意向度 + "status" => $request->param('status', ''),//客户状态 + "purchasing_power" => $request->param('purchasing_power', ''),//购买力 + "cognitive_idea" => $request->param('cognitive_idea', ''),//认知理念 + "optional_class_time" => $optional_class_time,//可选上课时间 + "distance" => $request->param('distance', ''),//距离 + ]; + + //六要素相关数据 + $six_speed_data = [ + "purchase_power" => $request->param('purchasing_power', ''),//需求购买力 + "concept_awareness" => $request->param('cognitive_idea', ''),//认知理念 + "promised_visit_time" => $promised_visit_time,//承诺到访时间 + "preferred_class_time" => $optional_class_time,//可选上课时间 + "distance" => $request->param('distance', ''),//距离 + "communication" => $request->param('communication', ''),//沟通备注 + "staff_id" => $request->param('staff_id', ''),//人员ID + ]; + + foreach($customer_resources_data as $k=>$v){ + if(!isset($v) || $v === ''){ + return fail("缺少必填项{$k}"); + } + } + foreach($six_speed_data as $k=>$v){ + if(!isset($v) || $v === ''){ + return fail("缺少必填项{$k}"); + } + } + + + $res = (new CustomerResourcesService())->editData($where,$customer_resources_data,$six_speed_data); + if(!$res['code']){ + return fail($res['msg']); + } + return success([]); + } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index a8cec341..9e03f657 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -206,6 +206,8 @@ Route::group(function () { Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add'); + //客户资源-编辑 + Route::post('customerResources/edit', 'apiController.CustomerResources/edit'); //资源共享-列表 Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); diff --git a/niucloud/app/model/six_speed/SixSpeed.php b/niucloud/app/model/six_speed/SixSpeed.php index 8a5c83fe..b7fde1a2 100644 --- a/niucloud/app/model/six_speed/SixSpeed.php +++ b/niucloud/app/model/six_speed/SixSpeed.php @@ -11,6 +11,7 @@ namespace app\model\six_speed; +use app\model\dict\Dict; use core\base\BaseModel; use think\model\concern\SoftDelete; use think\model\relation\HasMany; @@ -67,4 +68,59 @@ class SixSpeed extends BaseModel return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); } + + /** + * 获取需求购买力类型名称 + * @param $value + * @param $data + * @return array|mixed|string + */ + public function getPurchasePowerNameAttr($value, $data) + { + $key = 'customer_purchasing_power'; + $val = (String)$data['purchase_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 getConceptAwarenessNameAttr($value, $data) + { + $key = 'customer_purchasing_power'; + $val = (String)$data['concept_awareness']; + 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/CommonService.php b/niucloud/app/service/api/apiService/CommonService.php index 55e2cc3c..66ebc2a0 100644 --- a/niucloud/app/service/api/apiService/CommonService.php +++ b/niucloud/app/service/api/apiService/CommonService.php @@ -43,4 +43,41 @@ class CommonService extends BaseApiService } + /** + * 对比新旧数据改变 + * @param array $old_data 旧数据 + * @param array $new_data 新数据 + * @param array $ignoreFields 忽略验证的字段|默认[] + * @return array + */ + public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at']) + { + $changedFields = [];//改了那些字段 + $oldChanges = [];//数据修改前的样子 + $newChanges = [];//数据修改后的样子 + + foreach ($new_data as $key => $value) { + // 如果字段在忽略列表中,则跳过 + if (in_array($key, $ignoreFields)) { + continue; + } + + if (!isset($old_data[$key]) || $old_data[$key] != $value) { + $changedFields[] = $key; + $oldChanges[$key] = $old_data[$key] ?? null; + $newChanges[$key] = $value; + } + } + + return [ + 'changed_fields' => $changedFields, + 'old_values' => $oldChanges, + 'new_values' => $newChanges, + + 'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE), + 'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE), + 'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE) + ]; + } + } diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index 2c028ad0..1cc0bb86 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -11,10 +11,13 @@ namespace app\service\api\apiService; +use app\model\campus_person_role\CampusPersonRole; +use app\model\customer_resource_changes\CustomerResourceChanges; use app\model\customer_resources\CustomerResources; use app\model\personnel\Personnel; use app\model\resource_sharing\ResourceSharing; use app\model\six_speed\SixSpeed; +use app\model\six_speed_modification_log\SixSpeedModificationLog; use core\base\BaseApiService; use think\facade\Db; @@ -85,4 +88,123 @@ class CustomerResourcesService extends BaseApiService } } + //客户资源-编辑 + public function editData(array $where, array $customer_resources_data, array $six_speed_data) + { + $operator_id = $this->member_id;//当前登录用户的id(日志操作人的id) + $campus_id = 0;//日志操作人校区的id + $campus_id_arr = CampusPersonRole::where('person_id', $operator_id)->column('campus_id'); + if (count($campus_id_arr)) { + if (count($campus_id_arr) > 1) { + $campus_id = 0; + } else { + $campus_id = $campus_id_arr[0]; + } + } + + + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + + if (!$where) { + $res['msg'] = '查询条件不能为空'; + return $res; + } + + $date = date('Y-m-d H:i:s'); + $customer_resources_data['updated_at'] = $date; + $six_speed_data['updated_at'] = $date; + + //开启事物 + Db::startTrans(); + try { + + $customer_resources = CustomerResources::where('id', $where['id'])->find(); + if ($customer_resources) { + $customer_resources = $customer_resources->toArray(); + } + $update_1 = CustomerResources::where('id', $where['id'])->update($customer_resources_data);//客户资源表 + if (!$update_1) { + Db::rollback(); + return $res; + } + + + //更近客户资源日志表 + $compareData = (new CommonService)->compareData($customer_resources, $customer_resources_data); + if ($compareData['changed_fields']) { + $data = [ + "customer_resource_id" => $where['id'],//客户资源的ID + "operator_id" => $operator_id,//操作人的ID + "campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0 + "modified_fields" => $compareData['changed_fields_json'],//修改的哪些字段 + "old_values" => $compareData['old_values_json'],//修改前的值 + "new_values" => $compareData['new_values_json'],//修改后的值 + ]; + + $id = CustomerResourceChanges::insertGetId($data); + if (!$id) { + Db::rollback(); + return $res; + } + } + + + $six_speed_data['resource_id'] = $where['id']; + + //查六要素是否存在 + $six_speed = SixSpeed::where('resource_id', $where['id'])->find(); + if ($six_speed) { + $six_speed = $six_speed->toArray(); + //更新六要素 + $sixSpeedUpdate = SixSpeed::where('id', $six_speed['id'])->update($six_speed_data); + if (!$sixSpeedUpdate) { + Db::rollback(); + return $res; + } + + //更近六要素日志表 + $compareData = (new CommonService)->compareData($six_speed, $six_speed_data); + if ($compareData['changed_fields']) { + $data = [ + "operator_id" => $operator_id,//操作人的ID + "campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0 + "customer_resource_id" => $where['id'],//客户资源的ID + "modified_field" => $compareData['changed_fields_json'],//修改的哪些字段 + "old_value" => $compareData['old_values_json'],//修改前的值 + "new_value" => $compareData['new_values_json'],//修改后的值 + ]; + + $id = SixSpeedModificationLog::insertGetId($data); + if (!$id) { + Db::rollback(); + return $res; + } + } + } else { + //创建六要素 + $sixSpeedUpdate = SixSpeed::create($six_speed_data); + if (!$sixSpeedUpdate) { + Db::rollback(); + return $res; + } + } + + Db::commit(); + $res = [ + 'code' => 1, + 'msg' => '操作成功' + ]; + return $res; + } catch (\Exception $exception) { + Db::rollback(); + return $res; + } + } + + + } diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 9eac3a88..3f104fd0 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -97,7 +97,12 @@ class ResourceSharingService extends BaseApiService $data = $model->with([ 'customerResource'=>function($query){ $query->with([ - 'sixSpeed'=>function($query_2){}, + 'sixSpeed'=>function($query_2){ + $query_2->append([ + 'purchase_power_name',//购买力 + 'concept_awareness_name',//认知理念 + ]); + }, 'personnel'=>function($query_2){} ])->append([ 'source_channel_name',//来源渠道 From 74060299972942c9deaa95029e718e161e11372c Mon Sep 17 00:00:00 2001 From: wangzeyan <258785420@qq.com> Date: Wed, 21 May 2025 12:30:24 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/components.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/components.d.ts b/admin/components.d.ts index 4268e5eb..e1d612fe 100644 --- a/admin/components.d.ts +++ b/admin/components.d.ts @@ -21,6 +21,7 @@ declare module '@vue/runtime-core' { ElColorPicker: typeof import('element-plus/es')['ElColorPicker'] ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] ElContainer: typeof import('element-plus/es')['ElContainer'] + ElDatePicker: typeof import('element-plus/es')['ElDatePicker'] ElDialog: typeof import('element-plus/es')['ElDialog'] ElDrawer: typeof import('element-plus/es')['ElDrawer'] ElDropdown: typeof import('element-plus/es')['ElDropdown']