new files
This commit is contained in:
181
pro_v3.5.1/app/controller/admin/v1/agent/AgentLevelTask.php
Normal file
181
pro_v3.5.1/app/controller/admin/v1/agent/AgentLevelTask.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\admin\v1\agent;
|
||||
|
||||
|
||||
use app\controller\admin\AuthController;
|
||||
use app\services\agent\AgentLevelTaskServices;
|
||||
use FormBuilder\Exception\FormBuilderException;
|
||||
use think\annotation\Inject;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Response;
|
||||
|
||||
|
||||
/**
|
||||
* Class AgentLevelTask
|
||||
* @package app\controller\admin\v1\agent
|
||||
*/
|
||||
class AgentLevelTask extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AgentLevelTaskServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected AgentLevelTaskServices $services;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = $this->request->getMore([
|
||||
['id', 0],
|
||||
['status', ''],
|
||||
['keyword', '']
|
||||
]);
|
||||
if (!$where['id']) {
|
||||
return $this->fail('缺少参数ID');
|
||||
}
|
||||
$where['level_id'] = $where['id'];
|
||||
unset($where['id']);
|
||||
return $this->success($this->services->getLevelTaskList($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return Response
|
||||
* @throws FormBuilderException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
[$level_id] = $this->request->postMore([
|
||||
['level_id', 0]], true);
|
||||
if (!$level_id) {
|
||||
return $this->fail('缺少等级ID');
|
||||
}
|
||||
return $this->success($this->services->createForm((int)$level_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @return Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = $this->request->postMore([
|
||||
['level_id', 0],
|
||||
['name', ''],
|
||||
['type', ''],
|
||||
['number', 0],
|
||||
['desc', 0],
|
||||
['sort', 0],
|
||||
['status', 0]]);
|
||||
if (!$data['level_id']) return $this->fail('缺少等级ID');
|
||||
if (!$data['name']) return $this->fail('请输入等级名称');
|
||||
if (!$data['type']) return $this->fail('请选择任务类型');
|
||||
if (!$data['number']) return $this->fail('请输入限定数量');
|
||||
$this->services->checkTypeTask(0, $data);
|
||||
$data['add_time'] = time();
|
||||
$this->services->save($data);
|
||||
return $this->success('添加等级任务成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* @throws FormBuilderException
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return $this->success($this->services->editForm((int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = $this->request->postMore([
|
||||
['name', ''],
|
||||
['type', ''],
|
||||
['number', 0],
|
||||
['desc', 0],
|
||||
['sort', 0],
|
||||
['status', 0]]);
|
||||
if (!$data['name']) return $this->fail('请输入等级名称');
|
||||
if (!$data['type']) return $this->fail('请选择任务类型');
|
||||
if (!$data['number']) return $this->fail('请输入限定数量');
|
||||
if (!$levelTaskInfo = $this->services->getLevelTaskInfo((int)$id)) return $this->fail('编辑的任务不存在!');
|
||||
$this->services->checkTypeTask((int)$id, $data);
|
||||
$levelTaskInfo->name = $data['name'];
|
||||
$levelTaskInfo->type = $data['type'];
|
||||
$levelTaskInfo->number = $data['number'];
|
||||
$levelTaskInfo->desc = $data['desc'];
|
||||
$levelTaskInfo->sort = $data['sort'];
|
||||
$levelTaskInfo->status = $data['status'];
|
||||
$levelTaskInfo->save();
|
||||
return $this->success('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if (!$id) return $this->fail('参数错误,请重新打开');
|
||||
$levelTaskInfo = $this->services->getLevelTaskInfo((int)$id);
|
||||
if ($levelTaskInfo) {
|
||||
$res = $this->services->update($id, ['is_del' => 1]);
|
||||
if (!$res)
|
||||
return $this->fail('删除失败,请稍候再试!');
|
||||
}
|
||||
return $this->success('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param int $id
|
||||
* @param string $status
|
||||
* @return mixed
|
||||
*/
|
||||
public function set_status($id = 0, $status = '')
|
||||
{
|
||||
if ($status == '' || $id == 0) return $this->fail('参数错误');
|
||||
$this->services->update($id, ['status' => $status]);
|
||||
return $this->success($status == 0 ? '隐藏成功' : '显示成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user