TaskSystem/app/common/logic/task/TaskLogic.php

755 lines
36 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\common\logic\task;
use app\common\logic\finance\TownShareProfit;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use app\common\model\task\Task;
use app\common\logic\BaseLogic;
use app\common\model\Company;
use app\common\model\informationg\UserInformationg;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use think\facade\Db;
use think\facade\Log;
/**
* 任务逻辑
* Class TaskLogic
* @package app\adminapi\logic\task
*/
class TaskLogic extends BaseLogic
{
/**
* @notes 添加任务
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/05 13:39
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Task::create([
'title' => $params['title'],
'template_id' => $params['template_id'],
'company_id' => $params['company_id'],
// 'admin_id' => $params['admin_id'],
'start_time' => strtotime($params['start_time']),
'end_time' => strtotime($params['end_time']),
'director_uid' => $params['director_uid'],
'type' => $params['type'],
'status' => $params['status'],
'content' => $params['content'],
'extend' => json_encode($params['extend'])
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* 定时添加任务
*/
public static function CronAdd(array $v, $datas): bool
{
try {
if ($v['types'] == 3) {
$task = Task::where('template_id', $v['id'])->find();
if ($task) {
// 累计任务进行天数,单次任务结算时,用于判断任务是否超时
TaskTemplate::where('id', $v['id'])->inc('day_count')->update();
// Task::where('template_id', $v['id'])->update(['start_time' => strtotime($task['start_time']) + 86400, 'end_time' => strtotime($task['end_time']) + 86400]);
// TaskTemplate::where('id', $v['id'])->inc('day_count')->update();
return true;
}
}
$v_day_count=$v['day_count'];
$v_day_count=$v_day_count+1;
$time = strtotime(date('Y-m-d'));
$TaskSchedulingPlan_data = [
'create_user_id' => 0,
'company_id' => $v['company_id'],
'template_id' => $v['id'],
'scheduling_id' => $v['task_scheduling'],
'start_time' => $time,
'end_time' => $time + 86399,
'sn' => User::createUserSn(),
'status' => 1
];
$TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data);
$arr = [
'template_id' => $v['id'],
'scheduling_plan_id' => $TaskSchedulingPlan['id'],
'company_id' => $v['company_id'],
'title' => $v['title'],
'money' => $v['money'],
'type' => $v['type'],
'content' => $v['content'],
'start_time' => $time,
'end_time' => $time + 86399,
'create_time' => time(),
'update_time' => time(),
];
$data = $arr;
$data['money'] = self::task_money($v, $datas);
$data['extend'] = json_encode($v['extend']);
//信息更新
if ($v['type'] == 31) {
$finds = TaskTemplate::where('id', $v['id'])->field('information_count,information_day_count')->find();
$update = 0;
if ($finds['information_count'] > $finds['information_day_count']) {
$day_count = $finds['information_count'] - $finds['information_day_count'];
if ($day_count >= 5) {
$update = 5;
} else {
$update = $day_count;
}
}
$data["extend"] = json_encode(['informationg' => ['count' => 5, 'update' => $update]]);
TaskTemplate::where('id', $v['id'])->inc('information_day_count', 5)->update();
}
if ($v['type'] == 32) {
$data['director_uid'] = $datas['company_info']['user_id'];
}
//入股任务
if ($v['type'] == 35) {
$responsible_area = Company::where('id', $v['company_id'])->value('responsible_area');
if ($responsible_area) {
$responsible_area = explode(',', $responsible_area);
} else {
Log::error('定时任务添加失败:没有区域' . json_encode($v));
return false;
}
if (isset($v['extend']['shareholder'])) {
$shareholder_user = User::where('id', $v['extend']['shareholder']['user_id'])->field('id,nickname,brigade')->find();
$v['extend']['shareholder']['money'] = $v['recharge'];
$v['extend']['shareholder']['over_decimal'] = $v['over_decimal'];
foreach ($responsible_area as $kkk => $vvv) {
$v['extend']['shareholder']['user_list'][$kkk] = ['info' => $shareholder_user['nickname'] . '需缴纳' . $vvv . '队,股金:' . bcdiv($v['recharge'], count($responsible_area), 2), 'time' => $v['create_time']];
}
$data['director_uid'] = $v['extend']['shareholder']['user_id'];
}
$data['extend'] = json_encode($v['extend']);
$money_one = bcmul($v['stage_day_one'], $v['money'], 2);
$money_two = bcmul($v['stage_day_two'], $v['money_two'], 2);
$data['money'] = bcadd($money_one, $money_two);
}
//片区交易
if ($v['type'] == 33) {
//基础金额*(每日基户数*天数)//且户数小于公司总户数
$user_count = UserInformationg::where('company_id', $v['company_id'])->count();
//
if ($v_day_count == 0) {
$user_count_two = 5 * 1;
} else {
$user_count_two = 5 * $v_day_count;
}
if ($user_count_two > $user_count) {
$user_count_money = 58 * $user_count;
} else {
$user_count_money = 58 * $user_count_two;
}
$extend = [
'transaction' => ['arr' => ['day_money' => $user_count_money, 'total_price' => 0]]
];
$data['extend'] = json_encode($extend);
}
// 其他任务
if ($v['type'] == 34) {
// is_commit 是否提交 note 详情描述 annex 附件
$extend = [
'other'=> [
'is_commit' => 0,
'note' => '',
'annex' => [],
'video_annex' => [],
]
];
$data['extend'] = json_encode($extend);
}
$task_id = (new Task())->insertGetId($data);
TaskSchedulingPlan::where('id', $TaskSchedulingPlan['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
TaskTemplate::where('id', $v['id'])->inc('day_count')->update();
return true;
} catch (\Exception $e) {
Log::error('定时任务添加失败'.$e->getMessage().'。line'.$e->getLine());
return false;
}
}
//任务金额
private static function task_money($v, $datas)
{
$v_day_count=$v['day_count'];
$v_day_count=$v_day_count+1;
$stageDayOneAccumulative = $v['stage_day_one']; // 第一阶段天数
$stageDayTwoAccumulative = bcadd($v['stage_day_one'], $v['stage_day_two']); // 第二阶段天数 第一+第二
if ($v['types'] == 1 || $v['types'] == 3) {
if ($v_day_count <= $stageDayOneAccumulative) {
return $v['money'];
} else {
return $v['money_two'];
}
} elseif ($v['types'] == 2) {
if ($v_day_count<= $stageDayOneAccumulative) {
return $v['money'];
} elseif ($stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) {
return $v['money_two'];
} else {
return $v['money_three'];
}
} else {
if ($v_day_count <= $v['stage_day_one']) {
$a = $v['money'];
} else {
$a = $v['money_two'];
}
if ($v_day_count >= $v['stage_day_two']) {
TaskTemplate::where('id', $v['id'])->update(['status' => 0]);
}
return $a;
}
}
/**
* @notes 更新任务状态
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/05 13:39
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Task::where('id', $params['id'])->update(['status' => 3, 'update_time' => 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/05 13:39
*/
public static function delete(array $params): bool
{
return Task::destroy($params['id']);
}
/**
* @notes 获取任务详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/05 13:39
*/
public static function detail($params): array
{
$task = Task::findOrEmpty($params['id'])->toArray();
if ($task) {
if (isset($task['extend']['informationg'])) {
$task['extend']['informationg'] = UserInformationg::where('id', $task['extend']['informationg'])->field('name,phone,sex,age,update_time')
->find()->toArray();
}
}
return $task;
}
/**
* 定时添加任务
*/
public static function TownCronAdd(array $taskTemplate)
{
try {
Log::info(['镇管理公司定时任务下发-任务模板', $taskTemplate]);
// 单次任务不重复下发,在结算时刷新任务时间
if ($taskTemplate['types'] == 3) {
$task = Task::where('template_id', $taskTemplate['id'])->find();
if ($task) {
// 累计任务进行天数,单次任务结算时,用于判断任务是否超时
TaskTemplate::where('id', $taskTemplate['id'])->inc('day_count')->update();
return true;
}
}
$time = strtotime(date('Y-m-d'));
// 任务类型code
$taskType = (new DictData())->getTownTaskType($taskTemplate['type']);
$TaskSchedulingPlan_data = [
'create_user_id' => 0,
'company_id' => $taskTemplate['company_id'],
'template_id' => $taskTemplate['id'],
'scheduling_id' => $taskTemplate['task_scheduling'],
'start_time' => $time,
'end_time' => $time + 86399,
'sn' => User::createUserSn(),
'status' => 1
];
$TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data);
Log::info(['镇管理公司定时任务下发-添加plan结果', $TaskSchedulingPlan]);
$serviceManagerUser = User::where(['company_id'=>$taskTemplate['company_id'], 'group_id'=> 14])->find();
Log::info(['镇管理公司定时任务下发-服务部长user信息', $serviceManagerUser]);
$arr = [
'template_id' => $taskTemplate['id'],
'scheduling_plan_id' => $TaskSchedulingPlan['id'],
'company_id' => $taskTemplate['company_id'],
'title' => $taskTemplate['title'],
'money' => $taskTemplate['money'],
'type' => $taskTemplate['type'],
'content' => $taskTemplate['content'],
'start_time' => $time,
'end_time' => $time + 86399,
'director_uid' => $serviceManagerUser['id'], // 默认都指派给服务部长
'create_time' => time(),
'update_time' => time(),
];
$data = $arr;
$data['money'] = self::countTownTaskMoney($taskTemplate);
$extend = [];
// 督促小组服务团队学习任务 扩展信息
if ($taskType == 'town_task_type_4') {
$extend = ['town_task_type_4' => ['study_photo'=>[], 'sign_in_table'=>'', 'study_content'=> '']];
}
$data['extend'] = json_encode($extend);
$task_id = (new Task())->insertGetId($data);
Log::info(['镇管理公司定时任务下发-添加task结果', $task_id]);
TaskSchedulingPlan::where('id', $TaskSchedulingPlan['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
// 任务累计进行天数 +1
TaskTemplate::where('id', $taskTemplate['id'])->inc('day_count')->update();
} catch (\Exception $e) {
Log::error('定时任务添加失败'.$e->getMessage().'。line'.$e->getLine());
}
}
private static function countTownTaskMoney($tempalte)
{
$v_day_count = $tempalte['day_count'];
$v_day_count = $v_day_count + 1;
$stageDayOneAccumulative = $tempalte['stage_day_one']; // 第一阶段天数
$stageDayTwoAccumulative = bcadd($tempalte['stage_day_one'], $tempalte['stage_day_two']); // 第二阶段天数 第一+第二
$stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $tempalte['stage_day_three']); // 第二阶段天数 第二阶段累计值+第三
// 单次和循环任务
if ($tempalte['types'] == 1 || $tempalte['types'] == 3) {
if ($v_day_count <= $stageDayOneAccumulative) {
// 第一阶段金额
return $tempalte['money'];
} else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) {
// 第二阶段金额
return $tempalte['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) {
// 第三阶段金额
return $tempalte['new_money_three'];
}
} elseif ($tempalte['types'] == 2) { // 长期任务
if ($v_day_count<= $stageDayOneAccumulative) {
// 第一阶段金额
return $tempalte['money'];
} elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) {
// 第二阶段金额
return $tempalte['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) {
// 第三阶段金额
return $tempalte['new_money_three'];
} else {
// 长期金额
return $tempalte['money_three'];
}
} else {
if ($v_day_count <= $tempalte['stage_day_one']) {
$a = $tempalte['money'];
} else {
$a = $tempalte['money_two'];
}
if ($v_day_count >= $tempalte['stage_day_two']) {
TaskTemplate::where('id', $tempalte['id'])->update(['status' => 0]);
}
return $a;
}
}
/**
* 先判定任务是否已完成 再按每个任务对应的结算方式结算
* $taskSchedulePlan 包含 task_tempalte、task_schedule、task_schedule_plan 三张表的信息
*/
public static function townTaskSettlement($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
// 任务类型用的数据字典主键id将id和value作映射避免测试和正式环境数据字典数据不一致时出问题
$townTaskTypeList = DictData::where(['type_value' => 'town_task_type', 'status' => 1])->column('value', 'id');
switch ($townTaskTypeList[$taskTemplateInfo['type']]){
case 'town_task_type_1':
// 协助总负责人开展工作任务
self::dealTownTask1($taskSchedulePlan);
break;
case 'town_task_type_2':
// 拓展小组服务团队工作任务
self::dealTownTask2($taskSchedulePlan);
break;
case 'town_task_type_3':
// 督促小组服务团队完成任务,协助开展工作,解决问题任务
self::dealTownTask3($taskSchedulePlan);
break;
case 'town_task_type_4':
// 督促小组服务团队学习任务
self::dealTownTask4($taskSchedulePlan);
break;
case 'town_task_type_5':
// 督促小组服务团队完成需求手机和交易任务
self::dealTownTask5($taskSchedulePlan);
break;
case 'town_task_type_6':
// 督促小组服务团队入股村联络员所成立的公司任务
self::dealTownTask6($taskSchedulePlan);
break;
case 'town_task_type_7':
// 安全工作任务
self::dealTownTask7($taskSchedulePlan);
break;
default :
return true;
}
}
/**
* 系统自动判定镇管理公司下属小组服务公司 是否100%完成每日任务:三轮车任务,档案更新任务,平台交易任务
*/
private static function dealTownTask1($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find();
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
$groupServiceCompanyList = Company::where(['street' => $townCompany['street'], 'company_type' => 18])->select()->toArray();
$isDone = 1; // 任务是否完成标记
$isTaskSchedule = 0; // 下属小组服务公司是否有每日任务安排标记
foreach ($groupServiceCompanyList as $groupServiceCompany) {
// 查询小组服务公司是否有对应的每日任务安排
$templateList = TaskTemplate::where(['company_id' => $groupServiceCompany['id']])->whereIn('type', [31, 32, 33])->select()->toArray();
// 未做任务安排的小组服务公司不在判定范围内,跳出本次循环
if(count($templateList) === 3) {
$isTaskSchedule = 1;
// 查询小组服务公司的循环任务有没有全部做完 任意有一个任务没有做完,则判定为该小组服务公司没有完成每日任务,即协助总负责人开展工作任务也认定失败
foreach ($templateList as $template) {
$task = Task::where(['template_id' => $template['id'], 'status' => 3])->find();
if (empty($task)) {
$isDone = 0;
break;
}
}
} else {
continue;
}
}
// 下属小组服务公司有任务安排,也完成了任务
if ($isDone === 1 && $isTaskSchedule === 1) {
// 做任务结算,分润
(new TownShareProfit())->townTaskType1($taskInfo, $townCompany, $taskSchedulePlan);
} else {
// 关闭任务
(new Task())->closeTask($taskSchedulePlan['task_id']);
Log::info('协助总负责人开展工作任务,结算失败:' . $taskTemplateInfo['title'] . '未完成。任务:' . json_encode($taskInfo));
}
}
/**
* 拓展小组服务团队工作任务 单次任务
* 当前任务进行天数 < 第一阶段天数 只刷新任务时间
* 当前任务进行天数 = 第一阶段天数 做第一阶段结算 如果第一阶段已完成全部任务,也要刷新任务时间,等到第二阶段结算时才结束任务
* 当前任务进行天数 > 第一阶段天数 但未到第二阶段结算时间 继续刷新任务时间
* 当前任务进行天数 = (第一阶段+第二阶段)天数 未完成则关闭任务 完成则结算第二阶段金额
*/
private static function dealTownTask2($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
$day = $taskTemplateInfo['stage_day_one'] + $taskTemplateInfo['stage_day_two'];
$task = Task::where('id', $taskSchedulePlan['task_id'])->with('director_info')->find();
// 当前任务进行天数 < 第一阶段天数 只刷新任务时间
if($taskTemplateInfo['day_count'] < $taskTemplateInfo['stage_day_one']) {
self::flushTaskTime($taskSchedulePlan);
return true;
}
// 当前任务进行天数 = 第一阶段天数 做第一阶段结算 如果第一阶段已完成全部任务,也要刷新任务时间,等到第二阶段结算时才结束任务
if($taskTemplateInfo['day_count'] == $taskTemplateInfo['stage_day_one']) {
// 已签约的小组服务合同个数
$contractCount = Contract::where(['party_a' => $townCompany['id'], 'status' => 1, 'contract_type' => 25])->count();
if ($contractCount < 9) {
self::flushTaskTime($taskSchedulePlan);
return false;
}
$totalMoney = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money'], 2);
$taskMoney = 0;
switch ($contractCount) {
case 9:
$taskMoney = bcmul($totalMoney, 0.4, 2);
break;
case 10:
$taskMoney = bcmul($totalMoney, 0.4, 2);
break;
case 11:
$taskMoney = bcmul($totalMoney, 0.5, 2);
break;
case 12:
$taskMoney = bcmul($totalMoney, 0.6, 2);
break;
case 13:
$taskMoney = bcmul($totalMoney, 0.6, 2);
break;
case 14:
$taskMoney = bcmul($totalMoney, 0.7, 2);
break;
case 15:
$taskMoney = bcmul($totalMoney, 1, 2);
break;
}
if ($contractCount > 15) {
$taskMoney = bcmul($totalMoney, 1, 2);
}
$task['money'] = $taskMoney; // 任务金额
(new TownShareProfit())->townTaskType2($task, $townCompany, $taskSchedulePlan, 1, $contractCount);
}
// 当前任务进行天数 > 第一阶段天数 但未到第二阶段结算 继续刷新任务时间
if($taskTemplateInfo['day_count'] > $taskTemplateInfo['stage_day_one'] && $taskTemplateInfo['day_count'] < $day){
self::flushTaskTime($taskSchedulePlan);
}
// 当前任务进行天数 = 第一+第二阶段天数 第二阶段结算
if ($taskTemplateInfo['day_count'] == $day) {
// 已签约的小组服务合同个数
$contractCount = Contract::where(['party_a' => $townCompany['id'], 'status' => 1, 'contract_type' => 25])->count();
// 第二阶段未完成
if ($contractCount < 15) {
// 关闭任务,并且没有奖励
(new Task())->closeTask($taskSchedulePlan['task_id']);
return false;
}
$taskMoney = bcmul($taskTemplateInfo['stage_day_two'], $taskTemplateInfo['money_two'], 2);
$task['money'] = $taskMoney; // 任务金额
(new TownShareProfit())->townTaskType2($task, $townCompany, $taskSchedulePlan, 2, $contractCount);
}
}
private static function flushTaskTime($taskSchedulePlan)
{
$time = strtotime(date('Y-m-d')); // 今天的 0000:00
TaskSchedulingPlan::where(['id' => $taskSchedulePlan['id']])->update(
[
'create_time' => $time+86400, //第二天的00:00:00
'update_time' =>time(),
'start_time'=>$time+86400, //第二天的00:00:00
'end_time'=>$time+86400+86399 //第二天的 23:59:59
]);
Task::where('id', $taskSchedulePlan['task_id'])->update(
[
'create_time' => $time+86400,
'update_time' => time(),
'start_time'=> $time+86400,
'end_time'=> $time+86400+86399
]);
}
private static function dealTownTask3($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
$groupServiceCompanyList = Company::where(['street' => $townCompany['street'], 'company_type' => 18])->select()->toArray();
$task = Task::where('id', $taskSchedulePlan['task_id'])->with('director_info')->find();
// 完成任务情况
list($groupServiceCompanyCount, $doneTaskGroupServiceCompanyCount) = self::taskType3DoneInfo($groupServiceCompanyList);
$doneRate = bcdiv($doneTaskGroupServiceCompanyCount, $groupServiceCompanyCount,2);
// <80% 未完成任务 关闭本次任务
if (bccomp($doneRate, 0.8, 2) == -1) {
(new Task())->closeTask($taskSchedulePlan['task_id']);
return true;
} else {
// 结算 分润
(new TownShareProfit())->townTaskType3($task, $townCompany, $taskSchedulePlan);
}
}
public static function taskType3DoneInfo($groupServiceCompanyList)
{
$groupServiceCompanyCount = count($groupServiceCompanyList); // 团队总数
$doneTaskGroupServiceCompanyCount = 0; // 完成任务团队总数
// 判定完成条件 组建成功的小组服务团队 每日完成档案更新任务和三轮车任务 的团队数量 >= 80% 小于80%则视为未完成
foreach ($groupServiceCompanyList as $groupServiceCompany) {
// 档案更新任务
$taskType31 = Task::where(['company_id' => $groupServiceCompany['id'], 'type' => 31, 'status' => 3])->find();
// 三轮车任务
$taskType32 = Task::where(['company_id' => $groupServiceCompany['id'], 'type' => 32, 'status' => 3])->find();
if (!empty($taskType31) && !empty($taskType32)) {
$doneTaskGroupServiceCompanyCount++;
}
}
return [$groupServiceCompanyCount, $doneTaskGroupServiceCompanyCount];
}
/**
* 督促小组服务团队学习任务 长期任务 前置操作每天要从APP端提交资料上来根据提交资料来判定当天任务有没有完成
* 任务完成条件学习照片5张签到表一份培训内容大纲 >= 50个字每月提交>=4次
* 1 当前任务进行天数 < 第一阶段天数 只判断当天是否完成 状态未完成则关闭任务
* 2 当前任务进行天数 = 第一阶段天数 做第一阶段结算 且更改 task_schedule_plan 状态为已结算,后续将会根据这个时间来统计、判断各阶段的周期内是否达成完成条件(*
* 3 第一阶段天数 < 当前任务进行天数 < (第一 + 第二) 只判断当天是否完成 状态未完成则关闭任务
* 4 当前任务进行天数 = (第一阶段+第二阶段)天数 第二阶段结算 且更改 task_schedule_plan 状态为已结算
* 5 第一阶段+第二阶段 < 当前任务进行天数 < (第一 + 第二 + 第三阶段天数) 只判断当天是否完成 状态未完成则关闭任务
* 6 当前任务进行天数 = (第一 + 第二 + 第三阶段天数) 第三阶段结算 且更改 task_schedule_plan 状态为已结算
* 7 当前任务进行天数 > (第一 + 第二 + 第三阶段天数) 但 当前任务进行天数/30 != 0 只判断当天是否完成 状态未完成则关闭任务
* 8 当前任务进行天数/30 = 0, 长期阶段结算 且更改 task_schedule_plan 状态为已结算
*/
private static function dealTownTask4($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
$taskDayCount = $taskTemplateInfo['day_count']; // 任务累计进行天数
$task = Task::where(['id', $taskSchedulePlan['task_id']])->find();
$stageDayOneAccumulative = $taskTemplateInfo['stage_day_one']; // 第一阶段累计天数
$stageDayTwoAccumulative = bcadd($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['stage_day_two']); // 第二阶段累计天数 第一+第二
$stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $taskTemplateInfo['stage_day_three']); // 第三阶段累计天数 第二阶段累计值+第三阶段天数
// 1 当前任务进行天数 < 第一阶段天数 只判断当天是否完成 状态未完成则关闭任务
if ($taskDayCount < $stageDayOneAccumulative) {
if ($task['status'] != 3) {
(new Task())->closeTask($task['id']);
}
return false;
}
// 2 当前任务进行天数 = 第一阶段天数 做第一阶段结算 且更改 task_schedule_plan 状态为已结算,后续将会根据这个时间来筛选、统计、判断各阶段周期内是否达成完成条件
if($taskDayCount == $stageDayOneAccumulative){
$doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->count();
if ($doneTaskCount >= 4) {
$task['money'] = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money'], 2);
(new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan);
}
return false;
}
// 3 第一阶段天数 < 当前任务进行天数 < (第一 + 第二) 只判断当天是否完成 状态未完成则关闭任务
if ($stageDayOneAccumulative < $taskDayCount && $taskDayCount < $stageDayTwoAccumulative) {
if ($task['status'] != 3) {
(new Task())->closeTask($task['id']);
}
return false;
}
// 4 当前任务进行天数 = (第一阶段+第二阶段)天数 第二阶段结算 且更改 task_schedule_plan 状态为已结算
if ($taskDayCount == $stageDayTwoAccumulative) {
// 上一次做了结算的任务计划
$lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find();
// 上一次结算后到现在,完成的任务次数
$doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count();
if ($doneTaskCount >= 4) {
$task['money'] = bcmul($taskTemplateInfo['stage_day_two'], $taskTemplateInfo['money_two'], 2);
(new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan);
}
return false;
}
// 5 第一阶段+第二阶段 < 当前任务进行天数 < (第一 + 第二 + 第三阶段天数) 只判断当天是否完成 状态未完成则关闭任务
if ($stageDayTwoAccumulative < $taskDayCount && $taskDayCount < $stageDayThreeAccumulative) {
if ($task['status'] != 3) {
(new Task())->closeTask($task['id']);
}
return false;
}
// 6 当前任务进行天数 = (第一 + 第二 + 第三阶段天数) 第三阶段结算 且更改 task_schedule_plan 状态为已结算
if ($taskDayCount == $stageDayThreeAccumulative) {
// 上一次做了结算的任务计划
$lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find();
// 上一次结算后到现在,完成的任务次数
$doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count();
if ($doneTaskCount >= 4) {
$task['money'] = bcmul($taskTemplateInfo['stage_day_three'], $taskTemplateInfo['new_money_three'], 2);
(new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan);
}
return false;
}
// 7 当前任务进行天数 > (第一 + 第二 + 第三阶段天数) 但 当前任务进行天数/30 != 0 只判断当天是否完成 状态未完成则关闭任务
if($taskDayCount > $stageDayThreeAccumulative && $taskDayCount%30 != 0) {
if ($task['status'] != 3) {
(new Task())->closeTask($task['id']);
}
return false;
}
// 8 当前任务进行天数/30 = 0, 长期阶段结算 且更改 task_schedule_plan 状态为已结算
if ($taskDayCount > $stageDayThreeAccumulative && $taskDayCount%30 == 0) {
// 上一次做了结算的任务计划
$lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find();
// 上一次结算后到现在,完成的任务次数
$doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count();
if ($doneTaskCount >= 4) {
$task['money'] = bcmul(30, $taskTemplateInfo['money_three'], 2);
(new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan);
}
return false;
}
}
private static function dealTownTask5($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskScheduleInfo = $taskSchedulePlan['scheduling'];
}
private static function dealTownTask6($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskScheduleInfo = $taskSchedulePlan['scheduling'];
}
private static function dealTownTask7($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskScheduleInfo = $taskSchedulePlan['scheduling'];
}
}