From 4fbb7977d7d4c64464069609a6a8367ab24e8814 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Tue, 16 Jul 2024 09:50:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/WechatMiNiCheckPayOrder.php | 139 +++++++++++------- 1 file changed, 82 insertions(+), 57 deletions(-) diff --git a/app/common/command/WechatMiNiCheckPayOrder.php b/app/common/command/WechatMiNiCheckPayOrder.php index 7ebbcfdc..4429af98 100644 --- a/app/common/command/WechatMiNiCheckPayOrder.php +++ b/app/common/command/WechatMiNiCheckPayOrder.php @@ -34,40 +34,45 @@ class WechatMiNiCheckPayOrder extends Command protected function execute(Input $input, Output $output) { - $config = WeChatServer::getPayConfigBySource(1)['config']; - $app = Factory::payment($config); + Log::write('执行微信订单状态查询'); + try { + $config = WeChatServer::getPayConfigBySource(1)['config']; + $app = Factory::payment($config); - RechargeOrder::where('pay_status', PayEnum::UNPAID)->chunk(5, function ($orders) use ($app) { - foreach($orders as $order){ - Log::write('zhifu:' .$order['order_sn']); -// $result = $app->order->queryByOutTradeNumber($order['order_sn'] . $this->prefix); -// if (isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS') { -// $update_data['pay_time'] = time(); -// $update_data['pay_status'] = PayEnum::ISPAID; -// $update_data['transaction_id'] = isset($result['transaction_id']) ? $result['transaction_id'] : ''; -// $order->where('order_sn', $order->order_sn)->update($update_data); -// -// $user = User::find($order['user_id']); -// $total_money = $order['order_amount'] + $order['give_money']; -// $total_integral = $order['give_integral']; -// $user->user_money = ['inc', $total_money]; -// $user->user_integral = ['inc', $total_integral]; -// $user->user_growth = ['inc', $order['give_growth']]; -// $user->total_recharge_amount = ['inc', $total_money]; -// $user->save(); -// -// //记录余额 -// $total_money > 0 && AccountLogLogic::AccountRecord($user->id, $total_money, 1, AccountLog::recharge_money, '', $order['id'], $order['order_sn']); -// //记录积分 -// $total_integral > 0 && AccountLogLogic::AccountRecord($user->id, $total_integral, 1, AccountLog::recharge_give_integral); -// //记录成长值 -// $order['give_growth'] > 0 && AccountLogLogic::AccountRecord($user->id, $order['give_growth'], 1, AccountLog::recharge_give_growth); -// -// // 余额充值参与百亿补贴 -// self::recharge_billions($order, $order['user_id']); -// } - } - }); + RechargeOrder::where('pay_status', PayEnum::UNPAID)->chunk(5, function ($orders) use ($app) { + foreach($orders as $order){ + $result = $app->order->queryByOutTradeNumber($order['order_sn'] . $this->prefix); + //Log::write('订单状态查询-订单号:' . $order['order_sn'] . '; 订单状态:' . json_encode($result)); + if (isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS') { + $update_data['pay_time'] = time(); + $update_data['pay_status'] = PayEnum::ISPAID; + $update_data['transaction_id'] = isset($result['transaction_id']) ? $result['transaction_id'] : ''; + $order->where('order_sn', $order->order_sn)->update($update_data); + + $user = User::find($order['user_id']); + $total_money = $order['order_amount'] + $order['give_money']; + $total_integral = $order['give_integral']; + $user->user_money = ['inc', $total_money]; + $user->user_integral = ['inc', $total_integral]; + $user->user_growth = ['inc', $order['give_growth']]; + $user->total_recharge_amount = ['inc', $total_money]; + $user->save(); + + //记录余额 + $total_money > 0 && AccountLogLogic::AccountRecord($user->id, $total_money, 1, AccountLog::recharge_money, '', $order['id'], $order['order_sn']); + //记录积分 + $total_integral > 0 && AccountLogLogic::AccountRecord($user->id, $total_integral, 1, AccountLog::recharge_give_integral); + //记录成长值 + $order['give_growth'] > 0 && AccountLogLogic::AccountRecord($user->id, $order['give_growth'], 1, AccountLog::recharge_give_growth); + + // 余额充值参与百亿补贴 + self::recharge_billions($order, $order['user_id']); + } + } + }); + } catch(\Exception $e) { + Log::write('微信订单状态查询error: ' . $e->getMessage()); + } } private static function recharge_billions($order, $user_id) @@ -93,14 +98,14 @@ class WechatMiNiCheckPayOrder extends Command $data['order_id'] = $order['id']; $data['dtime'] = date("Y-m-d H:i:s"); $data['type'] = 2; // 类型是充值 - $data['subsidy_price'] = round($order['order_amount'] * $user_subsidy / 100,5); + $data['subsidy_price'] = round($order['order_amount'] * $user_subsidy / 100,6); $res = Db::name("user_billions")->save($data); $billions_msg = Db::name("user_billions")->where("state",0)->select()->toArray(); $subsidy = $order['order_amount'] * $all_user_subsidy / 100; if($is_d != null){ - $ufl = round($subsidy*$user_first_leader/100,5); - $subsidy_ufl = round($subsidy - $ufl,5); + $ufl = round($subsidy*$user_first_leader/100,6); + $subsidy_ufl = round($subsidy - $ufl,6); $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){ @@ -154,15 +159,17 @@ class WechatMiNiCheckPayOrder extends Command return -3; } // 剩余金额 - $ufl = round($ufl+$v['subsidy_price']-$v['order_price'],5); + $ufl = round($ufl+$v['subsidy_price']-$v['order_price'],6); }else{ - Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$ufl)->update(); + $subsidy_price_sum = round($v['subsidy_price']+$ufl,6); + 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,5); + $subsidy = round($subsidy_ufl + $ufl,6); } } // $first_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); @@ -172,8 +179,8 @@ class WechatMiNiCheckPayOrder extends Command // 数量超出前几位补贴用户 if($count > $user_start_num) { $start_subsidy = $subsidy * $user_start_subsidy / 100; - $average = round($start_subsidy / $user_start_num, 5); - $last = round($start_subsidy - $average * ($user_start_num - 1), 5); + $average = round($start_subsidy / $user_start_num, 6); + $last = round($start_subsidy - $average * ($user_start_num - 1), 6); for ($i = 0; $i < $user_start_num; $i++) { if ($i + 1 == $user_start_num) { $arr[$i] = $last; @@ -182,20 +189,20 @@ class WechatMiNiCheckPayOrder extends Command } } // 剩余人数补贴 - $end_average = round(($subsidy - $start_subsidy)/ ($count-$user_start_num), 5); - $end_last = round($subsidy - $start_subsidy - $end_average * ($count-$user_start_num - 1), 5); + $end_average = round(($subsidy - $start_subsidy)/ ($count-$user_start_num), 6); + $end_last = round($subsidy - $start_subsidy - $end_average * ($count-$user_start_num - 1), 6); for ($y = 0; $y < $count-$user_start_num; $y++) { if ($y + 1 == $count-$user_start_num) { - $arr1[$y] = $end_average; - } else { $arr1[$y] = $end_last; + } else { + $arr1[$y] = $end_average; } } }else{ $user_start_num = $count; // 数量不超出前几位补贴用户,按全部金额计算 - $average = round($subsidy/$count, 5); - $last = round($subsidy - $average * ($count - 1), 5); + $average = round($subsidy/$count, 6); + $last = round($subsidy - $average * ($count - 1), 6); for ($i = 0; $i < $count; $i++) { if ($i + 1 == $count) { $arr[$i] = $last; @@ -204,6 +211,7 @@ class WechatMiNiCheckPayOrder extends Command } } } + $billion_arr = $billion_arr_id = ""; foreach($billions_msg as $k=>$v){ if($k + 1 <= $user_start_num){ // var_dump($v['order_price']); @@ -263,14 +271,14 @@ class WechatMiNiCheckPayOrder extends Command // 剩余数量 $residue_count = $user_start_num - $k - 1; // 剩余金额 - $residue_price = round($arr[$k]+$v['subsidy_price']-$v['order_price'],5); + $residue_price = round($arr[$k]+$v['subsidy_price']-$v['order_price'],6); foreach($arr as $k1=>$v1){ if($k1 > $k){ $residue_price+=$arr[$k1]; } } - $average = round($residue_price/$residue_count,5); - $last = round($residue_price - $average*($residue_count-1),5); + $average = round($residue_price/$residue_count,6); + $last = round($residue_price - $average*($residue_count-1),6); foreach($arr as $k1=>$v1){ if($k1+1 == $user_start_num){ $arr[$k1] = $last; @@ -282,7 +290,10 @@ class WechatMiNiCheckPayOrder extends Command } }else{ - Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $arr[$k])->update(); + $subp = round($v['subsidy_price']+$arr[$k],6); + $billion_arr.=" when ".$v['billions_id']." then '".$subp."'"; + $billion_arr_id.=$v['billions_id'].","; + // Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $arr[$k])->update(); } }else{ if($v['order_price'] <= $arr1[$k - $user_start_num] + $v['subsidy_price']){ @@ -340,14 +351,14 @@ class WechatMiNiCheckPayOrder extends Command // 剩余数量 $residue_count = $count-$user_start_num - $k+$user_start_num - 1; // 剩余金额 - $residue_price = round($arr1[$k-$user_start_num]+$v['subsidy_price']-$v['order_price'],5); + $residue_price = round($arr1[$k-$user_start_num]+$v['subsidy_price']-$v['order_price'],6); foreach($arr1 as $k1=>$v1){ if($k1 > $k - $user_start_num){ $residue_price+=$arr1[$k1]; } } - $average = round($residue_price/$residue_count,5); - $last = round($residue_price - $average*($residue_count-1),5); + $average = round($residue_price/$residue_count,6); + $last = round($residue_price - $average*($residue_count-1),6); foreach($arr1 as $k1=>$v1){ if($k1+1 == $count-$user_start_num){ $arr1[$k1] = $last; @@ -358,13 +369,27 @@ class WechatMiNiCheckPayOrder extends Command } } }else{ - Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$arr1[$k-$user_start_num])->update(); + $subp = round($v['subsidy_price']+$arr1[$k-$user_start_num],6); + $billion_arr.=" when ".$v['billions_id']." then '".$subp."'"; + $billion_arr_id.=$v['billions_id'].","; + // Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$arr1[$k-$user_start_num])->update(); } } } + $billion_arr_id = explode(",",$billion_arr_id); + array_pop($billion_arr_id); + // print_r("
");
+        // var_dump($billion_arr_id);die;
+        $billion_arr_id = implode(",",$billion_arr_id);
+        $sql = "UPDATE `ls_user_billions` 
+        SET subsidy_price = CASE billions_id
+            $billion_arr
+        END
+        WHERE billions_id IN ($billion_arr_id)";
+        $query = Db::query($sql);
         if($is_d!=null){
             if($user['first_leader']>0){
-                $first_leader_percent = round($order['order_amount'] * $first_leader / 100, 5);
+                $first_leader_percent = round($order['order_amount'] * $first_leader / 100, 6);
 //                    Order::where('id', $order['id'])
 //                        ->inc('distribution_money',$first_leader_percent)->update();
                 UserDistribution::where('user_id', $user['first_leader'])
@@ -409,7 +434,7 @@ class WechatMiNiCheckPayOrder extends Command
             }
             // 3%对公司
             if($user['divide_role_user_id'] > 0&&$state>0 ){
-                $divide_percent = round($order['order_amount'] * $other_leader / 100, 5);
+                $divide_percent = round($order['order_amount'] * $other_leader / 100, 6);
 //                Order::where('id', $order['id'])
 //                    ->inc('distribution_money',$divide_percent)->update();
 //                $shopDistribution_msg =  UserShopDistribution::where('shop_id', $value['shop_id'])