21 changed files with 917 additions and 86 deletions
@ -0,0 +1,42 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\api\controller\apiController; |
||||
|
|
||||
|
use app\Request; |
||||
|
use app\service\api\apiService\CourseService; |
||||
|
use core\base\BaseApiService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 客户资源相关接口 |
||||
|
* Class Personnel |
||||
|
* @package app\api\controller\apiController |
||||
|
*/ |
||||
|
class ClassSpi extends BaseApiService |
||||
|
{ |
||||
|
|
||||
|
//课程列表 |
||||
|
public function jlClassList(Request $request){ |
||||
|
$id = $this->member_id; |
||||
|
dd(111); |
||||
|
return success((new CourseService())->list($id,$data)); |
||||
|
} |
||||
|
|
||||
|
//获取课程详情 |
||||
|
public function courseInfo(Request $request){ |
||||
|
$data = $this->request->params([ |
||||
|
["id",0] |
||||
|
]); |
||||
|
return success('SUCCESS',(new CourseService())->info($data['id'])); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\api\controller\apiController; |
||||
|
|
||||
|
use app\Request; |
||||
|
use app\service\api\apiService\CourseService; |
||||
|
use core\base\BaseApiService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 客户资源相关接口 |
||||
|
* Class Personnel |
||||
|
* @package app\api\controller\apiController |
||||
|
*/ |
||||
|
class Course extends BaseApiService |
||||
|
{ |
||||
|
|
||||
|
//课程列表 |
||||
|
public function courseList(Request $request){ |
||||
|
$id = $this->member_id; |
||||
|
$data = $this->request->params([ |
||||
|
["schedule_date",0] |
||||
|
]); |
||||
|
return success((new CourseService())->list($id,$data)); |
||||
|
} |
||||
|
|
||||
|
//获取课程详情 |
||||
|
public function courseInfo(Request $request){ |
||||
|
$data = $this->request->params([ |
||||
|
["id",0] |
||||
|
]); |
||||
|
return success('SUCCESS',(new CourseService())->info($data['id'])); |
||||
|
} |
||||
|
|
||||
|
//获取添加学员列表 |
||||
|
public function addStudentList(Request $request){ |
||||
|
$data = $this->request->params([ |
||||
|
["id",0] |
||||
|
]); |
||||
|
return success('SUCCESS',(new CourseService())->StudentList($data['id'])); |
||||
|
} |
||||
|
|
||||
|
//获取添加学员列表 |
||||
|
public function addStudent(Request $request){ |
||||
|
$data = $this->request->params([ |
||||
|
["student_id",0], |
||||
|
["schedule_id",0], |
||||
|
["time_slot",0], |
||||
|
["resources_id",1], |
||||
|
["person_id",1], |
||||
|
["course_date",''] |
||||
|
]); |
||||
|
return success('SUCCESS',(new CourseService())->addStudent($data)); |
||||
|
} |
||||
|
|
||||
|
//请假 |
||||
|
public function delStudentCourse(Request $request){ |
||||
|
$data = $this->request->params([ |
||||
|
["student_id",0], |
||||
|
["course_id",0] |
||||
|
]); |
||||
|
return success('SUCCESS',(new CourseService())->delStudentCourse($data)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,188 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\api\controller\apiController; |
||||
|
|
||||
|
use app\Request; |
||||
|
use app\service\api\apiService\CommonService; |
||||
|
use core\base\BaseApiService; |
||||
|
|
||||
|
/** |
||||
|
* 统计控制器相关接口 |
||||
|
* Class Personnel |
||||
|
* @package app\api\controller\apiController |
||||
|
*/ |
||||
|
class Statistics extends BaseApiService |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 员工端统计(销售)-获取销售首页数据统计 |
||||
|
*/ |
||||
|
public function marketHome(Request $request) |
||||
|
{ |
||||
|
$personnel_id = $request->param('personnel_id','');//员工表id |
||||
|
$role_key_arr = $request->param('role_key_arr','');//array 角色key |
||||
|
//字符转数组 |
||||
|
$role_key_arr = explode(',',$role_key_arr); |
||||
|
if(empty($personnel_id)|| empty($role_key_arr)){ |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
$firstDayOfMonth = date('m月01日'); // 获取本月第一天 |
||||
|
$lastDayOfMonth = date('m月t日'); // 获取本月最后一天 |
||||
|
$dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串 |
||||
|
|
||||
|
// $role_key_arr = ['sale'];//@todo 调试使用 |
||||
|
|
||||
|
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ |
||||
|
//市场人员统计数据(地推拉人头的) |
||||
|
$data = [ |
||||
|
'date_range'=>$dateRange,//拼接日期范围字符串 |
||||
|
'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 |
||||
|
//本月 |
||||
|
'month' => [ |
||||
|
'new_total' => ($newTotal = rand(100, 500)),//拉新总人数 |
||||
|
'new_total_rate' => min(100, round($newTotal / 1000 * 100, 2)),//拉新总人数比例(不超过100%) |
||||
|
'assigned_sales' => ($assignedSales = rand(50, 300)),//已分配给销售的人数 |
||||
|
'assigned_sales_rate' => min(100, round($assignedSales / $newTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) |
||||
|
'yesterday_new' => ($yesterdayNew = rand(5, 50)),//昨日拉新 |
||||
|
'yesterday_new_rate' => min(100, round($yesterdayNew / $newTotal * 100, 2)),//昨日拉新比例(不超过100%) |
||||
|
'today_new' => ($todayNew = rand(1, 20)),//今日拉新 |
||||
|
'today_new_rate' => min(100, round($todayNew / $newTotal * 100, 2)),//今日拉新比例(不超过100%) |
||||
|
], |
||||
|
//上月 |
||||
|
'last_month' => [ |
||||
|
'new_total' => ($lastNewTotal = rand(80, 400)),//拉新总人数 |
||||
|
'new_total_rate' => min(100, round($lastNewTotal / 800 * 100, 2)),//拉新总人数比例(不超过100%) |
||||
|
'assigned_sales' => ($lastAssignedSales = rand(40, 250)),//已分配给销售的人数 |
||||
|
'assigned_sales_rate' => min(100, round($lastAssignedSales / $lastNewTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) |
||||
|
'yesterday_new' => ($lastYesterdayNew = rand(3, 40)),//昨日拉新人数 |
||||
|
'yesterday_new_rate' => min(100, round($lastYesterdayNew / $lastNewTotal * 100, 2)),//昨日拉新人数比例(不超过100%) |
||||
|
'today_new' => ($lastTodayNew = rand(1, 15)),//今日拉新人数 |
||||
|
'today_new_rate' => min(100, round($lastTodayNew / $lastNewTotal * 100, 2)),//今日拉新人数比例(不超过100%) |
||||
|
] |
||||
|
]; |
||||
|
}elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ |
||||
|
//销售人员统计数据(买课的) |
||||
|
$data = [ |
||||
|
'date_range'=>$dateRange,//拼接日期范围字符串 |
||||
|
'role_type'=>'sale_type',//角色类型|market_type=市场,sale_type=销售 infoData.month |
||||
|
//本月 |
||||
|
'month' => [ |
||||
|
'assigned_clients' => ($assigned = rand(50, 300)),//分配给我的客户人数 |
||||
|
'contacted_clients' => ($contacted = rand(20, 150)),//已沟通的客户人数 |
||||
|
'contact_rate' => min(100, round($contacted / $assigned * 100, 2)),//沟通率(不超过100%) |
||||
|
'unconverted_clients' => ($unconverted = rand(10, 50)),//已沟通但没成交的客户人数 |
||||
|
'unconverted_rate' => min(100, round($unconverted / $contacted * 100, 2)),//未成交率(不超过100%) |
||||
|
'renewal_clients' => ($renewal = rand(5, 30)),//待续费的客户人数 |
||||
|
'renewal_rate' => min(100, round($renewal / $assigned * 100, 2)),//待续费率(不超过100%) |
||||
|
'closed_clients' => ($closed = rand(1, 20)),//已关单的客户人数 |
||||
|
'closed_rate' => min(100, round($closed / $contacted * 100, 2)),//关单率(不超过100%) |
||||
|
'conversion_rate' => min(100, round($closed / $assigned * 100, 2)),//整体转化率(不超过100%) |
||||
|
], |
||||
|
//上月 |
||||
|
'last_month' => [ |
||||
|
'assigned_clients' => ($lastAssigned = rand(40, 250)),//分配给我的客户人数 |
||||
|
'contacted_clients' => ($lastContacted = rand(15, 120)),//已沟通的客户人数 |
||||
|
'contact_rate' => min(100, round($lastContacted / $lastAssigned * 100, 2)),//沟通率(不超过100%) |
||||
|
'unconverted_clients' => ($lastUnconverted = rand(8, 40)),//已沟通但没成交的客户人数 |
||||
|
'unconverted_rate' => min(100, round($lastUnconverted / $lastContacted * 100, 2)),//未成交率(不超过100%) |
||||
|
'renewal_clients' => ($lastRenewal = rand(3, 25)),//待续费的客户人数 |
||||
|
'renewal_rate' => min(100, round($lastRenewal / $lastAssigned * 100, 2)),//待续费率(不超过100%) |
||||
|
'closed_clients' => ($lastClosed = rand(1, 15)),//已关单的客户人数 |
||||
|
'closed_rate' => min(100, round($lastClosed / $lastContacted * 100, 2)),//关单率(不超过100%) |
||||
|
'conversion_rate' => min(100, round($lastClosed / $lastAssigned * 100, 2)),//整体转化率(不超过100%) |
||||
|
] |
||||
|
]; |
||||
|
}else{ |
||||
|
return fail('角色权限不正确'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
return success($data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 员工端统计(销售)-获取销售数据页统计 |
||||
|
*/ |
||||
|
public function marketData(Request $request) |
||||
|
{ |
||||
|
$personnel_id = $request->param('personnel_id','');//员工表id |
||||
|
$role_key_arr = $request->param('role_key_arr','');//array 角色key |
||||
|
$role_key_arr = explode(',',$role_key_arr); |
||||
|
if(empty($personnel_id)|| empty($role_key_arr)){ |
||||
|
return fail('缺少参数'); |
||||
|
} |
||||
|
|
||||
|
// $role_key_arr = ['sale'];//@todo 调试使用 |
||||
|
|
||||
|
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ |
||||
|
//市场人员统计数据(地推拉人头的) |
||||
|
$data = [ |
||||
|
'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 |
||||
|
|
||||
|
'num_1' => ($assigned = rand(20, 150)),//本周已分配 |
||||
|
'num_2' => ($unassigned = rand(5, 50)),//本周未分配 |
||||
|
'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 |
||||
|
'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 |
||||
|
|
||||
|
'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 |
||||
|
'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 |
||||
|
'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) |
||||
|
'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) |
||||
|
'staff_list' => [ |
||||
|
['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
], |
||||
|
]; |
||||
|
}elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ |
||||
|
//销售人员统计数据(买课的) |
||||
|
$data = [ |
||||
|
'role_type'=>'sale',//角色类型|market_type=市场,sale_type=销售 |
||||
|
|
||||
|
'num_1' => ($assigned = rand(20, 150)),//本周已分配 |
||||
|
'num_2' => ($unassigned = rand(5, 50)),//本周未分配 |
||||
|
'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 |
||||
|
'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 |
||||
|
|
||||
|
'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 |
||||
|
'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 |
||||
|
'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) |
||||
|
'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) |
||||
|
'staff_list' => [ |
||||
|
['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], |
||||
|
], |
||||
|
]; |
||||
|
}else{ |
||||
|
return fail('角色权限不正确'); |
||||
|
} |
||||
|
return success($data); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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") |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\model\Assignment; |
||||
|
|
||||
|
use core\base\BaseModel; |
||||
|
use think\model\concern\SoftDelete; |
||||
|
use think\model\relation\HasMany; |
||||
|
use think\model\relation\HasOne; |
||||
|
use app\model\student\Student; |
||||
|
use app\model\customer_resources\CustomerResources; |
||||
|
/** |
||||
|
* 校区模型 |
||||
|
* Class Campus |
||||
|
* @package app\model\campus |
||||
|
*/ |
||||
|
class Assignment extends BaseModel |
||||
|
{ |
||||
|
|
||||
|
use SoftDelete; |
||||
|
|
||||
|
/** |
||||
|
* 数据表主键 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $pk = 'id'; |
||||
|
|
||||
|
/** |
||||
|
* 模型名称 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $name = 'assignment'; |
||||
|
|
||||
|
/** |
||||
|
* 定义软删除标记字段. |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $deleteTime = 'deleted_at'; |
||||
|
|
||||
|
/** |
||||
|
* 定义软删除字段的默认值. |
||||
|
* @var int |
||||
|
*/ |
||||
|
protected $defaultSoftDelete = 0; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public function student() |
||||
|
{ |
||||
|
return $this->hasOne(Student::class, 'id', 'student_id'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,185 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\api\apiService; |
||||
|
|
||||
|
use app\model\course_schedule\CourseSchedule; |
||||
|
use app\model\person_course_schedule\PersonCourseSchedule; |
||||
|
use app\model\student_course_usage\StudentCourseUsage; |
||||
|
use app\model\student\Student; |
||||
|
use app\model\assignment\Assignment; |
||||
|
use app\model\course\Course; |
||||
|
use app\model\student_courses\StudentCourses; |
||||
|
use core\base\BaseApiService; |
||||
|
use think\Model; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
/** |
||||
|
* 员工服务层 |
||||
|
* Class MemberService |
||||
|
* @package app\service\api\member |
||||
|
*/ |
||||
|
class CourseService extends BaseApiService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
$this->model = new Course(); |
||||
|
} |
||||
|
|
||||
|
//课程列表 |
||||
|
public function list($id,$data) |
||||
|
{ |
||||
|
$where = []; |
||||
|
if ($data['schedule_date']) { |
||||
|
$where[] = ['course_date','=', $data['schedule_date']]; |
||||
|
} |
||||
|
$CourseSchedule = new CourseSchedule(); |
||||
|
$search_model = $CourseSchedule |
||||
|
->where('coach_id', $id) |
||||
|
->where($where) |
||||
|
->with(['course' => function($query) { |
||||
|
$query->select(); |
||||
|
},'venue' => function($query) { |
||||
|
$query->select(); |
||||
|
}]); |
||||
|
$list = $this->pageQuery($search_model); |
||||
|
$PersonCourseSchedule = new PersonCourseSchedule(); |
||||
|
foreach ($list['data'] as $k => $v) { |
||||
|
$student = Db::name('person_course_schedule') |
||||
|
->alias('pcs') |
||||
|
->where('pcs.schedule_id', $v['id']) // 建议加上表别名避免冲突 |
||||
|
->join('school_student st', 'pcs.student_id = st.id') |
||||
|
->join('school_customer_resources cr', 'st.user_id = cr.id') |
||||
|
->join('school_member sm', 'cr.member_id = sm.member_id') |
||||
|
->field('st.name, sm.headimg as avatar') // 👈 正确方式取字段 |
||||
|
->select(); |
||||
|
$list['data'][$k]['student'] = $student; |
||||
|
} |
||||
|
return $list; |
||||
|
} |
||||
|
//获取课程详情 |
||||
|
public function info($data) |
||||
|
{ |
||||
|
$CourseSchedule = new CourseSchedule(); |
||||
|
$search_model = $CourseSchedule |
||||
|
->where('id', $data) |
||||
|
->with(['course' => function($query) { |
||||
|
$query->select(); |
||||
|
},'venue' => function($query) { |
||||
|
$query->select(); |
||||
|
},'coach' => function($query) { |
||||
|
$query->select(); |
||||
|
}]); |
||||
|
$list = $search_model->find(); |
||||
|
$student = Db::name('person_course_schedule') |
||||
|
->alias('pcs') |
||||
|
->where('pcs.schedule_id', $list['id']) |
||||
|
->join('school_student st', 'pcs.student_id = st.id') |
||||
|
->join('school_customer_resources cr', 'st.user_id = cr.id') |
||||
|
->join('school_member sm', 'cr.member_id = sm.member_id') |
||||
|
->field('st.name, sm.headimg as avatar') |
||||
|
->select(); |
||||
|
$list['student'] = $student; |
||||
|
$student_courses = Db::name('student_courses') |
||||
|
->alias('sc') |
||||
|
->where('sc.course_id', $list['id']) |
||||
|
->join('school_student_course_usage sscu', 'sc.id = sscu.student_course_id') |
||||
|
->field('sc.student_id,sc.end_date') |
||||
|
->select()->toArray(); |
||||
|
foreach ($student_courses as &$v){ |
||||
|
$student = Db::name('student') |
||||
|
->alias('st') |
||||
|
->where('st.id', $v['student_id']) |
||||
|
->join('school_customer_resources cr', 'st.user_id = cr.id') |
||||
|
->join('school_member sm', 'cr.member_id = sm.member_id') |
||||
|
->field('st.name, sm.headimg as avatar') |
||||
|
->find(); |
||||
|
$v['name'] = $student['name']; |
||||
|
$v['avatar'] = $student['avatar']; |
||||
|
} |
||||
|
$list['student_courses'] = $student_courses; |
||||
|
|
||||
|
$Assignment = new Assignment(); |
||||
|
$search_model = $Assignment->where('course_id', $data) |
||||
|
->with(['student' => function($query) { |
||||
|
$query->with(['customerResources' => function($query) { |
||||
|
$query->with(['member' => function($query) { |
||||
|
$query->select(); |
||||
|
}]); |
||||
|
}]); |
||||
|
}]); |
||||
|
$search_model_res = $search_model->select()->toArray(); |
||||
|
$groupedByStatus1 = []; |
||||
|
$groupedByStatus2 = []; |
||||
|
$groupedByStatus3 = []; |
||||
|
|
||||
|
foreach ($search_model_res as $item) { |
||||
|
if ($item['status'] == 1){ |
||||
|
array_push($groupedByStatus1,$item); |
||||
|
} else if ($item['status'] == 2){ |
||||
|
array_push($groupedByStatus2,$item); |
||||
|
} else if ($item['status'] == 3){ |
||||
|
array_push($groupedByStatus3,$item); |
||||
|
} |
||||
|
} |
||||
|
$list['groupedByStatus1'] = $groupedByStatus1; |
||||
|
$list['groupedByStatus2'] = $groupedByStatus2; |
||||
|
$list['groupedByStatus3'] = $groupedByStatus3; |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//获取添加学员列表 |
||||
|
public function StudentList($id) |
||||
|
{ |
||||
|
$StudentCourses = new StudentCourses(); |
||||
|
$PersonCourseSchedule = new PersonCourseSchedule(); |
||||
|
$student_arr = $PersonCourseSchedule->where('schedule_id',$id)->column('student_id'); |
||||
|
|
||||
|
$query = $StudentCourses->where('course_id', $id); |
||||
|
if (!empty($student_arr)) { |
||||
|
$query->whereNotIn('student_id', $student_arr); |
||||
|
} |
||||
|
$res = $query->field('student_id as value')->select()->toArray(); |
||||
|
$Student = new Student(); |
||||
|
foreach ($res as $k => &$v) { |
||||
|
$StudentName = $Student->where('id',$v['value'])->value('name'); |
||||
|
$v['text'] = $StudentName; |
||||
|
} |
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
public function addStudent($data) |
||||
|
{ |
||||
|
$PersonCourseSchedule = new PersonCourseSchedule(); |
||||
|
$res = $PersonCourseSchedule->create($data); |
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function delStudentCourse($data) |
||||
|
{ |
||||
|
$StudentCourseUsage = new StudentCourseUsage(); |
||||
|
$StudentCourses = new StudentCourses(); |
||||
|
$StudentCourses_id = $StudentCourses->where('student_id',$data['student_id'])->where('course_id',$data['course_id'])->value('id'); |
||||
|
$PersonCourseSchedule_id = $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->value('id'); |
||||
|
if ($PersonCourseSchedule_id) { |
||||
|
$StudentCourseUsage->where('student_course_id',$StudentCourses_id)->delete(); |
||||
|
return true; |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\api\apiService; |
||||
|
|
||||
|
use app\model\campus\Campus; |
||||
|
use app\model\campus_person_role\CampusPersonRole; |
||||
|
use app\model\dict\Dict; |
||||
|
use core\base\BaseApiService; |
||||
|
|
||||
|
/** |
||||
|
* 统计控制器的服务层 |
||||
|
* Class MemberService |
||||
|
* @package app\service\api\member |
||||
|
*/ |
||||
|
class StatisticsService extends BaseApiService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue