|
|
|
@ -41,7 +41,7 @@ class OrderTableService extends BaseApiService |
|
|
|
$limit = $page_params['limit']; |
|
|
|
|
|
|
|
$model = new OrderTable(); |
|
|
|
|
|
|
|
|
|
|
|
//员工表id |
|
|
|
if (!empty($where['staff_id'])) { |
|
|
|
$model = $model->where('staff_id', $where['staff_id']); |
|
|
|
@ -51,7 +51,7 @@ class OrderTableService extends BaseApiService |
|
|
|
if (!empty($where['resource_id'])) { |
|
|
|
$model = $model->where('resource_id', $where['resource_id']); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//学生表id |
|
|
|
if (!empty($where['student_id'])) { |
|
|
|
$model = $model->where('student_id', $where['student_id']); |
|
|
|
@ -65,11 +65,11 @@ class OrderTableService extends BaseApiService |
|
|
|
'personnel', |
|
|
|
'studentCourses' // 添加学员课程关联 |
|
|
|
]) |
|
|
|
->order('created_at','desc') // 使用created_at排序 |
|
|
|
->order('created_at', 'desc') // 使用created_at排序 |
|
|
|
->paginate([ |
|
|
|
'list_rows' => $limit, |
|
|
|
'page' => $page, |
|
|
|
])->toArray(); |
|
|
|
'list_rows' => $limit, |
|
|
|
'page' => $page, |
|
|
|
])->toArray(); |
|
|
|
|
|
|
|
return $data; |
|
|
|
} |
|
|
|
@ -129,7 +129,7 @@ class OrderTableService extends BaseApiService |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$success = OrderTable::create($data); |
|
|
|
|
|
|
|
// 如果订单创建成功且使用了赠品,更新赠品状态 |
|
|
|
@ -177,12 +177,12 @@ class OrderTableService extends BaseApiService |
|
|
|
'order_status' => $data['order_status'], |
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// 如果提供了支付单号,则更新 |
|
|
|
if (!empty($data['payment_id'])) { |
|
|
|
$updateData['payment_id'] = $data['payment_id']; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果订单状态为已支付,记录支付时间 |
|
|
|
if ($data['order_status'] === 'paid') { |
|
|
|
$updateData['payment_time'] = date('Y-m-d H:i:s'); |
|
|
|
@ -196,7 +196,7 @@ class OrderTableService extends BaseApiService |
|
|
|
$orderArray = $order->toArray(); |
|
|
|
$this->handlePaymentSuccess($orderArray); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
'code' => 1, |
|
|
|
'msg' => '订单状态更新成功', |
|
|
|
@ -235,6 +235,7 @@ class OrderTableService extends BaseApiService |
|
|
|
// 4.处理赠品 |
|
|
|
$this->handleGift($orderArray); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 支付成功后为学员分配课程 |
|
|
|
* @param array $orderData 订单数据 |
|
|
|
@ -246,7 +247,7 @@ class OrderTableService extends BaseApiService |
|
|
|
$student_id = $orderData['student_id']; |
|
|
|
$course_id = $orderData['course_id']; |
|
|
|
$resource_id = $orderData['resource_id']; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($student_id) || empty($course_id)) { |
|
|
|
\think\facade\Log::warning('学员分配课程失败:缺少学员ID或课程ID', $orderData); |
|
|
|
return false; |
|
|
|
@ -271,33 +272,38 @@ class OrderTableService extends BaseApiService |
|
|
|
$end_date = date('Y-m-d', strtotime('+' . $course['duration'] . ' days')); |
|
|
|
|
|
|
|
if ($existingCourse) { |
|
|
|
// 如果已有课程记录,累加课时数量 |
|
|
|
$updateData = [ |
|
|
|
'total_hours' => $existingCourse['total_hours'] + $course['session_count'], |
|
|
|
'gift_hours' => $existingCourse['gift_hours'] + $course['gift_session_count'], |
|
|
|
// 如果已有课程记录,计算新课程的开始时间 |
|
|
|
// 新课程从现有课程结束后的第二天开始 |
|
|
|
$new_start_date = date('Y-m-d', strtotime($existingCourse['end_date'] . ' +1 day')); |
|
|
|
$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 |
|
|
|
]; |
|
|
|
|
|
|
|
// 如果原有课程已过期,更新有效期 |
|
|
|
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('学员课程更新成功', [ |
|
|
|
$result = Db::table('school_student_courses')->insert($insertData); |
|
|
|
|
|
|
|
\think\facade\Log::info('学员课程新增成功', [ |
|
|
|
'student_id' => $student_id, |
|
|
|
'course_id' => $course_id, |
|
|
|
'added_hours' => $course['session_count'], |
|
|
|
'added_gift_hours' => $course['gift_session_count'] |
|
|
|
'existing_end_date' => $existingCourse['end_date'], |
|
|
|
'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 { |
|
|
|
// 创建新的课程记录 |
|
|
|
@ -317,15 +323,17 @@ class OrderTableService extends BaseApiService |
|
|
|
'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('学员课程创建成功', [ |
|
|
|
'student_id' => $student_id, |
|
|
|
'course_id' => $course_id, |
|
|
|
'total_hours' => $course['session_count'], |
|
|
|
'gift_hours' => $course['gift_session_count'], |
|
|
|
'start_date' => $start_date, |
|
|
|
'end_date' => $end_date |
|
|
|
'end_date' => $end_date, |
|
|
|
'course_plan_id' => $result |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
@ -350,7 +358,7 @@ class OrderTableService extends BaseApiService |
|
|
|
try { |
|
|
|
$student_id = $orderData['student_id']; |
|
|
|
$course_id = $orderData['course_id']; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($student_id) || empty($course_id)) { |
|
|
|
\think\facade\Log::warning('创建合同签署记录失败:缺少学员ID或课程ID', $orderData); |
|
|
|
return false; |
|
|
|
@ -384,12 +392,13 @@ class OrderTableService extends BaseApiService |
|
|
|
'deleted_at' => 0 |
|
|
|
]; |
|
|
|
|
|
|
|
$result = Db::table('school_contract_sign')->insert($insertData); |
|
|
|
|
|
|
|
$result = Db::table('school_contract_sign')->insert($insertData, true); |
|
|
|
|
|
|
|
if ($result) { |
|
|
|
OrderTable::find($orderData['id'])->update(['contract_id' => $result]); |
|
|
|
// 创建签署记录成功后,为甲乙双方生成数据源配置记录 |
|
|
|
$this->createDocumentDataSourceConfig($course['contract_id'], $orderData); |
|
|
|
|
|
|
|
|
|
|
|
\think\facade\Log::info('合同签署记录创建成功', [ |
|
|
|
'student_id' => $student_id, |
|
|
|
'contract_id' => $course['contract_id'], |
|
|
|
@ -456,7 +465,7 @@ class OrderTableService extends BaseApiService |
|
|
|
|
|
|
|
if (!empty($insert_data)) { |
|
|
|
$result = Db::table('school_document_data_source_config')->insertAll($insert_data); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
\think\facade\Log::info('文档数据源配置创建成功', [ |
|
|
|
'contract_id' => $contract_id, |
|
|
|
@ -464,7 +473,7 @@ class OrderTableService extends BaseApiService |
|
|
|
'records_count' => count($insert_data) |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $result ? true : false; |
|
|
|
} |
|
|
|
|
|
|
|
@ -492,7 +501,7 @@ class OrderTableService extends BaseApiService |
|
|
|
$payment_id = $orderData['payment_id'] ?? ''; |
|
|
|
$payment_type = $orderData['payment_type'] ?? ''; |
|
|
|
$order_amount = $orderData['order_amount'] ?? 0; |
|
|
|
|
|
|
|
|
|
|
|
if (empty($order_id) || empty($payment_id)) { |
|
|
|
\think\facade\Log::warning('创建支付记录失败:缺少订单ID或支付单号', $orderData); |
|
|
|
return false; |
|
|
|
@ -507,7 +516,7 @@ class OrderTableService extends BaseApiService |
|
|
|
} |
|
|
|
} |
|
|
|
$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]); |
|
|
|
return false; |
|
|
|
} |
|
|
|
@ -535,7 +544,7 @@ class OrderTableService extends BaseApiService |
|
|
|
]; |
|
|
|
|
|
|
|
$result = Db::table('school_pay')->insert($insertData); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
\think\facade\Log::info('支付记录创建成功', [ |
|
|
|
'order_id' => $order_id, |
|
|
|
@ -658,7 +667,7 @@ class OrderTableService extends BaseApiService |
|
|
|
'resource_id' => $resource_id, |
|
|
|
'error' => $e->getMessage() |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
'valid' => false, |
|
|
|
'message' => '赠品验证异常: ' . $e->getMessage() |
|
|
|
|