|
|
|
@ -12,7 +12,6 @@ |
|
|
|
namespace app\listener\personnel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use app\model\class_resources_rel\ClassResourcesRel; |
|
|
|
use app\model\contract\Contract; |
|
|
|
use app\model\contract_sign\ContractSign; |
|
|
|
@ -22,6 +21,7 @@ use app\model\customer_resources\CustomerResources; |
|
|
|
use app\model\order_table\OrderTable; |
|
|
|
use app\model\student_course_usage\StudentCourseUsage; |
|
|
|
use app\model\student_courses\StudentCourses; |
|
|
|
use app\service\api\apiService\OrderTableService; |
|
|
|
use think\facade\Db; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -43,7 +43,8 @@ class Student |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function studentXiaoke($data){ |
|
|
|
public function studentXiaoke($data) |
|
|
|
{ |
|
|
|
$courseSchedule = new CourseSchedule(); |
|
|
|
$studentCourses = new StudentCourses(); |
|
|
|
$student_course_usage = new StudentCourseUsage(); |
|
|
|
@ -58,80 +59,13 @@ class Student |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function studentAdd($order_info){ |
|
|
|
$order = new OrderTable(); |
|
|
|
$cust = new CustomerResources(); |
|
|
|
$class_resources_rel = new ClassResourcesRel(); |
|
|
|
$course = new Course(); |
|
|
|
$studentCourses = new StudentCourses(); |
|
|
|
|
|
|
|
$cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); |
|
|
|
|
|
|
|
// 1. 检查课程关联的合同 |
|
|
|
$contract = new Contract(); |
|
|
|
$contract_info = $contract |
|
|
|
->alias("a") |
|
|
|
->join(['school_course' => 'b'],'a.id = b.contract_id','left') |
|
|
|
->where(['b.id' => $order_info['course_id']]) |
|
|
|
->field("a.id,a.contract_template") |
|
|
|
->find(); |
|
|
|
|
|
|
|
// 2. 建立合同签订关系(同时设置personnel_id和student_id) |
|
|
|
if ($contract_info) { |
|
|
|
$contract_sign = new ContractSign(); |
|
|
|
$contract_sign->insert([ |
|
|
|
'contract_id' => $contract_info['id'], |
|
|
|
'personnel_id' => $order_info['resource_id'], // 客户资源ID |
|
|
|
'student_id' => $order_info['student_id'], // 学员ID |
|
|
|
'sign_file' => $contract_info['contract_template'], |
|
|
|
'type' => 2 |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 获取课程信息 |
|
|
|
$course_info = $course->where(['id' => $order_info['course_id']])->find(); |
|
|
|
|
|
|
|
// 4. 查询学员是否有有效的课程安排 |
|
|
|
$existing_course = $studentCourses |
|
|
|
->where([ |
|
|
|
'student_id' => $order_info['student_id'], |
|
|
|
'status' => 1 // 假设1表示正常状态 |
|
|
|
]) |
|
|
|
// 有效课程条件:总课时+赠送课时 - 已用总课时 - 已用赠送课时 > 0 且 结束时间 > 当前时间 |
|
|
|
->where('(total_hours + gift_hours - use_total_hours - use_gift_hours) > 0') |
|
|
|
->where('end_date > ?', [date('Y-m-d')]) |
|
|
|
->order('id', 'desc') // 按ID降序,取最新的一个 |
|
|
|
->find(); |
|
|
|
|
|
|
|
// 5. 计算开始时间和结束时间 |
|
|
|
if ($existing_course) { |
|
|
|
// 如果有有效课程,开始时间 = 最新课程的结束时间 + 1天,结束时间 = 开始时间 + duration天 |
|
|
|
$start_date = date("Y-m-d", strtotime($existing_course['end_date'] . " +1 day")); |
|
|
|
$end_date = date("Y-m-d", strtotime($start_date . " +" . $course_info['duration'] . " days")); |
|
|
|
} else { |
|
|
|
// 如果没有有效课程,开始时间 = 当前时间,结束时间 = 当前时间 + duration天 |
|
|
|
$start_date = date("Y-m-d"); |
|
|
|
$end_date = date("Y-m-d", strtotime("+" . $course_info['duration'] . " days")); |
|
|
|
public function studentAdd($order_info) |
|
|
|
{ |
|
|
|
if ($order_info['order_status'] == 'paid') { |
|
|
|
(new OrderTableService())->handlePaymentSuccess($order_info); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// 6. 插入学员课程记录 |
|
|
|
$student_course_id = $studentCourses->insertGetId([ |
|
|
|
'student_id' => $order_info['student_id'], |
|
|
|
'course_id' => $order_info['course_id'], |
|
|
|
'total_hours' => $course_info['session_count'], |
|
|
|
'gift_hours' => $course_info['gift_session_count'], |
|
|
|
'start_date' => $start_date, |
|
|
|
'end_date' => $end_date, |
|
|
|
'single_session_count' => $course_info['single_session_count'], |
|
|
|
'resource_id' => $order_info['resource_id'], |
|
|
|
'status' => 1 // 设置为正常状态 |
|
|
|
]); |
|
|
|
|
|
|
|
// 7. 更新订单表的course_plan_id |
|
|
|
$order->where(['id' => $order_info['id']])->update([ |
|
|
|
'course_plan_id' => $student_course_id |
|
|
|
]); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|