镇管理公司任务-任务5结算

This commit is contained in:
chenbo 2023-09-23 10:38:07 +08:00
parent cc90ca0130
commit 0e5697f454
3 changed files with 94 additions and 35 deletions

View File

@ -8,6 +8,7 @@ use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
use app\common\model\task\Task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\UserAccountLog;
use app\common\model\user\User;
use think\facade\Db;
@ -84,6 +85,26 @@ class TownShareProfit
return false;
}
}
public function townTaskType5($taskInfo, $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]);
// 更新镇交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
/**
* 分润
*/

View File

@ -25,6 +25,7 @@ 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\Exception;
use think\facade\Db;
use think\facade\Log;
@ -408,42 +409,47 @@ class TaskLogic extends BaseLogic
*/
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']]){
try {
$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;
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;
}
} catch (Exception $e) {
Log::error('镇管理任务结算失败'.$e->getMessage());
}
}
/**
@ -734,16 +740,44 @@ class TaskLogic extends BaseLogic
}
}
/**
* 查镇所属小组服务公司当日实际完成金额总和+镇管理公司的资金池
* 查镇所属小组服务公司当日任务目标金额总和
*/
private static function dealTownTask5($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskScheduleInfo = $taskSchedulePlan['scheduling'];
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
$townTask = Task::where('id', $taskSchedulePlan['task_id'])->find();
$groupServiceCompanyList = Company::where(['street' => $townCompany['street']])->select()->toArray();
$townTransactionPool = $taskTemplateInfo['transaction_pool']; // 镇交易池
$townTotalTradeAmount = 0; // 镇下属小组服务公司 每日实际总交易额
$targetAmount = 0; // 镇下属小组服务公司每日 目标总交易额
// 查镇所属小组服务公司当日任务目标金额总和
foreach ($groupServiceCompanyList as $groupServiceCompany) {
$tempTask = Task::withJoin(['task_schedule_plan'],'left')->where('task_schedule_plan.is_pay', 1)->where(['company_id'=> $groupServiceCompany['id'], 'status'=>3, 'type'=>33])->whereDay('start_time','today')->find();
if ($tempTask) {
$extend = json_decode($tempTask['extend'], true);
$targetAmount += $extend['transaction']['arr']['day_money'];
$townTotalTradeAmount += $extend['transaction']['arr']['total_price'];
}
}
// 完成条件: 查镇所属小组服务公司当日实际完成金额总和+镇管理公司的资金池 > 查镇所属小组服务公司当日任务目标金额总和
if(bcadd($townTransactionPool, $townTotalTradeAmount, 2) >= $targetAmount) {
// 将余下金额放入镇交易池
$leftTransactionPool = bcsub(bcadd($townTransactionPool, $townTotalTradeAmount, 2), $targetAmount, 2);
(new TownShareProfit())->townTaskType5($townTask, $townCompany, $taskSchedulePlan, $leftTransactionPool);
} else {
// 关闭任务
(new Task())->closeTask($taskSchedulePlan['task_id']);
}
}
private static function dealTownTask6($taskSchedulePlan)
{
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$taskScheduleInfo = $taskSchedulePlan['scheduling'];
}
private static function dealTownTask7($taskSchedulePlan)

View File

@ -53,4 +53,8 @@ class TaskTemplate extends BaseModel
return json_decode($value,true);
}
}
public function updateTransactionPool($id, $transactionPool)
{
return TaskTemplate::where('id', $id)->save(['transaction_pool' => $transactionPool]);
}
}