智慧教务系统 PHP-NiuCloud框架开发
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.
 
 
 
 
 
 

171 lines
5.4 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace addon\zhjw\app\service\admin\schedules;
use addon\zhjw\app\model\schedules\Schedules;
use addon\zhjw\app\model\staff\Staff;
use addon\zhjw\app\model\classes\Classes;
use core\base\BaseAdminService;
use DateInterval;
use DatePeriod;
use DateTime;
/**
* 排班管理服务层
* Class SchedulesService
* @package addon\zhjw\app\service\admin\schedules
*/
class SchedulesService extends BaseAdminService
{
public function __construct()
{
parent::__construct();
$this->model = new Schedules();
}
/**
* 获取排班管理列表
* @param array $where
* @return array
*/
public function getPage(array $where = [])
{
$field = 'id,staff_id,class_id,date_time,time_slot,task,is_deleted,create_time,update_time,created_by,created_role,updated_by,updated_role';
$order = 'id desc';
$search_model = $this->model->withSearch(["staff_id","class_id","date_time","task","create_time"], $where)->with(['staff','classes'])->field($field)->order($order);
$list = $this->pageQuery($search_model);
return $list;
}
/**
* 获取排班管理信息
* @param int $id
* @return array
*/
public function getInfo(int $id)
{
$field = 'id,staff_id,class_id,date_time,time_slot,task,is_deleted,create_time,update_time,created_by,created_role,updated_by,updated_role';
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['staff','classes'])->findOrEmpty()->toArray();
return $info;
}
public function get_info(array $data)
{
// $list = $this->model->where(['date_time' => '2025-04-01'])->order("id desc")->select()->toArray();
// $start_date = new DateTime('2025-04-02'); // 开始日期
// $end_date = new DateTime('2025-04-30'); // 月末(4 月 30 日)
// $interval = new DateInterval('P1D'); // 每次递增 1 天
// $period = new DatePeriod($start_date, $interval, $end_date->modify('+1 day'));
// foreach ($list as $k => $v) {
// unset($v['id']);
// foreach ($period as $date) {
// $v['date_time'] = $date->format('Y-m-d');
// $v['create_time'] = time();
// $v['update_time'] = time();
// $this->model->insert($v);
// }
// }
//
// echo "成功";die;
$list = $this->model->where($data)->order("time_slot asc")->select();
foreach ($list as $k => $v) {
$v['students_ids'] = explode(",", $v['students_ids']);
$v['time_slot'] = explode(",", $v['time_slot']);
}
$staff_id = isset($list[0]['staff_id']) ? $list[0]['staff_id'] : '';
return ['staff_id' => $staff_id,'schedules' => $list ? $list->toArray() :[]];
}
/**
* 添加排班管理
* @param array $data
* @return mixed
*/
public function add(array $data)
{
$del = $this->model->where([
['class_id', '=', $data['class_id']],
['date_time', '=', $data['date_time']],
['courses_id', '=', $data['courses_id']]
])->select();
foreach ($del as $k=>$v){
$v->delete();
}
foreach ($data['schedules'] as $k=>$v){
$start_time = strtotime($v['time_slot'][0]);
$end_time = strtotime($v['time_slot'][1]);
$diff_minutes = ($end_time - $start_time) / 3600;
$this->model->insert([
'staff_id' => $data['staff_id'],
'class_id' => $data['class_id'],
'courses_id' => $data['courses_id'],
'date_time' => $data['date_time'],
'time_slot' => implode(",",$v['time_slot']),
'task' => $v['task'],
'students_ids' => implode(",",$v['students_ids']),
'create_time' => time(),
'update_time' => time(),
'status' => 1,
'hour' => $diff_minutes
]);
}
return "添加成功";
}
/**
* 排班管理编辑
* @param int $id
* @param array $data
* @return bool
*/
public function edit(int $id, array $data)
{
$data['time_slot'] = implode(",",$data['time_slot']);
$this->model->where([['id', '=', $id]])->update($data);
return true;
}
/**
* 删除排班管理
* @param int $id
* @return bool
*/
public function del(int $id)
{
$model = $this->model->where([['id', '=', $id]])->find();
$res = $model->delete();
return $res;
}
public function getStaffAll(){
$staffModel = new Staff();
return $staffModel->select()->toArray();
}
public function getClassesAll(){
$classesModel = new Classes();
return $classesModel->select()->toArray();
}
}