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.
164 lines
4.5 KiB
164 lines
4.5 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/19 13:48:45
|
||
|
*/
|
||
|
|
||
|
namespace app\services\crud;
|
||
|
|
||
|
use app\services\BaseServices;
|
||
|
use think\exception\ValidateException;
|
||
|
use app\dao\crud\SchoolClassIpcDao;
|
||
|
use crmeb\services\FormBuilder;
|
||
|
|
||
|
/**
|
||
|
* Class CrudService
|
||
|
* @date 2023/10/19
|
||
|
* @package app\services\crud
|
||
|
*/
|
||
|
class SchoolClassIpcServices extends BaseServices
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* SchoolClassIpcServices constructor.
|
||
|
* @param SchoolClassIpcDao $dao
|
||
|
*/
|
||
|
public function __construct(SchoolClassIpcDao $dao)
|
||
|
{
|
||
|
$this->dao = $dao;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 主页数据接口
|
||
|
* @param array $where
|
||
|
* @return array
|
||
|
* @date 2023/10/19
|
||
|
*/
|
||
|
public function getCrudListIndex(array $where = [])
|
||
|
{
|
||
|
[$page, $limit] = $this->getPageValue();
|
||
|
$model = $this->dao->searchCrudModel($where, 'class_id,iot_id,id,create_time', 'id desc', ['classIdHasOne']);
|
||
|
$model->where('is_del', 0);
|
||
|
return ['count' => $model->count(), 'list' => $model->page($page ?: 1, $limit ?: 10)->select()->toArray()];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑和获取表单
|
||
|
* @date 2023/10/19
|
||
|
* @param int $id
|
||
|
* @return array
|
||
|
*/
|
||
|
public function getCrudForm(int $id = 0)
|
||
|
{
|
||
|
$url = '/crud/school_class_ipc';
|
||
|
$info = [];
|
||
|
if ($id) {
|
||
|
$info = $this->dao->get($id);
|
||
|
if (!$info) {
|
||
|
throw new ValidateException(100026);
|
||
|
}
|
||
|
$url .= '/' . $id;
|
||
|
}
|
||
|
$rule = [];
|
||
|
|
||
|
$rule[] = FormBuilder::number("class_id", "班级ID", $info["class_id"] ?? '');
|
||
|
$rule[] = FormBuilder::input("iot_id", "设备ID", $info["iot_id"] ?? '');
|
||
|
if (isset($info['create_time'])) {
|
||
|
$time = is_array($info['create_time']) ? $info['create_time'] : json_decode($info['create_time'], true);
|
||
|
} else {
|
||
|
$time = ['', ''];
|
||
|
}
|
||
|
$statTime = $time[0] ?? '';
|
||
|
$endTime = $time[1] ?? '';
|
||
|
$rule[] = FormBuilder::dateTimeRange("create_time", "添加时间", $statTime, $endTime);
|
||
|
if (isset($info['update_time'])) {
|
||
|
$time = is_array($info['update_time']) ? $info['update_time'] : json_decode($info['update_time'], true);
|
||
|
} else {
|
||
|
$time = ['', ''];
|
||
|
}
|
||
|
$statTime = $time[0] ?? '';
|
||
|
$endTime = $time[1] ?? '';
|
||
|
$rule[] = FormBuilder::dateTimeRange("update_time", "修改时间", $statTime, $endTime);
|
||
|
|
||
|
return create_form('关联列表', $rule, $url, $id ? 'PUT' : 'POST');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 新增
|
||
|
* @date 2023/10/19
|
||
|
* @param array $data
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function crudSave(array $data)
|
||
|
{
|
||
|
return $this->dao->save($data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改
|
||
|
* @date 2023/10/19
|
||
|
* @param int $id
|
||
|
* @param array $data
|
||
|
* @return \crmeb\basic\BaseModel
|
||
|
*/
|
||
|
public function crudUpdate(int $id, array $data)
|
||
|
{
|
||
|
return $this->dao->update($id, $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 通过设备ID查询数据
|
||
|
*/
|
||
|
public function selectDataByIotId($iot_id)
|
||
|
{
|
||
|
return $this->dao->selectDataByIotId($iot_id);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 通过班级ID查询数据
|
||
|
*/
|
||
|
public function selectDataByClassId($where)
|
||
|
{
|
||
|
$model = $this->dao->searchCrudModel($where, '*', 'id desc', ['classIdHasOne']);
|
||
|
return $model->select();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 查询单条数据
|
||
|
*/
|
||
|
public function read(array $where = [])
|
||
|
{
|
||
|
$model = $this->dao->searchCrudModel($where, '*', 'id desc', ['classIdHasOne']);
|
||
|
return $model->find();
|
||
|
}
|
||
|
|
||
|
public function ipcStatisticData()
|
||
|
{
|
||
|
$model = $this->dao->getThisModel()->field('id')->where('is_del', 0);
|
||
|
return $model->count();
|
||
|
}
|
||
|
|
||
|
public function selectBeClassId($classId)
|
||
|
{
|
||
|
$res = $this->dao->getOne([
|
||
|
'class_id' => $classId,
|
||
|
'is_del' => 0
|
||
|
]);
|
||
|
return is_null($res) ? false : true;
|
||
|
}
|
||
|
}
|