WokerTask/app/adminapi/controller/task_template/TaskTemplateController.php

168 lines
5.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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_template;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\task_template\TaskTemplateLists;
use app\common\logic\ShopRequestLogic;
use app\common\logic\task_template\TaskTemplateLogic;
use app\adminapi\validate\task_template\TaskTemplateValidate;
use app\common\model\Company;
use app\common\model\task\Task;
/**
* 任务模板控制器
* Class TaskTemplateController
* @package app\adminapi\controller\task_template
*/
class TaskTemplateController extends BaseAdminController
{
/**
* @notes 获取任务模板列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/06 17:30
*/
public function lists()
{
return $this->dataLists(new TaskTemplateLists());
}
/**
* @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'] = $this->adminId;
$company = Company::find($params['company_id']);
if ($company->company_type == 16) {
// 创建 镇合伙人公司 任务模板
$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');
$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');
$task = Task::where(['template_id' =>$params['id']])->whereDay('start_time', 'today')->find();
if(!empty($task)) {
return $this->fail('该任务今天已在进行中,无法删除');
}
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())->goCheck('detail');
$result = TaskTemplateLogic::detail($params);
return $this->data($result);
}
public function getProductList()
{
$param = $this->request->param(); // page keyword
$p['page'] = $param['page_no'] ?? 1;
$p['keyword'] = $param['keyword'] ??'';
$result = ShopRequestLogic::getProductList($p);;
// $result['data']['count'] = 1000;
$data = [
'lists' => $result['data']['data'],
'count' => $result['data']['count'],
'page_no' => $result['data']['page'],
'page_size' => 10,
];
return $this->data($data);
}
public function checkRole()
{
$params = $this->request->param();
if ($params['task_role'] == 1) {
$serviceManagerUser = (new User())->searchMaster($params['company_id']);
if (empty($serviceManagerUser)) {
return $this->fail('公司还没有负责人,无法指派任务');
}
}
if ($params['task_role'] == 2) {
$serviceManagerUser = (new User())->searchMarketingManager($params['company_id']);
if (empty($serviceManagerUser)) {
return $this->fail('公司还没有市场部长,无法指派任务');
}
}
if ($params['task_role'] == 3) {
$serviceManagerUser = (new User())->searchServiceManager($params['company_id']);
if (empty($serviceManagerUser)) {
return $this->fail('公司还没有服务部长,无法指派任务');
}
}
return $this->success('成功');
}
}