|
|
@ -65,11 +65,11 @@ class OrderTableService extends BaseApiService |
|
|
'personnel', |
|
|
'personnel', |
|
|
'studentCourses' // 添加学员课程关联 |
|
|
'studentCourses' // 添加学员课程关联 |
|
|
]) |
|
|
]) |
|
|
->order('created_at','desc') // 使用created_at排序 |
|
|
->order('created_at', 'desc') // 使用created_at排序 |
|
|
->paginate([ |
|
|
->paginate([ |
|
|
'list_rows' => $limit, |
|
|
'list_rows' => $limit, |
|
|
'page' => $page, |
|
|
'page' => $page, |
|
|
])->toArray(); |
|
|
])->toArray(); |
|
|
|
|
|
|
|
|
return $data; |
|
|
return $data; |
|
|
} |
|
|
} |
|
|
@ -235,6 +235,7 @@ class OrderTableService extends BaseApiService |
|
|
// 4.处理赠品 |
|
|
// 4.处理赠品 |
|
|
$this->handleGift($orderArray); |
|
|
$this->handleGift($orderArray); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 支付成功后为学员分配课程 |
|
|
* 支付成功后为学员分配课程 |
|
|
* @param array $orderData 订单数据 |
|
|
* @param array $orderData 订单数据 |
|
|
@ -271,33 +272,38 @@ class OrderTableService extends BaseApiService |
|
|
$end_date = date('Y-m-d', strtotime('+' . $course['duration'] . ' days')); |
|
|
$end_date = date('Y-m-d', strtotime('+' . $course['duration'] . ' days')); |
|
|
|
|
|
|
|
|
if ($existingCourse) { |
|
|
if ($existingCourse) { |
|
|
// 如果已有课程记录,累加课时数量 |
|
|
// 如果已有课程记录,计算新课程的开始时间 |
|
|
$updateData = [ |
|
|
// 新课程从现有课程结束后的第二天开始 |
|
|
'total_hours' => $existingCourse['total_hours'] + $course['session_count'], |
|
|
$new_start_date = date('Y-m-d', strtotime($existingCourse['end_date'] . ' +1 day')); |
|
|
'gift_hours' => $existingCourse['gift_hours'] + $course['gift_session_count'], |
|
|
$new_end_date = date('Y-m-d', strtotime($new_start_date . ' +' . $course['duration'] . ' days')); |
|
|
|
|
|
|
|
|
|
|
|
// 创建新的课程记录 |
|
|
|
|
|
$insertData = [ |
|
|
|
|
|
'student_id' => $student_id, |
|
|
|
|
|
'course_id' => $course_id, |
|
|
|
|
|
'total_hours' => $course['session_count'], |
|
|
|
|
|
'gift_hours' => $course['gift_session_count'], |
|
|
|
|
|
'start_date' => $new_start_date, |
|
|
|
|
|
'end_date' => $new_end_date, |
|
|
|
|
|
'use_total_hours' => 0, |
|
|
|
|
|
'use_gift_hours' => 0, |
|
|
|
|
|
'single_session_count' => $course['single_session_count'], |
|
|
|
|
|
'status' => 1, // 激活状态 |
|
|
|
|
|
'resource_id' => $resource_id, |
|
|
|
|
|
'created_at' => $now, |
|
|
'updated_at' => $now |
|
|
'updated_at' => $now |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
// 如果原有课程已过期,更新有效期 |
|
|
$result = Db::table('school_student_courses')->insert($insertData); |
|
|
if ($existingCourse['end_date'] < $start_date) { |
|
|
|
|
|
$updateData['start_date'] = $start_date; |
|
|
|
|
|
$updateData['end_date'] = $end_date; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 延长有效期 |
|
|
|
|
|
$updateData['end_date'] = date('Y-m-d', |
|
|
|
|
|
strtotime($existingCourse['end_date'] . ' +' . $course['duration'] . ' days') |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$result = Db::table('school_student_courses') |
|
|
|
|
|
->where('id', $existingCourse['id']) |
|
|
|
|
|
->update($updateData); |
|
|
|
|
|
|
|
|
|
|
|
\think\facade\Log::info('学员课程更新成功', [ |
|
|
\think\facade\Log::info('学员课程新增成功', [ |
|
|
'student_id' => $student_id, |
|
|
'student_id' => $student_id, |
|
|
'course_id' => $course_id, |
|
|
'course_id' => $course_id, |
|
|
'added_hours' => $course['session_count'], |
|
|
'existing_end_date' => $existingCourse['end_date'], |
|
|
'added_gift_hours' => $course['gift_session_count'] |
|
|
'new_start_date' => $new_start_date, |
|
|
|
|
|
'new_end_date' => $new_end_date, |
|
|
|
|
|
'new_hours' => $course['session_count'], |
|
|
|
|
|
'new_gift_hours' => $course['gift_session_count'] |
|
|
]); |
|
|
]); |
|
|
} else { |
|
|
} else { |
|
|
// 创建新的课程记录 |
|
|
// 创建新的课程记录 |
|
|
@ -317,15 +323,17 @@ class OrderTableService extends BaseApiService |
|
|
'updated_at' => $now |
|
|
'updated_at' => $now |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$result = Db::table('school_student_courses')->insert($insertData); |
|
|
$result = Db::table('school_student_courses')->insert($insertData, true); |
|
|
|
|
|
// 更新订单表 |
|
|
|
|
|
OrderTable::find($orderData['id'])->update(['course_plan_id' => $result]); |
|
|
\think\facade\Log::info('学员课程创建成功', [ |
|
|
\think\facade\Log::info('学员课程创建成功', [ |
|
|
'student_id' => $student_id, |
|
|
'student_id' => $student_id, |
|
|
'course_id' => $course_id, |
|
|
'course_id' => $course_id, |
|
|
'total_hours' => $course['session_count'], |
|
|
'total_hours' => $course['session_count'], |
|
|
'gift_hours' => $course['gift_session_count'], |
|
|
'gift_hours' => $course['gift_session_count'], |
|
|
'start_date' => $start_date, |
|
|
'start_date' => $start_date, |
|
|
'end_date' => $end_date |
|
|
'end_date' => $end_date, |
|
|
|
|
|
'course_plan_id' => $result |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -384,9 +392,10 @@ class OrderTableService extends BaseApiService |
|
|
'deleted_at' => 0 |
|
|
'deleted_at' => 0 |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$result = Db::table('school_contract_sign')->insert($insertData); |
|
|
$result = Db::table('school_contract_sign')->insert($insertData, true); |
|
|
|
|
|
|
|
|
if ($result) { |
|
|
if ($result) { |
|
|
|
|
|
OrderTable::find($orderData['id'])->update(['contract_id' => $result]); |
|
|
// 创建签署记录成功后,为甲乙双方生成数据源配置记录 |
|
|
// 创建签署记录成功后,为甲乙双方生成数据源配置记录 |
|
|
$this->createDocumentDataSourceConfig($course['contract_id'], $orderData); |
|
|
$this->createDocumentDataSourceConfig($course['contract_id'], $orderData); |
|
|
|
|
|
|
|
|
@ -507,7 +516,7 @@ class OrderTableService extends BaseApiService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$status = Db::table('school_pay')->where('out_trade_no', $payment_id)->find(); |
|
|
$status = Db::table('school_pay')->where('out_trade_no', $payment_id)->find(); |
|
|
if ($status){ |
|
|
if ($status) { |
|
|
\think\facade\Log::warning('创建支付记录失败:支付单号已存在', ['order_id' => $order_id, 'payment_id' => $payment_id]); |
|
|
\think\facade\Log::warning('创建支付记录失败:支付单号已存在', ['order_id' => $order_id, 'payment_id' => $payment_id]); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|