From 97f28f27f3e42d2537e9fc2776636b29e084783d Mon Sep 17 00:00:00 2001 From: xucong <850806214@qq.com> Date: Thu, 10 Oct 2024 11:26:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/shop/LocalStoreLogic.php | 26 +- app/index/controller/Index.php | 378 +++++++++++++++++++++-- 2 files changed, 370 insertions(+), 34 deletions(-) diff --git a/app/admin/logic/shop/LocalStoreLogic.php b/app/admin/logic/shop/LocalStoreLogic.php index f6ff2239..9546f1d6 100755 --- a/app/admin/logic/shop/LocalStoreLogic.php +++ b/app/admin/logic/shop/LocalStoreLogic.php @@ -233,24 +233,24 @@ class LocalStoreLogic extends Logic } $user_local_msg = LocalStore::where("user_id",$user_id)->where("store_state",1)->find(); - if ($user_local_msg != null) { - if ($user_local_msg['pay_image'] != null) { - $data['pay_image'] = $user_local_msg['pay_image']; - return $data; - } else { - $url = "bundle_b/pages/local_shop/local_pay"; - $save_dir = ROOT_PATH .'/uploads/localpay/'; - $scene = 'lid='.$lstore_id; - $a = time().$scene; - $qr_src = $a . '.jpg'; - } - }else{ +// if ($user_local_msg != null) { +// if ($user_local_msg['pay_image'] != null) { +// $data['pay_image'] = $user_local_msg['pay_image']; +// return $data; +// } else { +// $url = "bundle_b/pages/local_shop/local_pay"; +// $save_dir = ROOT_PATH .'/uploads/localpay/'; +// $scene = 'lid='.$lstore_id; +// $a = time().$scene; +// $qr_src = $a . '.jpg'; +// } +// }else{ $url = "bundle_b/pages/local_shop/local_pay"; $save_dir = ROOT_PATH .'/uploads/localpay/'; $scene = 'lid='.$lstore_id; $a = time().$scene; $qr_src = $a . '.jpg'; - } +// } try { $config = WeChatServer::getMnpConfig(); $app = Factory::miniProgram($config); diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 190a67a4..1509b5ae 100755 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -20,12 +20,12 @@ namespace app\index\controller; -use app\api\logic\BillionsLogic; use app\common\basics\IndexBase; +use app\common\server\ConfigServer; +use think\facade\Db; +use app\api\logic\BillionsLogic; use app\common\server\WeChatPayServer; use app\common\server\WeChatServer; -use think\Exception; -use think\facade\Db; class Index extends IndexBase { public function index() @@ -59,12 +59,12 @@ class Index extends IndexBase $this->redirect($url); } - - public function localReturn(){ - $re = $_REQUEST; - $data['content'] = $re; - $data['dtime'] = date("Y-m-d H:i:s"); - Db::name("local_return")->save($data); + + public function localReturn(){ + $re = $_REQUEST; + $data['content'] = $re; + $data['dtime'] = date("Y-m-d H:i:s"); + // Db::name("local_return")->save($data); // if (gettype($re) == "string") { // $data['content'] = $re; // $data['dtime'] = date("Y-m-d H:i:s"); @@ -75,29 +75,365 @@ class Index extends IndexBase // Db::name("local_return")->save($data); // } } - public function billions(){ + $result = Db::name("user_billions_surplus") ->where("residue_price",">","0") - ->where("user_start_price",">","0") + // ->where("user_start_price",">","0") ->find(); + // var_dump($result);die; + $r = array(); + $i = 0; if($result != null){ - $r = Db::name("user_billions")->alias("a") - ->join("user_billions_surplus_log b","a.billions_id = b.billions_id","left") - ->where("a.billions_id","<=",$result['billions_id']) - ->where("b.surplus_id IS NULL") - ->limit(1000) + $rst = Db::name("user_billions") + ->where("billions_id","<=",$result['billions_id']) + ->where("state",0) ->select()->toArray(); - foreach($r as $key=>$value){ + // print_r("
");
+            // var_dump($rst);
+            $rst1 =  Db::name("user_billions_surplus_log")->field("user_billion_id")
+                ->where("surplus_id",$result['surplus_id'])
+                ->select()->toArray();
+            $a = array();
+            foreach($rst1 as $key=>$value){
+                $a[] = $value['user_billion_id'];
+            }
+            //  print_r("
");
+            //   var_dump($result['surplus_id']);
+            // var_dump($a);
 
-                $ranking = BillionsLogic::getRanking($value['billions_id']);
+            foreach($rst as $key=>$value){
+                $b = array_search($value['billions_id'],$a);
+                //  var_dump($b);
+                // var_dump($value['billions_id']);
+                if($b===false){
+                    $r[$i]['billions_id'] = $value['billions_id'];
+                    $r[$i]['surplus_id'] = $result['surplus_id'];
+                    $r[$i]['user_id'] = $value['user_id'];
+                    $r[$i]['order_price'] = $value['order_price'];
+                    $r[$i]['subsidy_price'] = $value['subsidy_price'];
+                    $i = $i+1;
+                    if($i == 1000){
+                        break;
+                    }
+                }
+            }
+            //   print_r("
");
+            // var_dump($r);die;
+            // foreach($rst as $key=>$value){
+            //     $rs = Db::name("user_billions_surplus_log")
+            //     ->field("surplus_id")
+            //     ->where("user_billion_id",$value['billions_id'])
+            //      ->where("surplus_id",$result['surplus_id'])
+            //     ->find();
+            //     if($rs == null){
+            //         $r[$i]['billions_id'] = $value['billions_id'];
+            //         $r[$i]['surplus_id'] = $rs['surplus_id'];
+            //         $r[$i]['user_id'] = $value['user_id'];
+            //         $r[$i]['order_price'] = $value['order_price'];
+            //         $r[$i]['subsidy_price'] = $value['subsidy_price'];
+            //         $i = $i+1;
+            //         if($i == 1000){
+            //             break;
+            //         }
+            //     }
+            // }
+            // print_r("
");
+            // var_dump($r);die;
+            // die;
+            // $r = Db::name("user_billions")->alias("a")
+            // ->field("a.billions_id,b.surplus_id,a.user_id,a.order_price,a.subsidy_price")
+            // ->join("user_billions_surplus_log b","a.billions_id = b.billions_id","left")
+            // ->where("a.billions_id","<=",$result['billions_id'])
+            // ->where("b.surplus_id IS NULL")
+            // ->where("a.state",0)
+            // ->limit(1000)
+            // ->select()->toArray();
+            if(count($r)>0){
+                foreach($r as $key=>$value){
+                    $ranking = BillionsLogic::getRanking($value['billions_id']);
+                    $data['price'] = 0;
+                    if($ranking <= $result['user_start_num']){
+                        if($result['user_start_price'] >0){
+                            if($result['user_start_avg_price'] <= $result['user_start_price']){
+                                $dec_price = $data['price'] = $result['user_start_avg_price'];
+                            }else{
+                                $dec_price = $data['price'] = $result['user_start_price'];
+                            }
+                            Db::name("user_billions_surplus")
+                                ->where("surplus_id",$result['surplus_id'])
+                                ->dec("user_start_price",$dec_price)
+                                ->update();
+                        }
+                    }else{
+                        if($result['user_price'] <= $result['residue_price']){
+                            $dec_price = $data['price'] = $result['user_price'];
+                        }else{
+                            $dec_price = $data['price'] = $result['residue_price'];
+                        }
+                        Db::name("user_billions_surplus")
+                            ->where("surplus_id",$result['surplus_id'])
+                            ->dec("residue_price",$dec_price)
+                            ->update();
+                    }
+                    $data['surplus_id'] = $result['surplus_id'];
+                    $data['user_id'] = $value['user_id'];
+                    $data['billions_id'] = $result['billions_id'];
+                    $data['user_billion_id'] = $value['billions_id'];
+                    $data['dtime'] = date("Y-m-d H:i:s");
+                    Db::name("user_billions_surplus_log")->save($data);
+                    if($value['order_price'] <= $data['price'] + $value['subsidy_price']){
+                        // 查询用户总余额账户
+                        $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$value['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",$value['user_id'])->inc("total_amount",$value['order_price'])->update();
+                            if(!$first_update_subsidy_withdrawal){
+                                return -4;
+                            }
+                            $dat['subsidy_withdrawal_id'] = $first_user_all_account['id'];
+                            $dat['user_id'] = $value['user_id'];
+                            $dat['billions_id'] = $value['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] = $value['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' => $value['user_id'],
+                                    'money' => $value['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }else{
+                            $d['user_id'] = $value['user_id'];
+                            $d['total_amount'] = $value['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'] = $value['user_id'];
+                            $dat['billions_id'] = $value['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] =  $value['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' => $value['user_id'],
+                                    'money' => $value['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }
+                        // 更新排队状态
+                        $first_update_user_billions = Db::name("user_billions")->where("billions_id",$value['billions_id'])->update(['subsidy_price'=> $value['order_price'],"state"=>2]);
+                        if(!$first_update_user_billions){
+                            return -3;
+                        }
+                    }else{
+                        $subsidy_price_sum = round($value['subsidy_price']+$data['price'],8);
+                        Db::name("user_billions")->where("billions_id",$value['billions_id'])->update(['subsidy_price'=>$subsidy_price_sum]);
+                    }
+                }
+            }else{
+                if($result['user_start_price']>0){
+                    $rets = Db::name("user_billions")->where("state",0)->limit(1)->select()->toArray();
+                    if($rets[0]['order_price'] <= $result['user_start_price'] + $rets[0]['subsidy_price']){
+                        $p = $result['user_start_price'] + $rets[0]['subsidy_price'] - $rets[0]['order_price'];
+                        Db::name("user_billions_surplus")
+                            ->where("surplus_id",$result['surplus_id'])
+                            // ->dec("user_start_price",0)
+                            ->update(['user_start_price'=>$p]);
+                        // 查询用户总余额账户
+                        $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$rets[0]['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",$rets[0]['user_id'])->inc("total_amount",$rets[0]['order_price'])->update();
+                            if(!$first_update_subsidy_withdrawal){
+                                return -4;
+                            }
+                            $dat['subsidy_withdrawal_id'] = $first_user_all_account['id'];
+                            $dat['user_id'] = $rets[0]['user_id'];
+                            $dat['billions_id'] = $rets[0]['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] = $rets[0]['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' => $rets[0]['user_id'],
+                                    'money' => $rets[0]['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }else{
+                            $d['user_id'] = $rets[0]['user_id'];
+                            $d['total_amount'] = $rets[0]['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'] = $rets[0]['user_id'];
+                            $dat['billions_id'] = $rets[0]['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] =  $rets[0]['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' => $rets[0]['user_id'],
+                                    'money' => $rets[0]['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }
+                        // 更新排队状态
+                        $first_update_user_billions = Db::name("user_billions")->where("billions_id",$rets[0]['billions_id'])->update(['subsidy_price'=> $rets[0]['order_price'],"state"=>2]);
+                        if(!$first_update_user_billions){
+                            return -3;
+                        }
+                    }else{
+                        Db::name("user_billions_surplus")
+                            ->where("surplus_id",$result['surplus_id'])
+                            ->dec("user_start_price",0)
+                            ->update();
+                        $subsidy_price_sum = round($rets[0]['subsidy_price']+$result['user_start_price'],8);
+                        Db::name("user_billions")->where("billions_id",$rets[0]['billions_id'])->update(['subsidy_price'=>$subsidy_price_sum]);
+                    }
+                }
+
+
+
+
+
+                if($result['residue_price']>0){
+                    $rets = Db::name("user_billions")->where("state",0)->limit(1)->select()->toArray();
+                    if($rets[0]['order_price'] <= $result['residue_price'] + $rets[0]['subsidy_price']){
+                        $p = $result['residue_price'] + $rets[0]['subsidy_price'] - $rets[0]['order_price'];
+                        Db::name("user_billions_surplus")
+                            ->where("surplus_id",$result['surplus_id'])
+                            // ->dec("user_start_price",0)
+                            ->update(['residue_price'=>$p]);
+                        // 查询用户总余额账户
+                        $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$rets[0]['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",$rets[0]['user_id'])->inc("total_amount",$rets[0]['order_price'])->update();
+                            if(!$first_update_subsidy_withdrawal){
+                                return -4;
+                            }
+                            $dat['subsidy_withdrawal_id'] = $first_user_all_account['id'];
+                            $dat['user_id'] = $rets[0]['user_id'];
+                            $dat['billions_id'] = $rets[0]['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] = $rets[0]['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' => $rets[0]['user_id'],
+                                    'money' => $rets[0]['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }else{
+                            $d['user_id'] = $rets[0]['user_id'];
+                            $d['total_amount'] = $rets[0]['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'] = $rets[0]['user_id'];
+                            $dat['billions_id'] = $rets[0]['billions_id'];
+                            $dat['type'] = 1;
+                            $dat['money'] =  $rets[0]['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' => $rets[0]['user_id'],
+                                    'money' => $rets[0]['order_price']
+                                );
+                                sendBillionsSubsidySMS($send);
+                            }
+
+                            if(!$first_save_record){
+                                return -5;
+                            }
+                        }
+                        // 更新排队状态
+                        $first_update_user_billions = Db::name("user_billions")->where("billions_id",$rets[0]['billions_id'])->update(['subsidy_price'=> $rets[0]['order_price'],"state"=>2]);
+                        if(!$first_update_user_billions){
+                            return -3;
+                        }
+                    }else{
+                        Db::name("user_billions_surplus")
+                            ->where("surplus_id",$result['surplus_id'])
+                            ->update(["residue_price"=>0]);
+                        $subsidy_price_sum = round($rets[0]['order_price']+$result['residue_price'],8);
+                        Db::name("user_billions")->where("billions_id",$rets[0]['billions_id'])->update(['subsidy_price'=>$subsidy_price_sum]);
+                    }
+                }
             }
 
+
+            print_r("
");
+            var_dump($r);
+            // foreach($r as $key=>$value){
+            //     var_dump($value['billions_id']);
+            //      $data['name'] = $value['billions_id'];
+            //      Db::name("user_billions_test")->save($data);
+
+            // }
+
+            //  var_dump($r);
         }
 
     }
-
-    public function retund(){
+    // 退款
+    public function retund(){die();
         $config = WeChatServer::getPayConfigBySource(1)['config'];
         if (empty($config)) {
             throw new Exception('请联系管理员设置微信相关配置!');
@@ -115,7 +451,7 @@ class Index extends IndexBase
             'total_fee' => intval(strval(650 * 100)),//订单金额,单位为分
             'refund_fee' => intval(strval(650 * 100)),//退款金额
         ]);
-var_dump($result);
+        var_dump($result);
         if (isset($result['return_code']) && $result['return_code'] == 'FAIL') {
             throw new Exception($result['return_msg']);
         }