From 2174acedd3eeeddfd6fe0af022f219a0d46d9583 Mon Sep 17 00:00:00 2001 From: "1213317725@qq.com" <1213317725@qq.com> Date: Fri, 30 May 2025 11:19:13 +0800 Subject: [PATCH 01/12] 1 --- .../components/campus-person-role-edit.vue | 2 ++ niucloud/app/service/admin/auth/AuthService.php | 9 ++++++++- .../admin/campus_person_role/CampusPersonRoleService.php | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue b/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue index 7bc11b8b..749219bc 100644 --- a/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue +++ b/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue @@ -149,6 +149,8 @@ if(pageName == '市场人员列表'){ }else if(pageName == '销售人员列表'){ initialFormData.dept_id = 2; // campusPersonRoleTable.searchParam.role_id = 2; +}else if(pageName == '教练管理'){ + initialFormData.dept_id = 3; } const formData: Record = reactive({ ...initialFormData }) diff --git a/niucloud/app/service/admin/auth/AuthService.php b/niucloud/app/service/admin/auth/AuthService.php index ec9c9c58..c2b014d8 100644 --- a/niucloud/app/service/admin/auth/AuthService.php +++ b/niucloud/app/service/admin/auth/AuthService.php @@ -11,6 +11,8 @@ namespace app\service\admin\auth; +use app\model\campus_person_role\CampusPersonRole; +use app\model\personnel\Personnel; use app\Request; use app\service\admin\sys\MenuService; use app\service\admin\sys\RoleService; @@ -91,7 +93,12 @@ class AuthService extends BaseAdminService if ($is_admin) {//查询全部启用的权限 return ( new MenuService() )->getAllMenuList($status, $is_tree, $is_button); } else { - $user_role_ids = $user_info[ 'role_ids' ]; + $per = new Personnel(); + $CampusPersonRole = new CampusPersonRole(); + $per_id = $per->where(['sys_user_id' => $this->uid])->column('id'); + + $user_role_ids = $CampusPersonRole->where(['person_id' => $per_id])->column('role_id'); +// $role_service = new RoleService(); $menu_keys = $role_service->getMenuKeysByRoleIds($user_role_ids ?? []); return $menu_service->getMenuListByMenuKeys($menu_keys, $is_tree, is_button:$is_button); diff --git a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php index c16555c9..f6fa7706 100644 --- a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php +++ b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php @@ -93,6 +93,8 @@ class CampusPersonRoleService extends BaseAdminService public function add(array $data) { $res = $this->model->create($data); + + return $res->id; } From 9ba3e4dc7cc8d1d5334b80d880eb01389dc6ff73 Mon Sep 17 00:00:00 2001 From: "1213317725@qq.com" <1213317725@qq.com> Date: Fri, 30 May 2025 13:45:14 +0800 Subject: [PATCH 02/12] 1 --- niucloud/app/api/controller/login/Login.php | 42 +----- niucloud/app/event.php | 3 + niucloud/app/listener/personnel/Student.php | 124 ++++++++++++++++++ .../PersonCourseScheduleService.php | 7 +- niucloud/app/service/api/pay/PayService.php | 35 +---- 5 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 niucloud/app/listener/personnel/Student.php diff --git a/niucloud/app/api/controller/login/Login.php b/niucloud/app/api/controller/login/Login.php index 6bce779e..2ad930a0 100644 --- a/niucloud/app/api/controller/login/Login.php +++ b/niucloud/app/api/controller/login/Login.php @@ -12,6 +12,7 @@ namespace app\api\controller\login; use app\dict\member\MemberLoginTypeDict; +use app\model\order_table\OrderTable; use app\model\sys\SysConfig; use app\service\admin\sys\SystemService; use app\service\api\captcha\CaptchaService; @@ -138,43 +139,8 @@ class Login extends BaseController } public function test(){ - $pay_config = Db::name("campus_pay")->where(['campus_id' => 1])->find(); - - $sysConfig = new SysConfig(); - - $vx_config = $sysConfig->where(['config_key' => 'WECHAT'])->value("value"); - - $config = [ - // 必填-商户号 - 'mch_id' => $pay_config['mchid'], - // 必填-商户私钥 字符串或路径 - 'mch_secret_cert' => $pay_config['apiclient_cert'], - // 必填-商户公钥证书路径 - 'mch_public_cert_path' => $pay_config['apiclient_key'], - // 必填 - 'notify_url' => 'https://zh.hnhbty.cn/api/pay/qrcodenotify', - // 选填-公众号 的 app_id - 'mp_app_id' => $vx_config['app_id'], - // 选填-小程序 的 app_id - 'mini_app_id' => '', - 'mch_secret_key' => $pay_config['pay_sign_key'], - ]; - $params = [ - 'out_trade_no' => '123123', - 'body' => '测试', - 'money' => 100, - ]; - $pay = new PayLoader('Wechatpay', $config); - - $url = $pay->scan($params); - - $path = qrcode( - $url['code_url'], - '', - [], - 'upload/qrcode/pay/' - ); - - echo "";die; + $order = new OrderTable(); + $order_info = $order->where(['id' => 8])->find(); + event('Student', ['event_type' => 'add','order_info' => $order_info]); } } diff --git a/niucloud/app/event.php b/niucloud/app/event.php index 40759800..d8b36fcb 100644 --- a/niucloud/app/event.php +++ b/niucloud/app/event.php @@ -113,6 +113,9 @@ $system_event = [ //计算业绩 'CalculatePerformance' => [ 'app\listener\personnel\CalculatePerformance' ], + + //学员 + 'Student' => [ 'app\listener\personnel\Student' ], ], 'subscribe' => [ ], diff --git a/niucloud/app/listener/personnel/Student.php b/niucloud/app/listener/personnel/Student.php new file mode 100644 index 00000000..824a124f --- /dev/null +++ b/niucloud/app/listener/personnel/Student.php @@ -0,0 +1,124 @@ +studentAdd($params['data']); + } + + if ($params['event_type'] === 'xiaoke') { + $this->studentXiaoke($params['data']); + } + } + + public function studentXiaoke($data){ + $courseSchedule = new CourseSchedule(); + $studentCourses = new StudentCourses(); + $student_course_usage = new StudentCourseUsage(); + $schedule_info = $courseSchedule->where(['id' => $data['schedule_id']])->find(); + $studentCourses_info = $studentCourses->where(['student_id' => $data['student_id'],'course_id' => $schedule_info['course_id']])->find(); + + $student_course_usage->insert([ + 'student_course_id' => $studentCourses_info['id'], + 'used_hours' => $studentCourses_info['single_session_count'], + 'usage_date' => date("Y-m-d") + ]); + + } + + public function studentAdd($order_info){ + $student = new \app\model\student\Student(); + $order = new OrderTable(); + $cust = new CustomerResources(); + $class_resources_rel = new ClassResourcesRel(); + $course = new Course(); + $studentCourses = new StudentCourses(); + $order_count = $order->where(['resource_id' => $order_info['resource_id']])->count(); + $cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); + //创建学员关系逻辑 + if($order_count <= 1){ + $sex_arr = ['male' => 1, 'female' => 2, 'other' => 0]; + //首次支付创建学员 + $student_id = $student->insertGetId([ + 'name' => $cust_info['name'], + 'gender' => $sex_arr[$cust_info['gender']], + 'age' => $cust_info['age'], + 'campus_id' => $cust_info['campus'], + 'class_id' => $order_info['class_id'], + 'status' => 1, + 'user_id' => $order_info['resource_id'] + ]); + }else{ + $student_id = $student->where(['user_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']])->value('id'); + } + + //学员课程逻辑 + $course_info = $course->where(['id' => $order_info['course_id']])->find(); + $studentCourses->insert([ + 'student_id' => $student_id, + 'course_id' => $order_info['course_id'], + 'total_hours' => $course_info['session_count'], + 'gift_hours' => $course_info['gift_session_count'], + 'start_date' => date("Y-m-d"), + 'end_date' => date("Y-m-d", strtotime("+30 days")), + 'single_session_count' => $course_info['single_session_count'] + ]); + + + //班级资源关系逻辑 + $is_rel = $class_resources_rel->where( + ['resource_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']] + )->find(); + if($is_rel){ + $class_resources_rel->where(['id' => $is_rel['id']])->update(['status' => 2]); + }else{ + $class_resources_rel->insert([ + 'class_id' => $order_info['class_id'], + 'resource_id' => $order_info['resource_id'], + 'campus_id' => $cust_info['campus'], + 'source_type' => 'student', + 'join_time' => time(), + 'status' => 1, + 'create_time' => date("Y-m-d H:i:s"), + 'update_time' => date("Y-m-d H:i:s") + ]); + } + + + + + + } + + +} diff --git a/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php b/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php index 4825af1d..0bca593b 100644 --- a/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php +++ b/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php @@ -219,10 +219,9 @@ class PersonCourseScheduleService extends BaseAdminService return $data; } public function xk(int $id){ - $model = $this->model->where([['id', '=', $id]])->find(); - $res = $model->delete(); - return $res; - + $data = $this->model->where([['id', '=', $id]])->find(); + event('Student', ['event_type' => 'xiaoke','data' => $data]); + return true; } public function getCustomerResourcesAll(){ diff --git a/niucloud/app/service/api/pay/PayService.php b/niucloud/app/service/api/pay/PayService.php index 66f54dba..52e53909 100644 --- a/niucloud/app/service/api/pay/PayService.php +++ b/niucloud/app/service/api/pay/PayService.php @@ -166,9 +166,7 @@ class PayService extends BaseApiService public function qrcodeNotify($data,$order_id) { - $student = new Student(); $order = new OrderTable(); - $cust = new CustomerResources(); $order_info = $order->where(['id' => $order_id])->find(); if($order_info['order_status'] == 'pending' and !empty($order_info['ipv3'])){ $resource = $data['resource']; @@ -182,39 +180,8 @@ class PayService extends BaseApiService $order->where(['payment_id' => $info['out_trade_no']])->update(['order_status' => 'paid','payment_time' => date("Y-m-d H:i:s")]); - $order_count = $order->where(['resource_id' => $order_info['resource_id']])->count(); - $cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); - if($order_count <= 1){ - $sex_arr = ['male' => 1, 'female' => 2, 'other' => 0]; - //首次支付创建学员 - $student->insert([ - 'name' => $cust_info['name'], - 'gender' => $sex_arr[$cust_info['gender']], - 'age' => $cust_info['age'], - 'campus_id' => $cust_info['campus'], - 'class_id' => $order_info['class_id'], - 'status' => 1, - 'user_id' => $order_info['resource_id'] - ]); - } - $is_rel = Db::name("class_resources_rel")->where( - ['resource_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']] - )->find(); - if($is_rel){ - Db::name("class_resources_rel")->where(['id' => $is_rel['id']])->update(['status' => 2]); - }else{ - Db::name("class_resources_rel")->insert([ - 'class_id' => $order_info['class_id'], - 'resource_id' => $order_info['resource_id'], - 'campus_id' => $cust_info['campus'], - 'source_type' => 'student', - 'join_time' => time(), - 'status' => 1, - 'create_time' => date("Y-m-d H:i:s"), - 'update_time' => date("Y-m-d H:i:s") - ]); - } + event('Student', ['event_type' => 'add','data' => $order_info]); } } From 5eb8c0b7658ca8acf5efeeccae58311eda1a2298 Mon Sep 17 00:00:00 2001 From: LLL <15374889135@163.com> Date: Fri, 30 May 2025 15:32:01 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/apiController/Course.php | 36 ++++++++++ niucloud/app/api/route/route.php | 3 +- .../service/api/apiService/CourseService.php | 66 +++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 niucloud/app/api/controller/apiController/Course.php create mode 100644 niucloud/app/service/api/apiService/CourseService.php diff --git a/niucloud/app/api/controller/apiController/Course.php b/niucloud/app/api/controller/apiController/Course.php new file mode 100644 index 00000000..7621e567 --- /dev/null +++ b/niucloud/app/api/controller/apiController/Course.php @@ -0,0 +1,36 @@ +member_id; + $data = $this->request->params([ + ["schedule_date",0] + ]); + return success((new CourseService())->list($id,$data)); + } + +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index c2221d61..130537e4 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -276,7 +276,8 @@ Route::group(function () { - + //课程列表 + Route::get('course/courseList', 'apiController.course/courseList'); //教研管理文章列表 Route::get('teachingResearch/list', 'apiController.teachingResearch/list'); //教研管理文章详情 diff --git a/niucloud/app/service/api/apiService/CourseService.php b/niucloud/app/service/api/apiService/CourseService.php new file mode 100644 index 00000000..72619710 --- /dev/null +++ b/niucloud/app/service/api/apiService/CourseService.php @@ -0,0 +1,66 @@ +model = new Course(); + } + + //获取教研管理文章列表 + public function list($id,$data) + { + $where = []; + if ($data['schedule_date']) { + $where[] = ['course_date','=', $data['schedule_date']]; + } + $CourseSchedule = new CourseSchedule(); + $search_model = $CourseSchedule + ->where('coach_id', $id) + ->where($where) + ->with(['course' => function($query) { + $query->select(); + },'venue' => function($query) { + $query->select(); + }]); + $list = $this->pageQuery($search_model); + $PersonCourseSchedule = new PersonCourseSchedule(); + foreach ($list['data'] as $k => $v) { + $student = Db::name('person_course_schedule') + ->alias('pcs') + ->where('pcs.schedule_id', $v['id']) // 建议加上表别名避免冲突 + ->join('school_student st', 'pcs.student_id = st.id') + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') // 👈 正确方式取字段 + ->select(); + $list['data'][$k]['student'] = $student; + } + return $list; + } +} + From 94884d2274fe9ceeb62efb5cfe29d5e5645408b7 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 15:51:23 +0800 Subject: [PATCH 04/12] =?UTF-8?q?refactor(CustomerResources):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E9=97=B4=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 promised_visit_time 和 optional_class_time 参数处理 - 将时间参数转换为 Y-m-d H:i:s 格式- 更新 customer_resources_data 和 six_speed_data 中的时间字段 --- .../apiController/CustomerResources.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 16fc4e53..844f7611 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -28,6 +28,17 @@ class CustomerResources extends BaseApiService $date = date('Y-m-d'); + $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)); + } + $customer_resources_data = [ "create_year_month"=>date('Y-m'), "create_date"=>date('Y-m-d'), @@ -44,15 +55,15 @@ class CustomerResources extends BaseApiService "status" => $request->param('status', ''), "purchasing_power" => $request->param('purchasing_power', ''), "cognitive_idea" => $request->param('cognitive_idea', ''), - "optional_class_time" => $request->param('optional_class_time', ''), + "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" => $request->param('promised_visit_time', ''),//承诺到访时间 - "preferred_class_time" => $request->param('optional_class_time', ''),//可选上课时间 + "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 From a221698605c8c586eb91806288135634d32e05da Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 16:41:14 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD-=20=E5=9C=A8=20Co?= =?UTF-8?q?mmon=20=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20forgetPassword=20=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E9=87=8D=E7=BD=AE=E5=AF=86=E7=A0=81=20-=20=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=96=87=E4=BB=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=20API=20=E8=B7=AF=E7=94=B1=20-=20?= =?UTF-8?q?=E5=9C=A8=20CommonService=20=E4=B8=AD=E5=AE=9E=E7=8E=B0=20forge?= =?UTF-8?q?tPassword=20=E6=96=B9=E6=B3=95=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=E9=87=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=20-=20=E6=94=AF=E6=8C=81=E5=AD=A6=E7=94=9F=E5=92=8C?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E4=B8=A4=E7=A7=8D=E7=94=A8=E6=88=B7=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/apiController/Common.php | 26 +++++++++ niucloud/app/api/route/route.php | 6 ++- .../service/api/apiService/CommonService.php | 54 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Common.php b/niucloud/app/api/controller/apiController/Common.php index 27a570ee..9011ea0e 100644 --- a/niucloud/app/api/controller/apiController/Common.php +++ b/niucloud/app/api/controller/apiController/Common.php @@ -35,4 +35,30 @@ class Common extends BaseApiService } return success($res); } + + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + public function forgetPassword(Request $request) + { + $phone = $request->param('phone', '');//手机号 + $code = $request->param('code', '');//短信验证码 + $code_type = $request->param('code_type', '');//短信验证码类型(发送/验证 短信验证码的类型)|修改密码=editPassword + $password = $request->param('password', '');//新密码 + $user_type = $request->param('user_type', '');//用户类型|customer=学生|personnel=员工(销售/教师) + + if (empty($phone) || empty($code) || empty($code_type) || empty($password) || empty($user_type)) { + return fail('缺少必填参数'); + } + + //@todo 验证短信验证码是否正确(等发送短信验证码接入后在写) + //... + + + //重置密码 + $res = (new CommonService())->forgetPassword($phone, $password, $user_type); + 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 35b6b234..55ac4def 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -176,8 +176,8 @@ Route::group(function () { Route::post('personnelLogin', 'login.Login/personnelLogin'); //获取字典 Route::get('common/getDictionary', 'apiController.Common/getDictionary'); - //员工端-修改密码操作 - Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + Route::post('common/forgetPassword', 'apiController.Common/forgetPassword'); @@ -209,6 +209,8 @@ Route::group(function () { Route::post('personnel/edit', 'apiController.Personnel/edit'); //员工端-验证旧密码是否正确 Route::post('personnel/checkOldPwd', 'apiController.Personnel/checkOldPwd'); + //员工端-修改密码操作(通过旧密码修改新密码) + Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); //员工端-获取全部人员列表 diff --git a/niucloud/app/service/api/apiService/CommonService.php b/niucloud/app/service/api/apiService/CommonService.php index 26654fd4..5a41285a 100644 --- a/niucloud/app/service/api/apiService/CommonService.php +++ b/niucloud/app/service/api/apiService/CommonService.php @@ -12,6 +12,8 @@ namespace app\service\api\apiService; use app\model\dict\Dict; +use app\model\member\Member; +use app\model\sys\SysUser; use core\base\BaseApiService; /** @@ -43,6 +45,58 @@ class CommonService extends BaseApiService } + /** + * 忘记密码功能 - 根据用户类型重置密码 + * @param string $phone 用户手机号 + * @param string $new_password 用户新密码 + * @param string $user_type 用户类型|customer=学生|personnel=员工(销售/教师) + */ + public function forgetPassword($phone, $new_password, $user_type){ + if($user_type == 'personnel'){ + //重置员工(销售/教师)密码 + $update = SysUser::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + }else{ + //重置用户(学生)密码 + $update = Member::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + } + + + } + /** * 对比新旧数据改变 * @param array $old_data 旧数据 From 4d458814767268bb19ee1ae44761a2e1fdf5d934 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 16:44:37 +0800 Subject: [PATCH 06/12] =?UTF-8?q?fix(login):=20=E4=BC=98=E5=8C=96=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在查询员工信息后,增加对查询结果为空的检查 - 如果账号不存在,抛出 '账号不存在' 的异常 - 提升用户体验,明确提示错误原因 --- niucloud/app/service/api/login/LoginService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/niucloud/app/service/api/login/LoginService.php b/niucloud/app/service/api/login/LoginService.php index cff79559..3ce056fa 100644 --- a/niucloud/app/service/api/login/LoginService.php +++ b/niucloud/app/service/api/login/LoginService.php @@ -354,6 +354,9 @@ class LoginService extends BaseApiService { //查询员工信息 $member_info = (new Personnel())->where('phone', $params['phone'])->find(); + if(!$member_info){ + throw new ApiException('账号不存在'); + } if ($member_info->status != 2) throw new ApiException('账号状态异常禁止登录'); $user = (new SysUser())->where('username', $params['phone'])->find(); From 73ddecc4dc6649280ba66ae817e9383a485ff75c Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 17:15:54 +0800 Subject: [PATCH 07/12] =?UTF-8?q?feat(customer-resources):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=85=A8=E9=83=A8=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 getAll 方法,用于获取全部客户资源数据- 在路由中添加 getAll 接口 - 实现 CustomerResourcesService 中的 getAll 方法 - 接口支持根据客户姓名查询,返回客户资源列表 --- .../apiController/CustomerResources.php | 19 +++++++++++ niucloud/app/api/route/route.php | 2 ++ .../apiService/CustomerResourcesService.php | 33 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 844f7611..3112f01c 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -23,6 +23,25 @@ use core\base\BaseApiService; class CustomerResources extends BaseApiService { + + //获取全部客户资源 + public function getAll(Request $request){ + + $name = $request->param('name', '');//客户姓名 + if(empty($name)){ + return fail("缺少客户姓名"); + } + + $where = [ + 'name'=>$name + ]; + $res = (new CustomerResourcesService())->getAll($where); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + } + //客户资源添加 public function add(Request $request){ diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 55ac4def..23d89641 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -221,6 +221,8 @@ Route::group(function () { Route::post('customerResources/edit', 'apiController.CustomerResources/edit'); //客户资源-修改记录列表 Route::get('customerResources/getEditLogList', 'apiController.CustomerResources/getEditLogList'); + //客户资源-获取全部客户资源列表 + Route::get('customerResources/getAll', 'apiController.CustomerResources/getAll'); //资源共享-列表 diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index d8e99818..fa33da12 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -35,6 +35,39 @@ class CustomerResourcesService extends BaseApiService parent::__construct(); } + //获取全部客户资源数据 + public function getAll(array $where,string $field = '*') + { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + if(!$where){ + $res['msg'] = '查询条件不能为空'; + return $res; + } + $model = new CustomerResources(); + if(!empty($where['name'])){ + $model = $model->where('name', 'like', "%{$where['name']}%"); + } + $data = $model->field($field) + ->append([ + 'initial_intent_name' + ]) + ->select()->toArray(); + if (!$data) { + $res['msg'] = '暂无数据'; + return $res; + } + $res['code'] = 1; + $res['msg'] = '操作成功'; + $res['data'] = $data; + return $res; + + + } + //添加数据 public function addData(array $customer_resources_data, array $six_speed_data) { From 3258d6071d57ef9c8f9a8f78b5765ee058740c67 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 18:08:43 +0800 Subject: [PATCH 08/12] =?UTF-8?q?feat(customer-resources):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=B5=84=E6=BA=90=E5=88=86=E4=BA=AB=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CustomerResources 模型中添加 resourceSharingHasMany 方法,实现一对多关联资源共享表 - 在 CustomerResourcesService 中使用 with 方法预加载资源分享关联数据 --- .../app/model/customer_resources/CustomerResources.php | 9 +++++++++ .../service/api/apiService/CustomerResourcesService.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/niucloud/app/model/customer_resources/CustomerResources.php b/niucloud/app/model/customer_resources/CustomerResources.php index cd2e4f79..3e83166f 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -153,6 +153,15 @@ class CustomerResources extends BaseModel return $this->hasOne(SixSpeed::class, 'resource_id', 'id'); } + //一对多关联"资源共享表" + public function resourceSharingHasMany() + { + return $this->hasMany(ResourceSharing::class, 'resource_id', 'id'); + } + + + + /** * 获取客户初步意向度类型名称 * @param $value diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index fa33da12..7c3e77a9 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -52,6 +52,9 @@ class CustomerResourcesService extends BaseApiService $model = $model->where('name', 'like', "%{$where['name']}%"); } $data = $model->field($field) + ->with([ + 'resourceSharingHasMany' + ]) ->append([ 'initial_intent_name' ]) From 79afa5944daf5052dd4ec3a595c59e4aaab17637 Mon Sep 17 00:00:00 2001 From: LLL <15374889135@163.com> Date: Fri, 30 May 2025 19:55:28 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/apiController/ClassApi.php | 42 ++++++ .../api/controller/apiController/Course.php | 40 +++++- niucloud/app/api/route/route.php | 10 +- niucloud/app/model/assignment/Assignment.php | 61 +++++++++ .../customer_resources/CustomerResources.php | 5 +- .../service/api/apiService/CourseService.php | 121 +++++++++++++++++- 6 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 niucloud/app/api/controller/apiController/ClassApi.php create mode 100644 niucloud/app/model/assignment/Assignment.php diff --git a/niucloud/app/api/controller/apiController/ClassApi.php b/niucloud/app/api/controller/apiController/ClassApi.php new file mode 100644 index 00000000..83f4ec5b --- /dev/null +++ b/niucloud/app/api/controller/apiController/ClassApi.php @@ -0,0 +1,42 @@ +member_id; + dd(111); + return success((new CourseService())->list($id,$data)); + } + + //获取课程详情 + public function courseInfo(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->info($data['id'])); + } + +} diff --git a/niucloud/app/api/controller/apiController/Course.php b/niucloud/app/api/controller/apiController/Course.php index 7621e567..a4b7a69d 100644 --- a/niucloud/app/api/controller/apiController/Course.php +++ b/niucloud/app/api/controller/apiController/Course.php @@ -24,7 +24,7 @@ use core\base\BaseApiService; class Course extends BaseApiService { - //客户资源-修改记录列表 + //课程列表 public function courseList(Request $request){ $id = $this->member_id; $data = $this->request->params([ @@ -33,4 +33,42 @@ class Course extends BaseApiService return success((new CourseService())->list($id,$data)); } + //获取课程详情 + public function courseInfo(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->info($data['id'])); + } + + //获取添加学员列表 + public function addStudentList(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->StudentList($data['id'])); + } + + //获取添加学员列表 + public function addStudent(Request $request){ + $data = $this->request->params([ + ["student_id",0], + ["schedule_id",0], + ["time_slot",0], + ["resources_id",1], + ["person_id",1], + ["course_date",''] + ]); + return success('SUCCESS',(new CourseService())->addStudent($data)); + } + + //请假 + public function delStudentCourse(Request $request){ + $data = $this->request->params([ + ["student_id",0], + ["course_id",0] + ]); + return success('SUCCESS',(new CourseService())->delStudentCourse($data)); + } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 35b6b234..26d47356 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -274,10 +274,16 @@ Route::group(function () { - - + //获取添加学员列表 + Route::get('course/addStudentList', 'apiController.course/addStudentList'); + Route::post('course/addStudent', 'apiController.course/addStudent'); + Route::get('course/delStudentCourse', 'apiController.course/delStudentCourse'); + //班级列表 + Route::get('class/jlClassList', 'apiController.classApi/jlClassList'); //课程列表 Route::get('course/courseList', 'apiController.course/courseList'); + //获取课程详情 + Route::get('course/courseInfo', 'apiController.course/courseInfo'); //教研管理文章列表 Route::get('teachingResearch/list', 'apiController.teachingResearch/list'); //教研管理文章详情 diff --git a/niucloud/app/model/assignment/Assignment.php b/niucloud/app/model/assignment/Assignment.php new file mode 100644 index 00000000..e61c6873 --- /dev/null +++ b/niucloud/app/model/assignment/Assignment.php @@ -0,0 +1,61 @@ +hasOne(Student::class, 'id', 'student_id'); + } + +} diff --git a/niucloud/app/model/customer_resources/CustomerResources.php b/niucloud/app/model/customer_resources/CustomerResources.php index cd2e4f79..c6e16bd1 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -24,6 +24,7 @@ use think\model\relation\HasOne; use app\model\personnel\Personnel; use app\model\campus\Campus; +use app\model\member\Member; /** * 客户资源模型 @@ -127,7 +128,9 @@ class CustomerResources extends BaseModel } - + public function member(){ + return $this->hasOne(Member::class, 'member_id', 'member_id'); + } diff --git a/niucloud/app/service/api/apiService/CourseService.php b/niucloud/app/service/api/apiService/CourseService.php index 72619710..ddefbf3b 100644 --- a/niucloud/app/service/api/apiService/CourseService.php +++ b/niucloud/app/service/api/apiService/CourseService.php @@ -13,7 +13,11 @@ namespace app\service\api\apiService; use app\model\course_schedule\CourseSchedule; use app\model\person_course_schedule\PersonCourseSchedule; +use app\model\student_course_usage\StudentCourseUsage; +use app\model\student\Student; +use app\model\assignment\Assignment; use app\model\course\Course; +use app\model\student_courses\StudentCourses; use core\base\BaseApiService; use think\Model; use think\facade\Db; @@ -31,7 +35,7 @@ class CourseService extends BaseApiService $this->model = new Course(); } - //获取教研管理文章列表 + //课程列表 public function list($id,$data) { $where = []; @@ -62,5 +66,120 @@ class CourseService extends BaseApiService } return $list; } + //获取课程详情 + public function info($data) + { + $CourseSchedule = new CourseSchedule(); + $search_model = $CourseSchedule + ->where('id', $data) + ->with(['course' => function($query) { + $query->select(); + },'venue' => function($query) { + $query->select(); + },'coach' => function($query) { + $query->select(); + }]); + $list = $search_model->find(); + $student = Db::name('person_course_schedule') + ->alias('pcs') + ->where('pcs.schedule_id', $list['id']) + ->join('school_student st', 'pcs.student_id = st.id') + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') + ->select(); + $list['student'] = $student; + $student_courses = Db::name('student_courses') + ->alias('sc') + ->where('sc.course_id', $list['id']) + ->join('school_student_course_usage sscu', 'sc.id = sscu.student_course_id') + ->field('sc.student_id,sc.end_date') + ->select()->toArray(); + foreach ($student_courses as &$v){ + $student = Db::name('student') + ->alias('st') + ->where('st.id', $v['student_id']) + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') + ->find(); + $v['name'] = $student['name']; + $v['avatar'] = $student['avatar']; + } + $list['student_courses'] = $student_courses; + + $Assignment = new Assignment(); + $search_model = $Assignment->where('course_id', $data) + ->with(['student' => function($query) { + $query->with(['customerResources' => function($query) { + $query->with(['member' => function($query) { + $query->select(); + }]); + }]); + }]); + $search_model_res = $search_model->select()->toArray(); + $groupedByStatus1 = []; + $groupedByStatus2 = []; + $groupedByStatus3 = []; + + foreach ($search_model_res as $item) { + if ($item['status'] == 1){ + array_push($groupedByStatus1,$item); + } else if ($item['status'] == 2){ + array_push($groupedByStatus2,$item); + } else if ($item['status'] == 3){ + array_push($groupedByStatus3,$item); + } + } + $list['groupedByStatus1'] = $groupedByStatus1; + $list['groupedByStatus2'] = $groupedByStatus2; + $list['groupedByStatus3'] = $groupedByStatus3; + return $list; + } + + + //获取添加学员列表 + public function StudentList($id) + { + $StudentCourses = new StudentCourses(); + $PersonCourseSchedule = new PersonCourseSchedule(); + $student_arr = $PersonCourseSchedule->where('schedule_id',$id)->column('student_id'); + + $query = $StudentCourses->where('course_id', $id); + if (!empty($student_arr)) { + $query->whereNotIn('student_id', $student_arr); + } + $res = $query->field('student_id as value')->select()->toArray(); + $Student = new Student(); + foreach ($res as $k => &$v) { + $StudentName = $Student->where('id',$v['value'])->value('name'); + $v['text'] = $StudentName; + } + return $res; + } + + public function addStudent($data) + { + $PersonCourseSchedule = new PersonCourseSchedule(); + $res = $PersonCourseSchedule->create($data); + return $res; + } + + + public function delStudentCourse($data) + { + $StudentCourseUsage = new StudentCourseUsage(); + $StudentCourses = new StudentCourses(); + $StudentCourses_id = $StudentCourses->where('student_id',$data['student_id'])->where('course_id',$data['course_id'])->value('id'); + $PersonCourseSchedule_id = $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->value('id'); + if ($PersonCourseSchedule_id) { + $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->delete(); + return true; + } else { + return false; + } + } + + } From f76bd014064622d853bca9d7e27e200ccfa8b162 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 19:57:41 +0800 Subject: [PATCH 10/12] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E7=AB=AF=E7=BB=9F=E8=AE=A1=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=92=8C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Statistics 控制器,实现市场和销售数据统计功能 - 添加市场和销售首页数据统计、销售数据页统计、个人中新页统计等接口 - 实现根据角色权限返回不同统计数据的逻辑 - 新增 StatisticsService 服务层,用于处理统计相关的业务逻辑 - 在路由文件中注册新增的统计相关路由 --- .../controller/apiController/Statistics.php | 157 ++++++++++++++++++ niucloud/app/api/route/route.php | 8 + .../api/apiService/StatisticsService.php | 33 ++++ 3 files changed, 198 insertions(+) create mode 100644 niucloud/app/api/controller/apiController/Statistics.php create mode 100644 niucloud/app/service/api/apiService/StatisticsService.php diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php new file mode 100644 index 00000000..4e3ea205 --- /dev/null +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -0,0 +1,157 @@ +param('personnel_id','');//员工表id + $role_key_arr = $request->param('role_key_arr','');//array 角色key + $role_key_arr = explode(',',$role_key_arr); + if(empty($personnel_id)|| empty($role_key_arr)){ + return fail('缺少参数'); + } + $firstDayOfMonth = date('m月01日'); // 获取本月第一天 + $lastDayOfMonth = date('m月t日'); // 获取本月最后一天 + $dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串 + +// $role_key_arr = ['sale']; + + if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ + //市场人员统计数据(地推拉人头的) + $data = [ + 'date_range'=>$dateRange,//拼接日期范围字符串 + 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 + //本月 + 'month' => [ + 'new_total' => ($newTotal = rand(100, 500)),//拉新总人数 + 'new_total_rate' => min(100, round($newTotal / 1000 * 100, 2)),//拉新总人数比例(不超过100%) + 'assigned_sales' => ($assignedSales = rand(50, 300)),//已分配给销售的人数 + 'assigned_sales_rate' => min(100, round($assignedSales / $newTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) + 'yesterday_new' => ($yesterdayNew = rand(5, 50)),//昨日拉新 + 'yesterday_new_rate' => min(100, round($yesterdayNew / $newTotal * 100, 2)),//昨日拉新比例(不超过100%) + 'today_new' => ($todayNew = rand(1, 20)),//今日拉新 + 'today_new_rate' => min(100, round($todayNew / $newTotal * 100, 2)),//今日拉新比例(不超过100%) + ], + //上月 + 'last_month' => [ + 'new_total' => ($lastNewTotal = rand(80, 400)),//拉新总人数 + 'new_total_rate' => min(100, round($lastNewTotal / 800 * 100, 2)),//拉新总人数比例(不超过100%) + 'assigned_sales' => ($lastAssignedSales = rand(40, 250)),//已分配给销售的人数 + 'assigned_sales_rate' => min(100, round($lastAssignedSales / $lastNewTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) + 'yesterday_new' => ($lastYesterdayNew = rand(3, 40)),//昨日拉新人数 + 'yesterday_new_rate' => min(100, round($lastYesterdayNew / $lastNewTotal * 100, 2)),//昨日拉新人数比例(不超过100%) + 'today_new' => ($lastTodayNew = rand(1, 15)),//今日拉新人数 + 'today_new_rate' => min(100, round($lastTodayNew / $lastNewTotal * 100, 2)),//今日拉新人数比例(不超过100%) + ] + ]; + }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ + //销售人员统计数据(买课的) + $data = [ + 'date_range'=>$dateRange,//拼接日期范围字符串 + 'role_type'=>'sale_type',//角色类型|market_type=市场,sale_type=销售 infoData.month + //本月 + 'month' => [ + 'assigned_clients' => ($assigned = rand(50, 300)),//分配给我的客户人数 + 'contacted_clients' => ($contacted = rand(20, 150)),//已沟通的客户人数 + 'contact_rate' => min(100, round($contacted / $assigned * 100, 2)),//沟通率(不超过100%) + 'unconverted_clients' => ($unconverted = rand(10, 50)),//已沟通但没成交的客户人数 + 'unconverted_rate' => min(100, round($unconverted / $contacted * 100, 2)),//未成交率(不超过100%) + 'renewal_clients' => ($renewal = rand(5, 30)),//待续费的客户人数 + 'renewal_rate' => min(100, round($renewal / $assigned * 100, 2)),//待续费率(不超过100%) + 'closed_clients' => ($closed = rand(1, 20)),//已关单的客户人数 + 'closed_rate' => min(100, round($closed / $contacted * 100, 2)),//关单率(不超过100%) + 'conversion_rate' => min(100, round($closed / $assigned * 100, 2)),//整体转化率(不超过100%) + ], + //上月 + 'last_month' => [ + 'assigned_clients' => ($lastAssigned = rand(40, 250)),//分配给我的客户人数 + 'contacted_clients' => ($lastContacted = rand(15, 120)),//已沟通的客户人数 + 'contact_rate' => min(100, round($lastContacted / $lastAssigned * 100, 2)),//沟通率(不超过100%) + 'unconverted_clients' => ($lastUnconverted = rand(8, 40)),//已沟通但没成交的客户人数 + 'unconverted_rate' => min(100, round($lastUnconverted / $lastContacted * 100, 2)),//未成交率(不超过100%) + 'renewal_clients' => ($lastRenewal = rand(3, 25)),//待续费的客户人数 + 'renewal_rate' => min(100, round($lastRenewal / $lastAssigned * 100, 2)),//待续费率(不超过100%) + 'closed_clients' => ($lastClosed = rand(1, 15)),//已关单的客户人数 + 'closed_rate' => min(100, round($lastClosed / $lastContacted * 100, 2)),//关单率(不超过100%) + 'conversion_rate' => min(100, round($lastClosed / $lastAssigned * 100, 2)),//整体转化率(不超过100%) + ] + ]; + }else{ + return fail('角色权限不正确'); + } + + + return success($data); + } + + /** + * 员工端统计(销售)-获取销售数据页统计 + */ + public function marketData(Request $request) + { + $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 + if($userRole == 'sale'){ + //销售人员统计数据 + $data = [ + //本月 + 'month' => [], + //上月 + 'last_month' => [] + ]; + }else{ + //市场人员统计数据 + $data = [ + //本月 + 'month' => [], + //上月 + 'last_month' => [] + ]; + } + return success($data); + } + + /** + * 员工端统计(销售)-获取个人中新页统计 + */ + public function marketMy(Request $request) + { + $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 + if($userRole == 'sale'){ + //销售人员统计数据 + $data = [ + + ]; + }else{ + //市场人员统计数据 + $data = [ + //业绩单人数已签单人数已签 + ]; + } + return success($data); + } + +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 23d89641..2c7f02cd 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -215,6 +215,14 @@ Route::group(function () { //员工端-获取全部人员列表 Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); + + //员工端统计(销售)-获取销售首页数据统计 + Route::get('statistics/marketHome', 'apiController.Statistics/marketHome'); + //员工端统计(销售)-获取销售数据页统计 + Route::get('statistics/marketData', 'apiController.Statistics/marketData'); + //员工端统计(销售)-获取个人中新页统计 + Route::get('statistics/marketMy', 'apiController.Statistics/marketMy'); + //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add'); //客户资源-编辑 diff --git a/niucloud/app/service/api/apiService/StatisticsService.php b/niucloud/app/service/api/apiService/StatisticsService.php new file mode 100644 index 00000000..fbc027cc --- /dev/null +++ b/niucloud/app/service/api/apiService/StatisticsService.php @@ -0,0 +1,33 @@ + Date: Fri, 30 May 2025 21:55:06 +0800 Subject: [PATCH 11/12] =?UTF-8?q?refactor(app):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=B8=82=E5=9C=BA=E4=BA=BA=E5=91=98=E7=BB=9F=E8=AE=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了未使用的 marketMy 方法 - 优化了 marketData 方法,支持不同角色的统计需求 - 添加了参数验证和角色权限检查 -生成模拟数据以满足前端展示需求 --- .../controller/apiController/Statistics.php | 92 ++++++++++++------- niucloud/app/api/route/route.php | 2 - 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php index 4e3ea205..ad4fe7d9 100644 --- a/niucloud/app/api/controller/apiController/Statistics.php +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -38,7 +38,7 @@ class Statistics extends BaseApiService $lastDayOfMonth = date('m月t日'); // 获取本月最后一天 $dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串 -// $role_key_arr = ['sale']; +// $role_key_arr = ['sale'];//@todo 调试使用 if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ //市场人员统计数据(地推拉人头的) @@ -113,45 +113,75 @@ class Statistics extends BaseApiService */ public function marketData(Request $request) { - $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 - if($userRole == 'sale'){ - //销售人员统计数据 - $data = [ - //本月 - 'month' => [], - //上月 - 'last_month' => [] - ]; - }else{ - //市场人员统计数据 - $data = [ - //本月 - 'month' => [], - //上月 - 'last_month' => [] - ]; + $personnel_id = $request->param('personnel_id','');//员工表id + $role_key_arr = $request->param('role_key_arr','');//array 角色key + $role_key_arr = explode(',',$role_key_arr); + if(empty($personnel_id)|| empty($role_key_arr)){ + return fail('缺少参数'); } - return success($data); - } - /** - * 员工端统计(销售)-获取个人中新页统计 - */ - public function marketMy(Request $request) - { - $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 - if($userRole == 'sale'){ - //销售人员统计数据 +// $role_key_arr = ['sale'];//@todo 调试使用 + + if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ + //市场人员统计数据(地推拉人头的) $data = [ + 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], ]; - }else{ - //市场人员统计数据 + }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ + //销售人员统计数据(买课的) $data = [ - //业绩单人数已签单人数已签 + 'role_type'=>'sale',//角色类型|market_type=市场,sale_type=销售 + + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], ]; + }else{ + return fail('角色权限不正确'); } return success($data); } + + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 195b92be..9b55b060 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -220,8 +220,6 @@ Route::group(function () { Route::get('statistics/marketHome', 'apiController.Statistics/marketHome'); //员工端统计(销售)-获取销售数据页统计 Route::get('statistics/marketData', 'apiController.Statistics/marketData'); - //员工端统计(销售)-获取个人中新页统计 - Route::get('statistics/marketMy', 'apiController.Statistics/marketMy'); //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add'); From 6abe01255357edd3378b7739a438816c9c8da01c Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 22:08:19 +0800 Subject: [PATCH 12/12] =?UTF-8?q?refactor(niucloud):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20Statistics=20=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91-=20=E5=9C=A8=20Statistics.?= =?UTF-8?q?php=20=E6=96=87=E4=BB=B6=E4=B8=AD=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=B3=A8=E9=87=8A=E4=BB=A5=E8=A7=A3=E9=87=8A=20$role?= =?UTF-8?q?=5Fkey=5Farr=20=E5=8F=98=E9=87=8F=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E8=BF=87=E7=A8=8B-=20=E4=BD=BF=E7=94=A8=20explode=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=B0=86=E8=A7=92=E8=89=B2=20key=20=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=95=B0=E7=BB=84?= =?UTF-8?q?=20-=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E7=A9=BA=E7=9A=84=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E9=AB=98=E4=BA=86=E4=BB=A3=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E5=81=A5=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- niucloud/app/api/controller/apiController/Statistics.php | 1 + 1 file changed, 1 insertion(+) diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php index ad4fe7d9..19e6c2e2 100644 --- a/niucloud/app/api/controller/apiController/Statistics.php +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -30,6 +30,7 @@ class Statistics extends BaseApiService { $personnel_id = $request->param('personnel_id','');//员工表id $role_key_arr = $request->param('role_key_arr','');//array 角色key + //字符转数组 $role_key_arr = explode(',',$role_key_arr); if(empty($personnel_id)|| empty($role_key_arr)){ return fail('缺少参数');