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

426 lines
18 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\adminapi\logic\ConfigLogic;
use app\common\model\Company;
2023-08-07 09:36:32 +08:00
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;
use app\common\model\user\User;
2023-11-13 11:06:09 +08:00
use app\common\model\vehicle\VehicleRent;
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
{
try {
Db::startTrans();
2023-09-19 18:17:15 +08:00
// 其他任务可重复创建
if ($params['type'] != 34) {
$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-28 09:31:13 +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');
2023-08-30 15:23:15 +08:00
if($money_two+$params['money_two']>200){
2023-08-28 09:31:13 +08:00
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');
2023-08-30 15:23:15 +08:00
if($money_three+$params['money_three']>200){
2023-08-28 09:31:13 +08:00
self::setError('任务模板长期合计金额不能大于任务调度金额');
2023-08-18 21:13:51 +08:00
return false;
}
2023-08-24 16:08:13 +08:00
if($params['type']==32){
2023-11-13 11:06:09 +08:00
$VehicleRent = VehicleRent::where('rent_company_id',$params['company_id'])->find();
if(empty($VehicleRent)){
2023-08-24 16:44:48 +08:00
self::setError('该公司没有三轮车,请先租赁三轮车');
return false;
2023-08-24 16:08:13 +08:00
}
}
2023-09-20 13:46:17 +08:00
// 除了长期任务,其他阶段类型没有长期金额
if($params['types']!=2){
2023-08-28 09:31:13 +08:00
$params['money_three']=0;
2023-08-29 16:40:03 +08:00
}
if($params['type']==35){
$params['extend']=['shareholder'=>['user_id'=>$params['task_admin']]];
2023-08-28 09:31:13 +08:00
}
2023-09-19 18:17:15 +08:00
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-12-27 17:36:53 +08:00
// 'cron_time' => strtotime($params['cron_time']), // 定时下发日期
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-11-10 10:39:26 +08:00
$company = Company::find($params['company_id']);
2023-12-14 11:56:34 +08:00
if ($company->company_type == 16) {
// 创建 镇合伙人公司 任务模板
2023-11-10 10:39:26 +08:00
$taskScheduleAmount = 700;
} else {
$taskScheduleAmount = 200;
}
2023-11-18 18:25:17 +08:00
$find=TaskTemplate::where('task_scheduling', $params['task_scheduling'])->where('company_id',$params['company_id'])->where('type',$params['type'])->field('id,types,type,money,money_two,money_three,extend')->find();
2023-08-28 09:31:13 +08:00
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-11-10 10:39:26 +08:00
if($moeny+$params['money']-$find['money']>$taskScheduleAmount){
2023-08-28 09:31:13 +08:00
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
return false;
}
$money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
2023-11-10 10:39:26 +08:00
if($money_two+$params['money_two']-$find['money_two']>$taskScheduleAmount){
2023-08-28 09:31:13 +08:00
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');
2023-11-10 10:39:26 +08:00
if($money_three+$params['money_three']-$find['money_three']>$taskScheduleAmount){
2023-08-28 09:31:13 +08:00
self::setError('任务模板长期合计金额不能大于任务调度金额');
return false;
}
if($params['type']==32){
2023-11-13 11:06:09 +08:00
$VehicleRent = VehicleRent::where('rent_company_id',$params['company_id'])->find();
if(empty($VehicleRent)){
2023-08-28 09:31:13 +08:00
self::setError('该公司没有三轮车,请先租赁三轮车');
return false;
}
}
2023-09-20 13:46:17 +08:00
// 除了长期任务,其他阶段类型没有长期金额
if($params['types']!=2){
2023-08-28 09:31:13 +08:00
$params['money_three']=0;
}
2023-09-05 17:05:53 +08:00
if($params['type']==35){
$params['extend']=['shareholder'=>['user_id'=>$params['task_admin']]];
}
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-11-18 18:25:17 +08:00
'extend'=>json_encode(array_merge($find['extend'],$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();
}
public static function initCompanyWithdrawDeadline($companyId)
{
// 如果是公司第一次创建安排任务,初始化公司的可提现周期截止时间
$templateCount = TaskTemplate::where(['company_id' => $companyId])->count();
if ($templateCount == 1) {
$dictData = ConfigLogic::getDictTypeValueByType('withdraw_cycle');
$cycle = $dictData['withdraw_cycle_1']['value']; // 数据字典-提现周期 单位:天数
$today = strtotime(date('Y-m-d'));
$withdrawDeadline = $today + $cycle * 24 * 60 * 60 + 86400;
$company = Company::find($companyId);
$company->withdraw_deadline = $withdrawDeadline;
$company->save();
}
}
/**
* @notes 添加任务模板
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/06 17:30
*/
public static function addTownTaskTemplate(array $params): bool
{
try {
Db::startTrans();
// $params['extend']['task_role'] 扩展字段 任务角色 1总负责人 2市场部长 3服务部长
2023-10-25 17:55:18 +08:00
$taskScheduleAmount = 700;
if ($params['extend']['task_role'] == 1) {
$serviceManagerUser = (new User())->searchMaster($params['company_id']);
if (empty($serviceManagerUser)) {
self::setError('公司还没有负责人,无法指派任务');
return false;
}
}
if ($params['extend']['task_role'] == 2) {
$serviceManagerUser = (new User())->searchMarketingManager($params['company_id']);
if (empty($serviceManagerUser)) {
self::setError('公司还没有市场部长,无法指派任务');
return false;
}
}
if ($params['extend']['task_role'] == 3) {
$serviceManagerUser = (new User())->searchServiceManager($params['company_id']);
if (empty($serviceManagerUser)) {
self::setError('公司还没有服务部长,无法指派任务');
return false;
}
}
$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;
}
$moeny = TaskTemplate::where('company_id', $params['company_id'])->sum('money');
if($moeny + $params['money'] > $taskScheduleAmount){
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
return false;
}
$moneyTwo = TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
if($moneyTwo + $params['money_two'] > $taskScheduleAmount){
self::setError('任务模板二阶段合计金额不能大于任务调度金额');
return false;
}
$newMoneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('new_money_three');
if($newMoneyThree + $params['new_money_three'] > $taskScheduleAmount){
self::setError('任务模板三阶段合计金额不能大于任务调度金额');
return false;
}
$moneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('money_three');
if($moneyThree + $params['money_three']>$taskScheduleAmount){
self::setError('任务模板长期合计金额不能大于任务调度金额');
return false;
}
TaskTemplate::create([
'title' => $params['title'],
'admin_id' => $params['admin_id'],
'company_id' => $params['company_id'],
'task_scheduling' => $params['task_scheduling']??0,
'money' => $params['money'],
'money_two' => $params['money_two'],
'money_three' => $params['money_three'],
'type' => $params['type'],
'types' => $params['types'],
'status' => $params['status'],
'content' => $params['content'],
'extend'=>json_encode($params['extend']),
'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,
'recharge' => $params['recharge']??0,
'stage_day_three' => $params['stage_day_three']??0,
'new_money_three' => $params['new_money_three']??0,
2023-12-27 17:36:53 +08:00
// 'cron_time' => strtotime($params['cron_time']), // 定时下发日期
]);
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 addVillageTaskTemplate(array $params): bool
{
try {
Db::startTrans();
$serviceManagerUser = (new User())->searchLiaisonMan($params['company_id']);
if (empty($serviceManagerUser)) {
self::setError('公司还没有村联络员,无法指派任务');
return false;
}
$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;
}
$moeny = TaskTemplate::where('company_id', $params['company_id'])->sum('money');
if($moeny + $params['money'] > 200){
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
return false;
}
$moneyTwo = TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
if($moneyTwo + $params['money_two'] > 200){
self::setError('任务模板二阶段合计金额不能大于任务调度金额');
return false;
}
$newMoneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('new_money_three');
if($newMoneyThree + $params['new_money_three'] > 200){
self::setError('任务模板三阶段合计金额不能大于任务调度金额');
return false;
}
$moneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('money_three');
if($moneyThree + $params['money_three']>200){
self::setError('任务模板长期合计金额不能大于任务调度金额');
return false;
}
TaskTemplate::create([
'title' => $params['title'],
'admin_id' => $params['admin_id'],
'company_id' => $params['company_id'],
'task_scheduling' => $params['task_scheduling']??0,
'money' => $params['money'],
'money_two' => $params['money_two'],
'money_three' => $params['money_three'],
'type' => $params['type'],
'types' => $params['types'],
'status' => $params['status'],
'content' => $params['content'],
'extend'=>json_encode($params['extend']),
'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,
'recharge' => $params['recharge']??0,
'stage_day_three' => $params['stage_day_three']??0,
'new_money_three' => $params['new_money_three']??0,
2023-12-27 17:36:53 +08:00
// 'cron_time' => strtotime($params['cron_time']), // 定时下发日期
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
2023-08-07 09:36:32 +08:00
}