Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
f6002d7b57
  1. 40
      niucloud/app/api/controller/apiController/CustomerResources.php
  2. 12
      niucloud/app/api/controller/apiController/Personnel.php
  3. 1
      niucloud/app/api/controller/apiController/Test.php
  4. 3
      niucloud/app/api/route/route.php
  5. 185
      niucloud/app/job/schedule/HandleCourseSchedule.php
  6. 85
      niucloud/app/job/transfer/schedule/CourseScheduleJob.php
  7. 2
      niucloud/app/model/school/SchoolStudent.php
  8. 10
      niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php
  9. 92
      niucloud/app/service/admin/course_schedule/CourseScheduleService.php
  10. 28
      niucloud/app/service/api/apiService/CustomerResourcesService.php
  11. 69
      niucloud/app/service/api/apiService/PersonnelService.php
  12. 4
      uniapp/api/apiRoute.js
  13. 202
      uniapp/pages-market/clue/add_clues.vue
  14. 21
      uniapp/pages-market/clue/index.vue

40
niucloud/app/api/controller/apiController/CustomerResources.php

@ -24,6 +24,23 @@ use core\base\BaseApiService;
class CustomerResources extends 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) public function getAll(Request $request)
@ -61,7 +78,7 @@ class CustomerResources extends BaseApiService
$personnel = new Personnel(); $personnel = new Personnel();
$role_id = $personnel->alias("a") $role_id = $personnel->alias("a")
->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left') ->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'); ->value('b.role_id');
$customer_resources_data = [ $customer_resources_data = [
@ -69,8 +86,9 @@ class CustomerResources extends BaseApiService
"create_date" => $date, "create_date" => $date,
"source_channel" => $param['source_channel'] ?? '', "source_channel" => $param['source_channel'] ?? '',
"source" => $param['source'] ?? '', "source" => $param['source'] ?? '',
"consultant" => $param['consultant'] ?? 0, "consultant" => 0, // 设置为0而不是当前登录人
"name" => $param['name'] ?? '', "name" => $param['name'] ?? '',
"age" => $param['age'] ?? '', // 添加年龄字段
"gender" => $param['gender'] ?? 'other',//性别 "gender" => $param['gender'] ?? 'other',//性别
"phone_number" => $param['phone_number'] ?? '', "phone_number" => $param['phone_number'] ?? '',
"demand" => $param['demand'] ?? '', "demand" => $param['demand'] ?? '',
@ -109,7 +127,23 @@ class CustomerResources extends BaseApiService
return fail("手机号已存在"); 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']) { if (!$res['code']) {
return fail($res['msg']); return fail($res['msg']);
} }

12
niucloud/app/api/controller/apiController/Personnel.php

@ -93,6 +93,18 @@ class Personnel extends BaseApiService
return success($res); 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){ public function checkOldPwd(Request $request){
//获取员工信息 //获取员工信息

1
niucloud/app/api/controller/apiController/Test.php

@ -43,4 +43,5 @@ class Test extends BaseApiService
return success($res); return success($res);
} }
} }

3
niucloud/app/api/route/route.php

@ -225,6 +225,8 @@ Route::group(function () {
//员工端-获取全部人员列表 //员工端-获取全部人员列表
Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll');
//员工端-获取销售部门员工列表(根据校区筛选)
Route::get('personnel/getSalesPersonnelByCampus', 'apiController.Personnel/getSalesPersonnelByCampus');
//员工端-获取教练数据列表 //员工端-获取教练数据列表
Route::get('personnel/getCoachList', 'apiController.Personnel/getCoachList'); 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/leave', 'student.AttendanceController/leave');
// 学员取消 // 学员取消
Route::post('student/attendance/cancel', 'student.AttendanceController/cancel'); Route::post('student/attendance/cancel', 'student.AttendanceController/cancel');
})->middleware(ApiChannel::class) })->middleware(ApiChannel::class)
->middleware(ApiPersonnelCheckToken::class, true) ->middleware(ApiPersonnelCheckToken::class, true)
->middleware(ApiLog::class); ->middleware(ApiLog::class);

