更新任务结算和下发

This commit is contained in:
mkm 2023-09-05 15:52:01 +08:00
parent 9398bf0843
commit 07bccac83b
6 changed files with 76 additions and 75 deletions

View File

@ -42,11 +42,11 @@ class CeshiController extends BaseApiController
// TaskTemplate::where('id',109)->update(['transaction_pool'=>bcadd($transaction_pool,$day_money,2)]);
// }
$all=TaskSchedulingPlan::where('id',893)->with(['template_info','scheduling'])->select()->toArray();
foreach($all as $k=>$v){
queue(TaskInformationJob::class,$v);
}
return true;
// $all=TaskSchedulingPlan::where('id',893)->with(['template_info','scheduling'])->select()->toArray();
// foreach($all as $k=>$v){
// queue(TaskInformationJob::class,$v);
// }
// return true;
$plan_all = TaskScheduling::where('id',119)->with('company_info')->select()->toArray();
$plan_ids = [];
foreach ($plan_all as $k => $v) {

View File

@ -5,13 +5,14 @@ namespace app\api\controller;
use Symfony\Component\HttpClient\HttpClient;
use think\facade\Log;
use app\common\model\informationg\UserInformationg;
use app\common\model\task_template\TaskTemplate;
class RemoteController extends BaseApiController
{
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){
$start_time = date('Y-m-d');
@ -75,11 +76,12 @@ class RemoteController extends BaseApiController
$arr['total_price'] = $json['data']['total_price'];
//基础金额*(每日基户数*天数)//且户数小于公司总户数
$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;
}else{
$user_count_two = 5 * $company['day_count'];
$user_count_two = 5 * $day_count;
}
if ($user_count_two > $user_count) {
$user_count_money = 58 * $user_count;

View File

@ -58,7 +58,7 @@ class TaskController extends BaseApiController
foreach ($res as $k => $item) {
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(); // 可能要判断预存金是否满足
$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) {
$transaction_pool=TaskTemplate::where('id',$item['template_id'])->value('transaction_pool');
if($transaction_pool==0){

View File

@ -14,28 +14,29 @@ use think\facade\Log;
class ShareProfit
{
public function first($data, $company,$datas=[])
public function first($data, $company, $datas = [])
{
// if ($company['day_count'] <= $data['proportion_one']) {
// $proportion = $data['proportion_one'];
// } else {
// $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();
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']];
$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']];
@ -49,47 +50,48 @@ class ShareProfit
$this->Account($arr_two);
}
//公司
if($data['company_account_type']==1){
$deposit_count = bcadd($company['deposit'], $master_maoney,2);
$this->AccountLog($data['company_id'],$deposit_count,$master_maoney);
if ($data['company_account_type'] == 1) {
$deposit_count = bcadd($company['deposit'], $master_maoney, 2);
$this->AccountLog($data['company_id'], $deposit_count, $master_maoney);
$company_money_count = bcadd($company['company_money'], $master_maoney,2);
$this->AccountLog($data['company_id'],$company_money_count,$master_maoney);
$company_money_count = bcadd($company['company_money'], $master_maoney, 2);
$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)]);
}elseif($data['company_account_type']==2){
$company_money_count = bcadd($company['shareholder_money'], $data['money'],2);
$this->AccountLog($data['company_id'],$company_money_count,$data['money'],1,2);
Company::where('id', $data['company_id'])->update(['deposit'=>Db::raw('deposit+' . $master_maoney),
'company_money'=>Db::raw('company_money+' .$master_maoney),
'shareholder_money'=>Db::raw('shareholder_money+' . $datas['template_info']['over_decimal'])]);
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) {
$company_money_count = bcadd($company['shareholder_money'], $data['money'], 2);
$this->AccountLog($data['company_id'], $company_money_count, $data['money'], 1, 2);
Company::where('id', $data['company_id'])->update([
'deposit' => Db::raw('deposit+' . $master_maoney),
'company_money' => Db::raw('company_money+' . $master_maoney),
'shareholder_money' => Db::raw('shareholder_money+' . $datas['template_info']['over_decimal'])
]);
}
if(isset($datas['template_info']['type']) && $datas['template_info']['type'] ==35){
if($company['responsible_area']){
$responsible_area=explode(',',$company['responsible_area']);
}else{
Log::error('结算失败:没有区域'.json_encode($data));
if (isset($datas['template_info']['type']) && $datas['template_info']['type'] == 35) {
if ($company['responsible_area']) {
$responsible_area = explode(',', $company['responsible_area']);
} else {
Log::error('结算失败:没有区域' . json_encode($data));
return false;
}
$director_uid = Task::where('id', $datas['task_id'])->value('director_uid');
$shareholder_user = User::where('id', $director_uid)->field('id,nickname,brigade')->find();
$money=bcdiv($datas['template_info']['over_decimal'],count($responsible_area),2);
$left_amount=0;
$money = bcdiv($datas['template_info']['over_decimal'], count($responsible_area), 2);
$left_amount = 0;
foreach ($responsible_area as $kkk => $vvv) {
$left_amount+=bcadd(1000,$money,2);
$left_amount += bcadd(1000, $money, 2);
$company_log = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id'=>$datas['company_id'],
'change_object' => CompanyAccountLog::SHAREHOLDER,//变动对象
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY,//变动类型
'action' => CompanyAccountLog::INC,//1-增加 2-减少
'left_amount' =>$left_amount,//变动后数量
'change_amount' => $money,//变动数量
'remark' =>$shareholder_user['nickname'].'完成了'.$vvv.'队的股金:'.$money.'元',
'status'=>1,
'company_id' => $datas['company_id'],
'change_object' => CompanyAccountLog::SHAREHOLDER, //变动对象
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY, //变动类型
'action' => CompanyAccountLog::INC, //1-增加 2-减少
'left_amount' => $left_amount, //变动后数量
'change_amount' => $money, //变动数量
'remark' => $shareholder_user['nickname'] . '完成了' . $vvv . '队的股金:' . $money . '元',
'status' => 1,
];
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 = [
'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,
'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);
}

View File

@ -187,26 +187,26 @@ class TaskLogic extends BaseLogic
private static function task_money($v, $datas)
{
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'];
} else {
return $v['money_two'];
}
} 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'];
} elseif ($datas['company_info']['day_count'] <= $v['stage_day_two']) {
} elseif ($v['day_count'] <= $v['stage_day_two']) {
return $v['money_two'];
} else {
return $v['money_three'];
}
} else {
if ($datas['company_info']['day_count'] <= $v['stage_day_one']) {
if ($v['day_count'] <= $v['stage_day_one']) {
$a = $v['money'];
} else {
$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]);
}
return $a;

View File

@ -23,7 +23,6 @@ class TaskInformationJob
// if ($job->attempts() > 1) {
// //通过这个方法可以检查这个任务已经重试了几次了
// }
Db::startTrans();
try {
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(); // 可能要判断预存金是否满足
@ -124,23 +123,20 @@ class TaskInformationJob
$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));
return false;
}
if ($arr['status'] == 1) {
$arr['company_id'] = $data['scheduling']['company_id'];
$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'];
$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);
} 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));
}
//如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法