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.
 
 
 
 
 
 

225 lines
5.3 KiB

<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
/**
* school
* @author crud自动生成代码
* @date 2023/10/11
*/
namespace app\adminapi\controller\crud;
use app\adminapi\controller\AuthController;
use think\facade\App;
use app\services\crud\SchoolServices;
use app\services\crud\SchoolGradeServices;
/**
* Class School
* @date 2023/10/11
* @package app\adminapi\controller\crud
*/
class School extends AuthController
{
/**
* @var SchoolServices
*/
protected $service;
/**
* SchoolController constructor.
* @param App $app
* @param SchoolServices $service
*/
public function __construct(App $app, SchoolServices $service)
{
parent::__construct($app);
$this->service = $service;
}
/**
* 列表
* @date 2023/10/11
* @return \think\Response
*/
public function index()
{
$where = $this->request->getMore([
['school_name', ''],
['school_u_phone', ''],
['school_u_name', ''],
['create_time', ''],
['update_time', ''],
]);
return app('json')->success($this->service->getCrudListIndex($where));
}
/**
* 创建
* @return \think\Response
* @date 2023/10/11
*/
public function create()
{
return app('json')->success($this->service->getCrudForm());
}
/**
* 保存
* @return \think\Response
* @date 2023/10/11
*/
public function save()
{
$data = $this->request->postMore([
['school_name', ''],
['school_u_phone', ''],
['school_u_name', ''],
['create_time', date('Y-m-d H:i:s', time())],
]);
validate(\app\adminapi\validate\crud\SchoolValidate::class)->check($data);
$this->service->crudSave($data);
return app('json')->success(100021);
}
/**
* 编辑获取数据
* @param $id
* @return \think\Response
* @date 2023/10/11
*/
public function edit($id)
{
return app('json')->success($this->service->getCrudForm((int)$id));
}
/**
* 修改
* @param $id
* @return \think\Response
* @date 2023/10/11
*/
public function update($id)
{
if (!$id) {
return app('json')->fail(100100);
}
$data = $this->request->postMore([
['school_name', ''],
['school_u_phone', ''],
['school_u_name', ''],
['update_time', date('Y-m-d H:i:s', time())],
]);
validate(\app\adminapi\validate\crud\SchoolValidate::class)->check($data);
$this->service->crudUpdate((int)$id, $data);
return app('json')->success(100001);
}
/**
* 修改状态
* @param $id
* @return \think\Response
* @date 2023/10/11
*/
public function status($id)
{
if (!$id) {
return app('json')->fail(100100);
}
$data = $this->request->postMore([
['field', ''],
['value', '']
]);
$filedAll = [];
if (!in_array($data['field'], $filedAll)) {
return app('json')->fail(100100);
}
if ($this->service->update(['id' => $id], [$data['field'] => $data['value']])) {
return app('json')->success(100001);
} else {
return app('json')->fail(100100);
}
}
/**
* 删除
* @param $id
* @return \think\Response
* @date 2023/10/11
*/
public function delete($id)
{
if (!$id) {
return app('json')->fail(100100);
}
$SchoolGradeServices = app()->make(SchoolGradeServices::class);
if ($SchoolGradeServices->selectBySchoolId($id) == true) {
return app('json')->fail('该学校下有年级,请先删除年级');
}
if ($this->service->update(['id' => $id], ['is_del' => 1])) {
return app('json')->success(100002);
} else {
return app('json')->success(100008);
}
}
/**
* 查看
* @param $id
* @return \think\Response
* @date 2023/10/11
*/
public function read($id)
{
if (!$id) {
return app('json')->fail(100100);
}
$info = $this->service->get($id, ['*'], []);
if (!$info) {
return app('json')->fail(100100);
}
return app('json')->success($info->toArray());
}
/**
* 获取学校列表
*/
public function getSchoolList($id)
{
$selectSchoolData = $this->service->selectSchoolData();
if ($id > 0) {
unset($selectSchoolData[0]);
$selectSchoolData = array_values($selectSchoolData);
}
return app('json')->success($selectSchoolData);
}
}