|
|
@ -144,11 +144,11 @@ class CustomerResourcesService extends BaseApiService |
|
|
'resource_id' => $resource_id, |
|
|
'resource_id' => $resource_id, |
|
|
'assignee_type' => 'user', |
|
|
'assignee_type' => 'user', |
|
|
'assignee_id' => $assignee_id, |
|
|
'assignee_id' => $assignee_id, |
|
|
'is_primary' => 1, |
|
|
'is_primary' => 0, |
|
|
'assigned_by' => 0, |
|
|
'assigned_by' => 0, |
|
|
'assigned_at' => date("Y-m-d H:i:s"), |
|
|
'assigned_at' => date("Y-m-d H:i:s"), |
|
|
'campus_id' => $customer_resources_data['campus'], |
|
|
'campus_id' => $customer_resources_data['campus'], |
|
|
'assigned_source' => 'api' |
|
|
'assigned_source' => 'add' |
|
|
]); |
|
|
]); |
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
// 如果插入失败,记录日志但不影响主流程 |
|
|
// 如果插入失败,记录日志但不影响主流程 |
|
|
@ -164,7 +164,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
$student_data['user_id'] = $resource_id; // 设置user_id为新添加的客户资源ID |
|
|
$student_data['user_id'] = $resource_id; // 设置user_id为新添加的客户资源ID |
|
|
$student_data['updated_at'] = $date; |
|
|
$student_data['updated_at'] = $date; |
|
|
$student_data['created_at'] = $date; |
|
|
$student_data['created_at'] = $date; |
|
|
|
|
|
|
|
|
$studentAdd = SchoolStudent::create($student_data); |
|
|
$studentAdd = SchoolStudent::create($student_data); |
|
|
if (!$studentAdd) { |
|
|
if (!$studentAdd) { |
|
|
Db::rollback(); |
|
|
Db::rollback(); |
|
|
@ -720,7 +720,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
// 奖励配置(可以后续移到配置文件中) |
|
|
// 奖励配置(可以后续移到配置文件中) |
|
|
$rewardConfig = [ |
|
|
$rewardConfig = [ |
|
|
'gift_name' => '转介绍奖励', |
|
|
'gift_name' => '转介绍奖励', |
|
|
'gift_type' => 'referral_reward', |
|
|
'gift_type' => 'referral_reward', |
|
|
'reward_amount' => 100, // 奖励金额,可配置 |
|
|
'reward_amount' => 100, // 奖励金额,可配置 |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
@ -740,7 +740,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
Db::table('shcool_resources_gift')->insert($giftData); |
|
|
Db::table('shcool_resources_gift')->insert($giftData); |
|
|
|
|
|
|
|
|
Log::info("转介绍奖励发放成功:推荐人ID $referral_resource_id,新客户ID $new_resource_id"); |
|
|
Log::info("转介绍奖励发放成功:推荐人ID $referral_resource_id,新客户ID $new_resource_id"); |
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
@ -754,36 +754,36 @@ class CustomerResourcesService extends BaseApiService |
|
|
if (empty($data['id'])) { |
|
|
if (empty($data['id'])) { |
|
|
return ['code' => false, 'msg' => '缺少必要参数id']; |
|
|
return ['code' => false, 'msg' => '缺少必要参数id']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// 更新school_student_courses表中的字段 |
|
|
// 更新school_student_courses表中的字段 |
|
|
$update_data = []; |
|
|
$update_data = []; |
|
|
|
|
|
|
|
|
// 更新主教练ID |
|
|
// 更新主教练ID |
|
|
if (isset($data['main_coach_id'])) { |
|
|
if (isset($data['main_coach_id'])) { |
|
|
$update_data['main_coach_id'] = $data['main_coach_id']; |
|
|
$update_data['main_coach_id'] = $data['main_coach_id']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 更新助教IDs |
|
|
// 更新助教IDs |
|
|
if (isset($data['assistant_ids'])) { |
|
|
if (isset($data['assistant_ids'])) { |
|
|
$update_data['assistant_ids'] = $data['assistant_ids']; |
|
|
$update_data['assistant_ids'] = $data['assistant_ids']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 更新教务ID |
|
|
// 更新教务ID |
|
|
if (isset($data['education_id'])) { |
|
|
if (isset($data['education_id'])) { |
|
|
$update_data['education_id'] = $data['education_id']; |
|
|
$update_data['education_id'] = $data['education_id']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 如果没有需要更新的数据,直接返回成功 |
|
|
// 如果没有需要更新的数据,直接返回成功 |
|
|
if (empty($update_data)) { |
|
|
if (empty($update_data)) { |
|
|
return ['code' => true, 'msg' => '更新成功']; |
|
|
return ['code' => true, 'msg' => '更新成功']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 执行更新操作 |
|
|
// 执行更新操作 |
|
|
$res = \think\facade\Db::name('student_courses') |
|
|
$res = \think\facade\Db::name('student_courses') |
|
|
->where('id', $data['id']) |
|
|
->where('id', $data['id']) |
|
|
->update($update_data); |
|
|
->update($update_data); |
|
|
|
|
|
|
|
|
if ($res !== false) { |
|
|
if ($res !== false) { |
|
|
return ['code' => true, 'msg' => '更新成功']; |
|
|
return ['code' => true, 'msg' => '更新成功']; |
|
|
} else { |
|
|
} else { |
|
|
@ -803,11 +803,11 @@ class CustomerResourcesService extends BaseApiService |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
$resource_id = $where['resource_id'] ?? 0; |
|
|
$resource_id = $where['resource_id'] ?? 0; |
|
|
|
|
|
|
|
|
if (empty($resource_id)) { |
|
|
if (empty($resource_id)) { |
|
|
return ['code' => false, 'msg' => '缺少客户资源ID']; |
|
|
return ['code' => false, 'msg' => '缺少客户资源ID']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 查询赠品记录,同时关联查询赠送人信息 |
|
|
// 查询赠品记录,同时关联查询赠送人信息 |
|
|
$gift_records = Db::table('shcool_resources_gift') |
|
|
$gift_records = Db::table('shcool_resources_gift') |
|
|
->alias('g') |
|
|
->alias('g') |
|
|
@ -824,7 +824,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
->order('g.create_time', 'desc') |
|
|
->order('g.create_time', 'desc') |
|
|
->select() |
|
|
->select() |
|
|
->toArray(); |
|
|
->toArray(); |
|
|
|
|
|
|
|
|
// 处理数据格式 |
|
|
// 处理数据格式 |
|
|
$formatted_records = []; |
|
|
$formatted_records = []; |
|
|
foreach ($gift_records as $record) { |
|
|
foreach ($gift_records as $record) { |
|
|
@ -846,13 +846,13 @@ class CustomerResourcesService extends BaseApiService |
|
|
'create_time' => date('Y-m-d H:i:s', $record['create_time']) |
|
|
'create_time' => date('Y-m-d H:i:s', $record['create_time']) |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return [ |
|
|
return [ |
|
|
'code' => true, |
|
|
'code' => true, |
|
|
'msg' => '获取成功', |
|
|
'msg' => '获取成功', |
|
|
'data' => $formatted_records |
|
|
'data' => $formatted_records |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
Log::error('获取赠品记录失败:' . $e->getMessage()); |
|
|
Log::error('获取赠品记录失败:' . $e->getMessage()); |
|
|
return [ |
|
|
return [ |
|
|
@ -876,7 +876,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
'activity_reward' => '活动奖励', |
|
|
'activity_reward' => '活动奖励', |
|
|
'other' => '其他' |
|
|
'other' => '其他' |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
return $type_map[$gift_type] ?? $gift_type; |
|
|
return $type_map[$gift_type] ?? $gift_type; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -892,7 +892,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
1 => '可使用', |
|
|
1 => '可使用', |
|
|
2 => '已使用' |
|
|
2 => '已使用' |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
return $status_map[$gift_status] ?? '未知状态'; |
|
|
return $status_map[$gift_status] ?? '未知状态'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -986,7 +986,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
'msg' => '操作失败', |
|
|
'msg' => '操作失败', |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// 构建查询条件 |
|
|
// 构建查询条件 |
|
|
$query = Db::table('school_student') |
|
|
$query = Db::table('school_student') |
|
|
@ -994,17 +994,17 @@ class CustomerResourcesService extends BaseApiService |
|
|
->leftJoin('school_student_courses sc', 's.id = sc.student_id') |
|
|
->leftJoin('school_student_courses sc', 's.id = sc.student_id') |
|
|
->where('s.deleted_at', 0) |
|
|
->where('s.deleted_at', 0) |
|
|
->where('s.status', 1); // 只查询状态正常的学员 |
|
|
->where('s.status', 1); // 只查询状态正常的学员 |
|
|
|
|
|
|
|
|
// 按姓名搜索 |
|
|
// 按姓名搜索 |
|
|
if (!empty($where['name'])) { |
|
|
if (!empty($where['name'])) { |
|
|
$query->where('s.name', 'like', "%{$where['name']}%"); |
|
|
$query->where('s.name', 'like', "%{$where['name']}%"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 按手机号搜索 |
|
|
// 按手机号搜索 |
|
|
if (!empty($where['phone_number'])) { |
|
|
if (!empty($where['phone_number'])) { |
|
|
$query->where('s.contact_phone', 'like', "%{$where['phone_number']}%"); |
|
|
$query->where('s.contact_phone', 'like', "%{$where['phone_number']}%"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取学员基本信息和课程信息 |
|
|
// 获取学员基本信息和课程信息 |
|
|
$students = $query |
|
|
$students = $query |
|
|
->field([ |
|
|
->field([ |
|
|
@ -1033,22 +1033,22 @@ class CustomerResourcesService extends BaseApiService |
|
|
->group('s.id') |
|
|
->group('s.id') |
|
|
->order('s.created_at DESC') |
|
|
->order('s.created_at DESC') |
|
|
->select(); |
|
|
->select(); |
|
|
|
|
|
|
|
|
if (!$students) { |
|
|
if (!$students) { |
|
|
$res['msg'] = '暂无学员数据'; |
|
|
$res['msg'] = '暂无学员数据'; |
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 处理数据格式,计算课程进度 |
|
|
// 处理数据格式,计算课程进度 |
|
|
$result = []; |
|
|
$result = []; |
|
|
foreach ($students as $student) { |
|
|
foreach ($students as $student) { |
|
|
$totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); |
|
|
$totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); |
|
|
$usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); |
|
|
$usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); |
|
|
$remainingHours = $totalHours - $usedHours; |
|
|
$remainingHours = $totalHours - $usedHours; |
|
|
|
|
|
|
|
|
// 判断是否为体验课学员 |
|
|
// 判断是否为体验课学员 |
|
|
$isTrialStudent = empty($student['student_course_id']); |
|
|
$isTrialStudent = empty($student['student_course_id']); |
|
|
|
|
|
|
|
|
// 判断是否需要续费 |
|
|
// 判断是否需要续费 |
|
|
$needsRenewal = false; |
|
|
$needsRenewal = false; |
|
|
if (!$isTrialStudent) { |
|
|
if (!$isTrialStudent) { |
|
|
@ -1064,7 +1064,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
$needsRenewal = true; |
|
|
$needsRenewal = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$result[] = [ |
|
|
$result[] = [ |
|
|
'id' => $student['student_id'], |
|
|
'id' => $student['student_id'], |
|
|
'student_id' => $student['student_id'], |
|
|
'student_id' => $student['student_id'], |
|
|
@ -1108,16 +1108,16 @@ class CustomerResourcesService extends BaseApiService |
|
|
'expiryDate' => $student['end_date'] |
|
|
'expiryDate' => $student['end_date'] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$res['code'] = 1; |
|
|
$res['code'] = 1; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['data'] = $result; |
|
|
$res['data'] = $result; |
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
Log::error('搜索学员失败:' . $e->getMessage()); |
|
|
Log::error('搜索学员失败:' . $e->getMessage()); |
|
|
$res['msg'] = '搜索学员失败:' . $e->getMessage(); |
|
|
$res['msg'] = '搜索学员失败:' . $e->getMessage(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1133,16 +1133,16 @@ class CustomerResourcesService extends BaseApiService |
|
|
'msg' => '操作失败', |
|
|
'msg' => '操作失败', |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
$resourceId = $where['resource_id'] ?? 0; |
|
|
$resourceId = $where['resource_id'] ?? 0; |
|
|
$studentId = $where['student_id'] ?? 0; |
|
|
$studentId = $where['student_id'] ?? 0; |
|
|
|
|
|
|
|
|
if (!$resourceId && !$studentId) { |
|
|
if (!$resourceId && !$studentId) { |
|
|
$res['msg'] = '缺少必要参数'; |
|
|
$res['msg'] = '缺少必要参数'; |
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 构建查询条件 - 不限制status状态 |
|
|
// 构建查询条件 - 不限制status状态 |
|
|
$query = Db::table('school_student') |
|
|
$query = Db::table('school_student') |
|
|
->alias('s') |
|
|
->alias('s') |
|
|
@ -1150,7 +1150,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
->leftJoin('school_customer_resources cr', 's.user_id = cr.id') |
|
|
->leftJoin('school_customer_resources cr', 's.user_id = cr.id') |
|
|
->where('s.deleted_at', 0) |
|
|
->where('s.deleted_at', 0) |
|
|
->where('s.id', $studentId); |
|
|
->where('s.id', $studentId); |
|
|
|
|
|
|
|
|
// 获取学员基本信息和课程信息 |
|
|
// 获取学员基本信息和课程信息 |
|
|
$student = $query |
|
|
$student = $query |
|
|
->field([ |
|
|
->field([ |
|
|
@ -1180,7 +1180,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
'sc.course_id' |
|
|
'sc.course_id' |
|
|
]) |
|
|
]) |
|
|
->find(); |
|
|
->find(); |
|
|
|
|
|
|
|
|
if (!$student) { |
|
|
if (!$student) { |
|
|
$res['msg'] = '学员不存在'; |
|
|
$res['msg'] = '学员不存在'; |
|
|
return $res; |
|
|
return $res; |
|
|
@ -1190,10 +1190,10 @@ class CustomerResourcesService extends BaseApiService |
|
|
$totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); |
|
|
$totalHours = intval($student['total_hours'] ?: 0) + intval($student['gift_hours'] ?: 0); |
|
|
$usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); |
|
|
$usedHours = intval($student['use_total_hours'] ?: 0) + intval($student['use_gift_hours'] ?: 0); |
|
|
$remainingHours = $totalHours - $usedHours; |
|
|
$remainingHours = $totalHours - $usedHours; |
|
|
|
|
|
|
|
|
// 判断是否为体验课学员 |
|
|
// 判断是否为体验课学员 |
|
|
$isTrialStudent = empty($student['student_course_id']); |
|
|
$isTrialStudent = empty($student['student_course_id']); |
|
|
|
|
|
|
|
|
// 判断是否需要续费 |
|
|
// 判断是否需要续费 |
|
|
$needsRenewal = false; |
|
|
$needsRenewal = false; |
|
|
if (!$isTrialStudent) { |
|
|
if (!$isTrialStudent) { |
|
|
@ -1209,7 +1209,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
$needsRenewal = true; |
|
|
$needsRenewal = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$result = [ |
|
|
$result = [ |
|
|
'id' => $student['student_id'], |
|
|
'id' => $student['student_id'], |
|
|
'student_id' => $student['student_id'], |
|
|
'student_id' => $student['student_id'], |
|
|
@ -1254,15 +1254,15 @@ class CustomerResourcesService extends BaseApiService |
|
|
'usedHours' => $usedHours, |
|
|
'usedHours' => $usedHours, |
|
|
'expiryDate' => $student['end_date'] |
|
|
'expiryDate' => $student['end_date'] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$res['code'] = 1; |
|
|
$res['code'] = 1; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['data'] = $result; |
|
|
$res['data'] = $result; |
|
|
|
|
|
|
|
|
} catch (\Exception $exception) { |
|
|
} catch (\Exception $exception) { |
|
|
$res['msg'] = '获取预设学员信息失败:' . $exception->getMessage(); |
|
|
$res['msg'] = '获取预设学员信息失败:' . $exception->getMessage(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|