From f6002d7b5799075101ae13645e1dbc0f9f059c2c Mon Sep 17 00:00:00 2001 From: zeyan <258785420@qq.com> Date: Fri, 8 Aug 2025 12:10:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/CustomerResources.php | 40 +++- .../controller/apiController/Personnel.php | 12 ++ .../app/api/controller/apiController/Test.php | 1 + niucloud/app/api/route/route.php | 3 + .../app/job/schedule/HandleCourseSchedule.php | 185 ++++++++++++++-- .../transfer/schedule/CourseScheduleJob.php | 85 +++++++- niucloud/app/model/school/SchoolStudent.php | 2 +- .../CampusPersonRoleService.php | 10 +- .../course_schedule/CourseScheduleService.php | 92 +++++++- .../apiService/CustomerResourcesService.php | 28 ++- .../api/apiService/PersonnelService.php | 69 ++++++ uniapp/api/apiRoute.js | 4 + uniapp/pages-market/clue/add_clues.vue | 202 ++++++++++-------- uniapp/pages-market/clue/index.vue | 21 +- 14 files changed, 605 insertions(+), 149 deletions(-) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 100f20ad..adae3889 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -24,6 +24,23 @@ use core\base\BaseApiService; class CustomerResources extends BaseApiService { + /** + * 转换gender枚举值 + * school_customer_resources: male/female/other + * school_student: 1/2/0 + */ + private function convertGender($gender) + { + switch ($gender) { + case 'male': + return 1; + case 'female': + return 2; + case 'other': + default: + return 0; + } + } //获取全部客户资源 public function getAll(Request $request) @@ -61,7 +78,7 @@ class CustomerResources extends BaseApiService $personnel = new Personnel(); $role_id = $personnel->alias("a") ->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left') - ->where(['a.id' => $request->param('consultant', '')]) + ->where(['a.id' => $request->param('staff_id', '')]) // 使用staff_id而不是consultant ->value('b.role_id'); $customer_resources_data = [ @@ -69,8 +86,9 @@ class CustomerResources extends BaseApiService "create_date" => $date, "source_channel" => $param['source_channel'] ?? '', "source" => $param['source'] ?? '', - "consultant" => $param['consultant'] ?? 0, + "consultant" => 0, // 设置为0而不是当前登录人 "name" => $param['name'] ?? '', + "age" => $param['age'] ?? '', // 添加年龄字段 "gender" => $param['gender'] ?? 'other',//性别 "phone_number" => $param['phone_number'] ?? '', "demand" => $param['demand'] ?? '', @@ -109,7 +127,23 @@ class CustomerResources extends BaseApiService return fail("手机号已存在"); } - $res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data); + // 准备school_student表数据 + $student_data = [ + "name" => $param['name'] ?? '', + "gender" => $this->convertGender($param['gender'] ?? 'other'), // 转换gender枚举值 + "age" => floatval($param['age'] ?? 0), // 转换为decimal + "birthday" => $param['birthday'] ?? null, // 前端计算的生日 + "campus_id" => $param['campus'] ?? 0, + "headimg" => '', // 默认空字符串 + "trial_class_count" => 2, // 默认2 + "status" => 1, // 状态设置为1 + "created_person_id" => $request->param('staff_id', 0), // 当前登录人 + ]; + + // 获取当前登录人的staff_id + $staff_id = $request->param('staff_id', 0); + + $res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data, $student_data, $staff_id, $role_id); if (!$res['code']) { return fail($res['msg']); } diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index e0a98d42..ea0a4e98 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -93,6 +93,18 @@ class Personnel extends BaseApiService return success($res); } + //获取销售部门员工列表(根据校区筛选) + public function getSalesPersonnelByCampus(Request $request){ + //获取销售部门员工信息 + $campus = $request->param('campus', '');//校区id + + $res = (new PersonnelService())->getSalesPersonnelByCampus($campus); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + } + //验证新旧密码是否正确 public function checkOldPwd(Request $request){ //获取员工信息 diff --git a/niucloud/app/api/controller/apiController/Test.php b/niucloud/app/api/controller/apiController/Test.php index 93490b91..ff394263 100644 --- a/niucloud/app/api/controller/apiController/Test.php +++ b/niucloud/app/api/controller/apiController/Test.php @@ -43,4 +43,5 @@ class Test extends BaseApiService return success($res); } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 21cbac72..eebd7708 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -225,6 +225,8 @@ Route::group(function () { //员工端-获取全部人员列表 Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); + //员工端-获取销售部门员工列表(根据校区筛选) + Route::get('personnel/getSalesPersonnelByCampus', 'apiController.Personnel/getSalesPersonnelByCampus'); //员工端-获取教练数据列表 Route::get('personnel/getCoachList', 'apiController.Personnel/getCoachList'); @@ -577,6 +579,7 @@ Route::group(function () { Route::post('student/attendance/leave', 'student.AttendanceController/leave'); // 学员取消 Route::post('student/attendance/cancel', 'student.AttendanceController/cancel'); + })->middleware(ApiChannel::class) ->middleware(ApiPersonnelCheckToken::class, true) ->middleware(ApiLog::class); diff --git a/niucloud/app/job/schedule/HandleCourseSchedule.php b/niucloud/app/job/schedule/HandleCourseSchedule.php index b42b8084..9de59a8a 100644 --- a/niucloud/app/job/schedule/HandleCourseSchedule.php +++ b/niucloud/app/job/schedule/HandleCourseSchedule.php @@ -51,42 +51,98 @@ class HandleCourseSchedule extends BaseJob try { Db::startTrans(); - // 批量更新,避免循环操作 - $yesterday = date('Y-m-d', strtotime('-1 day')); + $currentDate = date('Y-m-d'); + $currentTime = date('H:i:s'); + $currentDateTime = date('Y-m-d H:i:s'); - // 先查询需要更新的记录数量 - $totalCount = CourseSchedule::where('course_date', '<', date('Y-m-d')) - ->where('status', '<>', 'completed') // 避免重复更新已完成的课程 - ->count(); + // 先处理time_slot,解析并更新start_time和end_time字段 + $this->updateTimeFields(); + + $completedCount = 0; + $upcomingCount = 0; + $ongoingCount = 0; + $pendingCount = 0; + + // 1. 更新已完成课程:course_date < 当天的课程 + $completedRows = CourseSchedule::where('course_date', '<', $currentDate) + ->where('status', '<>', 'completed') + ->update([ + 'status' => 'completed', + 'updated_at' => time() + ]); + $completedCount = $completedRows; + + // 2. 处理今天的课程,需要根据时间段判断状态 + $todaySchedules = CourseSchedule::where('course_date', '=', $currentDate) + ->whereIn('status', ['pending', 'upcoming', 'ongoing']) + ->select(); + + foreach ($todaySchedules as $schedule) { + $startTime = $schedule['start_time']; + $endTime = $schedule['end_time']; + + if (empty($startTime) || empty($endTime)) { + // 如果没有解析出时间,尝试从time_slot解析 + $timeData = $this->parseTimeSlot($schedule['time_slot']); + if ($timeData) { + $startTime = $timeData['start_time']; + $endTime = $timeData['end_time']; + + // 更新数据库中的时间字段 + CourseSchedule::where('id', $schedule['id'])->update([ + 'start_time' => $startTime, + 'end_time' => $endTime + ]); + } else { + continue; // 无法解析时间,跳过 + } + } - if ($totalCount == 0) { - Log::write('没有需要更新状态的过期课程'); - Db::commit(); - return [ - 'status' => 'success', - 'total_count' => 0, - 'updated_count' => 0, - 'message' => '没有需要更新状态的过期课程' - ]; + // 判断课程状态 + $newStatus = $this->determineStatus($currentTime, $startTime, $endTime); + + if ($newStatus !== $schedule['status']) { + CourseSchedule::where('id', $schedule['id'])->update([ + 'status' => $newStatus, + 'updated_at' => time() + ]); + + switch ($newStatus) { + case 'upcoming': + $upcomingCount++; + break; + case 'ongoing': + $ongoingCount++; + break; + case 'completed': + $completedCount++; + break; + default: + $pendingCount++; + break; + } + } } - // 批量更新过期课程状态 - $affectedRows = CourseSchedule::where('course_date', '<', date('Y-m-d')) - ->where('status', '<>', 'completed') // 避免重复更新 + // 3. 重置未来日期的课程为pending状态 + $futureRows = CourseSchedule::where('course_date', '>', $currentDate) + ->where('status', '<>', 'pending') ->update([ - 'status' => 'completed', + 'status' => 'pending', 'updated_at' => time() ]); + $pendingCount += $futureRows; - Log::write('批量更新了' . $affectedRows . '个过期课程状态为已完成,总共检查了' . $totalCount . '个课程'); + Log::write("课程状态更新完成 - 已完成: {$completedCount}个, 即将开始: {$upcomingCount}个, 进行中: {$ongoingCount}个, 待安排: {$pendingCount}个"); Db::commit(); return [ 'status' => 'success', - 'total_count' => $totalCount, - 'updated_count' => $affectedRows, - 'message' => '成功更新' . $affectedRows . '个过期课程状态' + 'completed_count' => $completedCount, + 'upcoming_count' => $upcomingCount, + 'ongoing_count' => $ongoingCount, + 'pending_count' => $pendingCount ]; } catch (\Exception $e) { @@ -100,4 +156,87 @@ class HandleCourseSchedule extends BaseJob ]; } } + + /** + * 更新课程安排表的start_time和end_time字段 + */ + private function updateTimeFields() + { + try { + // 查询所有没有start_time或end_time的记录 + $schedules = CourseSchedule::where(function($query) { + $query->whereNull('start_time') + ->whereOr('end_time', null) + ->whereOr('start_time', '') + ->whereOr('end_time', ''); + })->select(); + + foreach ($schedules as $schedule) { + $timeData = $this->parseTimeSlot($schedule['time_slot']); + if ($timeData) { + CourseSchedule::where('id', $schedule['id'])->update([ + 'start_time' => $timeData['start_time'], + 'end_time' => $timeData['end_time'] + ]); + } + } + } catch (\Exception $e) { + Log::write('更新时间字段失败:' . $e->getMessage()); + } + } + + /** + * 解析time_slot字符串,提取开始和结束时间 + * @param string $timeSlot 格式如 "09:00-10:30" + * @return array|null + */ + private function parseTimeSlot($timeSlot) + { + if (empty($timeSlot)) { + return null; + } + + // 支持多种格式:09:00-10:30, 09:00~10:30, 9:00-10:30 + if (preg_match('/(\d{1,2}:\d{2})\s*[-~~]\s*(\d{1,2}:\d{2})/', $timeSlot, $matches)) { + return [ + 'start_time' => $matches[1], + 'end_time' => $matches[2] + ]; + } + + return null; + } + + /** + * 根据当前时间和课程时间段判断课程状态 + * @param string $currentTime 当前时间 H:i:s + * @param string $startTime 开始时间 H:i:s + * @param string $endTime 结束时间 H:i:s + * @return string + */ + private function determineStatus($currentTime, $startTime, $endTime) + { + $currentTimestamp = strtotime($currentTime); + $startTimestamp = strtotime($startTime); + $endTimestamp = strtotime($endTime); + + // 如果当前时间在课程时间段内,状态为进行中 + if ($currentTimestamp >= $startTimestamp && $currentTimestamp <= $endTimestamp) { + return 'ongoing'; + } + + // 如果课程已结束,状态为已完成 + if ($currentTimestamp > $endTimestamp) { + return 'completed'; + } + + // 如果距离开始时间不足6小时,状态为即将开始 + $timeDiff = $startTimestamp - $currentTimestamp; + if ($timeDiff <= 6 * 3600 && $timeDiff > 0) { // 6小时 = 6 * 60 * 60 秒 + return 'upcoming'; + } + + // 其他情况为待安排 + return 'pending'; + } } diff --git a/niucloud/app/job/transfer/schedule/CourseScheduleJob.php b/niucloud/app/job/transfer/schedule/CourseScheduleJob.php index b9d317c8..a280a184 100644 --- a/niucloud/app/job/transfer/schedule/CourseScheduleJob.php +++ b/niucloud/app/job/transfer/schedule/CourseScheduleJob.php @@ -206,12 +206,20 @@ class CourseScheduleJob extends BaseJob $newSchedule->course_id = $schedule->course_id; $newSchedule->auto_schedule = 1; $newSchedule->created_by = 'system'; + + // 解析时间段并填充start_time和end_time + $timeData = $this->parseTimeSlot($schedule->time_slot); + $newSchedule->start_time = $timeData ? $timeData['start_time'] : null; + $newSchedule->end_time = $timeData ? $timeData['end_time'] : null; + + // 根据课程日期确定初始状态 + $newSchedule->status = $this->determineInitialStatus($courseDate, $timeData); // 复制其他所有字段(除了id和主键相关字段) $attributes = $schedule->toArray(); foreach ($attributes as $key => $value) { - // 跳过id和主键相关字段 - if ($key !== 'id' && $key !== 'course_date' && $key !== 'auto_schedule') { + // 跳过id、主键相关字段和我们已经设置的字段 + if (!in_array($key, ['id', 'course_date', 'auto_schedule', 'start_time', 'end_time', 'status', 'created_by'])) { $newSchedule->$key = $value; } } @@ -220,4 +228,77 @@ class CourseScheduleJob extends BaseJob return $newSchedule; } + + /** + * 解析time_slot字符串,提取开始和结束时间 + * @param string $timeSlot 格式如 "09:00-10:30" + * @return array|null + */ + private function parseTimeSlot($timeSlot) + { + if (empty($timeSlot)) { + return null; + } + + // 支持多种格式:09:00-10:30, 09:00~10:30, 9:00-10:30 + if (preg_match('/(\d{1,2}:\d{2})\s*[-~~]\s*(\d{1,2}:\d{2})/', $timeSlot, $matches)) { + return [ + 'start_time' => $matches[1], + 'end_time' => $matches[2] + ]; + } + + return null; + } + + /** + * 根据课程日期和时间段确定初始状态 + * @param string $courseDate 课程日期 + * @param array|null $timeData 时间数据 + * @return string + */ + private function determineInitialStatus($courseDate, $timeData) + { + $currentDate = date('Y-m-d'); + $currentTime = date('H:i:s'); + + // 如果是过去的日期,直接标记为已完成 + if ($courseDate < $currentDate) { + return 'completed'; + } + + // 如果是未来的日期,标记为待安排 + if ($courseDate > $currentDate) { + return 'pending'; + } + + // 如果是今天且有时间数据,根据时间判断状态 + if ($courseDate === $currentDate && $timeData) { + $startTime = $timeData['start_time']; + $endTime = $timeData['end_time']; + + $currentTimestamp = strtotime($currentTime); + $startTimestamp = strtotime($startTime); + $endTimestamp = strtotime($endTime); + + // 如果当前时间在课程时间段内,状态为进行中 + if ($currentTimestamp >= $startTimestamp && $currentTimestamp <= $endTimestamp) { + return 'ongoing'; + } + + // 如果课程已结束,状态为已完成 + if ($currentTimestamp > $endTimestamp) { + return 'completed'; + } + + // 如果距离开始时间不足6小时,状态为即将开始 + $timeDiff = $startTimestamp - $currentTimestamp; + if ($timeDiff <= 6 * 3600 && $timeDiff > 0) { + return 'upcoming'; + } + } + + // 其他情况默认为待安排 + return 'pending'; + } } \ No newline at end of file diff --git a/niucloud/app/model/school/SchoolStudent.php b/niucloud/app/model/school/SchoolStudent.php index f9978dd8..9ce59acc 100644 --- a/niucloud/app/model/school/SchoolStudent.php +++ b/niucloud/app/model/school/SchoolStudent.php @@ -9,7 +9,7 @@ use core\base\BaseModel; */ class SchoolStudent extends BaseModel { - protected $name = 'student'; + protected $table = 'school_student'; protected $pk = 'id'; /** diff --git a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php index d8ada696..b0502e17 100644 --- a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php +++ b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php @@ -19,6 +19,7 @@ use app\model\sys\SysRole; use app\model\departments\Departments; use core\base\BaseAdminService; +use think\facade\Db; /** @@ -117,16 +118,15 @@ class CampusPersonRoleService extends BaseAdminService { $tasks = $data['tasks']; unset($data['tasks']); - if($this->model->where([['id', '<>', $id]])->where(['person_id' => $data['person_id']])->find()){ - return fail("重复操作"); - } +// if($this->model->where([['id', '<>', $id]])->where(['person_id' => $data['person_id']])->find()){ +// return fail("重复操作"); +// } if($tasks){ $personnel_summary = new PersonnelSummary(); $personnel_summary->where(['id' => $tasks['id']])->update(['task_num' => $tasks['task_num']]); } - $db = app()->db; - $data['dept_id'] = $db->table('school_sys_role')->where('role_id', $data['role_id'])->value('dept_id'); + $data['dept_id'] = Db::table('school_sys_role')->where('role_id', $data['role_id'])->value('dept_id'); $this->model->where([['id', '=', $id]])->update($data); return success("操作成功"); diff --git a/niucloud/app/service/admin/course_schedule/CourseScheduleService.php b/niucloud/app/service/admin/course_schedule/CourseScheduleService.php index 79a3f739..aa80f57b 100644 --- a/niucloud/app/service/admin/course_schedule/CourseScheduleService.php +++ b/niucloud/app/service/admin/course_schedule/CourseScheduleService.php @@ -73,16 +73,24 @@ class CourseScheduleService extends BaseAdminService */ public function add(array $data) { + // 解析时间段,填充start_time和end_time字段 + $timeData = $this->parseTimeSlot($data['time_slot']); + $create = [ 'campus_id' => $data['campus_id'], 'venue_id' => $data['venue_id'], 'course_date' => $data['course_date'], 'time_slot' => $data['time_slot'], + 'start_time' => $timeData ? $timeData['start_time'] : null, + 'end_time' => $timeData ? $timeData['end_time'] : null, 'course_id' => $data['course_id'], 'coach_id' => $data['coach_id'], 'auto_schedule' => $data['auto_schedule'], - 'available_capacity' => (new Venue())->where('id', $data['venue_id'])->value('capacity') + 'available_capacity' => (new Venue())->where('id', $data['venue_id'])->value('capacity'), + 'status' => $this->determineInitialStatus($data['course_date'], $timeData), + 'created_by' => 'manual' ]; + $status = $this->model->where([ ['course_date', '=', $data['course_date']], ['time_slot', '=', $data['time_slot']], @@ -105,15 +113,22 @@ class CourseScheduleService extends BaseAdminService */ public function edit(int $id, array $data) { + // 解析时间段,填充start_time和end_time字段 + $timeData = $this->parseTimeSlot($data['time_slot']); + $create = [ 'campus_id' => $data['campus_id'], 'venue_id' => $data['venue_id'], 'course_date' => $data['course_date'], 'time_slot' => $data['time_slot'], + 'start_time' => $timeData ? $timeData['start_time'] : null, + 'end_time' => $timeData ? $timeData['end_time'] : null, 'course_id' => $data['course_id'], 'coach_id' => $data['coach_id'], - 'auto_schedule' => $data['auto_schedule'] + 'auto_schedule' => $data['auto_schedule'], + 'status' => $this->determineInitialStatus($data['course_date'], $timeData) ]; + $status = $this->model->where([ ['course_date', '=', $data['course_date']], ['time_slot', '=', $data['time_slot']], @@ -323,4 +338,77 @@ class CourseScheduleService extends BaseAdminService ->where('id', $data)->findOrEmpty(); return $info->toArray(); } + + /** + * 解析time_slot字符串,提取开始和结束时间 + * @param string $timeSlot 格式如 "09:00-10:30" + * @return array|null + */ + private function parseTimeSlot($timeSlot) + { + if (empty($timeSlot)) { + return null; + } + + // 支持多种格式:09:00-10:30, 09:00~10:30, 9:00-10:30 + if (preg_match('/(\d{1,2}:\d{2})\s*[-~~]\s*(\d{1,2}:\d{2})/', $timeSlot, $matches)) { + return [ + 'start_time' => $matches[1], + 'end_time' => $matches[2] + ]; + } + + return null; + } + + /** + * 根据课程日期和时间段确定初始状态 + * @param string $courseDate 课程日期 + * @param array|null $timeData 时间数据 + * @return string + */ + private function determineInitialStatus($courseDate, $timeData) + { + $currentDate = date('Y-m-d'); + $currentTime = date('H:i:s'); + + // 如果是过去的日期,直接标记为已完成 + if ($courseDate < $currentDate) { + return 'completed'; + } + + // 如果是未来的日期,标记为待安排 + if ($courseDate > $currentDate) { + return 'pending'; + } + + // 如果是今天且有时间数据,根据时间判断状态 + if ($courseDate === $currentDate && $timeData) { + $startTime = $timeData['start_time']; + $endTime = $timeData['end_time']; + + $currentTimestamp = strtotime($currentTime); + $startTimestamp = strtotime($startTime); + $endTimestamp = strtotime($endTime); + + // 如果当前时间在课程时间段内,状态为进行中 + if ($currentTimestamp >= $startTimestamp && $currentTimestamp <= $endTimestamp) { + return 'ongoing'; + } + + // 如果课程已结束,状态为已完成 + if ($currentTimestamp > $endTimestamp) { + return 'completed'; + } + + // 如果距离开始时间不足6小时,状态为即将开始 + $timeDiff = $startTimestamp - $currentTimestamp; + if ($timeDiff <= 6 * 3600 && $timeDiff > 0) { + return 'upcoming'; + } + } + + // 其他情况默认为待安排 + return 'pending'; + } } diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index 9af672f7..7205cd09 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -20,6 +20,7 @@ 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 app\model\school\SchoolStudent; use core\base\BaseApiService; use think\facade\Db; use think\facade\Event; @@ -112,7 +113,7 @@ class CustomerResourcesService extends BaseApiService } //添加数据 - public function addData(array $customer_resources_data, array $six_speed_data) + public function addData(array $customer_resources_data, array $six_speed_data, array $student_data = [], $staff_id = 0, $role_id = 0) { $date = date('Y-m-d H:i:s'); $customer_resources_data['updated_at'] = $date; @@ -136,23 +137,32 @@ class CustomerResourcesService extends BaseApiService Db::rollback(); return $res; } - // 资源共享表新增记录 - $personnel = new Personnel(); - $role_id = $personnel->alias("a") - ->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left') - ->where(['a.id' => $customer_resources_data['consultant']]) - ->value('b.role_id'); + // 资源共享表新增记录 - 使用传入的staff_id和role_id $resourceSharing = new ResourceSharing(); $resourceSharing->insert([ 'resource_id' => $resource_id, - 'user_id' => $customer_resources_data['consultant'], - 'role_id' => $role_id + 'user_id' => $staff_id, // 使用传入的登录人staff_id + 'role_id' => $role_id // 使用传入的登录人role_id ]); // 转介绍奖励逻辑:当source=3且有referral_resource_id时发放奖励 if ($customer_resources_data['source'] == '3' && !empty($customer_resources_data['referral_resource_id'])) { $this->grantReferralReward($customer_resources_data['referral_resource_id'], $resource_id); } + // 添加school_student表记录 + if (!empty($student_data)) { + $student_data['user_id'] = $resource_id; // 设置user_id为新添加的客户资源ID + $student_data['updated_at'] = $date; + $student_data['created_at'] = $date; + + $studentAdd = SchoolStudent::create($student_data); + if (!$studentAdd) { + Db::rollback(); + $res['msg'] = '添加学员记录失败'; + return $res; + } + } + Db::commit(); $res = [ 'code' => 1, diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index d206da8e..9a430ce4 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -821,4 +821,73 @@ class PersonnelService extends BaseApiService } } + /** + * 获取销售部门员工列表(根据校区筛选) + * @param string $campus + * @return array + */ + public function getSalesPersonnelByCampus($campus = '') + { + try { + $where = []; + + // 查询销售部门(dept_id=3)下的所有角色ID + $salesRoleIds = SysRole::where('dept_id', 3) + ->where('status', 1) + ->column('role_id'); + + if (empty($salesRoleIds)) { + return [ + 'code' => 1, + 'msg' => '暂无销售部门角色', + 'data' => [] + ]; + } + + // 构建校区人员角色关系查询条件 + $campusPersonWhere = [ + ['role_id', 'in', $salesRoleIds] + ]; + + // 根据传入的校区进行筛选 + if (!empty($campus)) { + $campusPersonWhere[] = ['campus_id', '=', $campus]; + } + + // 查询符合条件的销售人员ID + $salesPersonIds = CampusPersonRole::where($campusPersonWhere) + ->column('person_id'); + + if (empty($salesPersonIds)) { + return [ + 'code' => 1, + 'msg' => '暂无销售人员数据', + 'data' => [] + ]; + } + + // 从personnel表中获取人员信息,包含姓名和电话 + $salesPersonnel = $this->model + ->whereIn('id', $salesPersonIds) + ->where('deleted_at', 0) // 只获取未删除的人员 + ->field('id, name, phone') + ->order('create_time DESC') + ->select() + ->toArray(); + + return [ + 'code' => 1, + 'msg' => '获取成功', + 'data' => $salesPersonnel + ]; + + } catch (\Exception $e) { + return [ + 'code' => 0, + 'msg' => '获取销售人员列表失败:' . $e->getMessage(), + 'data' => [] + ]; + } + } + } diff --git a/uniapp/api/apiRoute.js b/uniapp/api/apiRoute.js index ae70b09d..73c3c5df 100644 --- a/uniapp/api/apiRoute.js +++ b/uniapp/api/apiRoute.js @@ -258,6 +258,10 @@ export default { async common_getPersonnelAll(data = {}) { return await http.get('/personnel/getPersonnelAll', data) }, + //获取销售部门员工列表(根据校区筛选) + async getSalesPersonnelByCampus(data = {}) { + return await http.get('/personnel/getSalesPersonnelByCampus', data) + }, //公共端-获取教练数据列表 async common_getCoachList(data = {}) { return await http.get('/personnel/getCoachList', data) diff --git a/uniapp/pages-market/clue/add_clues.vue b/uniapp/pages-market/clue/add_clues.vue index 45f425de..afb395a0 100644 --- a/uniapp/pages-market/clue/add_clues.vue +++ b/uniapp/pages-market/clue/add_clues.vue @@ -211,29 +211,26 @@ - + - - {{ formData.birthday ? formData.birthday : '请选择生日' }} - - + @@ -279,7 +276,7 @@ 0 && age < 150) { - this.formData.age = age + const age = parseFloat(parsedData.age) + if (!isNaN(age) && age >= 0) { + this.formData.age = age.toString() + // 自动计算生日 + this.handleAgeBlur() fillCount++ } } @@ -1256,6 +1253,89 @@ export default { + //年龄失去焦点处理 - 计算生日 + handleAgeBlur() { + if (!this.formData.age) { + this.formData.birthday = '' + return + } + + const age = parseFloat(this.formData.age) + + // 验证年龄范围(大于等于0,支持小数) + if (isNaN(age) || age < 0) { + uni.showToast({ + title: '年龄请输入大于等于0的数字', + icon: 'none' + }) + this.formData.age = '' + this.formData.birthday = '' + return + } + + // 验证小数位数不超过2位 + const ageStr = this.formData.age.toString() + if (ageStr.includes('.') && ageStr.split('.')[1].length > 2) { + uni.showToast({ + title: '年龄小数最多保留2位', + icon: 'none' + }) + return + } + + try { + // 计算生日 + const today = new Date() + const currentYear = today.getFullYear() + const currentMonth = today.getMonth() + 1 // getMonth()返回0-11 + const currentDay = today.getDate() + + // 计算出生年份和月份 + const yearsOld = Math.floor(age) + const monthsOld = Math.round((age - yearsOld) * 12) + + let birthYear = currentYear - yearsOld + let birthMonth = currentMonth + 3 // 当前月份+3个月 + let birthDay = currentDay + + // 处理月份超过12的情况 + if (birthMonth > 12) { + birthYear += 1 + birthMonth -= 12 + } + + // 如果有额外的月份,需要调整年份 + if (monthsOld > 0) { + birthMonth -= monthsOld + if (birthMonth <= 0) { + birthYear -= 1 + birthMonth += 12 + } + } + + // 处理日期边界(避免2月30日等无效日期) + const maxDaysInMonth = new Date(birthYear, birthMonth, 0).getDate() + if (birthDay > maxDaysInMonth) { + birthDay = maxDaysInMonth + } + + // 格式化生日 + const formattedMonth = String(birthMonth).padStart(2, '0') + const formattedDay = String(birthDay).padStart(2, '0') + this.formData.birthday = `${birthYear}-${formattedMonth}-${formattedDay}` + + console.log(`年龄: ${age}岁, 计算出的生日: ${this.formData.birthday}`) + + } catch (error) { + console.error('计算生日失败:', error) + uni.showToast({ + title: '生日计算失败,请重新输入', + icon: 'none' + }) + this.formData.birthday = '' + } + }, + //联系电话失去焦点时间 async handlePhoneBlur(){ if(!this.formData.phone_number){ @@ -1574,74 +1654,6 @@ export default { this.date_picker_show = false }, - // 打开生日选择器 - openBirthdayPicker() { - console.log('打开生日选择器') - this.picker_show_birthday = true - }, - - // 关闭生日选择器 - closeBirthdayPicker() { - console.log('关闭生日选择器') - this.picker_show_birthday = false - }, - - // 获取生日选择器的当前值 - getCurrentBirthdayValue() { - if (this.formData.birthday) { - return this.formData.birthday - } - // 默认返回30年前的日期作为初始值 - const defaultDate = new Date() - defaultDate.setFullYear(defaultDate.getFullYear() - 30) - return this.formatDate(defaultDate) - }, - - //生日选择器 - changePickerBirthday(e) { - console.log('生日选择器返回数据:', e) - let val = '' - - // 尝试多种方式获取返回值 - if (e.result) { - val = e.result - } else if (e.value) { - val = e.value - } else if (e.detail && e.detail.result) { - val = e.detail.result - } else if (e.detail && e.detail.value) { - val = e.detail.value - } else if (Array.isArray(e) && e.length >= 3) { - // 如果返回数组格式 [2023, 1, 15] - const year = e[0] - const month = String(e[1]).padStart(2, '0') - const day = String(e[2]).padStart(2, '0') - val = `${year}-${month}-${day}` - } - - // 处理不同的日期格式 - if (val && typeof val === 'string') { - // 如果是时间戳格式 - if (/^\d+$/.test(val)) { - const date = new Date(parseInt(val)) - val = this.formatDate(date) - } - // 如果包含时间部分,只保留日期部分 - else if (val.includes('T')) { - val = val.split('T')[0] - } - // 如果包含空格,只保留日期部分 - else if (val.includes(' ')) { - val = val.split(' ')[0] - } - // 统一日期格式 - val = this.normalizeDate(val) - } - - console.log('最终设置的生日值:', val) - this.formData.birthday = val - this.closeBirthdayPicker() - }, //下一步 index|0=添加客户,1六要素 async nextStep(index) { diff --git a/uniapp/pages-market/clue/index.vue b/uniapp/pages-market/clue/index.vue index ebe5d2f8..f48fe810 100644 --- a/uniapp/pages-market/clue/index.vue +++ b/uniapp/pages-market/clue/index.vue @@ -31,13 +31,16 @@ 所属校区:{{ v.customerResource.campus_name }} - 来源:{{ v.customerResource.source }} + 渠道:{{ v.customerResource.source }} - 来源渠道:{{ v.customerResource.source_channel }} + 线上渠道:{{ v.customerResource.source_channel }} 到访备注:{{ v.sixSpeed.consultation_remark || '' }} + + + 市场老师:{{ v.sixSpeed.consultation_remark || '' }} @@ -551,12 +554,10 @@ }, - //获取全部员工 + //获取销售部门员工(根据校区筛选) async getPersonnelAll(campus = '') { - let res = await apiRoute.common_getPersonnelAll({ - personnel_id: this.userInfo.id, //客户id - account_type: 'market', //账号类型|teacher=老师,market=销售 - campus: campus + let res = await apiRoute.getSalesPersonnelByCampus({ + campus: campus // 传入校区参数 }) if (res.code != 1) { uni.showToast({ @@ -568,13 +569,15 @@ let arr = [] res.data.forEach((v, k) => { + // 拼接姓名和电话显示 + let displayText = `${v.name} ${v.phone}` arr.push({ - text: v.name, + text: displayText, value: v.id, }) }) this.select_options = arr - console.log('员工', this.select_options) + console.log('销售部门员工', this.select_options) }, //获取列表-我的客户相关