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.
191 lines
5.4 KiB
191 lines
5.4 KiB
10 months ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* +----------------------------------------------------------------------
|
||
|
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
|
* +----------------------------------------------------------------------
|
||
|
* | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||
|
* +----------------------------------------------------------------------
|
||
|
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
|
* +----------------------------------------------------------------------
|
||
|
* | Author: CRMEB Team <admin@crmeb.com>
|
||
|
* +----------------------------------------------------------------------
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* 班级管理
|
||
|
* @author crud自动生成代码
|
||
|
* @date 2023/10/13 11:46:22
|
||
|
*/
|
||
|
|
||
|
namespace app\services\crud;
|
||
|
|
||
|
use app\services\BaseServices;
|
||
|
use think\exception\ValidateException;
|
||
|
use app\dao\crud\SchoolGradeClassDao;
|
||
|
use crmeb\services\FormBuilder;
|
||
|
|
||
|
use app\services\crud\SchoolGradeServices;
|
||
|
|
||
|
/**
|
||
|
* Class CrudService
|
||
|
* @date 2023/10/13
|
||
|
* @package app\services\crud
|
||
|
*/
|
||
|
class SchoolGradeClassServices extends BaseServices
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* SchoolGradeClassServices constructor.
|
||
|
* @param SchoolGradeClassDao $dao
|
||
|
*/
|
||
|
public function __construct(SchoolGradeClassDao $dao)
|
||
|
{
|
||
|
$this->dao = $dao;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 主页数据接口
|
||
|
* @param array $where
|
||
|
* @param int $school_id
|
||
|
* @param int $grade_id
|
||
|
* @return array
|
||
|
* @date 2023/10/13
|
||
|
*/
|
||
|
public function getCrudListIndex(array $where = [], $school_id = 0, $grade_id = 0)
|
||
|
{
|
||
|
[$page, $limit] = $this->getPageValue();
|
||
|
$model = $this->dao->searchCrudModel($where, '*', 'id desc', ['gradeIdHasOne']);
|
||
|
$model->where('is_del', 0);
|
||
|
|
||
|
if ($school_id > 0) {
|
||
|
$model->where('school_id', $school_id);
|
||
|
}
|
||
|
if ($grade_id > 0) {
|
||
|
$model->where('grade_id', $grade_id);
|
||
|
}
|
||
|
|
||
|
return ['count' => $model->count(), 'list' => $model->page($page ?: 1, $limit ?: 10)->select()->toArray()];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑和获取表单
|
||
|
* @date 2023/10/13
|
||
|
* @param int $id
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getCrudForm(int $id = 0)
|
||
|
{
|
||
|
$url = '/crud/school_grade_class';
|
||
|
$info = [];
|
||
|
if ($id) {
|
||
|
$info = $this->dao->get($id);
|
||
|
if (!$info) {
|
||
|
throw new ValidateException(100026);
|
||
|
}
|
||
|
$url .= '/' . $id;
|
||
|
}
|
||
|
$rule = [];
|
||
|
|
||
|
$rule[] = FormBuilder::input("class_name", "班级名称", $info["class_name"] ?? '');
|
||
|
|
||
|
$SchoolGradeServices = app()->make(SchoolGradeServices::class);
|
||
|
$gradeList = $SchoolGradeServices->selectGradeData();
|
||
|
if (!empty($gradeList)) {
|
||
|
foreach ($gradeList as $key => $value) {
|
||
|
$gradeList[$key]['label'] = $value['school_name'] . ':' . $value['grade_name'];
|
||
|
}
|
||
|
}
|
||
|
$rule[] = FormBuilder::select("grade_id", "年级名称", $info["grade_id"] ?? '')->setOptions($gradeList)->filterable(1);
|
||
|
|
||
|
|
||
|
return create_form('班级管理', $rule, $url, $id ? 'PUT' : 'POST');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 新增
|
||
|
* @date 2023/10/13
|
||
|
* @param array $data
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function crudSave(array $data)
|
||
|
{
|
||
|
$SchoolGradeServices = app()->make(SchoolGradeServices::class);
|
||
|
$gradeData = $SchoolGradeServices->selectGradeById($data['grade_id']);
|
||
|
$data['grade_name'] = $gradeData['grade_name'];
|
||
|
$data['school_id'] = $gradeData['school_id'];
|
||
|
$data['school_name'] = $gradeData['school_name'];
|
||
|
|
||
|
$res = $this->dao->save($data);
|
||
|
$res->save(['class_code' => creat_code('B') . $res->id]);
|
||
|
return $res;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改
|
||
|
* @date 2023/10/13
|
||
|
* @param int $id
|
||
|
* @param array $data
|
||
|
* @return \crmeb\basic\BaseModel
|
||
|
*/
|
||
|
public function crudUpdate(int $id, array $data)
|
||
|
{
|
||
|
$SchoolGradeServices = app()->make(SchoolGradeServices::class);
|
||
|
$gradeData = $SchoolGradeServices->selectGradeById($data['grade_id']);
|
||
|
$data['grade_name'] = $gradeData['grade_name'];
|
||
|
$data['school_id'] = $gradeData['school_id'];
|
||
|
$data['school_name'] = $gradeData['school_name'];
|
||
|
return $this->dao->update($id, $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 查询邀请码
|
||
|
*/
|
||
|
public function selectClassCodeData(string $code)
|
||
|
{
|
||
|
return $this->dao->selectClassCodeData($code);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取班级邀请码
|
||
|
*/
|
||
|
public function selectClassCode($id)
|
||
|
{
|
||
|
return $this->dao->selectClassCode($id);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 通过学校查询全部班级
|
||
|
*/
|
||
|
public function selectSchoolClass($schoolId)
|
||
|
{
|
||
|
return $this->dao->selectSchoolClass($schoolId);
|
||
|
}
|
||
|
|
||
|
public function classStatisticData()
|
||
|
{
|
||
|
$model = $this->dao->getThisModel()->field('id')->where('is_del', 0);
|
||
|
return $model->count();
|
||
|
}
|
||
|
|
||
|
public function getNameToData($className)
|
||
|
{
|
||
|
$model = $this->dao->getThisModel()->field('id')->where('class_name', $className)->where('is_del', 0);
|
||
|
return $model->select()->toArray();
|
||
|
}
|
||
|
|
||
|
public function selectByGradeId($gradeId)
|
||
|
{
|
||
|
$res = $this->dao->getOne([
|
||
|
'grade_id' => $gradeId,
|
||
|
'is_del' => 0
|
||
|
]);
|
||
|
return is_null($res) ? false : true;
|
||
|
}
|
||
|
|
||
|
public function getUserClassData(array $classIds)
|
||
|
{
|
||
|
return $this->dao->getColumn([['id', 'IN', $classIds]], 'class_name', 'id');
|
||
|
}
|
||
|
}
|