185
niucloud/app/job/schedule/HandleCourseSchedule.php

@ -51,42 +51,98 @@ class HandleCourseSchedule extends BaseJob
try { try {
Db::startTrans(); Db::startTrans();
// 批量更新,避免循环操作 $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 day')); $currentTime = date('H:i:s');
$currentDateTime = date('Y-m-d H:i:s');
// 先查询需要更新的记录数量 // 先处理time_slot,解析并更新start_time和end_time字段
$totalCount = CourseSchedule::where('course_date', '<', date('Y-m-d')) $this->updateTimeFields();
->where('status', '<>', 'completed') // 避免重复更新已完成的课程
->count();
if ($totalCount == 0) { $completedCount = 0;
Log::write('没有需要更新状态的过期课程'); $upcomingCount = 0;
Db::commit(); $ongoingCount = 0;
return [ $pendingCount = 0;
'status' => 'success',
'total_count' => 0,
'updated_count' => 0,
'message' => '没有需要更新状态的过期课程'
];
}
// 批量更新过期课程状态 // 1. 更新已完成课程:course_date < 当天的课程
$affectedRows = CourseSchedule::where('course_date', '<', date('Y-m-d')) $completedRows = CourseSchedule::where('course_date', '<', $currentDate)
->where('status', '<>', 'completed') // 避免重复更新 ->where('status', '<>', 'completed')
->update([ ->update([
'status' => 'completed', 'status' => 'completed',
'updated_at' => time() 'updated_at' => time()
]); ]);
$completedCount = $completedRows;
// 2. 处理今天的课程,需要根据时间段判断状态
$todaySchedules = CourseSchedule::where('course_date', '=', $currentDate)
->whereIn('status', ['pending', 'upcoming', 'ongoing'])
->select();
Log::write('批量更新了' . $affectedRows . '个过期课程状态为已完成,总共检查了' . $totalCount . '个课程'); 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; // 无法解析时间,跳过
}
}
// 判断课程状态
$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;
}
}
}
// 3. 重置未来日期的课程为pending状态
$futureRows = CourseSchedule::where('course_date', '>', $currentDate)
->where('status', '<>', 'pending')
->update([
'status' => 'pending',
'updated_at' => time()
]);
$pendingCount += $futureRows;
Log::write("课程状态更新完成 - 已完成: {$completedCount}个, 即将开始: {$upcomingCount}个, 进行中: {$ongoingCount}个, 待安排: {$pendingCount}个");
Db::commit(); Db::commit();
return [ return [
'status' => 'success', 'status' => 'success',
'total_count' => $totalCount, 'completed_count' => $completedCount,
'updated_count' => $affectedRows, 'upcoming_count' => $upcomingCount,
'message' => '成功更新' . $affectedRows . '个过期课程状态' 'ongoing_count' => $ongoingCount,
'pending_count' => $pendingCount
]; ];
} catch (\Exception $e) { } 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';
}
} }

85
niucloud/app/job/transfer/schedule/CourseScheduleJob.php

@ -207,11 +207,19 @@ class CourseScheduleJob extends BaseJob
$newSchedule->auto_schedule = 1; $newSchedule->auto_schedule = 1;
$newSchedule->created_by = 'system'; $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和主键相关字段) // 复制其他所有字段(除了id和主键相关字段)
$attributes = $schedule->toArray(); $attributes = $schedule->toArray();
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
// 跳过id和主键相关字段 // 跳过id、主键相关字段和我们已经设置的字段
if ($key !== 'id' && $key !== 'course_date' && $key !== 'auto_schedule') { if (!in_array($key, ['id', 'course_date', 'auto_schedule', 'start_time', 'end_time', 'status', 'created_by'])) {
$newSchedule->$key = $value; $newSchedule->$key = $value;
} }
} }
@ -220,4 +228,77 @@ class CourseScheduleJob extends BaseJob
return $newSchedule; 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';
}
} }

2
niucloud/app/model/school/SchoolStudent.php

