add 镇农科负责人任务结算
This commit is contained in:
parent
98bf3edbab
commit
a34a4e0bd4
@ -642,4 +642,15 @@ class TaskController extends BaseApiController
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交 镇农科负责人-信息收集
|
||||
* 将信息收集存入task_template表中
|
||||
*/
|
||||
publiC function commit_town_master_task_type_3()
|
||||
{
|
||||
$param = $this->request->param();
|
||||
$task = Task::where(['id'=>$param['id']])->find();
|
||||
$taskTemplate = TaskTemplate::where(['id'=>$task['template_id']])->find();
|
||||
}
|
||||
}
|
||||
|
@ -410,4 +410,40 @@ class TownShareProfit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function dealTaskSettlementMaster2(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
// 更改结算状态
|
||||
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
|
||||
// 更改任务状态
|
||||
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function dealTaskSettlementMaster5(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
// 更改结算状态
|
||||
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
|
||||
// 更改任务状态
|
||||
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace app\common\logic\task;
|
||||
use app\common\logic\finance\TownShareProfit;
|
||||
use app\common\logic\finance\VillageShareProfit;
|
||||
use app\common\logic\ShopRequestLogic;
|
||||
use app\common\model\Approve;
|
||||
use app\common\model\company\CompanyAccountLog;
|
||||
use app\common\model\CompanyComplaintFeedback;
|
||||
use app\common\model\contract\Contract;
|
||||
@ -438,6 +439,11 @@ class TaskLogic extends BaseLogic
|
||||
|
||||
$time = strtotime(date('Y-m-d'));
|
||||
$directorUid = 0; // 指派给
|
||||
if ($taskTemplate['extend']['task_role'] == 1) {
|
||||
$marketingManagerUser = (new User())->searchMaster($taskTemplate['company_id']);
|
||||
Log::info(['镇农科公司定时任务下发-负责人user信息', $marketingManagerUser]);
|
||||
$directorUid = $marketingManagerUser['id'];
|
||||
}
|
||||
if ($taskTemplate['extend']['task_role'] == 2) {
|
||||
$marketingManagerUser = (new User())->searchMarketingManager($taskTemplate['company_id']);
|
||||
Log::info(['镇农科公司定时任务下发-市场部长user信息', $marketingManagerUser]);
|
||||
@ -507,6 +513,9 @@ class TaskLogic extends BaseLogic
|
||||
$data = $arr;
|
||||
|
||||
// 不同角色,计算任务金额有差异
|
||||
if($taskTemplate['extend']['task_role'] == 1) {
|
||||
$data['money'] = self::countTownMasterTaskMoney($taskTemplate);
|
||||
}
|
||||
if($taskTemplate['extend']['task_role'] == 2) {
|
||||
$data['money'] = self::countTownTaskMarketingMoney($taskTemplate);
|
||||
}
|
||||
@ -623,9 +632,43 @@ class TaskLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
private static function countTownMasterTaskMoney()
|
||||
private static function countTownMasterTaskMoney($template)
|
||||
{
|
||||
$v_day_count = $template['day_count'];
|
||||
$v_day_count = $v_day_count + 1;
|
||||
$stageDayOneAccumulative = $template['stage_day_one']; // 第一阶段天数
|
||||
$stageDayTwoAccumulative = bcadd($template['stage_day_one'], $template['stage_day_two']); // 第二阶段天数 第一+第二
|
||||
$stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $template['stage_day_three']); // 第三阶段天数 第二阶段累计值+第三
|
||||
|
||||
// 单次和循环任务
|
||||
if ($template['types'] == 1 || $template['types'] == 3) {
|
||||
if ($v_day_count <= $stageDayOneAccumulative) {
|
||||
// 第一阶段金额
|
||||
return $template['money'];
|
||||
} else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) {
|
||||
// 第二阶段金额
|
||||
return $template['money_two'];
|
||||
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) {
|
||||
// 第三阶段金额
|
||||
return $template['new_money_three'];
|
||||
}
|
||||
} elseif ($template['types'] == 2) {
|
||||
// 长期任务
|
||||
|
||||
if ($v_day_count<= $stageDayOneAccumulative) {
|
||||
// 第一阶段金额
|
||||
return $template['money'];
|
||||
} elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) {
|
||||
// 第二阶段金额
|
||||
return $template['money_two'];
|
||||
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) {
|
||||
// 第三阶段金额
|
||||
return $template['new_money_three'];
|
||||
} else {
|
||||
// 长期金额
|
||||
return $template['money_three'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -637,9 +680,9 @@ class TaskLogic extends BaseLogic
|
||||
try {
|
||||
Log::info(['镇农科公司定时任务结算执行-任务计划', $taskSchedulePlan]);
|
||||
$taskTemplateInfo = $taskSchedulePlan['template_info'];
|
||||
// 负责人任务结算 todo
|
||||
// 负责人任务结算
|
||||
if ($taskTemplateInfo['extend']['task_role'] == 1) {
|
||||
|
||||
self::masterTaskSettlement($taskSchedulePlan);
|
||||
}
|
||||
// 市场部长任务结算
|
||||
if ($taskTemplateInfo['extend']['task_role'] == 2) {
|
||||
@ -656,6 +699,194 @@ class TaskLogic extends BaseLogic
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 镇农科负责人任务结算
|
||||
*/
|
||||
private static function masterTaskSettlement($taskSchedulePlan)
|
||||
{
|
||||
try {
|
||||
$taskTemplateInfo = $taskSchedulePlan['template_info'];
|
||||
// 任务类型用的数据字典主键id,将id和value作映射,避免测试和正式环境数据字典数据不一致时出问题
|
||||
$townTaskTypeList = DictData::where(['type_value' => 'town_task_type_master', 'status' => 1])->column('value', 'id');
|
||||
switch ($townTaskTypeList[$taskTemplateInfo['type']]){
|
||||
// 应用软件推广
|
||||
case 'town_task_type_master_2':
|
||||
self::masterTask2Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 信息收集与促销
|
||||
case 'town_task_type_master_3':
|
||||
self::masterTask3Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 种养殖基地订单匹配
|
||||
case 'town_task_type_master_4':
|
||||
self::masterTask4Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 村联络员招募
|
||||
case 'town_task_type_master_5':
|
||||
self::masterTask5Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 促成村联络员入股甲方
|
||||
case 'town_task_type_master_6':
|
||||
self::masterTask6Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 政策补贴申请
|
||||
case 'town_task_type_master_7':
|
||||
self::masterTask7Settlement($taskSchedulePlan);
|
||||
break;
|
||||
// 日常管理及其他临时任务
|
||||
case 'town_task_type_master_8':
|
||||
self::masterTask8Settlement($taskSchedulePlan);
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error(['镇农科任务结算失败',$e->getFile(), $e->getLine(), $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用软件推广 单次任务
|
||||
* 提前完成,截止提交时间,前面的钱一次性结算,往后至任务结束每天发放
|
||||
*/
|
||||
private static function masterTask2Settlement($taskSchedulePlan)
|
||||
{
|
||||
Log::info(['镇农科公司定时任务结算执行-'.$taskSchedulePlan['template_info']['title']]);
|
||||
$taskTemplateInfo = $taskSchedulePlan['template_info'];
|
||||
$dayCount = $taskTemplateInfo['day_count'];
|
||||
$taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find();
|
||||
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
|
||||
// 任务累计天数 < 第一阶段天数 如果任务状态为已完成,则一次性结算截止到今日的金额。
|
||||
if($dayCount < $taskTemplateInfo['stage_day_one']) {
|
||||
// 如果任务状态为已完成,表示今天用户有提交提前完成的凭证并且已通过审批,则一次性结算截止到今日的金额。
|
||||
if ($taskInfo['status'] == 3) {
|
||||
$taskInfo['money'] = bcmul($dayCount, $taskTemplateInfo['money'], 2);
|
||||
(new TownShareProfit())->dealTaskSettlementMaster2($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
} else {
|
||||
// 任务状态为未完成,查看该任务模板是否有提前完成标识,有则每日结算当天的金额。
|
||||
$extend = $taskTemplateInfo['extend'];
|
||||
if (isset($extend['early_finish']) && $extend['early_finish'] == 1) {
|
||||
$taskInfo['money'] = $taskTemplateInfo['money'];
|
||||
(new TownShareProfit())->dealTaskSettlementMaster2($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
}
|
||||
}
|
||||
// 刷新任务时间
|
||||
self::flushTaskTime($taskSchedulePlan);
|
||||
}
|
||||
|
||||
// 任务最后一天结算
|
||||
if ($dayCount == $taskTemplateInfo['stage_day_one']) {
|
||||
if (isset($extend['early_finish']) && $extend['early_finish'] == 1) {
|
||||
$taskInfo['money'] = $taskTemplateInfo['money'];
|
||||
(new TownShareProfit())->dealTaskSettlementMaster2($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
} else {
|
||||
// 状态为已完成,表示后台已通过审批
|
||||
if ($taskInfo['status'] == 3) {
|
||||
// 结算分润
|
||||
$approve = Approve::where(['business_id'=>$taskTemplateInfo['id']])->find();
|
||||
$amount = $approve['amount'];
|
||||
// 计算实际完成率
|
||||
$rate = bcdiv($amount, 300000, 2);
|
||||
if (bccomp($rate, 0.5, 2) == 1) {
|
||||
(new Task())->closeTask($taskSchedulePlan['task_id']);
|
||||
return false;
|
||||
}
|
||||
$totalMoney = bcmul($taskTemplateInfo['money'], $taskTemplateInfo['stage_day_one'], 2);
|
||||
$taskInfo['money'] = self::countTaskMarketingDirector4TaskMoney($totalMoney, $rate);
|
||||
(new TownShareProfit())->dealTaskSettlementMaster2($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function masterTask3Settlement($taskSchedulePlan)
|
||||
{
|
||||
Log::info(['镇农科公司定时任务结算执行-'.$taskSchedulePlan['template_info']['title']]);
|
||||
$taskTemplateInfo = $taskSchedulePlan['template_info'];
|
||||
$dayCount = $taskTemplateInfo['day_count'];
|
||||
$taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find();
|
||||
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
|
||||
// 任务累计天数 小于 第一阶段 关闭任务
|
||||
if ($dayCount < $taskTemplateInfo['stage_day_one']) {
|
||||
(new Task())->closeTask($taskSchedulePlan['task_id']);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 任务累计天数 = 第一阶段 收集信息 >= 1家
|
||||
if ($dayCount == $taskTemplateInfo['stage_day_one']) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static function masterTask4Settlement($taskSchedulePlan)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static function masterTask5Settlement($taskSchedulePlan)
|
||||
{
|
||||
Log::info(['镇农科公司定时任务结算执行-'.$taskSchedulePlan['template_info']['title']]);
|
||||
$taskTemplateInfo = $taskSchedulePlan['template_info'];
|
||||
$dayCount = $taskTemplateInfo['day_count'];
|
||||
$taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find();
|
||||
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
|
||||
// 行政村数量
|
||||
$villageCount = Db::name('geo_village')->where(['street_code' => $townCompany['street']])->count();
|
||||
// 村公司
|
||||
$villageCompanyList = Db::query("select id from la_company where company_type=:company_type and FIND_IN_SET(:street,responsible_area)", ['company_type' => 18,'street'=>$townCompany['street']], true);
|
||||
$ids = array_column($villageCompanyList, 'id');
|
||||
// 村联络员数量
|
||||
$liaisonManCount = User::where(['group_id'=>17])->whereIn('company_id', $ids)->count();
|
||||
|
||||
// 第一周期天数
|
||||
$stageOneDayCount = bcmul($villageCount, 4);
|
||||
|
||||
// 任务累计天数 小于 第一周期天数 关闭任务
|
||||
if ($dayCount < $stageOneDayCount) {
|
||||
(new Task())->closeTask($taskSchedulePlan['task_id']);
|
||||
}
|
||||
// 任务累计天数第一个周期结算
|
||||
if ($dayCount == $stageOneDayCount) {
|
||||
$rate = bcdiv($liaisonManCount, $villageCount, 2);
|
||||
if (bccomp($rate, 0.5, 2) == 1) {
|
||||
// 按个数结算
|
||||
$taskInfo['money'] = bcmul($liaisonManCount, 120, 2);
|
||||
(new TownShareProfit())->dealTaskSettlementMaster5($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
} else {
|
||||
(new Task())->closeTask($taskSchedulePlan['task_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// 任务累计天数 大于 第一周期天数, 每天结算
|
||||
if ($dayCount > $stageOneDayCount) {
|
||||
$rate = bcdiv($liaisonManCount, $villageCount, 2);
|
||||
if (bccomp($rate, 0.5, 2) == 1) {
|
||||
// 按实际完成率结算
|
||||
$taskInfo['money'] = bcmul($rate, $taskTemplateInfo['money_three'], 2);
|
||||
(new TownShareProfit())->dealTaskSettlementMaster5($taskInfo, $townCompany, $taskSchedulePlan);
|
||||
} else {
|
||||
(new Task())->closeTask($taskSchedulePlan['task_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function masterTask6Settlement($taskSchedulePlan)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static function masterTask7Settlement($taskSchedulePlan)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static function masterTask8Settlement($taskSchedulePlan)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $taskSchedulePlan
|
||||
* 市场部长任务结算
|
||||
@ -2506,7 +2737,7 @@ class TaskLogic extends BaseLogic
|
||||
$stageDayOneTotalTaskMoney = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money'], 2);
|
||||
$stageDayTwoTotalTaskMoney = bcmul($taskTemplateInfo['stage_day_two'], $taskTemplateInfo['money_two'], 2);
|
||||
$taskMoney = bcadd($stageDayOneTotalTaskMoney, $stageDayTwoTotalTaskMoney, 2);
|
||||
$taskInfo['money'] = $taskMoney;
|
||||
$task['money'] = $taskMoney;
|
||||
(new VillageShareProfit())->dealVillageTaskSettlement6($task, $villageCompany, $taskSchedulePlan);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user