TaskSystem/app/common/logic/task_template/TaskTemplateLogic.php

214 lines
8.4 KiB
PHP
Raw Normal View History

2023-08-07 09:36:32 +08:00
<?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\logic\task_template;
use app\common\model\task_template\TaskTemplate;
use app\common\logic\BaseLogic;
2023-08-24 16:08:13 +08:00
use app\common\model\company\CompanyProperty;
2023-08-22 14:32:57 +08:00
use app\common\model\informationg\UserInformationg;
2023-08-16 00:14:09 +08:00
use app\common\model\task_scheduling\TaskScheduling;
2023-08-07 09:36:32 +08:00
use think\facade\Db;
/**
* 任务模板逻辑
* Class TaskTemplateLogic
* @package app\adminapi\logic\task_template
*/
class TaskTemplateLogic extends BaseLogic
{
/**
* @notes 添加任务模板
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/06 17:30
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
2023-08-28 09:31:13 +08:00
$find=TaskTemplate::where('task_scheduling', $params['task_scheduling'])->where('company_id',$params['company_id'])->where('type',$params['type'])->field('id,types,type')->find();
if($find&&$params['type']==$find['type']){
self::setError('已经有同一种任务类型了');
return false;
}
2023-08-22 14:32:57 +08:00
if($params['type']==33){
$count=UserInformationg::where('company_id',$params['company_id'])->where('status',1)->count();
if($count<300){
self::setError('用户档案数量300不足无法创建任务模板');
return false;
}
}
2023-08-18 18:11:32 +08:00
2023-08-28 09:31:13 +08:00
$moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money');
if($moeny+$params['money']>200){
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
2023-08-18 21:13:51 +08:00
return false;
}
2023-08-28 09:31:13 +08:00
$money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
if($money_two+$params['money']>200){
self::setError('任务模板二阶段合计金额不能大于任务调度金额');
2023-08-18 21:13:51 +08:00
return false;
}
2023-08-28 09:31:13 +08:00
$money_three=TaskTemplate::where('company_id', $params['company_id'])->sum('money_three');
if($money_three+$params['money']>200){
self::setError('任务模板长期合计金额不能大于任务调度金额');
2023-08-18 21:13:51 +08:00
return false;
}
2023-08-24 16:08:13 +08:00
if($params['type']==32){
$object_id=CompanyProperty::where('company_id',$params['company_id'])->value('object_id');
if(!$object_id){
2023-08-24 16:44:48 +08:00
self::setError('该公司没有三轮车,请先租赁三轮车');
return false;
2023-08-24 16:08:13 +08:00
}
}
2023-08-28 09:31:13 +08:00
if($params['types']!=33){
$params['money_three']=0;
}
2023-08-07 09:36:32 +08:00
TaskTemplate::create([
'title' => $params['title'],
'admin_id' => $params['admin_id'],
2023-08-16 00:14:09 +08:00
'company_id' => $params['company_id'],
2023-08-18 16:32:41 +08:00
'task_scheduling' => $params['task_scheduling']??0,
2023-08-10 17:10:12 +08:00
'money' => $params['money'],
2023-08-16 09:53:11 +08:00
'money_two' => $params['money_two'],
'money_three' => $params['money_three'],
2023-08-07 09:36:32 +08:00
'type' => $params['type'],
2023-08-16 09:53:11 +08:00
'types' => $params['types'],
2023-08-07 09:36:32 +08:00
'status' => $params['status'],
2023-08-14 15:34:38 +08:00
'content' => $params['content'],
2023-08-18 10:12:56 +08:00
'extend'=>json_encode($params['extend']),
2023-08-16 09:53:11 +08:00
'stage_day_one' => $params['stage_day_one']??0,
'proportion_one' => $params['proportion_one']??0,
'stage_day_two' => $params['stage_day_two']??0,
'proportion_two' => $params['proportion_two']??0,
2023-08-28 18:46:43 +08:00
'recharge' => $params['recharge']??0,
2023-08-07 09:36:32 +08:00
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑任务模板
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/06 17:30
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
2023-08-28 09:31:13 +08:00
$find=TaskTemplate::where('task_scheduling', $params['task_scheduling'])->where('company_id',$params['company_id'])->where('type',$params['type'])->field('id,types,type')->find();
if($find && $find['id']!=$params['id']&&$params['type']==$find['type']){
self::setError('已经有同一种任务类型了');
return false;
}
if($params['type']==33){
$count=UserInformationg::where('company_id',$params['company_id'])->where('status',1)->count();
if($count<300){
self::setError('用户档案数量300不足无法创建任务模板');
return false;
}
}
2023-08-16 00:14:09 +08:00
$moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money');
2023-08-28 09:31:13 +08:00
if($moeny+$params['money']>200){
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
return false;
}
$money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
if($money_two+$params['money']>200){
self::setError('任务模板二阶段合计金额不能大于任务调度金额');
2023-08-16 00:14:09 +08:00
return false;
}
2023-08-28 09:31:13 +08:00
$money_three=TaskTemplate::where('company_id', $params['company_id'])->sum('money_three');
if($money_three+$params['money']>200){
self::setError('任务模板长期合计金额不能大于任务调度金额');
return false;
}
if($params['type']==32){
$object_id=CompanyProperty::where('company_id',$params['company_id'])->value('object_id');
if(!$object_id){
self::setError('该公司没有三轮车,请先租赁三轮车');
return false;
}
}
if($params['types']!=33){
$params['money_three']=0;
}
2023-08-07 09:36:32 +08:00
TaskTemplate::where('id', $params['id'])->update([
'title' => $params['title'],
'admin_id' => $params['admin_id'],
2023-08-10 17:10:12 +08:00
'money' => $params['money'],
2023-08-16 09:53:11 +08:00
'money_two' => $params['money_two'],
'money_three' => $params['money_three'],
2023-08-07 09:36:32 +08:00
'type' => $params['type'],
2023-08-16 09:53:11 +08:00
'types' => $params['types'],
2023-08-07 09:36:32 +08:00
'status' => $params['status'],
2023-08-14 15:34:38 +08:00
'content' => $params['content'],
2023-08-18 10:12:56 +08:00
'extend'=>json_encode($params['extend']),
2023-08-16 09:53:11 +08:00
'stage_day_one' => $params['stage_day_one']??0,
'proportion_one' => $params['proportion_one']??0,
'stage_day_two' => $params['stage_day_two']??0,
'proportion_two' => $params['proportion_two']??0,
2023-08-28 18:46:43 +08:00
'recharge' => $params['recharge']??0,
2023-08-07 09:36:32 +08:00
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除任务模板
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/06 17:30
*/
public static function delete(array $params): bool
{
return TaskTemplate::destroy($params['id']);
}
/**
* @notes 获取任务模板详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/06 17:30
*/
public static function detail($params): array
{
return TaskTemplate::findOrEmpty($params['id'])->toArray();
}
}