5 changed files with 135 additions and 76 deletions
@ -0,0 +1,124 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\listener\personnel; |
|||
|
|||
|
|||
|
|||
use app\model\class_resources_rel\ClassResourcesRel; |
|||
use app\model\course\Course; |
|||
use app\model\course_schedule\CourseSchedule; |
|||
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 think\facade\Db; |
|||
|
|||
/** |
|||
* 学员 |
|||
*/ |
|||
class Student |
|||
{ |
|||
|
|||
protected $personnel; |
|||
|
|||
public function handle(array $params) |
|||
{ |
|||
if ($params['event_type'] === 'add') { |
|||
$this->studentAdd($params['data']); |
|||
} |
|||
|
|||
if ($params['event_type'] === 'xiaoke') { |
|||
$this->studentXiaoke($params['data']); |
|||
} |
|||
} |
|||
|
|||
public function studentXiaoke($data){ |
|||
$courseSchedule = new CourseSchedule(); |
|||
$studentCourses = new StudentCourses(); |
|||
$student_course_usage = new StudentCourseUsage(); |
|||
$schedule_info = $courseSchedule->where(['id' => $data['schedule_id']])->find(); |
|||
$studentCourses_info = $studentCourses->where(['student_id' => $data['student_id'],'course_id' => $schedule_info['course_id']])->find(); |
|||
|
|||
$student_course_usage->insert([ |
|||
'student_course_id' => $studentCourses_info['id'], |
|||
'used_hours' => $studentCourses_info['single_session_count'], |
|||
'usage_date' => date("Y-m-d") |
|||
]); |
|||
|
|||
} |
|||
|
|||
public function studentAdd($order_info){ |
|||
$student = new \app\model\student\Student(); |
|||
$order = new OrderTable(); |
|||
$cust = new CustomerResources(); |
|||
$class_resources_rel = new ClassResourcesRel(); |
|||
$course = new Course(); |
|||
$studentCourses = new StudentCourses(); |
|||
$order_count = $order->where(['resource_id' => $order_info['resource_id']])->count(); |
|||
$cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); |
|||
//创建学员关系逻辑 |
|||
if($order_count <= 1){ |
|||
$sex_arr = ['male' => 1, 'female' => 2, 'other' => 0]; |
|||
//首次支付创建学员 |
|||
$student_id = $student->insertGetId([ |
|||
'name' => $cust_info['name'], |
|||
'gender' => $sex_arr[$cust_info['gender']], |
|||
'age' => $cust_info['age'], |
|||
'campus_id' => $cust_info['campus'], |
|||
'class_id' => $order_info['class_id'], |
|||
'status' => 1, |
|||
'user_id' => $order_info['resource_id'] |
|||
]); |
|||
}else{ |
|||
$student_id = $student->where(['user_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']])->value('id'); |
|||
} |
|||
|
|||
//学员课程逻辑 |
|||
$course_info = $course->where(['id' => $order_info['course_id']])->find(); |
|||
$studentCourses->insert([ |
|||
'student_id' => $student_id, |
|||
'course_id' => $order_info['course_id'], |
|||
'total_hours' => $course_info['session_count'], |
|||
'gift_hours' => $course_info['gift_session_count'], |
|||
'start_date' => date("Y-m-d"), |
|||
'end_date' => date("Y-m-d", strtotime("+30 days")), |
|||
'single_session_count' => $course_info['single_session_count'] |
|||
]); |
|||
|
|||
|
|||
//班级资源关系逻辑 |
|||
$is_rel = $class_resources_rel->where( |
|||
['resource_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']] |
|||
)->find(); |
|||
if($is_rel){ |
|||
$class_resources_rel->where(['id' => $is_rel['id']])->update(['status' => 2]); |
|||
}else{ |
|||
$class_resources_rel->insert([ |
|||
'class_id' => $order_info['class_id'], |
|||
'resource_id' => $order_info['resource_id'], |
|||
'campus_id' => $cust_info['campus'], |
|||
'source_type' => 'student', |
|||
'join_time' => time(), |
|||
'status' => 1, |
|||
'create_time' => date("Y-m-d H:i:s"), |
|||
'update_time' => date("Y-m-d H:i:s") |
|||
]); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
Loading…
Reference in new issue