142 lines
4.4 KiB
PHP
142 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace app\middleapi\controller;
|
|
|
|
use app\common\logic\task_template\TaskTemplateLogic;
|
|
use app\adminapi\validate\task_template\TaskTemplateValidate;
|
|
use app\common\model\Company;
|
|
use app\common\model\task_template\TaskTemplate;
|
|
use app\common\model\task_scheduling\TaskScheduling;
|
|
use app\common\controller\BaseLikeAdminController;
|
|
|
|
/**
|
|
* 任务模板控制器
|
|
* Class TaskTemplateController
|
|
* @package app\adminapi\controller\task_template
|
|
*/
|
|
class TaskTemplateController extends BaseLikeAdminController
|
|
{
|
|
|
|
/**
|
|
* @notes 获取任务模板列表
|
|
* @return \think\response\Json
|
|
* @author likeadmin
|
|
* @date 2023/08/06 17:30
|
|
*/
|
|
public function lists()
|
|
{
|
|
if(!$this->request->isPost()){
|
|
return $this->fail('请求方式错误');
|
|
}
|
|
$params=$this->request->post(['page_no','page_size','title', 'type', 'status', 'company_id']);
|
|
$where = [];
|
|
if (isset($params['title']) && $params['title'] != '') {
|
|
$where[] = ['title', 'like', '%' . $params['title'] . '%'];
|
|
}
|
|
if (isset($params['type']) && $params['type'] != '') {
|
|
$where[] = ['type', '=', $params['type']];
|
|
}
|
|
if (isset($params['status']) && $params['status'] != '') {
|
|
$where[] = ['status', '=', $params['status']];
|
|
}
|
|
if (isset($params['company_id']) && $params['company_id'] != '') {
|
|
$where[] = ['company_id', '=', $params['company_id']];
|
|
}
|
|
$pageNo = !empty($params['page_no']) ? $params['page_no'] : 1;
|
|
$pageSize = !empty($params['page_size']) ? $params['page_size'] : 20;
|
|
$data = TaskTemplate::where($where)
|
|
->with(['admin','data_type'])
|
|
->page($pageNo, $pageSize)
|
|
->order(['id' => 'desc'])
|
|
->select()
|
|
->toArray();
|
|
$count = TaskTemplate::where($where)->count();
|
|
$result = [
|
|
'lists' => $data,
|
|
'count' => $count,
|
|
'page_no' => $pageNo,
|
|
'page_size' => $pageSize
|
|
];
|
|
return $this->success('请求成功',$result);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 添加任务模板
|
|
* @return \think\response\Json
|
|
* @author likeadmin
|
|
* @date 2023/08/06 17:30
|
|
*/
|
|
public function add()
|
|
{
|
|
$params = (new TaskTemplateValidate())->post()->goCheck('add');
|
|
$params['admin_id'] = 1;
|
|
if (empty($params['extend'])) {
|
|
$params['extend'] = '{}';
|
|
}
|
|
$company = Company::find($params['company_id']);
|
|
if ($company->company_type == 41) {
|
|
// 创建 镇农科公司 任务模板
|
|
$result = TaskTemplateLogic::addTownTaskTemplate($params);
|
|
} else if ($company->company_type == 17) {
|
|
$result = TaskTemplateLogic::addVillageTaskTemplate($params);
|
|
} else {
|
|
$result = TaskTemplateLogic::add($params);
|
|
}
|
|
if (true === $result) {
|
|
TaskTemplateLogic::initCompanyWithdrawDeadline($params['company_id']);
|
|
return $this->success('添加成功', [], 1, 1);
|
|
}
|
|
return $this->fail(TaskTemplateLogic::getError());
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑任务模板
|
|
* @return \think\response\Json
|
|
* @author likeadmin
|
|
* @date 2023/08/06 17:30
|
|
*/
|
|
public function edit()
|
|
{
|
|
$params = (new TaskTemplateValidate())->post()->goCheck('edit');
|
|
if (empty($params['extend'])) {
|
|
$params['extend'] = '{}';
|
|
}
|
|
$params['admin_id'] = 1;
|
|
$result = TaskTemplateLogic::edit($params);
|
|
if (true === $result) {
|
|
return $this->success('编辑成功', [], 1, 1);
|
|
}
|
|
return $this->fail(TaskTemplateLogic::getError());
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除任务模板
|
|
* @return \think\response\Json
|
|
* @author likeadmin
|
|
* @date 2023/08/06 17:30
|
|
*/
|
|
public function delete()
|
|
{
|
|
$params = (new TaskTemplateValidate())->post()->goCheck('delete');
|
|
TaskTemplateLogic::delete($params);
|
|
return $this->success('删除成功', [], 1, 1);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取任务模板详情
|
|
* @return \think\response\Json
|
|
* @author likeadmin
|
|
* @date 2023/08/06 17:30
|
|
*/
|
|
public function detail()
|
|
{
|
|
$params = (new TaskTemplateValidate())->post()->goCheck('detail');
|
|
$result = TaskTemplateLogic::detail($params);
|
|
return $this->data($result);
|
|
}
|
|
|
|
} |