diff --git a/app/api/controller/CeshiController.php b/app/api/controller/CeshiController.php index 4c3484042..8f3b3c5fa 100644 --- a/app/api/controller/CeshiController.php +++ b/app/api/controller/CeshiController.php @@ -5,6 +5,7 @@ use app\common\logic\finance\ShareProfit; use app\common\logic\task\TaskLogic; use app\common\model\Company; use app\common\model\task\Task; +use app\common\model\task_scheduling\TaskScheduling; use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\task_template\TaskTemplate; use think\facade\Log; @@ -37,20 +38,82 @@ class CeshiController extends BaseApiController $time=strtotime(date('Y-m-d')); // $time=strtotime(date('Y-m-d')); // $tiem_end=$time+86399;where('cron_time','<',$time)-> - $all=TaskTemplate::where('status',1)->with('company')->select()->toArray(); - // $all=TaskTemplate::where('id',73)->with('company')->select()->toArray(); - // $all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray(); + $plan_all=TaskScheduling::where('status',1)->with('company_info')->select()->toArray(); + foreach($plan_all as $k=>$v){ + $all=TaskTemplate::where('status',1)->where('task_scheduling',$v['id'])->limit(30)->select()->toArray(); + if($all){ + $plan_all[$k]['template']=$all; + }else{ + unset($plan_all[$k]); + } + } $company_id=[]; - foreach($all as $k=>$v){ - TaskLogic::CronAdd($v); + foreach($plan_all as $k=>$v){ + + foreach($v['template'] as $kkk=>$vvv){ + if ($v['types'] == 1 ||$vvv['types'] == 3) { + if ($v['company_info'] && $v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'moeny','一'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } + } elseif ($v['types'] == 2) { + if ($v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'moeny','一'); + if($res==false){ + return false; + } + } elseif ($v['company_info']['day_count'] <=$vvv['stage_day_two']) { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_three','三'); + if($res==false){ + return false; + } + } + } else { + if ( $v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'money_three','三'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } + } + } + foreach($v['template'] as $kk=>$vv){ + halt($v); + TaskLogic::CronAdd($vv,$v); + } $company_id[]=$v['company_id']; } - $arr=array_unique($company_id); - if(count($arr)){ - Company::where('id','in',$arr)->inc('day_count')->update(); - } + Company::where('id','in',$company_id)->inc('day_count')->update(); } + public function stage_inspection($v,$moeny_type='moeny',$title='一'){ + $count_moeny=0; + foreach($v['template'] as $kkkk=>$vvvv){ + $count_moeny+=$vvvv[$moeny_type]; + } + if($count_moeny>200){ + Log::info($title.'阶段金额大于200无法下达'.json_encode($v['company_info'])); + return false; + } + return true; + } //三轮车判断 public function ceshi1(){ $params=[ @@ -74,10 +137,20 @@ class CeshiController extends BaseApiController } } - // public function ceshi2(){ - // $ - // $b=app(RemoteController::class)->shang_date_list(''); - - // } + public function ceshi2(){ + $all=TaskSchedulingPlan::where('id',699)->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray(); + foreach($all as $k=>$data){ + // $company = Company::where('id', $data['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足 + $task = Task::where('id', $data['task_id'])->field('director_uid')->where('status', 3)->with('director_info')->find(); + $arr['money'] = $data['template_info']['money']; + $arr['company_id'] = $data['scheduling']['company_id']; + $arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成人,的任务结算'; + $arr['proportion_one'] = $data['template_info']['proportion_one']; + $arr['proportion_two'] = $data['template_info']['proportion_two']; + $arr['sn'] = $data['sn']; + $arr['id'] = $data['id']; + } + halt($arr); + } } \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index ce8ec179c..379dbd1d4 100755 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -63,7 +63,7 @@ class IndexController extends BaseApiController */ public function config() { - $group_id=$this->userInfo['group_id']; + $group_id=$this->userInfo?$this->userInfo['group_id']:1; $result = IndexLogic::getConfigData($group_id); return $this->data($result); } diff --git a/app/api/controller/RemoteController.php b/app/api/controller/RemoteController.php index 91d17cff1..a06d33084 100644 --- a/app/api/controller/RemoteController.php +++ b/app/api/controller/RemoteController.php @@ -59,6 +59,7 @@ class RemoteController extends BaseApiController break; default: Log::error('任务结算失败,公司类型错误:' . $company['company_type']); + Log::error('片区交易错误:'.$company); return false; } try { diff --git a/app/api/controller/TaskController.php b/app/api/controller/TaskController.php index 0b136cb36..438e70874 100644 --- a/app/api/controller/TaskController.php +++ b/app/api/controller/TaskController.php @@ -19,10 +19,12 @@ class TaskController extends BaseApiController if ($this->userInfo['admin_id'] != 0) { $where[] = ['company_id', '=', $this->userInfo['company_id']]; } else { + $is_captain = User::where('id', $this->userId)->value('is_captain'); if ($is_captain == 1) { - $where[] = ['type', '=', 31]; + $where[] = ['type', 'in', [31,33]]; } else { + $where[] = ['type', '=', 33]; $where[] = ['director_uid', '=', $this->userId]; } $where[] = ['company_id', '=', $this->userInfo['company_id']]; diff --git a/app/common/logic/finance/ShareProfit.php b/app/common/logic/finance/ShareProfit.php index cc95d45d4..e703f3235 100644 --- a/app/common/logic/finance/ShareProfit.php +++ b/app/common/logic/finance/ShareProfit.php @@ -47,13 +47,11 @@ class ShareProfit } //公司 Company::where('id', $data['company_id'])->update(['deposit'=>Db::raw('deposit+' . $master_maoney), 'company_money'=>Db::raw('company_money+' .$master_maoney)]); - TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]); - Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); - Log::error('任务结算失败:' . $e->getMessage()); + Log::error('54-任务结算失败:' . $e->getMessage()); return false; } } diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index ef2ec2be9..06b3bc522 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -70,7 +70,7 @@ class TaskLogic extends BaseLogic /** * 定时添加任务 */ - public static function CronAdd(array $v): bool + public static function CronAdd(array $v,$datas): bool { try { $time=strtotime(date('Y-m-d')); @@ -98,18 +98,29 @@ class TaskLogic extends BaseLogic 'update_time' => time(), ]; $data = $arr; - $data['money'] = self::task_money($v); + $data['money'] = self::task_money($v,$datas); $data['extend'] = json_encode($v['extend']); + //信息更新 if ($v['type'] == 31) { - $data["extend"] = json_encode(['informationg' => ['count' => 5, 'update' => 0]]); + $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'] = $v['company']['user_id']; + $data['director_uid'] = $datas['company_info']['user_id']; } $task_id = (new Task())->insertGetId($data); TaskSchedulingPlan::where('id', $TaskSchedulingPlan['id'])->update(['task_id' => $task_id, 'is_execute' => 1]); - TaskTemplate::where('id', $v['id'])->update(['cron_time' => time()]); + // TaskTemplate::where('id', $v['id'])->update(['cron_time' => time()]); return true; } catch (\Exception $e) { Log::error('定时任务添加失败', [$e->getMessage()]); @@ -117,29 +128,29 @@ class TaskLogic extends BaseLogic } } //任务金额 - private static function task_money($v) + private static function task_money($v,$datas) { if ($v['types'] == 1 || $v['types'] == 3) { - if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) { + if ($datas['company_info'] && $datas['company_info']['day_count'] <= $v['stage_day_one']) { return $v['money']; } else { return $v['money_two']; } } elseif ($v['types'] == 2) { - if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) { + if ($datas['company_info']['day_count'] <= $v['stage_day_one']) { return $v['money']; - } elseif ($v['company'] && $v['company']['day_count'] <= $v['stage_day_two']) { + } elseif ($datas['company_info']['day_count'] <= $v['stage_day_two']) { return $v['money_two']; } else { return $v['money_three']; } } else { - if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) { + if ( $datas['company_info']['day_count'] <= $v['stage_day_one']) { $a = $v['money']; } else { $a = $v['money_two']; } - if ($v['company'] && $v['company']['day_count'] >= $v['stage_day_two']) { + if ($datas['company_info'] && $datas['company_info']['day_count'] >= $v['stage_day_two']) { TaskTemplate::where('id', $v['id'])->update(['status' => 0]); } return $a; diff --git a/app/common/logic/task_template/TaskTemplateLogic.php b/app/common/logic/task_template/TaskTemplateLogic.php index 2f51544b3..6e6900992 100644 --- a/app/common/logic/task_template/TaskTemplateLogic.php +++ b/app/common/logic/task_template/TaskTemplateLogic.php @@ -43,6 +43,11 @@ class TaskTemplateLogic extends BaseLogic { Db::startTrans(); try { + $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('已经有同一种任务类型了'); + return false; + } if($params['type']==33){ $count=UserInformationg::where('company_id',$params['company_id'])->where('status',1)->count(); if($count<300){ @@ -50,45 +55,20 @@ class TaskTemplateLogic extends BaseLogic return false; } } - $moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money'); - $money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two'); - $money_three=TaskTemplate::where('company_id', $params['company_id'])->sum('money_three'); - $SchedulingMoney=TaskScheduling::where('company_id', $params['company_id'])->value('money'); - if($moeny+$params['money']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); + $moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money'); + if($moeny+$params['money']>200){ + self::setError('任务模板一阶段合计金额不能大于任务调度金额'); return false; } - if($money_two+$params['money']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); + $money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two'); + if($money_two+$params['money']>200){ + self::setError('任务模板二阶段合计金额不能大于任务调度金额'); return false; } - if($money_three+$params['money']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($moeny+$params['money_two']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($money_two+$params['money_two']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($money_three+$params['money_two']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($moeny+$params['money_three']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($money_two+$params['money_three']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); - return false; - } - if($money_three+$params['money_three']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); + $money_three=TaskTemplate::where('company_id', $params['company_id'])->sum('money_three'); + if($money_three+$params['money']>200){ + self::setError('任务模板长期合计金额不能大于任务调度金额'); return false; } if($params['type']==32){ @@ -98,7 +78,9 @@ class TaskTemplateLogic extends BaseLogic return false; } } - + if($params['types']!=33){ + $params['money_three']=0; + } TaskTemplate::create([ 'title' => $params['title'], 'admin_id' => $params['admin_id'], @@ -139,12 +121,43 @@ class TaskTemplateLogic extends BaseLogic { Db::startTrans(); try { - $moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money'); - $SchedulingMoney=TaskScheduling::where('company_id', $params['company_id'])->value('money'); - if($moeny+$params['money']>$SchedulingMoney){ - self::setError('任务模板合计金额不能大于任务调度金额'); + $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 && $find['id']!=$params['id']&&$params['type']==$find['type']){ + self::setError('已经有同一种任务类型了'); return false; } + if($params['type']==33){ + $count=UserInformationg::where('company_id',$params['company_id'])->where('status',1)->count(); + if($count<300){ + self::setError('用户档案数量300不足,无法创建任务模板'); + return false; + } + } + $moeny=TaskTemplate::where('company_id', $params['company_id'])->sum('money'); + if($moeny+$params['money']>200){ + self::setError('任务模板一阶段合计金额不能大于任务调度金额'); + return false; + } + $money_two=TaskTemplate::where('company_id', $params['company_id'])->sum('money_two'); + if($money_two+$params['money']>200){ + self::setError('任务模板二阶段合计金额不能大于任务调度金额'); + return false; + } + $money_three=TaskTemplate::where('company_id', $params['company_id'])->sum('money_three'); + if($money_three+$params['money']>200){ + self::setError('任务模板长期合计金额不能大于任务调度金额'); + return false; + } + if($params['type']==32){ + $object_id=CompanyProperty::where('company_id',$params['company_id'])->value('object_id'); + if(!$object_id){ + self::setError('该公司没有三轮车,请先租赁三轮车'); + return false; + } + } + if($params['types']!=33){ + $params['money_three']=0; + } TaskTemplate::where('id', $params['id'])->update([ 'title' => $params['title'], 'admin_id' => $params['admin_id'], diff --git a/app/common/model/task_scheduling/TaskScheduling.php b/app/common/model/task_scheduling/TaskScheduling.php index b7bbc4135..6b5a83877 100644 --- a/app/common/model/task_scheduling/TaskScheduling.php +++ b/app/common/model/task_scheduling/TaskScheduling.php @@ -49,4 +49,8 @@ class TaskScheduling extends BaseModel { return $this->hasOne(Company::class, 'id', 'company_id')->bind(['company_name']); } + public function companyInfo() + { + return $this->hasOne(Company::class, 'id', 'company_id')->field('id,day_count,user_id'); + } } \ No newline at end of file diff --git a/app/job/TaskAdd.php b/app/job/TaskAdd.php index 21ce51c30..ddf382be5 100644 --- a/app/job/TaskAdd.php +++ b/app/job/TaskAdd.php @@ -4,6 +4,10 @@ namespace app\job; use app\common\logic\task\TaskLogic; use think\queue\Job; +use app\common\model\Company; +use app\common\model\task\Task; +use app\common\model\task_scheduling\TaskScheduling; +use app\common\model\task_template\TaskTemplate; /** * 任务下发执行的具体逻辑 @@ -16,7 +20,7 @@ class TaskAdd if ($job->attempts() > 3) { //通过这个方法可以检查这个任务已经重试了几次了 } - TaskLogic::CronAdd($v); + // TaskLogic::CronAdd($v); //如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法 $job->delete(); } diff --git a/app/job/TaskInformationJob.php b/app/job/TaskInformationJob.php index 99ece3f64..e8b6f5aee 100644 --- a/app/job/TaskInformationJob.php +++ b/app/job/TaskInformationJob.php @@ -11,6 +11,7 @@ use think\facade\Log; use app\common\model\Company; use app\common\model\informationg\UserInformationg; use think\facade\App; +use app\common\model\task_scheduling_plan\TaskSchedulingPlan; /** * 任务结算执行的具体逻辑 @@ -24,7 +25,7 @@ class TaskInformationJob // //通过这个方法可以检查这个任务已经重试了几次了 // } try { - + TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]); $company = Company::where('id', $data['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足 $arr['status'] = 0; //信息更新 @@ -36,13 +37,14 @@ class TaskInformationJob } $name = '小组队长'; $arr['status'] = 1; + Task::where('id', $data['task_id'])->update(['status' => 3]); } elseif //交易金额 ($data['template_info']['type'] == 33) { $shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company); if ($shang_date_total_price == false) { Log::info('任务结算失败,交易金额未达到要求:' . json_encode($data)); - Task::where('id', $data['task_id'])->update(['status' => 5,'extend'=>json_encode($shang_date_total_price)]); + Task::where('id', $data['task_id'])->update(['status' => 5]); return false; } if($shang_date_total_price['arr']['total_price']>$shang_date_total_price['arr']['day_money']){ @@ -58,7 +60,8 @@ class TaskInformationJob Task::where('id', $data['task_id'])->update(['status' => 5]); return true; } - + $name=$task['director_info']['nickname']; + $arr['status'] = 1; } else { //其他类型任务 @@ -74,7 +77,7 @@ class TaskInformationJob $arr['money'] = $data['template_info']['money']; $arr['company_id'] = $data['scheduling']['company_id']; - $arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成人:' . $name . ',的任务结算'; + $arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成方:' . $name . ',任务结算'; $arr['proportion_one'] = $data['template_info']['proportion_one']; $arr['proportion_two'] = $data['template_info']['proportion_two']; $arr['sn'] = $data['sn']; @@ -86,7 +89,8 @@ class TaskInformationJob if ($arr['status'] == 1) { (new ShareProfit())->first($arr, $company); } else { - Log::info('任务结算失败:' . $data['template_info']['title'] . '未完成' . json_encode($data)); + Task::where('id', $data['task_id'])->update(['status' => 5,'extend'=>json_encode($shang_date_total_price)]); + Log::info('89-任务结算失败:' . $data['template_info']['title'] . '未完成' . json_encode($data)); } //如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法 $job->delete(); diff --git a/app/task/TaskCron.php b/app/task/TaskCron.php index 7e5541300..fd39c7ee7 100644 --- a/app/task/TaskCron.php +++ b/app/task/TaskCron.php @@ -8,7 +8,8 @@ use think\facade\Log; use yunwuxin\cron\Task; use app\common\model\Company; use app\common\model\task_template\TaskTemplate; - +use app\common\logic\task\TaskLogic; +use app\common\model\task_scheduling\TaskScheduling; class TaskCron extends Task{ public function configure() @@ -26,18 +27,83 @@ class TaskCron extends Task{ // $time=strtotime(date('Y-m-d',strtotime('-1 day'))); $time=strtotime(date('Y-m-d')); // $tiem_end=$time+86399; - $all=TaskTemplate::where('cron_time','<',$time)->where('status',1)->with('company')->select()->toArray(); - // $all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray(); + $plan_all=TaskScheduling::where('cron_time','<',$time)->where('status',1)->with('company_info')->select()->toArray(); + $plan_ids=[]; + foreach($plan_all as $k=>$v){ + $all=TaskTemplate::where('status',1)->where('task_scheduling',$v['id'])->limit(30)->select()->toArray(); + $plan_ids[]=$v['id']; + if($all){ + $plan_all[$k]['template']=$all; + }else{ + unset($plan_all[$k]); + } + } $company_id=[]; - foreach($all as $k=>$v){ - queue(TaskAdd::class,$v); + foreach($plan_all as $k=>$v){ + foreach($v['template'] as $kkk=>$vvv){ + if ($v['types'] == 1 ||$vvv['types'] == 3) { + if ($v['company_info'] && $v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'moeny','一'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } + } elseif ($v['types'] == 2) { + if ($v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'moeny','一'); + if($res==false){ + return false; + } + } elseif ($v['company_info']['day_count'] <=$vvv['stage_day_two']) { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_three','三'); + if($res==false){ + return false; + } + } + } else { + if ( $v['company_info']['day_count'] <=$vvv['stage_day_one']) { + $res=$this->stage_inspection($v['template'],'money_three','三'); + if($res==false){ + return false; + } + } else { + $res=$this->stage_inspection($v['template'],'money_two','二'); + if($res==false){ + return false; + } + } + } + } + foreach($v['template'] as $kk=>$vv){ + TaskLogic::CronAdd($vv,$v); + } $company_id[]=$v['company_id']; } - $arr=array_unique($company_id); - if(count($arr)){ - Company::where('id','in',$arr)->inc('day_count')->update(); - } + Company::where('id','in',$company_id)->inc('day_count')->update(); + TaskScheduling::where('id','in',$plan_ids)->update(['cron_time' => time()]); Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s')); //...具体的任务执行 } + + public function stage_inspection($v,$moeny_type='moeny',$title='一'){ + $count_moeny=0; + foreach($v['template'] as $kkkk=>$vvvv){ + $count_moeny+=$vvvv[$moeny_type]; + } + if($count_moeny>200){ + Log::info($title.'阶段金额大于200无法下达'.json_encode($v['company_info'])); + return false; + } + return true; + } }