This commit is contained in:
mkm 2023-08-18 16:32:41 +08:00
parent e606fe2bd3
commit 635120bbe3
10 changed files with 177 additions and 121 deletions

View File

@ -6,6 +6,7 @@ use app\common\logic\task\TaskLogic;
use app\common\model\Company; use app\common\model\Company;
use app\common\model\task\Task; use app\common\model\task\Task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use think\facade\Log; use think\facade\Log;
use app\job\TaskInformationJob; use app\job\TaskInformationJob;
@ -49,6 +50,19 @@ halt(2);
} }
public function ceshi(){ public function ceshi(){
$time=strtotime(date('Y-m-d'));
// $time=strtotime(date('Y-m-d'));
// $tiem_end=$time+86399;
$all=TaskTemplate::where('cron_time','<',$time)->where('status',1)->with('company')->select()->toArray();
// $all=TaskTemplate::where('id',60)->with('company')->select()->toArray();
// $all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray();
$company_id=0;
foreach($all as $k=>$v){
TaskLogic::CronAdd($v);
$company_id=$v['company_id'];
}
halt(1);
$points = [ $points = [
[ [
"lat"=> 28.914962, "lat"=> 28.914962,

View File

@ -58,11 +58,16 @@ class TaskController extends BaseApiController{
$parmas=Request()->param(); $parmas=Request()->param();
$find=Task::where('id',$parmas['id'])->find(); $find=Task::where('id',$parmas['id'])->find();
if($find['type']==31){ if($find['type']==31){
$ids=$find['extend']['informationg']['ids']; if(isset($find['extend']['informationg'])){
$list= UserInformationg::where('id','in',$ids) $ids=['ids'];
->field('id,name,phone,sex,age,update_time, $list= UserInformationg::where('id','in',$ids)
area_id,area_id area_name,street_id,street_id street_name,village_id,village_id village_name,brigade_id,brigade_id brigade_name,address' ->field('id,name,phone,sex,age,update_time,
)->select()->toArray(); area_id,area_id area_name,street_id,street_id street_name,village_id,village_id village_name,brigade_id,brigade_id brigade_name,address'
)->select()->toArray();
}else{
$list=[];
}
}else{ }else{
$list=[]; $list=[];
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace app\common\logic\finance; namespace app\common\logic\finance;
use app\common\enum\user\AccountLogEnum; use app\common\enum\user\AccountLogEnum;
@ -11,52 +12,50 @@ use think\facade\Log;
class ShareProfit class ShareProfit
{ {
public function first($data,$company) public function first($data, $company)
{ {
if($company['day_count']<=$data['proportion_one']){ if ($company['day_count'] <= $data['proportion_one']) {
$proportion=$data['proportion_one']; $proportion = $data['proportion_one'];
}else{ } else {
$proportion=$data['proportion_two']; $proportion = $data['proportion_two'];
} }
//总金额除以2等于不可提现账号金额和收益 //总金额除以2等于不可提现账号金额和收益
$master_maoney=bcdiv($data['money'],2,2); $master_maoney = bcdiv($data['money'], 2, 2);
//收益的百分之25为负责人的收益其余为成员的平分收益 //收益的百分之25为负责人的收益其余为成员的平分收益
$master_maoney_user=bcdiv($master_maoney,2,2); $master_maoney_user = bcdiv($master_maoney, 2, 2);
//公司账户预存金 //公司账户预存金
$company_money=$master_maoney; // $company_money = $master_maoney;
//成员数量 //成员数量
$userAll=User::where('company_id',$data['company_id'])->where('admin_id',0)->field('id,user_money')->select(); $userAll = User::where('company_id', $data['company_id'])->where('admin_id', 0)->field('id,user_money')->select();
$yser_all_count=count($userAll); $yser_all_count = count($userAll);
$member_maoney_user=bcdiv($master_maoney_user,$yser_all_count,2); $member_maoney_user = bcdiv($master_maoney_user, $yser_all_count, 2);
//负责人 //负责人
Db::startTrans(); Db::startTrans();
try { try {
$arr=[$company['user_id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC,$master_maoney_user,$data['sn'],$data['msg'].'获得收益'.$master_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']]; $arr = [$company['user_id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $master_maoney_user, $data['sn'], $data['msg'] . '获得收益' . $master_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->master($arr); $this->master($arr);
$arr=[$company['user_id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC,$master_maoney_user,$data['sn'],$data['msg'].'获得账户余额'.$master_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->master($arr);
//成员 $arr = [$company['user_id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $master_maoney_user, $data['sn'], $data['msg'] . '获得账户余额' . $master_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
foreach ($userAll as $key => $value) { $this->master($arr);
$arr=[$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC,$member_maoney_user,$data['sn'],$data['msg'].'获得收益'.$member_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->member($arr);
$arr=[$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC,$member_maoney_user,$data['sn'],$data['msg'].'获得账户余额'.$member_maoney_user.'元',['company_id'=>$data['company_id'],'proportion'=>$proportion],$data['status']];
$this->member($arr);
}
//公司
if($data['status']==1){
Company::where('id',$data['company_id'])->inc('deposit',$master_maoney)->inc('company_money',$master_maoney)->update();
TaskSchedulingPlan::where('id',$data['id'])->update(['is_pay'=>1]);
}
Db::commit(); //成员
return true; foreach ($userAll as $key => $value) {
$arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $member_maoney_user, $data['sn'], $data['msg'] . '获得收益' . $member_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->member($arr);
$arr = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $member_maoney_user, $data['sn'], $data['msg'] . '获得账户余额' . $member_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']];
$this->member($arr);
}
//公司
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) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
Log::error('任务结算失败:'.$e->getMessage()); Log::error('任务结算失败:' . $e->getMessage());
return false; return false;
} }
} }
@ -64,20 +63,18 @@ class ShareProfit
/**负责人的分润 /**负责人的分润
* @param $data * @param $data
*/ */
private function master($data){ private function master($data)
if($data[7]==1){ {
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update(); User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('deposit+' . $data[3])]);
} return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
return AccountLogLogic::add($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]);
} }
/**成员分润 /**成员分润
* @param $data * @param $data
*/ */
private function member($data){ private function member($data)
if($data[7]==1){ {
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update(); User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('deposit+' . $data[3])]);
} return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
return AccountLogLogic::add($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]);
} }
} }

View File

@ -20,6 +20,7 @@ use app\common\logic\BaseLogic;
use app\common\model\informationg\UserInformationg; use app\common\model\informationg\UserInformationg;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate; use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use think\facade\Db; use think\facade\Db;
use think\facade\Log; use think\facade\Log;
@ -71,81 +72,82 @@ class TaskLogic extends BaseLogic
*/ */
public static function CronAdd(array $v): bool public static function CronAdd(array $v): bool
{ {
if ($v['template_info'] != null) { try {
try { $time=strtotime(date('Y-m-d'));
$TaskSchedulingPlan=TaskSchedulingPlan::create([
$arr = [ 'create_user_id' => 0,
'template_id' => $v['template_id'], 'company_id' => $v['company_id'],
'scheduling_plan_id' => $v['id'], 'template_id' => $v['id'],
'company_id' => $v['scheduling']['company_id'], 'scheduling_id' => $v['task_scheduling'],
'title' => $v['template_info']['title'], 'start_time' => $time,
'money' => $v['template_info']['money'], 'end_time' => $time+86399,
'type' => $v['template_info']['type'], 'sn' =>User::createUserSn(),
'content' => $v['template_info']['content'], 'status' => 1
'start_time' => strtotime($v['start_time']), ]);
'end_time' => strtotime($v['end_time']), $arr = [
'create_time' => time(), 'template_id' => $v['id'],
'update_time' => time(), 'scheduling_plan_id' => $TaskSchedulingPlan['id'],
]; 'company_id' => $v['company_id'],
$data = $arr; 'title' => $v['title'],
$data['money'] = self::task_money($v); 'money' => $v['money'],
if($v['template_info']['type'] == 31){ 'type' => $v['type'],
$data["extend"]=json_encode(['informationg'=>['count'=>5,'update'=>0]]); 'content' => $v['content'],
TaskTemplate::where('id',$v['template_id'])->inc('information_day_count',5)->update(); 'start_time' => $time,
}else{ 'end_time' => $time+86399,
$data["extend"]=json_encode([]); 'create_time' => time(),
} 'update_time' => time(),
if ($v['template_info']['type'] == 32) { ];
$data['director_uid'] = $v['company']['user_id']; $data = $arr;
} $data['money'] = self::task_money($v);
$data['extend'] = $v['template_info']['extend']; if ($v['type'] == 31) {
$task_id = (new Task())->insertGetId($data); $data["extend"] = json_encode(['informationg' => ['count' => 5, 'update' => 0]]);
TaskSchedulingPlan::where('id', $v['id'])->update(['task_id' => $task_id, 'is_execute' => 1]); TaskTemplate::where('id', $v['id'])->inc('information_day_count', 5)->update();
return true; } else {
} catch (\Exception $e) { $data["extend"] = json_encode([]);
Log::error('定时任务添加失败', [$e->getMessage()]);
return false;
} }
if ($v['type'] == 32) {
$data['director_uid'] = $v['company']['user_id'];
}
$data['extend'] = json_encode($v['extend']);
$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()]);
return true;
} catch (\Exception $e) {
Log::error('定时任务添加失败', [$e->getMessage()]);
return false;
} }
} }
//任务金额 //任务金额
private static function task_money($v) private static function task_money($v)
{ {
if ($v['template_info']['types'] == 1 || $v['template_info']['types'] == 3) { if ($v['types'] == 1 || $v['types'] == 3) {
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
return $v['template_info']['money']; return $v['money'];
} else { } else {
return $v['template_info']['money_two']; return $v['money_two'];
} }
} elseif ($v['template_info']['types'] == 2) { } elseif ($v['types'] == 2) {
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
return $v['template_info']['money']; return $v['money'];
} elseif ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_two']) { } elseif ($v['company'] && $v['company']['day_count'] <= $v['stage_day_two']) {
return $v['template_info']['money_two']; return $v['money_two'];
} else { } else {
return $v['template_info']['money_three']; return $v['money_three'];
} }
} else { } else {
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
$a = $v['template_info']['money']; $a = $v['money'];
} else { } else {
$a = $v['template_info']['money_two']; $a = $v['money_two'];
} }
if($v['company'] && $v['company']['day_count']>=$v['template_info']['stage_day_two']){ if ($v['company'] && $v['company']['day_count'] >= $v['stage_day_two']) {
TaskTemplate::where('id',$v['template_id'])->update(['status'=>0]); TaskTemplate::where('id', $v['id'])->update(['status' => 0]);
} }
return $a; return $a;
} }
} }
/**
* @notes 随机生成信息更新任务
*/
private static function random_informationg($company_id)
{
$res = UserInformationg::where('company_id', $company_id)->where('status', 1)->order('update_time', 'desc')->limit(5)->field('id,create_user_id')->select();
return $res;
}
/** /**
* @notes 更新任务状态 * @notes 更新任务状态
* @param array $params * @param array $params

View File

@ -51,6 +51,7 @@ class TaskTemplateLogic extends BaseLogic
'title' => $params['title'], 'title' => $params['title'],
'admin_id' => $params['admin_id'], 'admin_id' => $params['admin_id'],
'company_id' => $params['company_id'], 'company_id' => $params['company_id'],
'task_scheduling' => $params['task_scheduling']??0,
'money' => $params['money'], 'money' => $params['money'],
'money_two' => $params['money_two'], 'money_two' => $params['money_two'],
'money_three' => $params['money_three'], 'money_three' => $params['money_three'],

View File

@ -16,6 +16,7 @@ namespace app\common\model\task_template;
use app\common\model\auth\Admin; use app\common\model\auth\Admin;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\Company;
use app\common\model\dict\DictData; use app\common\model\dict\DictData;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -35,6 +36,10 @@ class TaskTemplate extends BaseModel
{ {
return $this->hasOne(Admin::class, 'id', 'admin_id')->bind(['admin_name'=>'name']); return $this->hasOne(Admin::class, 'id', 'admin_id')->bind(['admin_name'=>'name']);
} }
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id')->field('id,day_count,user_id');
}
public function dataType() public function dataType()
{ {

View File

@ -44,9 +44,10 @@ class TaskInformationJob
$name = $shang_date_total_price['name']; $name = $shang_date_total_price['name'];
$arr['status'] = $shang_date_total_price['arr']['status']; $arr['status'] = $shang_date_total_price['arr']['status'];
} else { } else {
//其他类型任务
$task_count = Task::where('id', $data['task_id'])->field('director_uid')->where('status', 3)->with('director_info')->find(); $task_count = Task::where('id', $data['task_id'])->field('director_uid')->where('status', 3)->with('director_info')->find();
if (empty($task_count)) { if (empty($task_count)) {
Log::error('列105 任务结算失败task_count为空:' . json_encode($data)); Log::info('列105 任务 '.$data['template_info']['title'].'结算失败,任务为空:' . json_encode($data));
return false; return false;
} }
$name = $task_count['director_info']['nickname']; $name = $task_count['director_info']['nickname'];
@ -62,10 +63,14 @@ class TaskInformationJob
$arr['sn'] = $data['sn']; $arr['sn'] = $data['sn'];
$arr['id'] = $data['id']; $arr['id'] = $data['id'];
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('列122 任务结算失败:' . $e->getMessage() . json_encode($data)); Log::error('列122 任务结算失败:'.$data['template_info']['title'] . $e->getMessage() . json_encode($data));
return false; return false;
} }
(new ShareProfit())->first($arr, $company); if($arr['status']==1){
(new ShareProfit())->first($arr, $company);
}else{
Log::error('任务结算失败:'.$data['template_info']['title'].'未完成' . json_encode($data));
}
//如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法 //如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法
$job->delete(); $job->delete();
} }

View File

@ -4,17 +4,17 @@ namespace app\task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\job\TaskAdd; use app\job\TaskAdd;
use app\job\TaskInformationJob;
use think\facade\Log; use think\facade\Log;
use yunwuxin\cron\Task; use yunwuxin\cron\Task;
use app\common\model\Company; use app\common\model\Company;
use app\common\model\task_template\TaskTemplate;
class TaskCron extends Task{ class TaskCron extends Task{
public function configure() public function configure()
{ {
$this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释 // $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
// $this->everyMinute(); $this->everyMinute();
} }
/** /**
* 执行任务 * 执行任务
@ -22,18 +22,12 @@ class TaskCron extends Task{
*/ */
protected function execute() protected function execute()
{ {
Log::error('定时任务执行成功'.date('Y-m-d H:i:s'));
//任务结算
$all=TaskSchedulingPlan::whereDay('end_time','yesterday')->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray();
foreach($all as $k=>$v){
queue(TaskInformationJob::class,$v);
}
//任务下发 //任务下发
// $time=strtotime(date('Y-m-d',strtotime('+1 day'))); // $time=strtotime(date('Y-m-d',strtotime('-1 day')));
$time=strtotime(date('Y-m-d')); $time=strtotime(date('Y-m-d'));
$tiem_end=$time+86399; // $tiem_end=$time+86399;
$all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray(); $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();
$company_id=0; $company_id=0;
foreach($all as $k=>$v){ foreach($all as $k=>$v){
queue(TaskAdd::class,$v); queue(TaskAdd::class,$v);
@ -43,7 +37,7 @@ class TaskCron extends Task{
Company::where('id',$company_id)->inc('day_count')->update(); Company::where('id',$company_id)->inc('day_count')->update();
} }
Log::error('定时任务执行成功2'); Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s'));
//...具体的任务执行 //...具体的任务执行
} }
} }

View File

@ -0,0 +1,32 @@
<?php
namespace app\task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\job\TaskInformationJob;
use think\facade\Log;
use yunwuxin\cron\Task;
class TaskSettlementCron extends Task{
public function configure()
{
// $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
$this->everyMinute();
}
/**
* 任务结算
* @return mixed
*/
protected function execute()
{
$all=TaskSchedulingPlan::whereDay('end_time','yesterday')->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray();
foreach($all as $k=>$v){
queue(TaskInformationJob::class,$v);
}
Log::error('定时任务结算执行成功'.date('Y-m-d H:i:s'));
//...具体的任务执行
}
}

View File

@ -5,6 +5,7 @@
return [ return [
'tasks' => [ 'tasks' => [
app\task\TaskCron::class, app\task\TaskCron::class,
app\task\TaskSettlementCron::class,
// app\task\Ceshi::class, // app\task\Ceshi::class,
] ]
]; ];