You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
355 lines
11 KiB
355 lines
11 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\chat_friends\ChatFriends;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\person_course_schedule\PersonCourseSchedule;
|
|
use app\model\personnel\Personnel;
|
|
use app\model\student_course_usage\StudentCourseUsage;
|
|
use app\model\venue\Venue;
|
|
use core\base\BaseApiService;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 测试-控制器服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class PersonCourseScheduleService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
//查询列表
|
|
public function getList(array $where)
|
|
{
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数
|
|
$page = $page_params['page'];
|
|
$limit = $page_params['limit'];
|
|
|
|
$model = new PersonCourseSchedule();
|
|
//判断有没有客户资源id
|
|
if (!empty($where['resources_id'])) {
|
|
$model = $model->where('resources_id', $where['resources_id']);
|
|
}
|
|
|
|
//上课日期
|
|
if (!empty($where['course_date'])) {
|
|
$model = $model->where('school_person_course_schedule.course_date', $where['course_date']);
|
|
}
|
|
|
|
//判断有没有客户上课状态
|
|
if (array_key_exists('status', $where) && $where['status'] != '') {
|
|
// $model = $model->where('status', $where['status']);
|
|
$model = $model->where('school_person_course_schedule.status', $where['status']);
|
|
}
|
|
|
|
$venues_info = [];//场地信息
|
|
// 判断有没有场地ID
|
|
if (!empty($where['venue_id'])) {
|
|
$model = $model->hasWhere('courseScheduleHasOne', ['venue_id' => $where['venue_id']]);
|
|
$venues_info = Venue::where('id', $where['venue_id'])->find();
|
|
if ($venues_info) {
|
|
$venues_info = $venues_info->toArray();
|
|
} else {
|
|
$venues_info = [];
|
|
}
|
|
}
|
|
|
|
$data = $model->order('course_date', 'desc')
|
|
->with([
|
|
//课程安排表
|
|
'courseScheduleHasOne' => function ($query) {
|
|
$query->with([
|
|
'venue',//场地
|
|
'campus',//校区
|
|
'course',//课程
|
|
'coach',//教练
|
|
]);
|
|
},
|
|
])
|
|
->paginate([
|
|
'list_rows' => $limit,
|
|
'page' => $page,
|
|
])
|
|
->toArray();
|
|
|
|
$data['venues_info'] = $venues_info;//场地信息详情
|
|
return $data;
|
|
}
|
|
|
|
//查询详情
|
|
public function getInfo(array $where)
|
|
{
|
|
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '暂无数据',
|
|
'data' => []
|
|
];
|
|
|
|
$model = new PersonCourseSchedule();
|
|
//判断有无人员与课程安排关系表id
|
|
if (!empty($where['person_course_schedule_id'])) {
|
|
$model = $model->where('id', $where['person_course_schedule_id']);
|
|
}
|
|
$data = $model
|
|
->with([
|
|
//课程安排表
|
|
'courseScheduleHasOne' => function ($query) {
|
|
$query->with([
|
|
'venue',//场地
|
|
'campus',//校区
|
|
'course',//课程
|
|
'coach',//教练
|
|
]);
|
|
},
|
|
])
|
|
->find();
|
|
|
|
|
|
if ($data) {
|
|
$data = $data->toArray();
|
|
|
|
if (empty($data['courseScheduleHasOne']['id'])) {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '暂无课程安排数据',
|
|
'data' => []
|
|
];
|
|
return $res;
|
|
}
|
|
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => $data
|
|
];
|
|
return $res;
|
|
} else {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '暂无数据',
|
|
'data' => []
|
|
];
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
//修改人员与课程安排关系表
|
|
public function editStatus($person_course_schedule_id, array $data)
|
|
{
|
|
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '操作失败',
|
|
'data' => []
|
|
];
|
|
|
|
if (empty($data['updated_at'])) {
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
}
|
|
|
|
$model = PersonCourseSchedule::where('id', $person_course_schedule_id)->find();
|
|
if (!$model) {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '未找到课程安排信息',
|
|
'data' => []
|
|
];
|
|
return $res;
|
|
}
|
|
|
|
//状态0待上课1已上课2请假
|
|
if (in_array($model['status'], [0, 2])) {
|
|
$edit = PersonCourseSchedule::where('id', $person_course_schedule_id)->update($data);
|
|
|
|
if ($edit) {
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => []
|
|
];
|
|
}
|
|
return $res;
|
|
} elseif ($model['status'] == 1) {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '该课程已上课无法请假',
|
|
'data' => []
|
|
];
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
//获取排课日期
|
|
public function getCalendar(array $where)
|
|
{
|
|
$data = PersonCourseSchedule::where('resources_id', $where['resources_id'])
|
|
->where('course_date', '>=', $where['start_date'])
|
|
->where('course_date', '<=', $where['end_date'])
|
|
->select()
|
|
->toArray();
|
|
|
|
$result = [];
|
|
$currentDate = strtotime($where['start_date']);
|
|
$endDate = strtotime($where['end_date']);
|
|
|
|
while ($currentDate <= $endDate) {
|
|
$dateStr = date('Y-m-d', $currentDate);
|
|
$today = date('d', $currentDate);
|
|
$weekDay = date('w', $currentDate);
|
|
$weekMap = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
|
$weekStr = $weekMap[$weekDay];
|
|
|
|
$result[] = [
|
|
'date' => $dateStr,
|
|
'status' => '1', // 默认状态为正常
|
|
'is_sign' => '0', // 是否有课|1=有课,0=没课
|
|
'week' => $weekStr,
|
|
'today' => $today
|
|
];
|
|
|
|
$currentDate = strtotime('+1 day', $currentDate);
|
|
}
|
|
|
|
foreach ($data as $v) {
|
|
foreach ($result as &$rv) {
|
|
if ($rv['date'] == $v['course_date']) {
|
|
//0待上课1已上课2请假
|
|
if (in_array($v['status'], [0, 1])) {
|
|
$status = '1';
|
|
} else {
|
|
$status = '2';
|
|
}
|
|
$rv['status'] = $status;//状态1是正常 2请假
|
|
$rv['is_sign'] = '1';//是否有课|1=有课,0=没课
|
|
}
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
//获取学生排课的全部场地列表
|
|
public function getVenueListAll(array $where)
|
|
{
|
|
$schedule_id = PersonCourseSchedule::where('resources_id', $where['resources_id'])
|
|
->where('course_date', $where['course_date'])
|
|
->distinct(true)
|
|
->column('schedule_id');
|
|
|
|
if(!$schedule_id){
|
|
return [];
|
|
}
|
|
|
|
$venue_id = CourseSchedule::whereIn('id',$schedule_id)->distinct(true)->column('venue_id');
|
|
if(!$venue_id){
|
|
return [];
|
|
}
|
|
|
|
$res = Venue::whereIn('id',$venue_id)
|
|
->with([
|
|
'campus'
|
|
])
|
|
->select()->toArray();
|
|
|
|
return $res;
|
|
}
|
|
|
|
//获取学生排课的教练列表
|
|
public function memberCoachList(array $where)
|
|
{
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数
|
|
$page = $page_params['page'];
|
|
$limit = $page_params['limit'];
|
|
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '暂无课程安排',
|
|
'data' => []
|
|
];
|
|
|
|
$schedule_id = PersonCourseSchedule::where('resources_id', $where['resources_id'])->distinct(true)->column('schedule_id');
|
|
if(!$schedule_id){
|
|
return $res;
|
|
}
|
|
$coach_id = CourseSchedule::whereIn('id',$schedule_id)->distinct(true)->column('coach_id');
|
|
if(!$coach_id){
|
|
return $res;
|
|
}
|
|
|
|
$data = Personnel::whereIn('id', $coach_id)
|
|
->paginate([
|
|
'list_rows' => $limit,
|
|
'page' => $page,
|
|
])
|
|
->toArray();
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => $data
|
|
];
|
|
return $res;
|
|
|
|
}
|
|
|
|
//获取学生课时消费记录列表
|
|
public function getStudentCourseUsageList(array $where)
|
|
{
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数
|
|
$page = $page_params['page'];
|
|
$limit = $page_params['limit'];
|
|
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '暂无更多',
|
|
'data' => []
|
|
];
|
|
|
|
$schedule_id = PersonCourseSchedule::where('resources_id',$where['resources_id'])
|
|
->where('status',1)
|
|
->distinct(true)
|
|
->column('schedule_id');
|
|
|
|
if(!$schedule_id){
|
|
return $res;
|
|
}
|
|
|
|
$data = StudentCourseUsage::whereIn('student_course_id',$schedule_id)
|
|
->order('usage_date', 'desc')
|
|
->with([
|
|
'studentCourseHasOne' => function ($query) {
|
|
$query->append(['course']);
|
|
}
|
|
])
|
|
->paginate([
|
|
'list_rows' => $limit,
|
|
'page' => $page,
|
|
])
|
|
->toArray();
|
|
|
|
if(!count($data['data'])){
|
|
return $res;
|
|
}
|
|
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => $data
|
|
];
|
|
|
|
return $res;
|
|
}
|
|
}
|
|
|