From 460d2b65eadd823efb399dd2c166cfe181732ece Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 21 Sep 2023 14:12:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=95=87=E7=AE=A1=E7=90=86=E5=85=AC?= =?UTF-8?q?=E5=8F=B8=E4=BB=BB=E5=8A=A1=E4=B8=8B=E5=8F=91=E5=92=8C=E7=BB=93?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LoginLogic.php | 9 + app/common/logic/finance/TownShareProfit.php | 108 +++++++++ app/common/logic/task/TaskLogic.php | 224 +++++++++++++++++++ app/job/TownTaskAdd.php | 23 ++ app/job/TownTaskSettlementJob.php | 26 +++ app/task/TownTaskCron.php | 51 +++++ app/task/TownTaskSettlementCron.php | 39 ++++ 7 files changed, 480 insertions(+) create mode 100644 app/common/logic/finance/TownShareProfit.php create mode 100644 app/job/TownTaskAdd.php create mode 100644 app/job/TownTaskSettlementJob.php create mode 100644 app/task/TownTaskCron.php create mode 100644 app/task/TownTaskSettlementCron.php diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index 806d0e615..7192e8ce9 100755 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -70,6 +70,15 @@ class LoginLogic extends BaseLogic if ($params['is_captain']) { $group_id=2; } + // 镇管理公司服务部长 + if ($params['is_service_manager'] == 1) { + $user = User::where(['company_id' => $params['company_id'], 'group_id' => 14])->find(); + if (!empty($user)) { + self::setError('公司已创建服务部长账号'); + return false; + } + $group_id=14; + } User::create([ 'sn' => $userSn, 'avatar' => $avatar, diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php new file mode 100644 index 000000000..50906c256 --- /dev/null +++ b/app/common/logic/finance/TownShareProfit.php @@ -0,0 +1,108 @@ +where('admin_id', 0)->field('id,user_money')->select(); + $userAllCount = count($userAll); + // 每个成员的收益 + $perUserMoney = bcdiv($masterUserMoney, $userAllCount, 2); + + $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,完成方:服务部长。'; + // 服务部长 + $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); + $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterUserMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->master($arr); + $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterUserMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->Account($arr_two); + + // 成员 + foreach ($userAll as $value) { + $arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得收益' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->member($arr); + $arr_two = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得账户余额' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->Account($arr_two); + } + + // 公司 + if ($taskSchedulePlan['company_account_type'] == 1) { + $deposit_count = bcadd($company['deposit'], $masterMoney, 2); + $this->AccountLog($company['id'], $deposit_count, $masterMoney); + $company_money_count = bcadd($company['company_money'], $masterMoney, 2); + $this->AccountLog($company['id'], $company_money_count, $masterMoney); + Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error('54-任务结算失败:' . $e->getMessage()); + return false; + } + } + + public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1) + { + $company_log = [ + 'sn' => generate_sn(UserAccountLog::class, 'sn', 20), + 'company_id' => $companyId, + 'change_object' => $change_object, //变动对象 + 'change_type' => $change_type, //变动类型 + 'action' => $action, //1-增加 2-减少 + 'left_amount' => $left_amount, //变动后数量 + 'change_amount' => $changeAmount, //变动数量 + 'status' => 1, + ]; + CompanyAccountLog::create($company_log); + } + /**负责人的分润 + * @param $data + */ + private function master($data) + { + User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]); + return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); + } + + /**成员分润 + * @param $data + */ + private function member($data) + { + User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]); + return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); + } + + private function Account($data) + { + return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); + } +} diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index 3a4f38b24..256750118 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -15,6 +15,8 @@ namespace app\common\logic\task; +use app\common\logic\finance\TownShareProfit; +use app\common\model\dict\DictData; use app\common\model\task\Task; use app\common\logic\BaseLogic; use app\common\model\Company; @@ -281,4 +283,226 @@ class TaskLogic extends BaseLogic } 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) { + return true; + } + } + $time = strtotime(date('Y-m-d')); + + $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); + $data['extend'] = json_encode($taskTemplate['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]); + 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; + // 单次和循环任务 + if ($tempalte['types'] == 1 || $tempalte['types'] == 3) { + if ($v_day_count <= $tempalte['stage_day_one']) { + // 第一阶段金额 + return $tempalte['money']; + } else if ($v_day_count <= $tempalte['stage_day_two']) { + // 第二阶段金额 + return $tempalte['money_two']; + } else if ($v_day_count <= $tempalte['stage_day_three']) { + // 第三阶段金额 + return $tempalte['new_money_three']; + } + } elseif ($tempalte['types'] == 2) { // 长期任务 + if ($v_day_count<= $tempalte['stage_day_one']) { + // 第一阶段金额 + return $tempalte['money']; + } elseif ($v_day_count <= $tempalte['stage_day_two']) { + // 第二阶段金额 + return $tempalte['money_two']; + } else if ($v_day_count <= $tempalte['stage_day_three']) { + // 第三阶段金额 + 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 { + // 关闭任务 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 5]); + Log::info('协助总负责人开展工作任务,结算失败:' . $taskTemplateInfo['title'] . '未完成。任务:' . json_encode($taskInfo)); + } + } + + private static function dealTownTask2($taskSchedulePlan) + { + $taskTemplateInfo = $taskSchedulePlan['template_info']; + $taskScheduleInfo = $taskSchedulePlan['scheduling']; + } + + private static function dealTownTask3($taskSchedulePlan) + { + $taskTemplateInfo = $taskSchedulePlan['template_info']; + $taskScheduleInfo = $taskSchedulePlan['scheduling']; + } + + private static function dealTownTask4($taskSchedulePlan) + { + $taskTemplateInfo = $taskSchedulePlan['template_info']; + $taskScheduleInfo = $taskSchedulePlan['scheduling']; + } + + 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']; + } } diff --git a/app/job/TownTaskAdd.php b/app/job/TownTaskAdd.php new file mode 100644 index 000000000..e5eb68359 --- /dev/null +++ b/app/job/TownTaskAdd.php @@ -0,0 +1,23 @@ +attempts() > 3) { + //通过这个方法可以检查这个任务已经重试了几次了 + } + TaskLogic::TownCronAdd($template); + //如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法 + $job->delete(); + } +} diff --git a/app/job/TownTaskSettlementJob.php b/app/job/TownTaskSettlementJob.php new file mode 100644 index 000000000..86d93a782 --- /dev/null +++ b/app/job/TownTaskSettlementJob.php @@ -0,0 +1,26 @@ +delete(); + } +} \ No newline at end of file diff --git a/app/task/TownTaskCron.php b/app/task/TownTaskCron.php new file mode 100644 index 000000000..835f4a604 --- /dev/null +++ b/app/task/TownTaskCron.php @@ -0,0 +1,51 @@ +daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释 + // $this->everyMinute();//每分钟 + } + /** + * 镇管理公司任务下发 + */ + protected function execute() + { + //任务下发 + $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')); + } + +} \ No newline at end of file diff --git a/app/task/TownTaskSettlementCron.php b/app/task/TownTaskSettlementCron.php new file mode 100644 index 000000000..677ca7547 --- /dev/null +++ b/app/task/TownTaskSettlementCron.php @@ -0,0 +1,39 @@ +daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释 + // $this->everyMinute();//每分钟 + } + /** + * 镇管理公司任务结算 + * @return mixed + */ + protected function execute() + { + Log::info('定时任务结算执行-开始'.date('Y-m-d H:i:s')); + //yesterday 昨日未结算的任务计划 + $taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','yesterday') + ->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')); + + //...具体的任务执行 + } +} \ No newline at end of file From 20db4a4dd3d83f27f330b4e57dd48c12292d83da Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 21 Sep 2023 14:39:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=95=87=E7=AE=A1=E7=90=86=E5=85=AC?= =?UTF-8?q?=E5=8F=B8=E5=88=9B=E5=BB=BA=E4=BB=BB=E5=8A=A1=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8C=E6=A0=A1=E9=AA=8C=E5=85=AC=E5=8F=B8=E6=9C=89=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=88=9B=E5=BB=BA=E6=9C=8D=E5=8A=A1=E9=83=A8=E9=95=BF?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/task_template/TaskTemplateLogic.php | 6 ++++++ app/common/model/user/User.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/common/logic/task_template/TaskTemplateLogic.php b/app/common/logic/task_template/TaskTemplateLogic.php index 45d08dc71..dbba253f4 100644 --- a/app/common/logic/task_template/TaskTemplateLogic.php +++ b/app/common/logic/task_template/TaskTemplateLogic.php @@ -22,6 +22,7 @@ use app\common\logic\BaseLogic; use app\common\model\company\CompanyProperty; use app\common\model\informationg\UserInformationg; use app\common\model\task_scheduling\TaskScheduling; +use app\common\model\user\User; use think\facade\Db; @@ -250,6 +251,11 @@ class TaskTemplateLogic extends BaseLogic try { Db::startTrans(); + $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('已经有同一种任务类型了'); diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 7900abf44..bfd91e78d 100755 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -220,4 +220,9 @@ class User extends BaseModel return []; } } + + public function searchServiceManager($companyId) + { + return User::where(['company_id' => $companyId, 'group_id'=> 14])->find(); + } } \ No newline at end of file From d6ecaf63d937af6321180bb1a26195ab18d4bf01 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 21 Sep 2023 15:43:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=95=87=E7=AE=A1=E7=90=86=E5=85=AC?= =?UTF-8?q?=E5=8F=B8-=E5=8D=8F=E5=8A=A9=E6=80=BB=E8=B4=9F=E8=B4=A3?= =?UTF-8?q?=E4=BA=BA=E5=BC=80=E5=B1=95=E5=B7=A5=E4=BD=9C=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/finance/TownShareProfit.php | 55 +++++++------------ app/common/logic/task/TaskLogic.php | 4 +- .../model/company/CompanyAccountLog.php | 4 +- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php index 50906c256..98cef9598 100644 --- a/app/common/logic/finance/TownShareProfit.php +++ b/app/common/logic/finance/TownShareProfit.php @@ -16,50 +16,37 @@ class TownShareProfit { public function townTaskType1($taskInfo, $company, $taskSchedulePlan) { - // if ($company['day_count'] <= $data['proportion_one']) { - // $proportion = $data['proportion_one']; - // } else { - // $proportion = $data['proportion_two']; - // } - Db::startTrans(); try { + Db::startTrans(); + $proportion = 0; //总金额除以2等于不可提现账号金额和收益 $masterMoney = bcdiv($taskInfo['money'], 2, 2); - //收益的25%为负责人的收益 其余为成员的平分收益 - $masterUserMoney = bcdiv($masterMoney, 2, 2); - - //成员数量 - $userAll = User::where('company_id', $company['company_id'])->where('admin_id', 0)->field('id,user_money')->select(); - $userAllCount = count($userAll); - // 每个成员的收益 - $perUserMoney = bcdiv($masterUserMoney, $userAllCount, 2); - - $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,完成方:服务部长。'; - // 服务部长 + $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; + //服务部长收益 任务金额的50%为服务部长的收益 $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); - $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterUserMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]); + // 用户收益变动 + $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; $this->master($arr); - $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterUserMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + // 用户余额变动 + $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; $this->Account($arr_two); - // 成员 - foreach ($userAll as $value) { - $arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得收益' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->member($arr); - $arr_two = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得账户余额' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->Account($arr_two); - } - // 公司 - if ($taskSchedulePlan['company_account_type'] == 1) { - $deposit_count = bcadd($company['deposit'], $masterMoney, 2); - $this->AccountLog($company['id'], $deposit_count, $masterMoney); - $company_money_count = bcadd($company['company_money'], $masterMoney, 2); - $this->AccountLog($company['id'], $company_money_count, $masterMoney); - Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); - } + $deposit_count = bcadd($company['deposit'], $masterMoney, 2); + // 公司收益变动记录 + $this->AccountLog($company['id'], $deposit_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_DEPOSIT); + $company_money_count = bcadd($company['company_money'], $masterMoney, 2); + //公司余额变动记录 + $this->AccountLog($company['id'], $company_money_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_COMPANY_MONEY); + // 变更公司收益和余额 + Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); + + // 更改任务状态 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index 256750118..b983cedf2 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -459,9 +459,9 @@ class TaskLogic extends BaseLogic continue; } } - + // 下属小组服务公司有任务安排,也完成了任务 if ($isDone === 1 && $isTaskSchedule === 1) { - // 下属小组服务公司有任务安排,也完成了任务 做任务结算,分润 + // 做任务结算,分润 (new TownShareProfit())->townTaskType1($taskInfo, $townCompany, $taskSchedulePlan); } else { // 关闭任务 diff --git a/app/common/model/company/CompanyAccountLog.php b/app/common/model/company/CompanyAccountLog.php index 378ae3c45..476ccd4d2 100644 --- a/app/common/model/company/CompanyAccountLog.php +++ b/app/common/model/company/CompanyAccountLog.php @@ -76,11 +76,11 @@ class CompanyAccountLog extends BaseModel */ /** - * 保证金 + * 任务收益 */ const TASK_INC_DEPOSIT = 200; /** - * 收益 + * 公司余额 */ const TASK_INC_COMPANY_MONEY = 201; /** From c7587538b61e939040ba9242be6eade24f1f60ea Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 21 Sep 2023 16:54:05 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=8F=E7=BB=84=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=201=E4=B8=8B=E5=8F=91=E5=8D=95=E6=AC=A1?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=EF=BC=8C=E5=B0=86=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9A=84=E4=BB=BB=E5=8A=A1=E7=B4=AF=E8=AE=A1?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=A4=A9=E6=95=B0+1=EF=BC=8C=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E6=97=B6=E7=94=A8=E4=BA=8E=E5=88=A4=E6=96=AD=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=98=AF=E5=90=A6=E8=B6=85=E6=97=B6=202=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=BB=93=E7=AE=97=E6=97=B6=E5=88=A4=E6=96=AD=E3=80=90?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E4=BB=BB=E5=8A=A1=E3=80=91=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E8=A6=81?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=E3=80=82=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=88=99=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/task/TaskLogic.php | 22 +++++++++++++++- app/job/TaskInformationJob.php | 40 ++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index b983cedf2..e6ceca0a9 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -79,6 +79,8 @@ class TaskLogic extends BaseLogic 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; @@ -400,7 +402,7 @@ class TaskLogic extends BaseLogic self::dealTownTask1($taskSchedulePlan); break; case 'town_task_type_2': - // 协助总负责人开展工作任务 + // 协助总负责人开展工作任务 单次任务 周期内未完成要刷新任务的时间 self::dealTownTask2($taskSchedulePlan); break; case 'town_task_type_3': @@ -474,6 +476,24 @@ class TaskLogic extends BaseLogic { $taskTemplateInfo = $taskSchedulePlan['template_info']; $taskScheduleInfo = $taskSchedulePlan['scheduling']; + $day = $taskTemplateInfo['stage_day_one'] + $taskTemplateInfo['stage_day_two']; + if($taskTemplateInfo['day_count']>$day){ + Task::where('id', $taskSchedulePlan['task_id'])->update(['status' =>5]); + Log::info($taskTemplateInfo['title'] . '结算失败,任务为超时:' . json_encode($taskSchedulePlan)); + return false; + } + + $task = Task::where('id', $taskSchedulePlan['task_id'])->field('director_uid,status,money,start_time,end_time')->with('director_info')->find(); + if($taskTemplateInfo['day_count'] <= $day){ + TaskSchedulingPlan::where('id', $taskSchedulePlan['id'])->update(['is_pay' => 0]); + try{ + Task::where('id', $taskSchedulePlan['task_id'])->update(['create_time' => $task['start_time']+86400,'update_time' =>time(),'start_time'=>$task['start_time']+86400,'end_time'=>$task['start_time']+86400+86399]); + }catch(\Exception $e){ + $start_time = strtotime(date('Y-m-d')); + Task::where('id', $taskSchedulePlan['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]); + } + } + } private static function dealTownTask3($taskSchedulePlan) diff --git a/app/job/TaskInformationJob.php b/app/job/TaskInformationJob.php index 3b399b32a..9506d352b 100644 --- a/app/job/TaskInformationJob.php +++ b/app/job/TaskInformationJob.php @@ -93,6 +93,11 @@ class TaskInformationJob $arr['money'] = $task_35['money']; $arr['company_account_type'] = 2; }else{ + /** + * 判断入股任务 单次类型 是否超时 + * 未超时时刷新开始结束时间 + * 超时则关闭 + */ if($data['template_info']['day_count']<=$day){ TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]); try{ @@ -100,10 +105,10 @@ class TaskInformationJob }catch(\Exception $e){ $start_time = strtotime(date('Y-m-d')); Task::where('id', $data['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]); - } return false; } + if($data['template_info']['day_count']>$day){ Task::where('id', $data['task_id'])->update(['status' =>5]); Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data)); @@ -117,15 +122,32 @@ class TaskInformationJob } else { //其他类型任务 - $task_count = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->with('director_info')->find(); - if (empty($task_count)) { - Log::info('其他任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data)); - Task::where('id', $data['task_id'])->update(['status' => 5]); - return false; + $task = Task::where('id', $data['task_id'])->with('director_info')->find(); + if ($task['status'] == 3) { + $name = $task['director_info']['nickname']; + $arr['status'] = 1; + $arr['money'] = $task['money']; + } else if ($task['status'] == 2) { + // 是否超时 + $day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two']; + + if($data['template_info']['day_count'] >= $day){ + Task::where('id', $data['task_id'])->update(['status' =>5]); + Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data)); + return false; + } + + if($data['template_info']['day_count'] < $day){ + TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]); + try{ + Task::where('id', $data['task_id'])->update(['create_time' => $task['start_time']+86400,'update_time' =>time(),'start_time'=>$task['start_time']+86400,'end_time'=>$task['start_time']+86400+86399]); + }catch(\Exception $e){ + $start_time = strtotime(date('Y-m-d')); + Task::where('id', $data['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]); + } + return false; + } } - $name = $task_count['director_info']['nickname']; - $arr['status'] = 1; - $arr['money'] = $task_count['money']; } } catch (\Exception $e) { Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));