更新
This commit is contained in:
parent
e606fe2bd3
commit
635120bbe3
@ -6,6 +6,7 @@ use app\common\logic\task\TaskLogic;
|
||||
use app\common\model\Company;
|
||||
use app\common\model\task\Task;
|
||||
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
||||
use app\common\model\task_template\TaskTemplate;
|
||||
use think\facade\Log;
|
||||
use app\job\TaskInformationJob;
|
||||
|
||||
@ -49,6 +50,19 @@ halt(2);
|
||||
}
|
||||
|
||||
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 = [
|
||||
[
|
||||
"lat"=> 28.914962,
|
||||
|
@ -58,7 +58,8 @@ class TaskController extends BaseApiController{
|
||||
$parmas=Request()->param();
|
||||
$find=Task::where('id',$parmas['id'])->find();
|
||||
if($find['type']==31){
|
||||
$ids=$find['extend']['informationg']['ids'];
|
||||
if(isset($find['extend']['informationg'])){
|
||||
$ids=['ids'];
|
||||
$list= UserInformationg::where('id','in',$ids)
|
||||
->field('id,name,phone,sex,age,update_time,
|
||||
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'
|
||||
@ -66,6 +67,10 @@ class TaskController extends BaseApiController{
|
||||
}else{
|
||||
$list=[];
|
||||
}
|
||||
|
||||
}else{
|
||||
$list=[];
|
||||
}
|
||||
return $this->success('ok',$list);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic\finance;
|
||||
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
@ -11,52 +12,50 @@ use think\facade\Log;
|
||||
|
||||
class ShareProfit
|
||||
{
|
||||
public function first($data,$company)
|
||||
public function first($data, $company)
|
||||
{
|
||||
if($company['day_count']<=$data['proportion_one']){
|
||||
$proportion=$data['proportion_one'];
|
||||
}else{
|
||||
$proportion=$data['proportion_two'];
|
||||
if ($company['day_count'] <= $data['proportion_one']) {
|
||||
$proportion = $data['proportion_one'];
|
||||
} else {
|
||||
$proportion = $data['proportion_two'];
|
||||
}
|
||||
//总金额除以2等于不可提现账号金额和收益
|
||||
$master_maoney=bcdiv($data['money'],2,2);
|
||||
$master_maoney = bcdiv($data['money'], 2, 2);
|
||||
//收益的百分之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();
|
||||
$yser_all_count=count($userAll);
|
||||
$member_maoney_user=bcdiv($master_maoney_user,$yser_all_count,2);
|
||||
$userAll = User::where('company_id', $data['company_id'])->where('admin_id', 0)->field('id,user_money')->select();
|
||||
$yser_all_count = count($userAll);
|
||||
$member_maoney_user = bcdiv($master_maoney_user, $yser_all_count, 2);
|
||||
|
||||
//负责人
|
||||
Db::startTrans();
|
||||
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);
|
||||
|
||||
|
||||
$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']];
|
||||
$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);
|
||||
|
||||
//成员
|
||||
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']];
|
||||
$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']];
|
||||
$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]);
|
||||
}
|
||||
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('任务结算失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -64,20 +63,18 @@ class ShareProfit
|
||||
/**负责人的分润
|
||||
* @param $data
|
||||
*/
|
||||
private function master($data){
|
||||
if($data[7]==1){
|
||||
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update();
|
||||
}
|
||||
return AccountLogLogic::add($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]);
|
||||
private function master($data)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
|
||||
/**成员分润
|
||||
* @param $data
|
||||
*/
|
||||
private function member($data){
|
||||
if($data[7]==1){
|
||||
User::where('id',$data[0])->inc('user_money',$data[3])->inc('deposit',$data[3])->update();
|
||||
}
|
||||
return AccountLogLogic::add($data[0],$data[1],$data[2],$data[3],$data[4],$data[5],$data[6],$data[7]);
|
||||
private function member($data)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ use app\common\logic\BaseLogic;
|
||||
use app\common\model\informationg\UserInformationg;
|
||||
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
||||
use app\common\model\task_template\TaskTemplate;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
@ -71,81 +72,82 @@ class TaskLogic extends BaseLogic
|
||||
*/
|
||||
public static function CronAdd(array $v): bool
|
||||
{
|
||||
if ($v['template_info'] != null) {
|
||||
try {
|
||||
|
||||
$time=strtotime(date('Y-m-d'));
|
||||
$TaskSchedulingPlan=TaskSchedulingPlan::create([
|
||||
'create_user_id' => 0,
|
||||
'company_id' => $v['company_id'],
|
||||
'template_id' => $v['id'],
|
||||
'scheduling_id' => $v['task_scheduling'],
|
||||
'start_time' => $time,
|
||||
'end_time' => $time+86399,
|
||||
'sn' =>User::createUserSn(),
|
||||
'status' => 1
|
||||
]);
|
||||
$arr = [
|
||||
'template_id' => $v['template_id'],
|
||||
'scheduling_plan_id' => $v['id'],
|
||||
'company_id' => $v['scheduling']['company_id'],
|
||||
'title' => $v['template_info']['title'],
|
||||
'money' => $v['template_info']['money'],
|
||||
'type' => $v['template_info']['type'],
|
||||
'content' => $v['template_info']['content'],
|
||||
'start_time' => strtotime($v['start_time']),
|
||||
'end_time' => strtotime($v['end_time']),
|
||||
'template_id' => $v['id'],
|
||||
'scheduling_plan_id' => $TaskSchedulingPlan['id'],
|
||||
'company_id' => $v['company_id'],
|
||||
'title' => $v['title'],
|
||||
'money' => $v['money'],
|
||||
'type' => $v['type'],
|
||||
'content' => $v['content'],
|
||||
'start_time' => $time,
|
||||
'end_time' => $time+86399,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
$data = $arr;
|
||||
$data['money'] = self::task_money($v);
|
||||
if($v['template_info']['type'] == 31){
|
||||
$data["extend"]=json_encode(['informationg'=>['count'=>5,'update'=>0]]);
|
||||
TaskTemplate::where('id',$v['template_id'])->inc('information_day_count',5)->update();
|
||||
}else{
|
||||
$data["extend"]=json_encode([]);
|
||||
if ($v['type'] == 31) {
|
||||
$data["extend"] = json_encode(['informationg' => ['count' => 5, 'update' => 0]]);
|
||||
TaskTemplate::where('id', $v['id'])->inc('information_day_count', 5)->update();
|
||||
} else {
|
||||
$data["extend"] = json_encode([]);
|
||||
}
|
||||
if ($v['template_info']['type'] == 32) {
|
||||
if ($v['type'] == 32) {
|
||||
$data['director_uid'] = $v['company']['user_id'];
|
||||
}
|
||||
$data['extend'] = $v['template_info']['extend'];
|
||||
$data['extend'] = json_encode($v['extend']);
|
||||
$task_id = (new Task())->insertGetId($data);
|
||||
TaskSchedulingPlan::where('id', $v['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
|
||||
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)
|
||||
{
|
||||
if ($v['template_info']['types'] == 1 || $v['template_info']['types'] == 3) {
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) {
|
||||
return $v['template_info']['money'];
|
||||
if ($v['types'] == 1 || $v['types'] == 3) {
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
|
||||
return $v['money'];
|
||||
} else {
|
||||
return $v['template_info']['money_two'];
|
||||
return $v['money_two'];
|
||||
}
|
||||
} elseif ($v['template_info']['types'] == 2) {
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) {
|
||||
return $v['template_info']['money'];
|
||||
} elseif ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_two']) {
|
||||
return $v['template_info']['money_two'];
|
||||
} elseif ($v['types'] == 2) {
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
|
||||
return $v['money'];
|
||||
} elseif ($v['company'] && $v['company']['day_count'] <= $v['stage_day_two']) {
|
||||
return $v['money_two'];
|
||||
} else {
|
||||
return $v['template_info']['money_three'];
|
||||
return $v['money_three'];
|
||||
}
|
||||
} else {
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) {
|
||||
$a = $v['template_info']['money'];
|
||||
if ($v['company'] && $v['company']['day_count'] <= $v['stage_day_one']) {
|
||||
$a = $v['money'];
|
||||
} else {
|
||||
$a = $v['template_info']['money_two'];
|
||||
$a = $v['money_two'];
|
||||
}
|
||||
if($v['company'] && $v['company']['day_count']>=$v['template_info']['stage_day_two']){
|
||||
TaskTemplate::where('id',$v['template_id'])->update(['status'=>0]);
|
||||
if ($v['company'] && $v['company']['day_count'] >= $v['stage_day_two']) {
|
||||
TaskTemplate::where('id', $v['id'])->update(['status' => 0]);
|
||||
}
|
||||
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 更新任务状态
|
||||
* @param array $params
|
||||
|
@ -51,6 +51,7 @@ class TaskTemplateLogic extends BaseLogic
|
||||
'title' => $params['title'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'company_id' => $params['company_id'],
|
||||
'task_scheduling' => $params['task_scheduling']??0,
|
||||
'money' => $params['money'],
|
||||
'money_two' => $params['money_two'],
|
||||
'money_three' => $params['money_three'],
|
||||
|
@ -16,6 +16,7 @@ namespace app\common\model\task_template;
|
||||
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\Company;
|
||||
use app\common\model\dict\DictData;
|
||||
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']);
|
||||
}
|
||||
public function company()
|
||||
{
|
||||
return $this->hasOne(Company::class, 'id', 'company_id')->field('id,day_count,user_id');
|
||||
}
|
||||
|
||||
public function dataType()
|
||||
{
|
||||
|
@ -44,9 +44,10 @@ class TaskInformationJob
|
||||
$name = $shang_date_total_price['name'];
|
||||
$arr['status'] = $shang_date_total_price['arr']['status'];
|
||||
} else {
|
||||
//其他类型任务
|
||||
$task_count = Task::where('id', $data['task_id'])->field('director_uid')->where('status', 3)->with('director_info')->find();
|
||||
if (empty($task_count)) {
|
||||
Log::error('列105 任务结算失败,task_count为空:' . json_encode($data));
|
||||
Log::info('列105 任务 '.$data['template_info']['title'].'结算失败,任务为空:' . json_encode($data));
|
||||
return false;
|
||||
}
|
||||
$name = $task_count['director_info']['nickname'];
|
||||
@ -62,10 +63,14 @@ class TaskInformationJob
|
||||
$arr['sn'] = $data['sn'];
|
||||
$arr['id'] = $data['id'];
|
||||
} 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;
|
||||
}
|
||||
if($arr['status']==1){
|
||||
(new ShareProfit())->first($arr, $company);
|
||||
}else{
|
||||
Log::error('任务结算失败:'.$data['template_info']['title'].'未完成' . json_encode($data));
|
||||
}
|
||||
//如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法
|
||||
$job->delete();
|
||||
}
|
||||
|
@ -4,17 +4,17 @@ namespace app\task;
|
||||
|
||||
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
||||
use app\job\TaskAdd;
|
||||
use app\job\TaskInformationJob;
|
||||
use think\facade\Log;
|
||||
use yunwuxin\cron\Task;
|
||||
use app\common\model\Company;
|
||||
use app\common\model\task_template\TaskTemplate;
|
||||
|
||||
class TaskCron extends Task{
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
|
||||
// $this->everyMinute();
|
||||
// $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
|
||||
$this->everyMinute();
|
||||
}
|
||||
/**
|
||||
* 执行任务
|
||||
@ -22,18 +22,12 @@ class TaskCron extends Task{
|
||||
*/
|
||||
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'));
|
||||
$tiem_end=$time+86399;
|
||||
$all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray();
|
||||
// $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();
|
||||
$company_id=0;
|
||||
foreach($all as $k=>$v){
|
||||
queue(TaskAdd::class,$v);
|
||||
@ -43,7 +37,7 @@ class TaskCron extends Task{
|
||||
|
||||
Company::where('id',$company_id)->inc('day_count')->update();
|
||||
}
|
||||
Log::error('定时任务执行成功2');
|
||||
Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s'));
|
||||
//...具体的任务执行
|
||||
}
|
||||
}
|
||||
|
32
app/task/TaskSettlementCron.php
Normal file
32
app/task/TaskSettlementCron.php
Normal 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'));
|
||||
|
||||
//...具体的任务执行
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
return [
|
||||
'tasks' => [
|
||||
app\task\TaskCron::class,
|
||||
app\task\TaskSettlementCron::class,
|
||||
// app\task\Ceshi::class,
|
||||
]
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user