diff --git a/app/adminapi/controller/approve/ApproveController.php b/app/adminapi/controller/approve/ApproveController.php index b1dc1cc81..c6cb12bba 100644 --- a/app/adminapi/controller/approve/ApproveController.php +++ b/app/adminapi/controller/approve/ApproveController.php @@ -120,6 +120,21 @@ class ApproveController extends BaseAdminController $approve->amount = $params['amount']; $approve->save(); } + if ($approve->type == Approve::APPROVE_TYPE_8) { + // 需要手动输入申请的政策补贴金额 + $approve->amount = $params['amount']; + $approve->save(); + } + if ($approve->type == Approve::APPROVE_TYPE_9) { + $taskSchedulePlan = TaskSchedulingPlan::where('la_task_scheduling_plan.id', $task['scheduling_plan_id']) + ->where('is_pay',0) + ->with(['template_info']) + ->withJoin(['scheduling'], 'left') + ->where('scheduling.company_type', 17) + ->find() + ->toArray(); + TaskLogic::masterTask8Settlement($taskSchedulePlan); + } } // 拒绝 diff --git a/app/api/controller/CronController.php b/app/api/controller/CronController.php index c6ff2c5aa..e8cc62762 100644 --- a/app/api/controller/CronController.php +++ b/app/api/controller/CronController.php @@ -21,33 +21,13 @@ use app\job\TaskAdd; */ class CronController extends BaseApiController { - public array $notNeedLogin = ['settlement','task_add', 'town_task_add', 'town_task_settlement','village_task_add']; - - /** - * 小组服务公司任务结算 - */ - public function settlement(){ -// $all=TaskSchedulingPlan::where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray(); - $all = TaskSchedulingPlan::whereDay('end_time','today') - ->withJoin(['scheduling'], 'left') - ->where('scheduling.company_type', 18) - ->where('is_pay',0) - ->with(['template_info']) - ->select() - ->toArray(); - foreach($all as $k=>$v){ - queue(TaskInformationJob::class,$v); - } - Log::info('小组服务公司定时任务结算执行成功'.date('Y-m-d H:i:s')); - return $this->success('小组服务公司定时任务结算执行成功'); - - } + public array $notNeedLogin = ['settlement','task_add', 'town_task_add', 'town_task_settlement','village_task_add', 'village_task_settlement']; /** * 小组服务公司任务下发 */ public function task_add(){ - //任务下发 + //任务下发 // $time=strtotime(date('Y-m-d',strtotime('-1 day'))); $time = strtotime(date('Y-m-d')); // $tiem_end=$time+86399; @@ -78,60 +58,23 @@ class CronController extends BaseApiController } /** - * 镇农科公司任务结算 + * 小组服务公司任务结算 */ - public function town_task_settlement() - { - Log::info('镇农科公司定时任务结算执行-开始'.date('Y-m-d H:i:s')); - //today 今日未结算的任务计划 - $taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','today') + public function settlement(){ +// $all=TaskSchedulingPlan::where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray(); + $all = TaskSchedulingPlan::whereDay('end_time','today') ->withJoin(['scheduling'], 'left') - ->where('scheduling.company_type', 41) + ->where('scheduling.company_type', 18) ->where('is_pay',0) ->with(['template_info']) ->select() ->toArray(); - foreach($taskSchedulingPlanList as $taskSchedulingPlan){ - queue(TownTaskSettlementJob::class, $taskSchedulingPlan); + foreach($all as $k=>$v){ + queue(TaskInformationJob::class,$v); } - Log::info('镇农科公司定时任务结算执行-结束'.date('Y-m-d H:i:s')); - return $this->success('镇农科公司定时任务结算执行成功'); - } + Log::info('小组服务公司定时任务结算执行成功'.date('Y-m-d H:i:s')); + return $this->success('小组服务公司定时任务结算执行成功'); - /** - * 镇农科公司任务下发 - */ - public function town_task_add() - { - //任务下发 - $time = strtotime(date('Y-m-d')); - // 查询系统 所有镇农科公司 未下发 的 任务安排 - $taskSchedulingList = TaskScheduling::where('cron_time', '<', $time) - ->where('status', 1) - ->where('company_type', 41) - ->with('company_info') - ->select() - ->toArray(); - - $taskSchedulingIds = []; - $companyIds = []; - foreach ($taskSchedulingList as $k => $taskScheduling) { - $templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray(); - $taskSchedulingIds[] = $taskScheduling['id']; - $companyIds[] = $taskScheduling['company_id']; - foreach ($templateList as $template) { - queue(TownTaskAdd::class, $template); -// TaskLogic::TownCronAdd($template); // 手动下发用 - } - - if (empty($templateList)) { - unset($taskSchedulingList[$k]); - } - } - Company::where('id', 'in', $companyIds)->inc('day_count')->update(); - TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]); - Log::info('镇农科公司定时任务下发执行成功' . date('Y-m-d H:i:s')); - return $this->success('镇农科公司定时任务下发执行成功'); } /** @@ -190,4 +133,61 @@ class CronController extends BaseApiController Log::info('村管理公司定时任务结算执行-结束'.date('Y-m-d H:i:s')); return $this->success('村管理公司定时任务结算执行成功'); } + + /** + * 镇农科公司任务下发 + */ + public function town_task_add() + { + //任务下发 + $time = strtotime(date('Y-m-d')); + // 查询系统 所有镇农科公司 未下发 的 任务安排 + $taskSchedulingList = TaskScheduling::where('cron_time', '<', $time) + ->where('status', 1) + ->where('company_type', 41) + ->with('company_info') + ->select() + ->toArray(); + + $taskSchedulingIds = []; + $companyIds = []; + foreach ($taskSchedulingList as $k => $taskScheduling) { + $templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray(); + $taskSchedulingIds[] = $taskScheduling['id']; + $companyIds[] = $taskScheduling['company_id']; + foreach ($templateList as $template) { + queue(TownTaskAdd::class, $template); +// TaskLogic::TownCronAdd($template); // 手动下发用 + } + + if (empty($templateList)) { + unset($taskSchedulingList[$k]); + } + } + Company::where('id', 'in', $companyIds)->inc('day_count')->update(); + TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]); + Log::info('镇农科公司定时任务下发执行成功' . date('Y-m-d H:i:s')); + return $this->success('镇农科公司定时任务下发执行成功'); + } + + /** + * 镇农科公司任务结算 + */ + public function town_task_settlement() + { + Log::info('镇农科公司定时任务结算执行-开始'.date('Y-m-d H:i:s')); + //today 今日未结算的任务计划 + $taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','today') + ->withJoin(['scheduling'], 'left') + ->where('scheduling.company_type', 41) + ->where('is_pay',0) + ->with(['template_info']) + ->select() + ->toArray(); + foreach($taskSchedulingPlanList as $taskSchedulingPlan){ + queue(TownTaskSettlementJob::class, $taskSchedulingPlan); + } + Log::info('镇农科公司定时任务结算执行-结束'.date('Y-m-d H:i:s')); + return $this->success('镇农科公司定时任务结算执行成功'); + } } \ No newline at end of file diff --git a/app/api/controller/TaskController.php b/app/api/controller/TaskController.php index 60685a67e..a37204abe 100644 --- a/app/api/controller/TaskController.php +++ b/app/api/controller/TaskController.php @@ -549,8 +549,8 @@ class TaskController extends BaseApiController 'other'=> [ 'is_commit' => 1, 'note' => $parmas['note'], - 'annex' => ['annex'], - 'video_annex' => ['video_annex'], + 'annex' => $parmas['annex'], + 'video_annex' => $parmas['video_annex'], ] ]; Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend), 'update_time'=>time(), 'director_uid'=>$this->userId]); // director_uid 指派人 @@ -606,8 +606,8 @@ class TaskController extends BaseApiController 'other'=> [ 'is_commit' => 1, 'note' => $parmas['note'], - 'annex' => ['annex'], - 'video_annex' => ['video_annex'], + 'annex' => $parmas['annex'], + 'video_annex' => $parmas['video_annex'], ] ]; Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend), 'update_time'=>time(), 'director_uid'=>$this->userId]); // director_uid 指派人 @@ -642,4 +642,77 @@ 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(); + $extend = json_decode($taskTemplate['extend'], true); + $extend['purchase_sales_info'][] = $param['purchase_sales_info']; + $taskTemplate->save(['extend'=>json_encode($extend)]); + return $this->success('成功', []); + } + + /** + * 提交 镇农科负责人-政策补贴申请 + * 上传凭证,后台审批,填写实际完成金额 + */ + publiC function commit_town_master_task_type_7() + { + try { + $parmas = $this->request->param(); // id annex video_annex + $task = TaskLogic::detail($parmas); + if (empty($task)) { + $this->fail('任务不存在'); + } + if (empty($parmas['annex']) && empty($parmas['video_annex'])) { + $this->fail('没有上传凭证,无法提交审核'); + } + + $extend = [ + 'other'=> [ + 'is_commit' => 1, + 'note' => $parmas['note'], + 'annex' => $parmas['annex'], + 'video_annex' => $parmas['video_annex'], + ] + ]; + Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend), 'update_time'=>time(), 'director_uid'=>$this->userId]); // director_uid 指派人 + + // 片区经理 + $areaManagerId = User::where(['id' => $this->userId])->with('company')->value('area_manager'); + + + // 没有则创建审批任务 + $approveModel = Approve::where(['task_id' => $task['id']])->findOrEmpty(); + if ($approveModel->isEmpty()) { + $approveModel->type = Approve::APPROVE_TYPE_6; + $approveModel->flow_id = 1; + $approveModel->name = $task['title']; + $approveModel->admin_id = 0; // 后台发起人id 暂时为0 + $approveModel->user_id = $this->userId; // 前台发起人用户id + $approveModel->task_id = $task['id']; // 任务id + $approveModel->department_id = '0'; + $approveModel->check_admin_ids = $areaManagerId; // 当前审批人ID 片区经理的admin_id + $approveModel->check_status = 1; // 状态 0待审核,1审核中,2审核通过,3审核不通过,4撤销审核 + $approveModel->other_type = 6; + $approveModel->extend = json_encode($extend); + $approveModel->create_time = time(); + $approveModel->update_time = time(); + $re = $approveModel->save(); + } else { + // 有则更新状态 + $approveModel->check_status = 1; // 状态 0待审核,1审核中,2审核通过,3审核不通过,4撤销审核 + $approveModel->save(); + } + return $this->success('ok', []); + } catch (Exception $e) { + return $this->fail($e->getMessage()); + } + } } diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 7374b8ecc..435fb5ee5 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -58,7 +58,7 @@ class VehicleController extends BaseApiController return $this->fail('数据不存在'); } //判断是否是镇街公司 - if($party_b['company_type'] != 16){ + if($party_b['company_type'] != 41){ return ['code'=>0,'msg'=>'非镇街公司不能签约']; } //发送生成合同给物流信息 @@ -237,11 +237,11 @@ class VehicleController extends BaseApiController } //获取签约信息 $contract = Contract::where('party_b',$this->userInfo['company_id'])->where('signing_timer',2)->findOrEmpty(); - if(empty($contract) || empty($party_a)){ + if($contract->isEmpty()){ return $this->fail('未找到签约镇街公司'); } $party_a = Company::field('id,company_name,master_name,master_phone,master_email,is_contract,organization_code,company_type')->where('id',$contract['party_a'])->find(); - if($party_a['company_type'] != 16){ + if($party_a['company_type'] != 41){ return $this->fail('不能与非镇街公司签约'); } if($party_a['is_contract'] != 1){ @@ -386,7 +386,7 @@ class VehicleController extends BaseApiController if(empty($company)){ return $this->fail('数据错误'); } - if($company['company_type'] != 16){ + if($company['company_type'] != 41){ return $this->fail('非镇街公司不能访问'); } //获取小组服务公司申请信息 @@ -587,7 +587,7 @@ class VehicleController extends BaseApiController if(empty($company)){ return $this->fail('请求错误'); } - if($company['company_type'] != 16){ + if($company['company_type'] != 41){ return $this->fail('非镇街公司不能访问'); } $data = VehicleContract::field('id,contract_no,contract_url,status,create_time,update_time')->where('contract_logistic_id','<>',0)->where('company_b_id',$company['id'])->select(); diff --git a/app/common/logic/ShopRequestLogic.php b/app/common/logic/ShopRequestLogic.php index 75764e394..2594ed241 100644 --- a/app/common/logic/ShopRequestLogic.php +++ b/app/common/logic/ShopRequestLogic.php @@ -199,4 +199,20 @@ class ShopRequestLogic extends BaseLogic return false; } } + + /** + * 查询镇农科公司负责片区内的种养殖商户和供应链商户交易额 + */ + public static function getTownTradeAmount($param) + { + try { + $requestResponse = HttpClient::create()->request('GET', env('url.shop_prefix'). '', [ + 'query' => $param + ]); + return json_decode($requestResponse->getContent(), true); + } catch (Exception $e) { + self::setError($e->getMessage()); + return false; + } + } } \ No newline at end of file diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php index eea76bd64..46f9572a4 100644 --- a/app/common/logic/finance/TownShareProfit.php +++ b/app/common/logic/finance/TownShareProfit.php @@ -157,18 +157,19 @@ class TownShareProfit $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; - //负责人收益 todo + //负责人收益 if ($taskSchedulePlan['template_info']['extend']['task_role'] == 1) { - + $serviceManagerUser = (new User())->searchMaster($company['id']); + Log::info([$taskSchedulePlan['template_info']['title'].'结算-市场部长用户信息', $serviceManagerUser]); } //市场部长收益 if ($taskSchedulePlan['template_info']['extend']['task_role'] == 2) { - $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 16])->find(); + $serviceManagerUser = (new User())->searchMarketingManager($company['id']);; Log::info([$taskSchedulePlan['template_info']['title'].'结算-市场部长用户信息', $serviceManagerUser]); } //服务部长收益 任务金额的50%为服务部长的收益 if ($taskSchedulePlan['template_info']['extend']['task_role'] == 3) { - $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); + $serviceManagerUser = (new User())->searchServiceManager($company['id']);; Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]); } @@ -410,4 +411,114 @@ 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 dealTaskSettlementMaster4(Task $taskInfo, Company $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,'money' => $taskInfo['money']]); + // 更新镇交易池 + (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; + } + } + + 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; + } + } + + public function dealTaskSettlementMaster6(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 dealTaskSettlementMaster7(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 dealTaskSettlementMaster8(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; + } + } } diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index ebd408c32..b0a39898a 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -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,322 @@ 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': + // 如果当天做了临时任务的情况下,需要通过审批才结算 + $task = Task::where('id', $taskSchedulePlan['task_id'])->find(); + if(isset($task['extend']['is_commit']) && $task['extend']['is_commit'] == 1) { + return true; + } + 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); + } + } + } + + } + + + // todo + 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']) { + + } + } + + /** + * @param $taskSchedulePlan + * 督促种养殖商户和供应链商户交易 + */ + private static function masterTask4Settlement($taskSchedulePlan) + { + Log::info(['镇农科公司定时任务结算执行-'.$taskSchedulePlan['template_info']['title']]); + $taskTemplateInfo = $taskSchedulePlan['template_info']; + $taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find(); + $townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find(); + + // 任务交易池,用于叠加交易额 + $townTransactionPool = $taskTemplateInfo['transaction_pool']; + // 行政村数量 + $villageCount = Db::name('geo_village')->where(['street_code' => $townCompany['street']])->count(); + // 每日目标金额 + $targetAmount = bcmul($villageCount, 329 , 2); + // 查询镇农科辖区 当日的 种养殖商户和供应链商户交易额 + $param = [ + 'start_time' => strtotime(date('Y-m-d', time())), + 'end_time' => strtotime(date('Y-m-d', time())) + 86399, + 'responsible_area' => $townCompany['responsible_area'], + 'type' => 'street', + ]; + $result = ShopRequestLogic::getTownTradeAmount($param); // todo 对接接口 + $tradeAmount = $result['data']['trade_amount']; + + // 总交易额 交易池金额+商城交易额 + $totalAmount = bcadd($townTransactionPool, $tradeAmount, 2); + + // 完成条件: 总交易额 >= 每日目标金额 + if (bccomp($totalAmount, $targetAmount, 2) == 0 || bccomp($totalAmount, $targetAmount, 2) == 1) { + $leftTransactionPool = bcsub($totalAmount, $targetAmount, 2); + // 任务结算 + (new TownShareProfit())->dealTaskSettlementMaster4($taskInfo, $townCompany, $taskSchedulePlan, $leftTransactionPool); + } else { + (new Task())->closeTask($taskSchedulePlan['task_id']); + } + } + + 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' => 17,'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']); + } + } + } + + /** + * @param $taskSchedulePlan + * 促成村联络员入股甲方 单次 + * 任务累计天数 小于 第一阶段 刷新任务时间 + * 任务累计天数 = 第一阶段 结算 + */ + private static function masterTask6Settlement($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(); + // 小组服务公司总数 + $groupServiceCompanyList = Company::where(['company_type'=> 18])->whereIn('street', $townCompany['responsible_area'])->select()->toArray(); + $groupServiceCompanyCount = count($groupServiceCompanyList); + + // 任务累计天数 小于 第一阶段 刷新任务时间 + if ($dayCount < $taskTemplateInfo['stage_day_one']) { + self::flushTaskTime($taskSchedulePlan); + } + + // 任务累计天数 = 第一阶段 结算 + if ($dayCount == $taskTemplateInfo['stage_day_one']) { + // 目标任务金额 行政村数量*6000 + 小组服务团队数量*3000 + $targetShareholderedMoney = bcadd(bcmul($villageCount, 6000, 2), bcmul($groupServiceCompanyCount, 3000, 2), 2); + + $companyIds = []; + foreach ($groupServiceCompanyList as $groupServiceCompany) { + $companyIds[] = $groupServiceCompany['id']; + } + + // 村公司 + $villageCompanyList = Db::query("select id from la_company where company_type=:company_type and FIND_IN_SET(:street,responsible_area)", ['company_type' => 17,'street'=>$townCompany['street']], true); + foreach ($villageCompanyList as $villageCompany) { + $companyIds[] = $villageCompany['id']; + } + + // 已入股股金总额 + $shareholderedMoney = CompanyAccountLog::where(['change_object'=>CompanyAccountLog::SHAREHOLDER, 'change_type'=>CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY]) + ->whereIn('company_id', $companyIds) + ->sum('change_amount'); + + $rate = bcdiv($shareholderedMoney, $targetShareholderedMoney, 2); + + if (bccomp($rate, 0.5, 2) == -1) { + (new Task())->closeTask($taskSchedulePlan['task_id']); + return true; + } + $totalMoney = bcmul($taskTemplateInfo['money'], $taskTemplateInfo['stage_day_one'], 2); + $taskInfo['money'] = self::countSettelmentMoney($rate, $totalMoney); + (new TownShareProfit())->dealTaskSettlementMaster6($taskInfo, $townCompany, $taskSchedulePlan); + } + } + + /** + * @param $taskSchedulePlan + * 政策补贴申请 单次 + */ + private static function masterTask7Settlement($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']) { + self::flushTaskTime($taskSchedulePlan); + } + + if ($dayCount == $taskTemplateInfo['stage_day_one']) { + // 审批通过后,任务状态会变更为已完成状态,审批是会根据凭证填入实际申请的政策补贴金额,根据该金额计算任务结算金额 + if ($taskInfo['status'] == 3) { + $approve = Approve::where(['task_id' => $taskSchedulePlan['task_id']])->find(); + if ($approve->check_status == 2) { + $amount = $approve['amount']; // 审批通过后的金额 + $rate = bcdiv($amount, $taskTemplateInfo['extend']['target'], 2); + if (bccomp($rate, 0.5, 2) == -1) { + (new Task())->closeTask($taskSchedulePlan['task_id']); + } + $totalMoney = bcmul($taskTemplateInfo['money'], $taskTemplateInfo['stage_day_one'], 2); + $taskInfo['money'] = self::countTaskMarketingDirector4TaskMoney($totalMoney, $rate); + (new TownShareProfit())->dealTaskSettlementMaster7($taskInfo, $townCompany, $taskSchedulePlan); + } + } else { + // 关闭任务 + (new Task())->closeTask($taskSchedulePlan['task_id']); + } + } + } + + public static function masterTask8Settlement($taskSchedulePlan) + { + $taskTemplateInfo = $taskSchedulePlan['template_info']; + $villageCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find(); + $task = Task::where('id', $taskSchedulePlan['task_id'])->find(); + $task['money'] = $taskTemplateInfo['money_three']; + (new TownShareProfit())->dealTaskSettlementMaster8($task, $villageCompany, $taskSchedulePlan); + } + /** * @param $taskSchedulePlan * 市场部长任务结算 @@ -2134,7 +2493,10 @@ class TaskLogic extends BaseLogic $groupServiceCompanyCount = Company::where(['street' => $townCompany['street'], 'company_type'=> 18])->count(); // 小组服务完成股金上交数 - $sharecapitalPaidCount= Db::name('company_sharecapital_change_log')->where(['parent_company_id'=>$villageCompanyList['id']])->count(); + $sharecapitalPaidCount = 0; + foreach ($villageCompanyList as $villageCompany) { + $sharecapitalPaidCount += Db::name('company_sharecapital_change_log')->where(['parent_company_id'=>$villageCompany['id']])->count(); + } $rate = bcdiv($sharecapitalPaidCount, $groupServiceCompanyCount, 2); @@ -2506,7 +2868,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); } diff --git a/app/common/model/Approve.php b/app/common/model/Approve.php index 714e664f5..eb27e92fa 100644 --- a/app/common/model/Approve.php +++ b/app/common/model/Approve.php @@ -21,6 +21,9 @@ class Approve extends BaseModel const APPROVE_TYPE_7 = 7; // 镇农科负责人任务-应用软件推广 + const APPROVE_TYPE_8 = 8; // 镇农科负责人任务-政策补贴申请 + const APPROVE_TYPE_9 = 9; // 镇农科负责人任务-日常管理及其他临时任务 + public function task() { return $this->hasOne(Task::class, 'id', 'task_id');