更新任务结算和下发
This commit is contained in:
parent
9398bf0843
commit
07bccac83b
@ -42,11 +42,11 @@ class CeshiController extends BaseApiController
|
|||||||
|
|
||||||
// TaskTemplate::where('id',109)->update(['transaction_pool'=>bcadd($transaction_pool,$day_money,2)]);
|
// TaskTemplate::where('id',109)->update(['transaction_pool'=>bcadd($transaction_pool,$day_money,2)]);
|
||||||
// }
|
// }
|
||||||
$all=TaskSchedulingPlan::where('id',893)->with(['template_info','scheduling'])->select()->toArray();
|
// $all=TaskSchedulingPlan::where('id',893)->with(['template_info','scheduling'])->select()->toArray();
|
||||||
foreach($all as $k=>$v){
|
// foreach($all as $k=>$v){
|
||||||
queue(TaskInformationJob::class,$v);
|
// queue(TaskInformationJob::class,$v);
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
$plan_all = TaskScheduling::where('id',119)->with('company_info')->select()->toArray();
|
$plan_all = TaskScheduling::where('id',119)->with('company_info')->select()->toArray();
|
||||||
$plan_ids = [];
|
$plan_ids = [];
|
||||||
foreach ($plan_all as $k => $v) {
|
foreach ($plan_all as $k => $v) {
|
||||||
|
@ -5,13 +5,14 @@ namespace app\api\controller;
|
|||||||
use Symfony\Component\HttpClient\HttpClient;
|
use Symfony\Component\HttpClient\HttpClient;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
use app\common\model\informationg\UserInformationg;
|
use app\common\model\informationg\UserInformationg;
|
||||||
|
use app\common\model\task_template\TaskTemplate;
|
||||||
|
|
||||||
class RemoteController extends BaseApiController
|
class RemoteController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public array $notNeedLogin = ['index'];
|
public array $notNeedLogin = ['index'];
|
||||||
|
|
||||||
public function shang_date_total_price($company,$isDay=1,$arr=[])
|
public function shang_date_total_price($company,$isDay=1,$arr=[],$template_id)
|
||||||
{
|
{
|
||||||
if($isDay==1){
|
if($isDay==1){
|
||||||
$start_time = date('Y-m-d');
|
$start_time = date('Y-m-d');
|
||||||
@ -75,11 +76,12 @@ class RemoteController extends BaseApiController
|
|||||||
$arr['total_price'] = $json['data']['total_price'];
|
$arr['total_price'] = $json['data']['total_price'];
|
||||||
//基础金额*(每日基户数*天数)//且户数小于公司总户数
|
//基础金额*(每日基户数*天数)//且户数小于公司总户数
|
||||||
$user_count = UserInformationg::where('company_id', $company['id'])->count();
|
$user_count = UserInformationg::where('company_id', $company['id'])->count();
|
||||||
|
$day_count=TaskTemplate::where('id',$template_id)->value('day_count');
|
||||||
//
|
//
|
||||||
if($company['day_count']==0){
|
if($day_count==0){
|
||||||
$user_count_two = 5 * 1;
|
$user_count_two = 5 * 1;
|
||||||
}else{
|
}else{
|
||||||
$user_count_two = 5 * $company['day_count'];
|
$user_count_two = 5 * $day_count;
|
||||||
}
|
}
|
||||||
if ($user_count_two > $user_count) {
|
if ($user_count_two > $user_count) {
|
||||||
$user_count_money = 58 * $user_count;
|
$user_count_money = 58 * $user_count;
|
||||||
|
@ -58,7 +58,7 @@ class TaskController extends BaseApiController
|
|||||||
foreach ($res as $k => $item) {
|
foreach ($res as $k => $item) {
|
||||||
if ($item['type'] == 33) {
|
if ($item['type'] == 33) {
|
||||||
$company = Company::where('id', $item['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade,responsible_area')->find(); // 可能要判断预存金是否满足
|
$company = Company::where('id', $item['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade,responsible_area')->find(); // 可能要判断预存金是否满足
|
||||||
$find = App(RemoteController::class)->shang_date_total_price($company,1,$param);
|
$find = App(RemoteController::class)->shang_date_total_price($company,1,$param,$item['template_id']);
|
||||||
if ($find != false) {
|
if ($find != false) {
|
||||||
$transaction_pool=TaskTemplate::where('id',$item['template_id'])->value('transaction_pool');
|
$transaction_pool=TaskTemplate::where('id',$item['template_id'])->value('transaction_pool');
|
||||||
if($transaction_pool==0){
|
if($transaction_pool==0){
|
||||||
|
@ -14,28 +14,29 @@ use think\facade\Log;
|
|||||||
|
|
||||||
class ShareProfit
|
class ShareProfit
|
||||||
{
|
{
|
||||||
public function first($data, $company,$datas=[])
|
public function first($data, $company, $datas = [])
|
||||||
{
|
{
|
||||||
// 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'];
|
||||||
// }
|
// }
|
||||||
$proportion=0;
|
|
||||||
//总金额除以2等于不可提现账号金额和收益
|
|
||||||
$master_maoney = bcdiv($data['money'], 2, 2);
|
|
||||||
//收益的百分之25为负责人的收益其余为成员的平分收益
|
|
||||||
$master_maoney_user = bcdiv($master_maoney, 2, 2);
|
|
||||||
//公司账户预存金
|
|
||||||
// $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);
|
|
||||||
|
|
||||||
//负责人
|
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
|
$proportion = 0;
|
||||||
|
//总金额除以2等于不可提现账号金额和收益
|
||||||
|
$master_maoney = bcdiv($data['money'], 2, 2);
|
||||||
|
//收益的百分之25为负责人的收益其余为成员的平分收益
|
||||||
|
$master_maoney_user = bcdiv($master_maoney, 2, 2);
|
||||||
|
//公司账户预存金
|
||||||
|
// $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);
|
||||||
|
|
||||||
|
//负责人
|
||||||
|
|
||||||
$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_two = [$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_two = [$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']];
|
||||||
@ -49,47 +50,48 @@ class ShareProfit
|
|||||||
$this->Account($arr_two);
|
$this->Account($arr_two);
|
||||||
}
|
}
|
||||||
//公司
|
//公司
|
||||||
if($data['company_account_type']==1){
|
if ($data['company_account_type'] == 1) {
|
||||||
$deposit_count = bcadd($company['deposit'], $master_maoney,2);
|
$deposit_count = bcadd($company['deposit'], $master_maoney, 2);
|
||||||
$this->AccountLog($data['company_id'],$deposit_count,$master_maoney);
|
$this->AccountLog($data['company_id'], $deposit_count, $master_maoney);
|
||||||
|
|
||||||
$company_money_count = bcadd($company['company_money'], $master_maoney,2);
|
$company_money_count = bcadd($company['company_money'], $master_maoney, 2);
|
||||||
$this->AccountLog($data['company_id'],$company_money_count,$master_maoney);
|
$this->AccountLog($data['company_id'], $company_money_count, $master_maoney);
|
||||||
|
|
||||||
Company::where('id', $data['company_id'])->update(['deposit'=>Db::raw('deposit+' . $master_maoney), 'company_money'=>Db::raw('company_money+' .$master_maoney)]);
|
Company::where('id', $data['company_id'])->update(['deposit' => Db::raw('deposit+' . $master_maoney), 'company_money' => Db::raw('company_money+' . $master_maoney)]);
|
||||||
|
} elseif ($data['company_account_type'] == 2) {
|
||||||
}elseif($data['company_account_type']==2){
|
$company_money_count = bcadd($company['shareholder_money'], $data['money'], 2);
|
||||||
$company_money_count = bcadd($company['shareholder_money'], $data['money'],2);
|
$this->AccountLog($data['company_id'], $company_money_count, $data['money'], 1, 2);
|
||||||
$this->AccountLog($data['company_id'],$company_money_count,$data['money'],1,2);
|
Company::where('id', $data['company_id'])->update([
|
||||||
Company::where('id', $data['company_id'])->update(['deposit'=>Db::raw('deposit+' . $master_maoney),
|
'deposit' => Db::raw('deposit+' . $master_maoney),
|
||||||
'company_money'=>Db::raw('company_money+' .$master_maoney),
|
'company_money' => Db::raw('company_money+' . $master_maoney),
|
||||||
'shareholder_money'=>Db::raw('shareholder_money+' . $datas['template_info']['over_decimal'])]);
|
'shareholder_money' => Db::raw('shareholder_money+' . $datas['template_info']['over_decimal'])
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($datas['template_info']['type']) && $datas['template_info']['type'] ==35){
|
if (isset($datas['template_info']['type']) && $datas['template_info']['type'] == 35) {
|
||||||
if($company['responsible_area']){
|
if ($company['responsible_area']) {
|
||||||
$responsible_area=explode(',',$company['responsible_area']);
|
$responsible_area = explode(',', $company['responsible_area']);
|
||||||
}else{
|
} else {
|
||||||
Log::error('结算失败:没有区域'.json_encode($data));
|
Log::error('结算失败:没有区域' . json_encode($data));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$director_uid = Task::where('id', $datas['task_id'])->value('director_uid');
|
$director_uid = Task::where('id', $datas['task_id'])->value('director_uid');
|
||||||
$shareholder_user = User::where('id', $director_uid)->field('id,nickname,brigade')->find();
|
$shareholder_user = User::where('id', $director_uid)->field('id,nickname,brigade')->find();
|
||||||
$money=bcdiv($datas['template_info']['over_decimal'],count($responsible_area),2);
|
$money = bcdiv($datas['template_info']['over_decimal'], count($responsible_area), 2);
|
||||||
$left_amount=0;
|
$left_amount = 0;
|
||||||
foreach ($responsible_area as $kkk => $vvv) {
|
foreach ($responsible_area as $kkk => $vvv) {
|
||||||
$left_amount+=bcadd(1000,$money,2);
|
$left_amount += bcadd(1000, $money, 2);
|
||||||
$company_log = [
|
$company_log = [
|
||||||
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
|
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
|
||||||
'company_id'=>$datas['company_id'],
|
'company_id' => $datas['company_id'],
|
||||||
'change_object' => CompanyAccountLog::SHAREHOLDER,//变动对象
|
'change_object' => CompanyAccountLog::SHAREHOLDER, //变动对象
|
||||||
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY,//变动类型
|
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY, //变动类型
|
||||||
'action' => CompanyAccountLog::INC,//1-增加 2-减少
|
'action' => CompanyAccountLog::INC, //1-增加 2-减少
|
||||||
'left_amount' =>$left_amount,//变动后数量
|
'left_amount' => $left_amount, //变动后数量
|
||||||
'change_amount' => $money,//变动数量
|
'change_amount' => $money, //变动数量
|
||||||
'remark' =>$shareholder_user['nickname'].'完成了'.$vvv.'队的股金:'.$money.'元',
|
'remark' => $shareholder_user['nickname'] . '完成了' . $vvv . '队的股金:' . $money . '元',
|
||||||
'status'=>1,
|
'status' => 1,
|
||||||
];
|
];
|
||||||
CompanyAccountLog::create($company_log);
|
CompanyAccountLog::create($company_log);
|
||||||
}
|
}
|
||||||
@ -103,16 +105,17 @@ class ShareProfit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function AccountLog($companyId,$left_amount,$changeAmount,$change_object=1,$change_type=1,$action=1){
|
public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1)
|
||||||
|
{
|
||||||
$company_log = [
|
$company_log = [
|
||||||
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
|
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
|
||||||
'company_id'=>$companyId,
|
'company_id' => $companyId,
|
||||||
'change_object' => $change_object,//变动对象
|
'change_object' => $change_object, //变动对象
|
||||||
'change_type' => $change_type,//变动类型
|
'change_type' => $change_type, //变动类型
|
||||||
'action' => $action,//1-增加 2-减少
|
'action' => $action, //1-增加 2-减少
|
||||||
'left_amount' => $left_amount,//变动后数量
|
'left_amount' => $left_amount, //变动后数量
|
||||||
'change_amount' => $changeAmount,//变动数量
|
'change_amount' => $changeAmount, //变动数量
|
||||||
'status'=>1,
|
'status' => 1,
|
||||||
];
|
];
|
||||||
CompanyAccountLog::create($company_log);
|
CompanyAccountLog::create($company_log);
|
||||||
}
|
}
|
||||||
|
@ -187,26 +187,26 @@ class TaskLogic extends BaseLogic
|
|||||||
private static function task_money($v, $datas)
|
private static function task_money($v, $datas)
|
||||||
{
|
{
|
||||||
if ($v['types'] == 1 || $v['types'] == 3) {
|
if ($v['types'] == 1 || $v['types'] == 3) {
|
||||||
if ($datas['company_info'] && $datas['company_info']['day_count'] <= $v['stage_day_one']) {
|
if ($v['day_count'] <= $v['stage_day_one']) {
|
||||||
return $v['money'];
|
return $v['money'];
|
||||||
} else {
|
} else {
|
||||||
return $v['money_two'];
|
return $v['money_two'];
|
||||||
}
|
}
|
||||||
} elseif ($v['types'] == 2) {
|
} elseif ($v['types'] == 2) {
|
||||||
if ($datas['company_info']['day_count'] <= $v['stage_day_one']) {
|
if ($v['day_count'] <= $v['stage_day_one']) {
|
||||||
return $v['money'];
|
return $v['money'];
|
||||||
} elseif ($datas['company_info']['day_count'] <= $v['stage_day_two']) {
|
} elseif ($v['day_count'] <= $v['stage_day_two']) {
|
||||||
return $v['money_two'];
|
return $v['money_two'];
|
||||||
} else {
|
} else {
|
||||||
return $v['money_three'];
|
return $v['money_three'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($datas['company_info']['day_count'] <= $v['stage_day_one']) {
|
if ($v['day_count'] <= $v['stage_day_one']) {
|
||||||
$a = $v['money'];
|
$a = $v['money'];
|
||||||
} else {
|
} else {
|
||||||
$a = $v['money_two'];
|
$a = $v['money_two'];
|
||||||
}
|
}
|
||||||
if ($datas['company_info'] && $datas['company_info']['day_count'] >= $v['stage_day_two']) {
|
if ($v['day_count'] >= $v['stage_day_two']) {
|
||||||
TaskTemplate::where('id', $v['id'])->update(['status' => 0]);
|
TaskTemplate::where('id', $v['id'])->update(['status' => 0]);
|
||||||
}
|
}
|
||||||
return $a;
|
return $a;
|
||||||
|
@ -23,7 +23,6 @@ class TaskInformationJob
|
|||||||
// if ($job->attempts() > 1) {
|
// if ($job->attempts() > 1) {
|
||||||
// //通过这个方法可以检查这个任务已经重试了几次了
|
// //通过这个方法可以检查这个任务已经重试了几次了
|
||||||
// }
|
// }
|
||||||
Db::startTrans();
|
|
||||||
try {
|
try {
|
||||||
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]);
|
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]);
|
||||||
$company = Company::where('id', $data['company_id'])->field('id,deposit,responsible_area,company_money,shareholder_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
|
$company = Company::where('id', $data['company_id'])->field('id,deposit,responsible_area,company_money,shareholder_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
|
||||||
@ -124,23 +123,20 @@ class TaskInformationJob
|
|||||||
$arr['status'] = 1;
|
$arr['status'] = 1;
|
||||||
$arr['money'] = $task_count['money'];
|
$arr['money'] = $task_count['money'];
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($arr['status'] == 1) {
|
||||||
$arr['company_id'] = $data['scheduling']['company_id'];
|
$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_one'] = $data['template_info']['proportion_one'];
|
||||||
// $arr['proportion_two'] = $data['template_info']['proportion_two'];
|
// $arr['proportion_two'] = $data['template_info']['proportion_two'];
|
||||||
$arr['sn'] = $data['sn'];
|
$arr['sn'] = $data['sn'];
|
||||||
$arr['id'] = $data['id'];
|
$arr['id'] = $data['id'];
|
||||||
Db::commit();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollback();
|
|
||||||
Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($arr['status'] == 1) {
|
|
||||||
(new ShareProfit())->first($arr, $company,$data);
|
(new ShareProfit())->first($arr, $company,$data);
|
||||||
} else {
|
} else {
|
||||||
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]);
|
||||||
Log::info('任务status=0结算失败:' . $data['template_info']['title'] . '未完成' . json_encode($data));
|
Log::info('任务status=0结算失败:' . $data['template_info']['title'] . '未完成' . json_encode($data));
|
||||||
}
|
}
|
||||||
//如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法
|
//如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法
|
||||||
|
Loading…
x
Reference in New Issue
Block a user