|
|
|
@ -19,6 +19,7 @@ use app\model\assignment\Assignment; |
|
|
|
use app\model\course\Course; |
|
|
|
use app\model\student_courses\StudentCourses; |
|
|
|
use core\base\BaseApiService; |
|
|
|
use DateTime; |
|
|
|
use think\Model; |
|
|
|
use think\facade\Db; |
|
|
|
|
|
|
|
@ -217,6 +218,101 @@ class CourseService extends BaseApiService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getDate(array $baseDate) |
|
|
|
{ |
|
|
|
$dates = []; |
|
|
|
|
|
|
|
$this_date = $baseDate['date'] ?: date('Y-m-d'); |
|
|
|
|
|
|
|
$date = new DateTime($this_date); |
|
|
|
|
|
|
|
for ($i = -2; $i <= 4; $i++) { |
|
|
|
$tempDate = clone $date; // 避免修改原始对象 |
|
|
|
$tempDate->modify("$i days"); |
|
|
|
|
|
|
|
$status = false; |
|
|
|
if($baseDate['day'] == $tempDate->format('d')){ |
|
|
|
$status = true; |
|
|
|
}else if(empty($baseDate['day'])){ |
|
|
|
if($tempDate->format('Y-m-d') === date('Y-m-d')){ |
|
|
|
$status = true; |
|
|
|
} |
|
|
|
} |
|
|
|
$dates[] = [ |
|
|
|
'date' => $tempDate->format('Y-m-d'), |
|
|
|
'day' => $tempDate->format('d'), |
|
|
|
'week' => getChineseWeekday($tempDate), |
|
|
|
'status' => $status |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
return ['dates' => $dates,'date' => $this_date]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function listAll($data) |
|
|
|
{ |
|
|
|
$where = []; |
|
|
|
if ($data['schedule_date']) { |
|
|
|
$where[] = ['course_date','=', $data['schedule_date']]; |
|
|
|
} |
|
|
|
$CourseSchedule = new CourseSchedule(); |
|
|
|
$list = $CourseSchedule |
|
|
|
->where($where) |
|
|
|
->with(['course' => function($query) { |
|
|
|
$query->select(); |
|
|
|
},'venue' => function($query) { |
|
|
|
$query->select(); |
|
|
|
},'campus','studentCourses'])->select()->toArray(); |
|
|
|
foreach ($list 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[$k]['student'] = $student; |
|
|
|
} |
|
|
|
return $list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function addSchedule(array $data){ |
|
|
|
$CourseSchedule = new CourseSchedule(); |
|
|
|
$personCourseSchedule = new PersonCourseSchedule(); |
|
|
|
if($personCourseSchedule->where([ |
|
|
|
'resources_id' => $data['resources_id'], |
|
|
|
'schedule_id' => $data['schedule_id'] |
|
|
|
])->find()){ |
|
|
|
return fail("重复添加"); |
|
|
|
} |
|
|
|
|
|
|
|
$personCourseSchedule->insert([ |
|
|
|
'resources_id' => $data['resources_id'], |
|
|
|
'person_id' => $this->member_id, |
|
|
|
'person_type' => $data['person_type'], |
|
|
|
'schedule_id' => $data['schedule_id'], |
|
|
|
'course_date' => $data['course_date'], |
|
|
|
'time_slot' => $data['time_slot'], |
|
|
|
]); |
|
|
|
$CourseSchedule->where(['id' => $data['schedule_id']])->dec("available_capacity")->update(); |
|
|
|
return success("添加成功"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function schedule_list(array $data){ |
|
|
|
$personCourseSchedule = new PersonCourseSchedule(); |
|
|
|
$list = $personCourseSchedule |
|
|
|
->alias('a') |
|
|
|
->join(['school_customer_resources' => 'b'],'a.resources_id = b.id','left') |
|
|
|
->where('a.schedule_id',$data['schedule_id']) |
|
|
|
->field("b.name,a.status") |
|
|
|
->select()->toArray(); |
|
|
|
|
|
|
|
return $list; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|