@ -9,7 +9,7 @@ use core\base\BaseModel;
*/ */
class SchoolStudent extends BaseModel class SchoolStudent extends BaseModel
{ {
protected $name = 'student'; protected $table = 'school_student';
protected $pk = 'id'; protected $pk = 'id';
/** /**

10
niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php

@ -19,6 +19,7 @@ use app\model\sys\SysRole;
use app\model\departments\Departments; use app\model\departments\Departments;
use core\base\BaseAdminService; use core\base\BaseAdminService;
use think\facade\Db;
/** /**
@ -117,16 +118,15 @@ class CampusPersonRoleService extends BaseAdminService
{ {
$tasks = $data['tasks']; $tasks = $data['tasks'];
unset($data['tasks']); unset($data['tasks']);
if($this->model->where([['id', '<>', $id]])->where(['person_id' => $data['person_id']])->find()){ // if($this->model->where([['id', '<>', $id]])->where(['person_id' => $data['person_id']])->find()){
return fail("重复操作"); // return fail("重复操作");
} // }
if($tasks){ if($tasks){
$personnel_summary = new PersonnelSummary(); $personnel_summary = new PersonnelSummary();
$personnel_summary->where(['id' => $tasks['id']])->update(['task_num' => $tasks['task_num']]); $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); $this->model->where([['id', '=', $id]])->update($data);
return success("操作成功"); return success("操作成功");

92
niucloud/app/service/admin/course_schedule/CourseScheduleService.php

@ -73,16 +73,24 @@ class CourseScheduleService extends BaseAdminService
*/ */
public function add(array $data) public function add(array $data)
{ {
// 解析时间段,填充start_time和end_time字段
$timeData = $this->parseTimeSlot($data['time_slot']);
$create = [ $create = [
'campus_id' => $data['campus_id'], 'campus_id' => $data['campus_id'],
'venue_id' => $data['venue_id'], 'venue_id' => $data['venue_id'],
'course_date' => $data['course_date'], 'course_date' => $data['course_date'],
'time_slot' => $data['time_slot'], 'time_slot' => $data['time_slot'],
'start_time' => $timeData ? $timeData['start_time'] : null,
'end_time' => $timeData ? $timeData['end_time'] : null,
'course_id' => $data['course_id'], 'course_id' => $data['course_id'],
'coach_id' => $data['coach_id'], 'coach_id' => $data['coach_id'],
'auto_schedule' => $data['auto_schedule'], '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([ $status = $this->model->where([
['course_date', '=', $data['course_date']], ['course_date', '=', $data['course_date']],
['time_slot', '=', $data['time_slot']], ['time_slot', '=', $data['time_slot']],
@ -105,15 +113,22 @@ class CourseScheduleService extends BaseAdminService
*/ */
public function edit(int $id, array $data) public function edit(int $id, array $data)
{ {
// 解析时间段,填充start_time和end_time字段
$timeData = $this->parseTimeSlot($data['time_slot']);
$create = [ $create = [
'campus_id' => $data['campus_id'], 'campus_id' => $data['campus_id'],
'venue_id' => $data['venue_id'], 'venue_id' => $data['venue_id'],
'course_date' => $data['course_date'], 'course_date' => $data['course_date'],
'time_slot' => $data['time_slot'], 'time_slot' => $data['time_slot'],
'start_time' => $timeData ? $timeData['start_time'] : null,
'end_time' => $timeData ? $timeData['end_time'] : null,
'course_id' => $data['course_id'], 'course_id' => $data['course_id'],
'coach_id' => $data['coach_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([ $status = $this->model->where([
['course_date', '=', $data['course_date']], ['course_date', '=', $data['course_date']],
['time_slot', '=', $data['time_slot']], ['time_slot', '=', $data['time_slot']],
@ -323,4 +338,77 @@ class CourseScheduleService extends BaseAdminService
->where('id', $data)->findOrEmpty(); ->where('id', $data)->findOrEmpty();
return $info->toArray(); 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';
}
} }

28
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\resource_sharing\ResourceSharing;
use app\model\six_speed\SixSpeed; use app\model\six_speed\SixSpeed;
use app\model\six_speed_modification_log\SixSpeedModificationLog; use app\model\six_speed_modification_log\SixSpeedModificationLog;
use app\model\school\SchoolStudent;
use core\base\BaseApiService; use core\base\BaseApiService;
use think\facade\Db; use think\facade\Db;
use think\facade\Event; 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'); $date = date('Y-m-d H:i:s');
$customer_resources_data['updated_at'] = $date; $customer_resources_data['updated_at'] = $date;
@ -136,23 +137,32 @@ class CustomerResourcesService extends BaseApiService
Db::rollback(); Db::rollback();
return $res; return $res;
} }
// 资源共享表新增记录 // 资源共享表新增记录 - 使用传入的staff_id和role_id
$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');
$resourceSharing = new ResourceSharing(); $resourceSharing = new ResourceSharing();
$resourceSharing->insert([ $resourceSharing->insert([
'resource_id' => $resource_id, 'resource_id' => $resource_id,
'user_id' => $customer_resources_data['consultant'], 'user_id' => $staff_id, // 使用传入的登录人staff_id
'role_id' => $role_id 'role_id' => $role_id // 使用传入的登录人role_id
]); ]);
// 转介绍奖励逻辑:当source=3且有referral_resource_id时发放奖励 // 转介绍奖励逻辑:当source=3且有referral_resource_id时发放奖励
if ($customer_resources_data['source'] == '3' && !empty($customer_resources_data['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); $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(); Db::commit();
$res = [ $res = [
'code' => 1, 'code' => 1,

69
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' => []
];
}
}
} }

4
uniapp/api/apiRoute.js

@ -258,6 +258,10 @@ export default {
async common_getPersonnelAll(data = {}) { async common_getPersonnelAll(data = {}) {
return await http.get('/personnel/getPersonnelAll', data) return await http.get('/personnel/getPersonnelAll', data)
}, },
//获取销售部门员工列表(根据校区筛选)
async getSalesPersonnelByCampus(data = {}) {
return await http.get('/personnel/getSalesPersonnelByCampus', data)
},
//公共端-获取教练数据列表 //公共端-获取教练数据列表
async common_getCoachList(data = {}) { async common_getCoachList(data = {}) {
return await http.get('/personnel/getCoachList', data) return await http.get('/personnel/getCoachList', data)

202
uniapp/pages-market/clue/add_clues.vue

@ -211,29 +211,26 @@
</view> </view>
</fui-form-item> </fui-form-item>
<!--生日--> <!--年龄-->
<fui-form-item <fui-form-item
label="生日" label="年龄"
labelSize='26' labelSize='26'
prop="birthday" prop="age"
background='#434544' background='#434544'
labelColor='#fff' labelColor='#fff'
:bottomBorder='false'> :bottomBorder='false'>
<view class="input-title" style="margin-right:14rpx;"> <view class="input-title" style="margin-right:14rpx;">
<view <fui-input
@click="openBirthdayPicker" :borderBottom="false"
style="color: #fff; cursor: pointer;"> :padding="[0]"
{{ formData.birthday ? formData.birthday : '请选择生日' }} placeholder="请输入年龄(如5.3)"
</view> v-model="formData.age"
<fui-date-picker backgroundColor="#434544"
:show="picker_show_birthday" size="26"
type="3" color="#fff"
:minDate="minDate" type="digit"
:maxDate="maxDate" @blur="handleAgeBlur"
:value="getCurrentBirthdayValue()" ></fui-input>
@change="changePickerBirthday"
@cancel="closeBirthdayPicker"
></fui-date-picker>
</view> </view>
</fui-form-item> </fui-form-item>
@ -279,7 +276,7 @@
<!--客户初步意向度--> <!--客户初步意向度-->
<fui-form-item <fui-form-item
label="客户初步意向度" label="客户初步意向度"
labelWidth="240"
labelSize='26' labelSize='26'
prop="" prop=""
background='#434544' background='#434544'
@ -370,6 +367,7 @@
<!--可选上课时间--> <!--可选上课时间-->
<fui-form-item <fui-form-item
label="可选上课时间" label="可选上课时间"
labelWidth="240"
labelSize='26' labelSize='26'
prop="" prop=""
background='#434544' background='#434544'
@ -389,6 +387,7 @@
<fui-form-item <fui-form-item
label="承诺到访时间" label="承诺到访时间"
labelSize='26' labelSize='26'
labelWidth="240"
prop="" prop=""
background='#434544' background='#434544'
labelColor='#fff' labelColor='#fff'
@ -616,14 +615,14 @@ export default {
source:'',// source:'',//
consultant:'',// consultant:'',//
name:'',// name:'',//
age:'',// age:'',//()
gender:'male',//|male-, female-, other- gender:'male',//|male-, female-, other-
phone_number:'',// phone_number:'',//
demand:'',// demand:'',//
decision_maker:'',// decision_maker:'',//
initial_intent:'',//: high-, medium-, low- initial_intent:'',//: high-, medium-, low-
status:'pending',//: active-, inactive-, pending- status:'pending',//: active-, inactive-, pending-
birthday:'',// birthday:'',//()
// //
purchasing_power:'',// purchasing_power:'',//
@ -709,10 +708,6 @@ export default {
data_picker_input_name:'',//input_name data_picker_input_name:'',//input_name
date_picker_show:false,// date_picker_show:false,//
//
picker_show_birthday: false,
minDate: '1900-01-01', //
maxDate: new Date().toISOString().split('T')[0], //
@ -862,9 +857,11 @@ export default {
fillCount++ fillCount++
} }
if (parsedData.age) { if (parsedData.age) {
const age = parseInt(parsedData.age) const age = parseFloat(parsedData.age)
if (!isNaN(age) && age > 0 && age < 150) { if (!isNaN(age) && age >= 0) {
this.formData.age = age this.formData.age = age.toString()
//
this.handleAgeBlur()
fillCount++ 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
}
}
// 230
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(){ async handlePhoneBlur(){
if(!this.formData.phone_number){ if(!this.formData.phone_number){
@ -1574,74 +1654,6 @@ export default {
this.date_picker_show = false 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 // index|0=,1
async nextStep(index) { async nextStep(index) {

21
uniapp/pages-market/clue/index.vue

@ -31,13 +31,16 @@
所属校区{{ v.customerResource.campus_name }} 所属校区{{ v.customerResource.campus_name }}
</view> </view>
<view class="card-con"> <view class="card-con">
来源{{ v.customerResource.source }} 渠道{{ v.customerResource.source }}
</view> </view>
<view class="card-con" v-if="v.customerResource.source_channel"> <view class="card-con" v-if="v.customerResource.source_channel">
来源渠道{{ v.customerResource.source_channel }} 线上渠道{{ v.customerResource.source_channel }}
</view> </view>
<view class="card-con" v-if="v.sixSpeed && v.sixSpeed.consultation_remark"> <view class="card-con" v-if="v.sixSpeed && v.sixSpeed.consultation_remark">
到访备注{{ v.sixSpeed.consultation_remark || '' }} 到访备注{{ v.sixSpeed.consultation_remark || '' }}
</view>
<view class="card-con" v-if="v.sixSpeed && v.sixSpeed.consultation_remark">
市场老师{{ v.sixSpeed.consultation_remark || '' }}
</view> </view>
</view> </view>
<view class="card-right"> <view class="card-right">
@ -551,12 +554,10 @@
}, },
// //
async getPersonnelAll(campus = '') { async getPersonnelAll(campus = '') {
let res = await apiRoute.common_getPersonnelAll({ let res = await apiRoute.getSalesPersonnelByCampus({
personnel_id: this.userInfo.id, //id campus: campus //
account_type: 'market', //|teacher=,market=
campus: campus
}) })
if (res.code != 1) { if (res.code != 1) {
uni.showToast({ uni.showToast({
@ -568,13 +569,15 @@
let arr = [] let arr = []
res.data.forEach((v, k) => { res.data.forEach((v, k) => {
//
let displayText = `${v.name} ${v.phone}`
arr.push({ arr.push({
text: v.name, text: displayText,
value: v.id, value: v.id,
}) })
}) })
this.select_options = arr this.select_options = arr
console.log('员工', this.select_options) console.log('销售部门员工', this.select_options)
}, },
//- //-

Loading…
Cancel
Save