add 任务类别-后台

This commit is contained in:
chenbo 2024-02-22 10:19:16 +08:00
parent 907c48c206
commit fe29d2137a
5 changed files with 431 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\task;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\task\TaskTypeLists;
use app\adminapi\logic\task\TaskTypeLogic;
use app\adminapi\validate\task\TaskTypeValidate;
/**
* TaskType控制器
* Class TaskTypeController
* @package app\adminapi\controller\task
*/
class TaskTypeController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function lists()
{
return $this->dataLists(new TaskTypeLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function add()
{
$params = (new TaskTypeValidate())->post()->goCheck('add');
$result = TaskTypeLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(TaskTypeLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function edit()
{
$params = (new TaskTypeValidate())->post()->goCheck('edit');
$result = TaskTypeLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(TaskTypeLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function delete()
{
$params = (new TaskTypeValidate())->post()->goCheck('delete');
TaskTypeLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function detail()
{
$params = (new TaskTypeValidate())->goCheck('detail');
$result = TaskTypeLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\task;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\task\TaskType;
use app\common\lists\ListsSearchInterface;
/**
* TaskType列表
* Class TaskTypeLists
* @package app\adminapi\liststask
*/
class TaskTypeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function setSearch(): array
{
return [
'=' => ['num', 'name'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function lists(): array
{
return TaskType::where($this->searchWhere)
->field(['id', 'dataid', 'project', 'num', 'name', 'superior_sort', 'level', 'remarks'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function count(): int
{
return TaskType::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,118 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\task;
use app\common\model\task\TaskType;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* TaskType逻辑
* Class TaskTypeLogic
* @package app\adminapi\logic\task
*/
class TaskTypeLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/22 10:06
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
TaskType::create([
'dataid' => $params['dataid'],
'project' => $params['project'],
'num' => $params['num'],
'name' => $params['name'],
'superior_sort' => $params['superior_sort'],
'level' => $params['level'],
'remarks' => $params['remarks'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/22 10:06
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
TaskType::where('id', $params['id'])->update([
'dataid' => $params['dataid'],
'project' => $params['project'],
'num' => $params['num'],
'name' => $params['name'],
'superior_sort' => $params['superior_sort'],
'level' => $params['level'],
'remarks' => $params['remarks'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/22 10:06
*/
public static function delete(array $params): bool
{
return TaskType::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/22 10:06
*/
public static function detail($params): array
{
return TaskType::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\task;
use app\common\validate\BaseValidate;
/**
* TaskType验证器
* Class TaskTypeValidate
* @package app\adminapi\validate\task
*/
class TaskTypeValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return TaskTypeValidate
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return TaskTypeValidate
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return TaskTypeValidate
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return TaskTypeValidate
* @author likeadmin
* @date 2024/02/22 10:06
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\task;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* TaskType模型
* Class TaskType
* @package app\common\model\task
*/
class TaskType extends BaseModel
{
use SoftDelete;
protected $name = 'task_type';
protected $deleteTime = 'delete_time';
}