From 839895ca4d44ef5182cfa63cd60f9e452ef6f5d5 Mon Sep 17 00:00:00 2001 From: xucong <850806214@qq.com> Date: Mon, 23 Sep 2024 16:03:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=94=AF=E4=BB=98=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Billions.php | 3 + app/api/logic/BillionsLogic.php | 125 +++++++++++++++++++++ app/api/logic/OrderLogic.php | 9 ++ app/common/logic/PayNotifyLogic.php | 161 ++++++++++++++++++++++++++-- app/common/model/AccountLog.php | 14 +-- 5 files changed, 294 insertions(+), 18 deletions(-) diff --git a/app/api/controller/Billions.php b/app/api/controller/Billions.php index 6ee450a5..036ed997 100755 --- a/app/api/controller/Billions.php +++ b/app/api/controller/Billions.php @@ -29,10 +29,13 @@ class Billions extends Api foreach($list['list'] as $key=>$value){ $ranking = BillionsLogic::getRanking($value['billions_id']); $list['list'][$key]['ranking'] = $ranking; + BillionsLogic::checkBillions($value['billions_id'],$ranking,$this->user_id); } return JsonServer::success('获取成功', $list); } + // 脚本1分钟运行一次 + /** * @notes 提现 */ diff --git a/app/api/logic/BillionsLogic.php b/app/api/logic/BillionsLogic.php index 0c59f6ad..773e1a71 100755 --- a/app/api/logic/BillionsLogic.php +++ b/app/api/logic/BillionsLogic.php @@ -115,6 +115,131 @@ class BillionsLogic extends Logic return Billions::where($where)->count(); } + // 计算队列金额 + public static function checkBillions($billion,$ranking,$user_id){ + $result = Db::name("user_billions_surplus") + ->where("residue_price",">","0") + ->where("user_start_price",">","0") + ->select()->toArray(); + foreach($result as $key=>$value){ + $result = Db::name("user_billions_surplus_log") + ->where("surplus_id",$value['surplus_id']) + ->where("user_billion_id",$billion) + ->find(); + if($value['billions_id']>=$billion){ + if($result == null){ + $d['surplus_id'] = $value['surplus_id']; + $d['user_id'] = $user_id; + $d['billions_id'] = $value['billions_id']; + $d['user_billion_id'] = $billion; + $d['dtime'] = date("Y-m-d H:i:s"); + if($ranking <= $value['user_start_num']){ + if($value['user_start_price'] >0){ + if($value['user_start_avg_price'] <= $value['user_start_price']){ + $dec_price = $d['price'] = $value['user_start_avg_price']; + }else{ + $dec_price = $d['price'] = $value['user_start_price']; + } + Db::name("user_billions_surplus") + ->where("surplus_id",$value['surplus_id']) + ->dec("user_start_price",$dec_price) + ->update(); + } + }else{ + if($value['user_price'] <= $value['residue_price']){ + $dec_price = $d['price'] = $value['user_price']; + }else{ + $dec_price = $d['price'] = $value['residue_price']; + } + Db::name("user_billions_surplus") + ->where("surplus_id",$value['surplus_id']) + ->dec("residue_price",$dec_price) + ->update(); + } + Db::name("user_billions_surplus_log") + ->save($d); + $my_billions = Db::name("user_billions")->where("billions_id",$billion)->where("state",0)->find(); + if($my_billions!=null){ + if($my_billions['order_price'] <= $d['price']+ $my_billions['subsidy_price']){ + // 查询用户总余额账户 + $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$user_id)->find(); + if($first_user_all_account != null){ + // 判断账户是否可用 + if($first_user_all_account['state'] == 0 || $first_user_all_account['state'] == 2){ + return -2; + } + // 更新主表 + $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$user_id)->inc("total_amount",$my_billions['order_price'])->update(); + if(!$first_update_subsidy_withdrawal){ + return -4; + } + $dat['subsidy_withdrawal_id'] = $first_user_all_account['id']; + $dat['user_id'] = $user_id; + $dat['billions_id'] = $billion; + $dat['type'] = 1; + $dat['money'] = $my_billions['order_price']; + $dat['create_time'] = date("Y-m-d H:i:s"); + // 插入提现记录 + $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); + if ($first_save_record) { + $send = array( + 'user_id' => $user_id, + 'money' => $my_billions['order_price'] + ); + sendBillionsSubsidySMS($send); + } + + if(!$first_save_record){ + return -5; + } + }else{ + $d['user_id'] = $user_id; + $d['total_amount'] = $my_billions['order_price']; + $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); + if(!$first_update_subsidy_withdrawal){ + return -4; + } + $dat['subsidy_withdrawal_id'] = $first_update_subsidy_withdrawal; + $dat['user_id'] = $user_id; + $dat['billions_id'] = $billion; + $dat['type'] = 1; + $dat['money'] = $my_billions['order_price']; + $dat['create_time'] = date("Y-m-d H:i:s"); + // 插入提现记录 + $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); + if ($first_save_record) { + $send = array( + 'user_id' => $user_id, + 'money' => $my_billions['order_price'] + ); + sendBillionsSubsidySMS($send); + } + + if(!$first_save_record){ + return -5; + } + } + // 更新排队状态 + $first_update_user_billions = Db::name("user_billions")->where("billions_id",$billion)->update(['subsidy_price'=> $my_billions['order_price'],"state"=>2]); + if(!$first_update_user_billions){ + return -3; + } + }else{ + $subsidy_price_sum = round($my_billions['subsidy_price']+$d['price'],8); + Db::name("user_billions")->where("billions_id",$billion)->update(['subsidy_price'=>$subsidy_price_sum]); + + // Db::name("user_billions") + // ->where("billions_id",$billion) + // ->inc("subsidy_price",$d['price']) + // ->update(); + + } + } + } + } + } + return true; + } // 提现进行记录 public static function withdrawRecord($id, $user_id){ Db::startTrans(); diff --git a/app/api/logic/OrderLogic.php b/app/api/logic/OrderLogic.php index d5bcb56a..2ca3b05a 100755 --- a/app/api/logic/OrderLogic.php +++ b/app/api/logic/OrderLogic.php @@ -1739,6 +1739,15 @@ class OrderLogic extends Logic if($order['billions_type'] == 0){ return false; } + if(isset($order['id'])){ + $check_order = Db::name("user_billions") + ->where("order_id",$order['id']) + ->where("type",$order['type']) + ->find(); + if($check_order != null){ + return true; + } + } $user_subsidy = 2; // 自我补贴 $all_user_subsidy = 20; //全用户获取的比例 $user_start_num = 1; // 补贴前几位数量 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index cbee8e4f..71c3ce57 100755 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -422,8 +422,7 @@ class PayNotifyLogic } } } - - private static function recharge_billions($order, $user_id,$type="") + private static function recharge_billions_old($order, $user_id,$type="") { if(isset($order['id'])){ $check_order = Db::name("user_billions") @@ -799,6 +798,149 @@ class PayNotifyLogic // WHERE billions_id IN ($billion_arr_id)"; // $query = Db::query($sql); // 本地生活微信支付 推广商家收益 + + } + + private static function recharge_billions($order, $user_id,$type="") + { + if(isset($order['id'])){ + $check_order = Db::name("user_billions") + ->where("order_id",$order['id']) + ->where("type",$order['type']) + ->find(); + if($check_order != null){ + return true; + } + } + + $user_subsidy = 2; // 自我补贴 + $all_user_subsidy = 20; //全用户获取的比例 + $user_start_num = 1; // 补贴前几位数量 + $user_start_subsidy = 40; //补贴前几位比例 全用户比例中扣除 + $user_end_subsidy = 60; //补贴剩余部分比例 + $user_first_leader = 40; // 推广者排队补贴 + $first_leader = 5; //分销推广者补贴 + $store_subsidy = 5; // 店铺推广者补贴 如没有补贴给店铺拥有者 + $donglonghui = 5; //东龙汇服务费 + $other_leader = 3; //分公司收入 如没有则并入东龙汇 + $shop_com = 60; // 商家获取收入 + $user = Db::name("user")->where(['id' => $user_id])->find(); + $first_leader_user = Db::name("user")->where("id", $user['first_leader'])->find(); + $is_d = Distribution::where('user_id', $user['first_leader'] )->where('is_distribution', 1 )->find(); + $data['order_price'] = $order['order_amount']; // 改为充值金额 + $data['user_id'] = $user_id; + $data['goods_id'] = 0; // 充值接口不需要该参数 + $data['shop_id'] = 0; // 充值接口不需要该参数 + $data['goods_num'] = 1; // 充值接口设置为1 + $data['order_id'] = $order['id']; + $data['dtime'] = date("Y-m-d H:i:s"); + $data['type'] = $order['type']; // 类型是充值 + $data['subsidy_price'] = round($order['order_amount'] * $user_subsidy / 100,8); + $res = Db::name("user_billions")->insertGetId($data); + $subsidy = $order['order_amount'] * $all_user_subsidy / 100; + if($is_d != null){ + $ufl = round($subsidy*$user_first_leader/100,8); + $subsidy_ufl = round($subsidy - $ufl,8); + $first_billions_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); + if(count($first_billions_msg) > 0){ + foreach($first_billions_msg as $k=>$v){ + if($ufl > 0){ + if($v['order_price'] <= $ufl+$v['subsidy_price']){ + // 查询用户总余额账户 + $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->find(); + if($first_user_all_account != null){ + // 判断账户是否可用 + if($first_user_all_account['state'] == 0 || $first_user_all_account['state'] == 2){ + return -2; + } + // 更新主表 + $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); + if(!$first_update_subsidy_withdrawal){ + return -4; + } + $dat['subsidy_withdrawal_id'] = $first_user_all_account['id']; + $dat['user_id'] = $v['user_id']; + $dat['billions_id'] = $v['billions_id']; + $dat['type'] = 1; + $dat['money'] = $v['order_price']; + $dat['create_time'] = date("Y-m-d H:i:s"); + // 插入提现记录 + $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); + if ($first_save_record) { + $send = array( + 'user_id' => $v['user_id'], + 'money' => $v['order_price'] + ); + sendBillionsSubsidySMS($send); + } + + if(!$first_save_record){ + return -5; + } + }else{ + $d['user_id'] = $v['user_id']; + $d['total_amount'] = $v['order_price']; + $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); + if(!$first_update_subsidy_withdrawal){ + return -4; + } + $dat['subsidy_withdrawal_id'] = $first_update_subsidy_withdrawal; + $dat['user_id'] = $v['user_id']; + $dat['billions_id'] = $v['billions_id']; + $dat['type'] = 1; + $dat['money'] = $v['order_price']; + $dat['create_time'] = date("Y-m-d H:i:s"); + // 插入提现记录 + $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); + if ($first_save_record) { + $send = array( + 'user_id' => $v['user_id'], + 'money' => $v['order_price'] + ); + sendBillionsSubsidySMS($send); + } + + if(!$first_save_record){ + return -5; + } + } + // 更新排队状态 + $first_update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); + if(!$first_update_user_billions){ + return -3; + } + // 剩余金额 + $ufl = round($ufl+$v['subsidy_price']-$v['order_price'],8); + }else{ + $subsidy_price_sum = round($v['subsidy_price']+$ufl,8); + Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$subsidy_price_sum]); + // Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$ufl)->update(); + $ufl = 0; + } + } + + } + $subsidy = round($subsidy_ufl + $ufl,8); + } + self::atcl($order,$store_subsidy,$type,$user,$first_leader,$other_leader); + } + $billions_count = Db::name("user_billions")->where("state",0)->count(); + $data_surplus['billions_id'] = $res; + $data_surplus['subsidy_all_price'] = $subsidy; + $data_surplus['user_start_num'] = $user_start_num; + $data_surplus['user_start_subsidy'] = $user_start_subsidy; + $data_surplus['user_start_price'] = round($subsidy*$user_start_subsidy/100,8); + $data_surplus['user_start_avg_price'] = round($data_surplus['user_start_price']/$user_start_num,8); + $data_surplus['residue_price'] = $subsidy-$data_surplus['user_start_price']; + if($billions_count>$user_start_num){ + $data_surplus['user_price'] = round(($subsidy-$data_surplus['user_start_price'])/($billions_count-$user_start_num),8); + } + $data_surplus['dtime'] = date("Y-m-d H:i:s"); + $rest = Db::name("user_billions_surplus")->save($data_surplus); + return $rest; + } + + public static function atcl($order,$store_subsidy,$type,$user,$first_leader,$other_leader){ if(isset($order['lstore_id'])){ $local_msg = Db::name("local_store") ->where("lstore_id",$order['lstore_id']) @@ -839,22 +981,21 @@ class PayNotifyLogic $remark = $remark1 =$remark2= ""; $source_type = $source_type1 =$source_type2= 0; if($type == "balance_rechange"){ - $remark = "推广用户充值佣金增加"; + $remark = "用户充值佣金"; $source_type = AccountLog::recharge_billions_inc_earnings; - $remark1 = "无极会员推广充值佣金增加"; + $remark1 = "无极充值佣金"; $source_type1 = AccountLog::electrodeless_rechange_inc_earnings; - $remark2 = "无极公司推广充值佣金增加"; + $remark2 = "无极公司充值佣金"; $source_type2 = AccountLog::company_electrodeless_rechange_inc_earnings; } if($type == "local_pay"){ - $remark = "本地生活推广用户支付佣金增加"; + $remark = "本地生活用户佣金"; $source_type = AccountLog::local_user_inc_earnings; - $remark1 = "无极会员推广本地生活支付佣金增加"; + $remark1 = "无极本地生活用户佣金"; $source_type1 = AccountLog::electrodeless_local_inc_earnings; - $remark2 = "无极公司推广本地生活支付佣金增加"; + $remark2 = "无极公司本地生活用户佣金"; $source_type2 = AccountLog::company_electrodeless_local_inc_earnings; } - if($is_d!=null){ if($user['first_leader']>0){ $first_leader_percent = round($order['order_amount'] * $first_leader / 100, 8); // Order::where('id', $order['id']) @@ -979,11 +1120,9 @@ class PayNotifyLogic 'settlement_time' => time() ]); } - } return true; } - /** * @notes 积分订单回调 * @param $order_sn diff --git a/app/common/model/AccountLog.php b/app/common/model/AccountLog.php index 3e6e9e75..48fdabe8 100755 --- a/app/common/model/AccountLog.php +++ b/app/common/model/AccountLog.php @@ -119,13 +119,13 @@ class AccountLog extends Models self::after_sale_refund => '售后退回余额', self::baiyibutie => '百亿补贴结算获得佣金', self::billions_inc_earnings => '百亿返补佣金增加', - self::local_inc_earnings => '推广本地商家收款佣金增加', - self::balance_rechange_inc_earnings => '推广用户充值佣金增加', - self::electrodeless_rechange_inc_earnings => '无极会员推广充值佣金增加', - self::company_electrodeless_rechange_inc_earnings => '无极公司推广充值佣金增加', - self::local_user_inc_earnings => '本地生活推广用户支付佣金增加', - self::electrodeless_local_inc_earnings => '无极会员推广本地生活支付佣金增加', - self::company_electrodeless_local_inc_earnings => '无极公司推广本地生活支付佣金增加', + self::local_inc_earnings => '本地商家佣金', + self::balance_rechange_inc_earnings => '用户充值佣金', + self::electrodeless_rechange_inc_earnings => '无极用户充值佣金', + self::company_electrodeless_rechange_inc_earnings => '无极公司用户充值佣金', + self::local_user_inc_earnings => '本地生活用户佣金', + self::electrodeless_local_inc_earnings => '无极本地生活用户佣金', + self::company_electrodeless_local_inc_earnings => '无极公司本地生活用户佣金', self::withdraw_to_balance => '佣金提现', self::withdraw_dec_earnings => '提现扣减佣金', self::withdraw_back_earnings => '拒绝提现返还佣金',