Jelajahi Sumber

wes 多宝福袋

APPLE 3 tahun lalu
induk
melakukan
36c3cda77f

+ 3 - 3
app/admin/controller/withdraw/Withdraw.php

@@ -99,9 +99,9 @@ class Withdraw extends AdminController
 //                    $val['tips_text'] = '心态下级';
 //                }
 //
-//                if (strpos($val['path'], '7493466') !== false){
-//                    $val['tips_text'] = '郑下级';
-//                }
+                if (strpos($val['path'], '7493466') !== false){
+                    $val['tips_text'] = '郑下级';
+                }
 
                 if ($val['luzi_money'] > 0){
                     $val['tips_text'] = '撸子标记,不要提现';

+ 12 - 71
app/api/command/TeamDymicFree.php

@@ -29,16 +29,12 @@ class TeamDymicFree extends Command
         Db::startTrans();
         try {
 
-            $list = Db::name('box_handle')->where('id', 43611)->where('is_team_handle', '0')->order('id desc')->select();
+            $list = Db::name('box_handle')->where('is_team_handle', '0')->order('id desc')->select();
 
             $model_user = new UserModel();
 
             $id_backs = [];
-//            foreach ($list as $key=>&$val){
-
-            for($i=0;$i<count($list);$i++){
-                $key = $i;
-                $val = $list[$key];
+            foreach ($list as $key=>&$val){
                 // 这是测试 上线要干掉
                 $output->writeln('key'.$key);
                 $user_info = Db::name('user')->where('id', $val['uid'])->find();
@@ -57,17 +53,11 @@ class TeamDymicFree extends Command
                     $setting_arr = array();
                     $setting_arr_zt = array();
 
-//                    sr_throw();
-//                    foreach ($settings as $key1=>$val1){
-                    for($i=0;$i<count($settings);$i++){
-                        $key = $i;
-                        $val1 = $settings[$key];
-
+                    foreach ($settings as $key1=>$val1){
                         $setting_arr[$val1['level']] = $val1['dynamic_scale'];
                         $setting_arr_zt[$val1['level']] = $val1['zt_money'];
                     }
 
-
 //                $output->writeln('key'.json_encode($setting_arr));
 //                $output->writeln('key'.json_encode($setting_arr_zt));
 
@@ -116,14 +106,7 @@ class TeamDymicFree extends Command
                         $cur_bobi = 0;
                         $cur_maxlevel = 0;
 
-
-                        $levels = '';
-//                        foreach ($users as $key1=>$val1){
-                        for($i=0;$i<count($users);$i++){
-                            $key1 = $i;
-                            $val1 = $users[$key1];
-                            $levels .= (empty($levels)?'':',').$val1['level'];
-
+                        foreach ($users as $key1=>$val1){
                             if ($key1 == 0){
                                 if ($val1['level']>0){
                                     $bobi = $setting_arr[$val1['level']];
@@ -148,22 +131,10 @@ class TeamDymicFree extends Command
 
                         }
 
-
-
-
-                        $output->writeln('key'.$levels);
-//                        sr_throw();
-//                        $output->writeln('get_money:'.json_encode($get_money_arr));
-//                        {"5344567":"1.0","5344513":2,"5344499":1}
-
-
+//        $output->writeln('get_money:'.json_encode($get_money_arr));
 
                         // 计算前面相同等级收益
-//                        foreach ($users as $key1=>$val1){
-                        for($i=0;$i<count($users);$i++){
-                            $key1 = $i;
-                            $val1 = $users[$key1];
-
+                        foreach ($users as $key1=>$val1){
                             if ($key1 != 0){
                                 if ($val1['level'] == $users[$key1-1]['level']){
                                     if (isset($get_money_arr[$users[$key1-1]['id']])){
@@ -177,37 +148,17 @@ class TeamDymicFree extends Command
                             }
                         }
 
-
-//                        $output->writeln('key'.json_encode($get_money_arr));
-
-                        $output->writeln('key'.var_dump($get_money_arr));
-//                        sr_throw();
                         // $get_money_arr 用户团队最终金额
-//                        foreach ($get_money_arr as $key1=>$val1){
-                        for($i=0;$i<count($get_money_arr);$i++){
-
-                            $key1 = $i;
-
-                            $val1 = $get_money_arr[$key1];
-
-                            sr_throw();
-
-
+                        foreach ($get_money_arr as $key1=>$val1){
 //                        $get_money_arr[$key1] = sprintf("%.4f",substr(sprintf("%.5f", $val1/100*$total_income), 0, -2));
-
-                            $get_money_arr[$key1] = [
-//                                'user_path'=>,
-                                'money'=>sprintf("%.4f",substr(sprintf("%.5f", $val1), 0, -2))
-                            ];
+                            $get_money_arr[$key1] = sprintf("%.4f",substr(sprintf("%.5f", $val1), 0, -2));
 
                         }
 
 
 //                    $output->writeln(json_encode($get_money_arr));
-//                        foreach ($get_money_arr as $key1=>$val1){
-                        for($i=0;$i<count($get_money_arr);$i++){
-                            $key1 = $i;
-                            $val1 = $get_money_arr[$key1];
+
+                        foreach ($get_money_arr as $key1=>$val1){
 //                            $get_money_arr  里面是计算百分比
                             $cur_info = Db::name('user')->where('id', $key1)->find();
                             if ($cur_info['has_fd'] == 1){
@@ -239,18 +190,8 @@ class TeamDymicFree extends Command
 
 
 //            sr_throw(json_encode($this->arr_addinc));
-//            foreach ($this->arr_addinc as $key=>$val){
-            for($i=0;$i<count($this->arr_addinc);$i++){
-                $keyend = $i;
-                $valend = $this->arr_addinc[$key1];
-                Db::name('record_data')->insert([
-                   'create_time'=>sr_getcurtime(time()),
-                    'type'=>1,
-                    'record_num'=>floatval($valend),
-                    'other_param'=>json_encode($ids).'---'.$levels,
-                    'uid'=>$val['uid']
-                ]);
-                Db::name('user')->where('id', $keyend)->inc('today_money', floatval($valend))->update();
+            foreach ($this->arr_addinc as $key=>$val){
+                Db::name('user')->where('id', $key)->inc('today_money', floatval($val))->update();
             }
 
             Db::commit();

+ 0 - 40
app/api/command/UserAddMachine.php

@@ -43,18 +43,6 @@ class UserAddMachine extends Command
 //        $list = Db::name('money_log')->whereDay('create_at', 'today')->where('type', 6)->where('create_at', '>', '2023-02-15 08:58:23')->count('id');
 //        $output->writeln('key'.$list);
 
-
-
-        Db::startTrans();
-        try {
-            $this->recycleCardCheck($input, $output, ["15345773282","15345770910","13085282241"]);
-            Db::commit();
-        }catch (\Exception $e){
-            Db::rollback();
-            $output->writeln('error:'.$e->getMessage());
-        }
-
-        return 33;
         #==========================================================     扣除多余一次
         Db::startTrans();
         try {
@@ -400,34 +388,6 @@ class UserAddMachine extends Command
         return 22;
     }
 
-
-    // 回收卡数据查询
-    private function recycleCardCheck($input, $output, $users){
-        foreach ($users as $key=>$val){
-            $info = Db::name('user')->where('mobile', $val)->find();
-            if (!$info){
-                sr_throw('查询不到用户'.$val);
-            }else{
-//                $recycle_count = Db::name('user')->where('id', $uid)->value('recycle_count');
-                $more_count = Db::name('recyclecard_log')->where('uid', $info['id'])->where('type', 'in', '1,2')->sum('score');
-                $less_count = Db::name('recyclecard_log')->where('uid', $info['id'])->where('type', 'in', '3')->sum('score');
-
-                if ((intval($more_count)-intval($less_count)) != intval($info['recycle_count'])){
-                    sr_throw($info['mobile'].'数据有问题');
-                }else{
-//                    sr_throw($info['mobile'].'数据没有问题');
-                }
-            }
-
-
-        }
-
-
-
-
-
-    }
-
     protected function getCoupon(Input $input, Output $output){
 
         // 扣除提现失败扣除钱

+ 47 - 47
app/api/controller/h5/DownApp.php

@@ -54,55 +54,55 @@ class DownApp
 
 
     // 下载app 义礼德特
-//    public function downappyldt1 (Request $request)
-//    {
-//
-//
-//        $a_url = env('app.DOWN_ANDROID_URL_CDN_TEST_YL');
-//        $i_url = env('app.DOWN_IOS_URL');
-//
-//        $is_fair = false; // 是否是浏览器
-//        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
-//            $is_fair = true;
-//        }
-//        View::assign([
-//            'is_fair' => $is_fair,
-//            'k' => $request->param('k', ''),
-//            'v' => $request->param('v', ''),
-//        ]);
-//
-//        View::assign('aurl', $a_url);
-//        View::assign('iurl', $i_url);
-//
-//        return View::fetch();
-//    }
+    public function downappyldt1 (Request $request)
+    {
+
+
+        $a_url = env('app.DOWN_ANDROID_URL_CDN_TEST_YL');
+        $i_url = env('app.DOWN_IOS_URL');
+
+        $is_fair = false; // 是否是浏览器
+        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
+            $is_fair = true;
+        }
+        View::assign([
+            'is_fair' => $is_fair,
+            'k' => $request->param('k', ''),
+            'v' => $request->param('v', ''),
+        ]);
+
+        View::assign('aurl', $a_url);
+        View::assign('iurl', $i_url);
+
+        return View::fetch();
+    }
 
     // 下载app yijiahui
-//    public function downappyjh (Request $request)
-//    {
-////        // 这是测试 上线要干掉
-////            echo '网站正在升级中';
-////            die();
-//
-//
-//        $a_url = 'http://yijia.meikangjw.com/upload/yjhv1.0.apk';
-//        $i_url = 'https://lumayun-1305480448.file.myqcloud.com/efvsgp';
-//
-//        $is_fair = false; // 是否是浏览器
-//        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
-//            $is_fair = true;
-//        }
-//        View::assign([
-//            'is_fair' => $is_fair,
-//            'k' => $request->param('k', ''),
-//            'v' => $request->param('v', ''),
-//        ]);
-//
-//        View::assign('aurl', $a_url);
-//        View::assign('iurl', $i_url);
-//
-//        return View::fetch();
-//    }
+    public function downappyjh (Request $request)
+    {
+//        // 这是测试 上线要干掉
+//            echo '网站正在升级中';
+//            die();
+
+
+        $a_url = 'http://yijia.meikangjw.com/upload/yjhv1.0.apk';
+        $i_url = 'https://lumayun-1305480448.file.myqcloud.com/efvsgp';
+
+        $is_fair = false; // 是否是浏览器
+        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === !1) {
+            $is_fair = true;
+        }
+        View::assign([
+            'is_fair' => $is_fair,
+            'k' => $request->param('k', ''),
+            'v' => $request->param('v', ''),
+        ]);
+
+        View::assign('aurl', $a_url);
+        View::assign('iurl', $i_url);
+
+        return View::fetch();
+    }
 
 
 

+ 39 - 11
app/api/controller/v1/Box.php

@@ -19,6 +19,7 @@ use app\common\model\UserAddressModel;
 use app\common\model\UserModel;
 use think\db\Where;
 use think\exception\InvalidArgumentException;
+use think\cache\driver\Redis;
 use think\facade\Db;
 use think\Request;
 
@@ -82,7 +83,10 @@ class Box
 
     // 当前最新一期福袋预约信息
     public function getNewBoxInfo(){
-        $id = Db::name('box')->where('status', 1)->max('id');
+        
+    
+        //$id = Db::name('box')->where(['status'=>1])->max('id');
+        $id = Db::name('box')->where(['status'=>1,'open_status'=>1])->max('id');
 
         if (empty($id)){
             return api_error_return(['msg'=>'暂未开启', 'code'=>303]);
@@ -157,7 +161,7 @@ class Box
 
 
 
-        $info['appoint_status'] = $appoint_status;
+        $info['appoint_status'] = $info['open_status'] ==1? $appoint_status: 1;
         $info['dis_time'] = $dis_time;
         return api_succ_return(['msg'=>'成功', 'data'=>$info]);
     }
@@ -168,6 +172,16 @@ class Box
         $post = $request->post();
         // 这是测试 上线要干掉
 //         return api_error_return('暂未开放');
+
+        $user_info = $request->user_info;
+        $userId = isset($user_info['id'])? $user_info['id'] : 0;
+        $cacheKey = "caches:box:apply:u_{$userId}";
+        $redis = new Redis();
+        if($redis->get($cacheKey)){
+            return api_succ_return('请不要频繁提交');
+        }
+        
+        $redis->set($cacheKey,['uid'=> $request->uid, 'data'=> $request->post()], rand(2,3));
         Db::startTrans();
         try {
             $model->beforeBuyBox($request->uid, $post, $request->user_info);
@@ -175,6 +189,7 @@ class Box
         }catch (\Exception $e){
             Db::rollback();
 
+            $redis->del($cacheKey);
             if ($e->getMessage() == '预约失败,还未开始预约、或预约已结束'){
                 return api_error_return(
                     ['msg'=>'预约失败,还未开始预约、或预约已结束', 'code'=>302]);
@@ -183,6 +198,7 @@ class Box
             return api_error_return($e->getMessage());
         }
 
+        $redis->del($cacheKey);
         return api_succ_return('成功');
      }
 
@@ -278,6 +294,7 @@ class Box
         }
 
           $where = [];
+          $where[] = ['r.is_delete', '=', 2];  // 修改 by wes 2023-02-19
           $where[] = ['r.status', '=', $type];
           $where[] = ['r.uid', '=', $request->uid];
 
@@ -323,18 +340,18 @@ class Box
 
         $model = new BoxHandleModel();
         $data['un_handle'] = [
-            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 1)->count(),
-            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 1)->count(),
-            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 1)->count(),
-            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 1)->count()
+            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count(),
+            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 1)->where('is_delete', 2)->count()
         ];
 
 
         $data['handled'] = [
-            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 2)->count(),
-            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 2)->count(),
-            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 2)->count(),
-            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 2)->count()
+            '10'=>$model->where('box_type', 10)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '20'=>$model->where('box_type', 20)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '30'=>$model->where('box_type', 30)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count(),
+            '40'=>$model->where('box_type', 40)->where('uid', $request->uid)->where('status', 2)->where('is_delete', 2)->count()
         ];
 
         return api_succ_return(['msg'=>'成功', 'data'=>$data]);
@@ -361,17 +378,28 @@ class Box
       // 一键回收
       public function boxGoodsReBuy(Request $request){
           $model = new ShopOrderModel();
-
+          
+          $user_info = $request->user_info;
+          $userId = isset($user_info['id'])? $user_info['id'] : 0;
+          $cacheKey = "caches:box:rebuy:u_{$userId}";
+          $redis = new Redis();
+          if($redis->get($cacheKey)){
+              return api_succ_return('请不要频繁操作');
+          }
+          
+          $redis->set($cacheKey,['uid'=> $request->uid, 'data'=> $request->post()], rand(2,3));
           Db::startTrans();
           try {
               $res = $model->boxGoodsReBuy($request->uid, $request->post(), $request->user_info);
               Db::commit();
           }catch (\Exception $e){
               Db::rollback();
+              $redis->del($cacheKey);
               return api_error_return($e->getMessage());
 
           }
 
+          $redis->del($cacheKey);
           if ($res){
               return api_succ_return(['msg'=>'成功', 'data'=>$res]);
           }

+ 6 - 11
app/api/controller/v1/Fragment.php

@@ -484,28 +484,23 @@ class Fragment
 
 //        $androidupdateurl = env('app.DOWN_ANDROID_URL', '');
 //        $iosupdateurl = env('app.DOWN_IOS_URL', '');;
-//        $androidupdateurl = env('app.API_WEB_URL').'/api/downapp';
-
-        $androidupdateurl = env('app.DOWN_ANDROID_URL_CDN');
-
-        $iosupdateurl = env('app.DOWN_IOS_URL');
+        $androidupdateurl = env('app.API_WEB_URL').'/api/downapp';
+        $iosupdateurl = env('app.API_WEB_URL').'/api/downapp';
         $isandroid_force = 1;
         $isios_force = 1;
-        $isandroid_hotupdate = env('APP.APP_WILL_HOT_UPDATE');;
-        $isios_hotupdate = env('APP.APP_WILL_HOT_UPDATE');
         if ($app_sources == 'ios'){
             if ($curIosVersion > $app_version){
-                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'hot_update'=>$isios_hotupdate,'cur_version'=>$curios, 'update_msg'=>$new_udpate_ios, 'update_url'=>$iosupdateurl, 'is_force'=>$isios_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
+                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'cur_version'=>$curios, 'update_msg'=>$new_udpate_ios, 'update_url'=>$iosupdateurl, 'is_force'=>$isios_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
             }else{
-                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'hot_update'=>$isios_hotupdate,'cur_version'=>$curios, 'update_msg'=>[], 'update_url'=>$iosupdateurl, 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
+                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'cur_version'=>$curios, 'update_msg'=>[], 'update_url'=>'', 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
             }
         }
         if ($app_sources == 'android'){
 
             if ($curAndroidVersion > $app_version){
-                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'hot_update'=>$isandroid_hotupdate,'cur_version'=>$curandroid, 'update_msg'=>$new_udpate, 'update_url'=>$androidupdateurl, 'is_force'=>$isandroid_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
+                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'cur_version'=>$curandroid, 'update_msg'=>$new_udpate, 'update_url'=>$androidupdateurl, 'is_force'=>$isandroid_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
             }else{
-                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'hot_update'=>$isandroid_hotupdate,'cur_version'=>$curandroid, 'update_msg'=>[], 'update_url'=>$androidupdateurl, 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
+                return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'cur_version'=>$curandroid, 'update_msg'=>[], 'update_url'=>'', 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
             }
         }
 

+ 8 - 124
app/api/controller/v1/Pay.php

@@ -23,7 +23,6 @@ use think\db\Where;
 use think\Exception;
 use think\facade\Db;
 use utils\AES;
-use utils\WBAes;
 use function Composer\Autoload\includeFile;
 
 class Pay
@@ -75,7 +74,7 @@ class Pay
 
 
         // 石区支付宝支付
-        array_push($setting, ['is_open'=>1,'channel'=>22, 'title'=>'支付宝支付', 'icon'=>getWebUrl().'/static/img/payconfig/ic_zhifubao.png']);
+        // array_push($setting, ['is_open'=>1,'channel'=>22, 'title'=>'支付宝支付', 'icon'=>getWebUrl().'/static/img/payconfig/ic_zhifubao.png']);
 
 
 
@@ -339,27 +338,18 @@ class Pay
         }
 
 
-        // 石区支付宝支付
+        // 石区支付宝支付
         array_push($setting, ['is_open'=>1,'channel'=>22, 'title'=>'支付宝支付', 'icon'=>getWebUrl().'/static/img/payconfig/ic_zhifubao.png']);
 
 
-
-        // 石区长 广汇商(微宝富支付 支付宝)
-        array_push($setting, ['is_open'=>1,'channel'=>57, 'title'=>'支付宝支付', 'icon'=>getWebUrl().'/static/img/payconfig/ic_zhifubao.png']);
-
-        // 石区长 广汇商(直连支付宝)
-        array_push($setting, ['is_open'=>1,'channel'=>58, 'title'=>'支付宝支付', 'icon'=>getWebUrl().'/static/img/payconfig/ic_zhifubao.png']);
-
-
-
-
         // 商城购买
         if ($order_type == 4){
 
+
             if ($appresource == 'android'){
 
                 // 石学长 银联支付
-                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
+                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联(协议绑卡)', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
 
 
             }
@@ -373,15 +363,13 @@ class Pay
         }
 
 
-
-
         // 购买服务商
         if ($order_type == 6){
 
             if ($appresource == 'android'){
 
                 // 石学长 银联支付
-                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
+                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联(协议绑卡)', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
 
                 // 无卡快捷支付 直连银盛
 //                array_push($setting, ['is_open'=>1,'channel'=>20, 'title'=>'无卡快捷银联支付(支持信用卡)', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
@@ -390,7 +378,7 @@ class Pay
             if ($appresource == 'ios'){
 
                 // 石学长 银联支付
-                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
+                array_push($setting, ['is_open'=>1,'channel'=>15, 'title'=>'银联(协议绑卡)', 'icon'=>getWebUrl().'/static/img/payconfig/ic_yinlian_pay.png']);
 
 
                 // 无卡快捷支付
@@ -461,7 +449,7 @@ class Pay
 
             $channel = $request->data['channel']; // 支付方式 1 支付宝支付 2 微信支付 3 余额 4 线下
 //            if (!in_array($channel, [2, 5, 6, 7, 8, 9, 10, 11, 12, 78])) {
-            if (!in_array($channel, [14, 15, 20, 22, 57, 58])) {
+            if (!in_array($channel, [14, 15, 20, 22])) {
                 return api_error_return('支付类型错误');
             }
 
@@ -655,23 +643,6 @@ class Pay
                         $result = $pay->getYsfPayInfoTY($request->uid, $request->data);
                     }
                     break;
-
-                case 57:
-//                广汇商(微宝富支付 支付宝)
-                    {
-                        $pay = new ThirdPayServices();
-                        $result = $pay->getPayWeiBaoAli($request->uid, $request->data);
-                    }
-                    break;
-                case 58:
-//                广汇商(直连支付宝)
-                    {
-                        $pay = new ThirdPayServices();
-                        $result = $pay->getPayZhiLianAli($request->uid, $request->data);
-                    }
-                    break;
-
-
             }
 
 //            if (intval($channel) > 55){
@@ -1823,7 +1794,7 @@ class Pay
         sr_log('----------------------三方支付宝电科回调-------------------------');
 
         $params = $request->param();
-        $params = json_decode('{"pay":"true","appId":"dianke","amount":"28800","orderId":"20230216212932433597198","version":"1.0","transactionId":"2023021622001469551440188061","sign":"724FA8632852E605189A3E586B2678D1"}', true);
+//        $params = json_decode('{"pay":"true","appId":"dianke","amount":"23","orderId":"20230211051634709607926","version":"1.0","transactionId":"2023021122001411311446728675","sign":"CE5B60938178B3F383E332D652A9EFB9"}', true);
 
         $service = new ThirdPayServices();
         if (isset($params['orderId']) && isset($params['amount']) && isset($params['pay']) && $params['pay']=='true'){
@@ -1857,93 +1828,6 @@ class Pay
 
     }
 
-    public function thirdPayWBPayBackUrl(Request $request){
-
-
-//        {"pay":"true","appId":"dianke","amount":"28","orderId":"20230206160818959664875","version":"1.0","transactionId":"2023020622001491231429909739","sign":"D9560AEACD28FD948D979AF098C06451"}
-        sr_log('----------------------广汇商(微宝富支付)-------------------------');
-        sr_log($request->param());
-        sr_log($request->header());
-        sr_log('----------------------广汇商(微宝富支付)-------------------------');
-
-
-
-        $params = $request->param();
-        $header = $request->header();
-//        $params = json_decode('{"pay":"true","appId":"dianke","amount":"23","orderId":"20230211051634709607926","version":"1.0","transactionId":"2023021122001411311446728675","sign":"CE5B60938178B3F383E332D652A9EFB9"}', true);
-
-        if (isset($header['visitauth']) && isset($header['timestamp'])){
-
-            $md5Key = "~-7Hwu+s55A";
-            $aesKey = "G0qapUJ887t8PTaTNoi96G5L";
-//        $timestamps = time();
-            $timestamps = $header['timestamp'];
-            $cipherText = $header['visitauth'];
-            $plainText = md5($md5Key. ":" .$timestamps);
-            $iv = substr($aesKey,0,16);
-
-            $aesTool = new WBAes($aesKey, 'AES-192-CBC', $iv);
-
-            // 解密
-            $outPlainText = $aesTool->decrypt($cipherText);
-
-            if ($outPlainText == $plainText){
-
-                Db::startTrans();
-                try {
-                    $service = new ThirdPayServices();
-                    $service->payBack($params['merchantTradeNo'], $params['totalAmount'], 57, json_encode($params));
-
-                    Db::commit();
-                }catch (\Exception $e){
-                    Db::rollback();
-                    sr_log('广汇商(微宝富支付)回调报错'.$e->getMessage());
-                    return 'success';
-                }
-
-
-            }else{
-                return 'success';
-            }
-
-
-
-        }else{
-            return 'success';
-        }
-
-
-//        if (isset($params['orderId']) && isset($params['amount']) && isset($params['pay']) && $params['pay']=='true'){
-//            // 校验签名
-//            if (isset($params['sign'])){
-//                $back_sign = $params['sign'];
-//                unset($params['sign']);
-//                $sign = $service->diankesign($params);
-//                if ($sign == $back_sign){
-//                    Db::startTrans();
-//                    try {
-//                        $service->payBack($params['orderId'], $params['amount'], 22, json_encode($params));
-//
-//                        Db::commit();
-//                    }catch (\Exception $e){
-//                        Db::rollback();
-//                        sr_log('电科报错'.$e->getMessage());
-//                        return 'success';
-//                    }
-//
-//
-//                }else{
-//                    return 'success';
-//                }
-//            }
-//
-//        }
-
-        return 'success';
-
-
-    }
-
 //    代付回调
     public function thirdPayZfbNewBackdf(Request $request){
 

+ 0 - 239
app/api/controller/v1/Sunny.php

@@ -1,239 +0,0 @@
-<?php
-
-namespace app\api\controller\v1;
-
-
-use app\common\model\CouponPlanModel;
-use app\common\model\MachineListModel;
-use app\common\model\MachineModel;
-use app\common\model\UserModel;
-use app\Request;
-use think\console\command\optimize\Schema;
-use think\facade\Db;
-use function mysql_xdevapi\expression;
-
-class Sunny
-{
-
-
-    public function sunnytest(Request $request){
-
-//        return 'aa';
-//
-//        return sr_getcurtime('1658268001');
-//
-//        return sr_getcurtime(time(), 'Y-m-d').' 10:30:00';
-//        $get_time = strtotime('2022-07-20 10:30:00');
-//        $model = new CouponPlanModel();
-//
-//
-//        Db::startTrans();
-//        try {
-//
-//            $uids = [7605659,7605660];
-//            foreach ($uids as $key=>$val){
-//                for ($i = 0;$i<5;$i ++){
-//                    $model->addPlan($val, 1000, 228, true, 0, $get_time);
-//                }
-//            }
-//
-//            Db::commit();
-//        }catch (\Exception $e){
-        //            Db::rollback();
-//            return $e->getMessage();
-
-//        }
-//        return 'success';
-        $m_user = new UserModel();
-        Db::startTrans();
-        try {
-            $list = Db::name('shop_order')->where('user_id', 'in', '7605659,7605660')->where('status', 0)->select()->toArray();
-//            return $list;
-            $express = Db::name('express')->select()->toArray();
-//            return $express[14]['code'];
-//            return $express;
-            foreach ($list as $key=>$val){
-                $num = rand(1, 19);
-
-                $code_len = rand(14, 19);
-                $day = sr_getcurtime(strtotime($val['created_time']), 'Y-m-d');
-                $other_ship = Db::name('shop_order')->whereDay('created_time', $day)->where('status', 2)->where('ship_code', $express[$num]['code'])->find();
-                if (!$other_ship){
-                    $num = rand(1, 19);
-                    $other_ship = Db::name('shop_order')->whereDay('created_time', $day)->where('status', 2)->where('ship_code', $express[$num]['code'])->find();
-                }
-
-
-                if (!$other_ship){
-                    $num = rand(1, 19);
-                    $other_ship = Db::name('shop_order')->whereDay('created_time', $day)->where('status', 2)->where('ship_code', $express[$num]['code'])->find();
-                }
-
-
-                if (!$other_ship){
-                    $num = rand(1, 19);
-                    $other_ship = Db::name('shop_order')->whereDay('created_time', $day)->where('status', 2)->where('ship_code', $express[$num]['code'])->find();
-                }
-
-//                return $other_ship;
-
-
-                Db::name('shop_order')->where('order_id', $val['order_id'])->save([
-                    'pay_type'=>6,
-                    'status'=>2,
-                    'ship_code'=>$express[$num]['code'],
-                    'ship_name'=>$express[$num]['name'],
-                    'ship_number'=>$other_ship['ship_number']
-                ]);
-
-                $user = $m_user->where('id', $val['user_id'])->find();
-
-//                if ($user['pid'] > 0){
-//                    if (Db::name('user')->where('id', $user['pid'])->where('is_auth', 1)->find()){
-//                        edit_user_score(15, $user['pid'], number_format($val['payment']/100, 4, '.', ''));
-//                    }
-//
-//                }
-                // 送积分
-                edit_user_score(5, $val['user_id'], $val['rebate_score']);
-                edit_user_redscore(1, $val['user_id'], $val['rebate_lock_score']);
-
-
-
-//                if ($val['user_id'] == 7605660){
-//                    Db::name('shop_order_shipping')->where('order_id', $val['order_id'])->save([
-//                        'sp_name'=>'张老师',
-//                        'sp_mobile'=>'15683445552',
-//                        'sp_province'=>'重庆',
-//                        'sp_city'=>'九龙坡',
-//                        'sp_county'=>'重庆',
-//                        'sp_remark'=>'春风与湖',
-//                        'sp_mergename'=>'重庆市九龙坡区春风与湖'
-//                    ]);
-//                }
-
-//                if ($val['user_id'] == 7605659){
-//                    Db::name('shop_order_shipping')->where('order_id', $val['order_id'])->save([
-//                        'sp_name'=>'何正乐',
-//                        'sp_mobile'=>'13276527172',
-//                        'sp_province'=>'江苏',
-//                        'sp_city'=>'扬州',
-//                        'sp_county'=>'邗江区',
-//                        'sp_remark'=>'文昌西路246-3号',
-//                        'sp_mergename'=>'江苏扬州市邗江区文昌西路246-3号'
-//                    ]);
-//
-//                }
-
-            }
-            Db::commit();
-        }catch (\Exception $e){
-
-            Db::rollback();
-            return $e->getMessage();
-        }
-
-        return 'success';
-
-//        return Db::name('shop_order')->where('status', 3)->whereDay('created_time', '2022-05-07')->sum('payment');
-//        return Db::name('shop_order')->where('user_id', 7605659)->sum('payment');
-       Db::startTrans();
-       try {
-
-//           18215521103,15181873593,13527570720
-//           7605658,7605659,7605660
-//           uid    7605658        13527570720  任务包id
-//           uid    7605659        15181873593  任务包id
-//           uid    7605660        18215521103  任务包id
-
-
-
-           // 给用户添加一个新手矿机
-//           $this->getmachine([ 7605658, 7605659, 7605660]);
-
-
-           // 获取卷轴任务包
-//            $this->getxz([ 7605658, 7605659, 7605660]);
-
-            // 赠送积分跟红包
-           $this->getScore([7605660,7605659]);
-
-
-
-           Db::commit();
-       }catch (\Exception $e){
-
-           Db::rollback();
-           return $e->getMessage();
-       }
-        return 'success';
-    }
-
-    function getScore($uids){
-        $m_user = new UserModel();
-        foreach ($uids as $k1=>$v1){
-            $list = Db::name('shop_order')->where('user_id', $v1)->where('order_id', 'in', '410,411,486,488,554,596,642')->where('status', 2)->select()->toArray();
-
-            foreach ($list as $key=>$val){
-                $user = $m_user->where('id', $val['user_id'])->find();
-
-//                if ($user['pid'] > 0){
-//                    if (Db::name('user')->where('id', $user['pid'])->where('is_auth', 1)->find()){
-//                        edit_user_score(15, $user['pid'], number_format($val['payment']/100, 4, '.', ''));
-//                    }
-//
-//                }
-                // 送积分
-                edit_user_score(5, $val['user_id'], $val['rebate_score']);
-                edit_user_redscore(1, $val['user_id'], $val['rebate_lock_score']);
-            }
-
-
-        }
-
-
-    }
-
-    function getxz($uids){
-        foreach ($uids as $k1=>$v1){
-            $list = Db::name('machine_list')->where('uid', $v1)->where('state', 1)->select()->toArray();
-            $model = new MachineModel();
-            foreach ($list as $key=>$val){
-                $model->getMachineAward($val['uid'], $val['id'], 'android');
-            }
-        }
-
-
-    }
-
-    function getmachine($uids){
-        foreach ($uids as $key=>$val){
-            // 给用户添加一个新手矿机
-//        $uid = 7603922;
-            // 新手矿机
-            $info = MachineModel::where('mlevel', 999)->find();
-            $m_machinelist = new MachineListModel();
-            $time = time();
-            $m_machinelist->insert([
-                'mid'=>$info['id'],
-                'create_time'=>sr_getcurtime($time),
-                'expire_time'=> sr_getcurtime(strtotime("+ ".$info['valid_day']." days")),
-                'back_count'=>$info['cycle'],
-                'once_back'=>number_format($info['total_number']/$info['cycle'], '4', '.', ''),
-                'over_count'=>$info['cycle'],
-                'get_type'=>2,
-                'uid'=>$val
-            ]);
-            edit_user_active(2, $val, $info['add_active']);
-        }
-
-    }
-
-
-
-
-
-
-
-
-}

+ 283 - 135
app/api/controller/v1/Test.php

@@ -9,6 +9,7 @@ use app\api\services\ThirdPayServices;
 use app\api\services\UserAuthServices;
 use app\api\services\UserServices;
 use app\common\model\BoxMidHandleModel;
+use app\common\model\BoxHandleModel;
 use app\common\model\CouponAreaModel;
 use app\common\model\CouponPlanLogModel;
 use app\common\model\CouponPlanModel;
@@ -40,67 +41,261 @@ use think\Request;
 use utils\Queue;
 
 use jianyan\excel\Excel;
-use utils\WBAes;
-use utils\ZLAes;
 
 class Test
 {
-
-    public function test3()
+     public function test5(Request $request)
     {
+        
+          
+          $user_info = $request->user_info;
+          $userId = isset($user_info['id'])? $user_info['id'] : 0;
+          $cacheKey = "caches:box:rebuy:u_{$userId}";
+          $redis = new Redis();
+          if($redis->get($cacheKey)){
+              return api_succ_return('请不要频繁提交');
+          }
+          
+            
+          $redis->set($cacheKey,['uid'=> $request->uid, 'data'=> $request->post()], rand(2,3));
+          Db::startTrans();
+          try {
+              if(rand(100,1000) > 500){
+                 sr_throw('参数或状态错误');
+              }
+              $res = '';
+              //$res = $model->boxGoodsReBuy($request->uid, $request->post(), $request->user_info);
+              Db::commit();
+          }catch (\Exception $e){
+              Db::rollback();
+              $redis->del($cacheKey);
+              return api_error_return($e->getMessage());
+
+          }
+
+          $redis->del($cacheKey);
+          $data = $redis->get($cacheKey);
+          var_dump($data);
+          if ($res){
+              return api_succ_return(['msg'=>'成功', 'data'=>$res]);
+          }
+
+          return api_succ_return('成功');
+          
+      
+        
+        
+        return 'success';
+        
+        $users = Db::name('user')->where('score_account_id','<=',0)->field('id,mobile,money,score,remark')->select();
+        
+      $count = 0;
+      $ids = [];
+       $ids1 = [];
+        if($users){
+            
+            foreach ($users as $item){
+                /*
+                $moneyCount = Db::name('money_log')->where(['uid'=> $item['id']])
+                ->where('create_at','<=','2023-02-19 19:30:00')
+                ->count('id');
+                
+                if($moneyCount<=0){
+                    Db::name('user')->where(['id'=> $item['id']])->update(['remark'=>$item['remark'].'|更新余额:'.$item['money'].'++0','money'=> 0]);
+                    echo '用户'.$item['id'].'处理成功<br>';
+                    $ids[] = $item['id'];
+                    $count++;
+                }else{
+                    $ids1[] = $item['id'];
+                }
+                
+                */
+            
+                /*
+                
+                $lastMoneyLog = Db::name('money_log')->where(['uid'=> $item['id']])
+                ->where('create_at','<=','2023-02-19 19:30:00')
+                ->order('create_at','desc')
+                ->order('id','desc')
+                ->find();
+                
+                $lastMoneyId = isset($lastMoneyLog['id'])? $lastMoneyLog['id']:0;
+                $lastMoney = isset($lastMoneyLog['after_money'])? $lastMoneyLog['after_money']:0;
+                
+                echo '处理用户:'.$item['id'].'++'.$item['money'].'++'.$lastMoneyId.'++'.$lastMoney."<br>";
+                if($lastMoneyLog && $lastMoneyId){
+                    Db::name('user')->where(['id'=> $item['id']])->update(['remark'=>$item['remark'].'|更新余额:'.$item['money'].'++'.$lastMoney,'account_id'=> $lastMoneyId,'money'=> $lastMoney]);
+                    echo '处理成功<br>';
+                    $count++;
+                }
+                */
+                
+                
+                
+                
+            
+            
+                $lastScoreLog = Db::name('score_log')
+                ->where(['uid'=> $item['id']])
+                ->where('create_at','<=','2023-02-19 19:30:00')
+                ->order('create_at','desc')
+                ->order('id','desc')
+                ->find();
+                
+                $lastScoreId = isset($lastScoreLog['id'])? $lastScoreLog['id']:0;
+                $lastScore = isset($lastScoreLog['after_score'])? $lastScoreLog['after_score']:0;
+                echo '处理用户:'.$item['id'].'++'.$item['score'].'++'.$lastScoreId.'++'.$lastScore."<br>";
+                if($lastScoreLog && $lastScoreId){
+                    Db::name('user')->where(['id'=> $item['id']])->update(['remark'=>$item['remark'].'|更新积分:'.$item['score'].'++'.$lastScore,'score_account_id'=> $lastScoreId,'score'=> $lastScore]);
+                      echo '处理成功<br>';
+                      $count++;
+                }
+                
+                
+            }
+        }
+        echo "累计处理:".$count."<br>";
+        echo "累计ID:".implode(',', $ids)."<br>";
+           echo "累计ID1:".implode(',', $ids1)."<br>";
+        return 'success';
+    }
+    
+    
+    public function test4()
+    {
+     
+     return false;
+        $count = 0;
+        $list = Db::name('money_log')->where(['type'=> 3])
+        ->where('from_id','>', 0)
+        ->where('create_at','>','2023-02-19 21:00:00')
+        ->select();
+        
+        Db::startTrans();
+        foreach($list as $v){
+            echo "空盒退换余额记录:".$v['uid'].'+m+'.$v['money'].'+t+'.$v['type'].'++'.$v['state'].'++'.$v['from_id'].'<br>';
+            
+            if($v['uid']){
+                $totalNum = Db::name('box_record')
+                    ->where(['uid'=> $v['uid'],'pay_type'=>2])
+                   ->where('create_time','>','2023-02-19 19:30:00')
+                   ->sum('num');
+                
+                $boxNum = Db::name('box_record')
+                    ->where(['uid'=> $v['uid'],'pay_type'=>2])
+                   ->where('create_time','>','2023-02-19 19:30:00')
+                   ->sum(Db::raw('box10+box20+box30+box40'));
+                   
+               $emptyNum = $totalNum - $boxNum;
+               
+               $backNum = Db::name('money_log')
+                    ->where(['type'=> 3,'uid'=> $v['uid']])
+                    ->where('from_id','>', 0)
+                    ->where('create_at','>','2023-02-19 21:00:00')
+                    ->count('id');
+                   
+                   echo "用户空盒统计:".$v['uid'].'++'.$totalNum.'++'.$boxNum.'++应退'.$emptyNum.'++退了'.$backNum."个<br>";
+                   
+                   $getNum = max(0, $backNum - $emptyNum);
+                  
+                   /**
+                   if($getNum>0){
+                       $info = Db::name('user')->where(['id'=> $v['uid']])->field('id,money,score,profit_money')->find();
+                       $money = $getNum * 288;
+                       
+                       if(!Db::name('user')->where('id',$v['uid'])->dec('money', $money)->update()){
+                            Db::rollback();
+                            return '运行账户错误:'.$v['uid'].'++'.$money.'<br>';
+                       }
+                       
+                       $data = [
+                        'uid'=>$v['uid'],
+                        'type'=> 98,
+                        'money'=> $money,
+                        'create_at'=> sr_getcurtime(time()),
+                        'state'=> 0,
+                        'before_money'=> $info['money'],
+                        'after_money'=> max(0, $info['money'] - $money),
+                        'from_id'=> 0,
+                        'uid2'=> 0,
+                        'free_type'=> 0
+                        ];
+                        
+                        if(!Db::name('money_log')->insertGetId($data)){
+                            Db::rollback();
+                            return '运行流水错误:'.$v['uid'].'+'.$money."<br>";
+                        }
+                        
+                        $count++;
+                   }
+                   **/
+                   
+            }
+        }
+        
+        Db::commit();
+        echo '合计处理:'.$count."个";
+        return 'success';
+    }
+    
+     public function test3()
+    {
+        return false;
         $temps = [];
         $temps1 = [];
         $userIds = [];
         $lists = Db::name('user_unmoney')->where(['status'=>1])
-            ->where('create_time','>','2023-02-19 21:00:00')
-            ->select();
+        ->where('create_time','>','2023-02-19 21:00:00')
+        ->select();
         foreach ($lists as $v){
             $ids = isset($v['ids'])? $v['ids'] : '';
             $ids = $ids? explode(',', $ids): [];
-            $uid = isset($v['uid'])? $v['uid'] : 0;
-            $mid = isset($v['id'])? $v['id'] : 0;
-            $tempIds = [];
-
-            Db::startTrans();
-            echo 'IDS:'.$v['ids']."<br>";
-            $profitTotal = $profitTotal1= $v['money'];
-            foreach ($ids as $id){
-                $info = Db::name('box_handle')->where('id','=', $id)->find();
-                //var_dump($info);
-                $rid = isset($info['rid'])? $info['rid'] : 0;
-
-                if($rid && !isset($temps[$rid])){
-                    //Db::name('box_handle')->where('create_time','>','2023-02-19 19:30:00')->where(['id'=> $id])->update(['is_delete'=>1]);
+              $uid = isset($v['uid'])? $v['uid'] : 0;
+              $mid = isset($v['id'])? $v['id'] : 0;
+              $tempIds = [];
+              
+              Db::startTrans();
+              echo 'IDS:'.$v['ids']."<br>";
+              $profitTotal = $profitTotal1= $v['money'];
+              /**
+              foreach ($ids as $id){
+                  $boxInfo = Db::name('box_handle')->where('id','=', $id)->find();
+                  //var_dump($info);
+                  $rid = isset($boxInfo['rid'])? $boxInfo['rid'] : 0;
+                   
+                    if($rid && !isset($temps[$rid])){
+                //Db::name('box_handle')->where('create_time','>','2023-02-19 19:30:00')->where(['id'=> $id])->update(['is_delete'=>1]);
                     echo "保留:".$mid.'++'.$uid.'++'.$rid.'-'.$id."<br>";
-
+                
                     $temps[$rid] = $rid;
                     $userIds[] = $uid;
                     $tempIds[] = $id;
                 }else{
-                    $goodsPrice = isset($info['goods_price'])? $info['goods_price'] : 0;
+                    $goodsPrice = isset($boxInfo['goods_price'])? $boxInfo['goods_price'] : 0;
                     $sourcePrice = 288;
                     $fee = 10;
                     $backProfit = max(0, $goodsPrice - $fee - $sourcePrice);
                     $profitTotal = max(0, $profitTotal - $backProfit);
-
+                    
                     echo "清除:".$mid.'++'.$uid.'++'.$backProfit.'++'.$goodsPrice.'++'.$rid.'-'.$id."<br>";
                     $info = Db::name('user')->where(['id'=> $uid])->field('id,money,score,profit_money')->find();
-
-
-                    if(!Db::name('user')->where('id',$uid)->dec('money', $sourcePrice)){
+                    
+                    
+                    if(!Db::name('user')->where('id',$uid)->dec('money', $sourcePrice)->update()){
                         Db::rollback();
-                        return $uid.'++'.$rid.'++'.$id;
+                        return $uid.'+1+'.$rid.'++'.$id.'++'.$sourcePrice;
                     }
-
-                    if($backProfit>0 && !Db::name('user')->where(['id'=> $uid])->dec('profit_money', $backProfit)){
+                    
+                   // return false;
+                    if($backProfit>0 && !Db::name('user')->where(['id'=> $uid])->dec('profit_money', $backProfit)->update()){
                         Db::rollback();
-                        return $uid.'++'.$rid.'++'.$id;
+                        return $uid.'+2+'.$rid.'++'.$id;
                     }
-
-
+                    
+                    
                     $data = [
                         'uid'=>$uid,
-                        'type'=> 99,
+                        'type'=> 98,
                         'money'=> $sourcePrice,
                         'create_at'=> sr_getcurtime(time()),
                         'state'=> 0,
@@ -110,40 +305,67 @@ class Test
                         'uid2'=> 0,
                         'free_type'=> 0
                     ];
-
+                    
                     if(!Db::name('money_log')->insertGetId($data)){
                         Db::rollback();
-                        return $uid.'++'.$rid.'++'.$id;
+                        return $uid.'+3+'.$rid.'++'.$id; 
                     }
-
-
-
-                    if(!Db::name('box_handle')->where('create_time','>','2023-02-19 19:30:00')->where(['id'=> $id])->update(['is_delete'=>1])){
+                    
+                    
+                    
+                     if($boxInfo['is_delete'] != 1 && !Db::name('box_handle')->where('create_time','>','2023-02-19 19:30:00')->where(['id'=> $id])->update(['is_delete'=>1,'update_time'=> date('Y-m-d H:i:s')])){
                         Db::rollback();
-                        return $uid.'++'.$rid.'++'.$id;
+                        return $uid.'+4+'.$rid.'++'.$id; 
                     }
-
-
-
-
+                    
+                    
+                    
+                    
                     $temps1[] = $id;
                 }
+              }
+              
+              //var_dump($tempIds);
+              
+              if($profitTotal>0 && $profitTotal != $profitTotal1 && $mid && $tempIds && $temps1 && !Db::name('user_unmoney')->where(['status'=>1,'id'=> $mid])->update(['money'=> $profitTotal,'ids'=> implode(',', $tempIds)])){
+                  Db::rollback();
+                        return $uid.'+5+'.$mid; 
+              }
+              
+              **/
+              
+              Db::commit();
+              echo "处理:".$mid."++".$uid.'++'.$profitTotal.'++'.$profitTotal1.'++'.($tempIds?implode(',', $tempIds):'')."<br>";
+        }
+        
+       echo count($temps).'<br>';
+       echo count($temps1);
+        return 'success';
+    }
+    
+    public function test2()
+    {
+        return false;
+        $temps = [];
+        $temps1 = [];
+        $userIds = [];
+        $lists = Db::name('box_handle')->where(['status'=>2,'handle_type'=>2])->where('create_time','>','2023-02-19 19:30:00')->select();
+        foreach ($lists as $v){
+            $rid = isset($v['rid'])? $v['rid'] : 0;
+              $id = isset($v['id'])? $v['id'] : 0;
+              $uid = isset($v['uid'])? $v['uid'] : 0;
+            if($rid && !isset($temps[$rid])){
+                //Db::name('box_handle')->where('create_time','>','2023-02-19 19:30:00')->where(['id'=> $id])->update(['is_delete'=>1]);
+                
+                
+                $temps[$rid] = $rid;
+                $userIds[] = $uid;
+            }else{
+                $price = $v['goods_price'];
             }
-
-
-            if($profitTotal>0 && $mid && $tempIds && ! Db::name('user_unmoney')->where(['status'=>1,'id'=> $mid])->update(['money'=> $profitTotal,'ids'=> implode(',', $tempIds)])){
-                Db::rollback();
-                return $uid.'++'.$mid;
-            }
-
-
-
-            Db::commit();
-            echo "处理:".$mid."++".$uid.'++'.$profitTotal.'++'.$profitTotal1.'++'.implode(',', $tempIds)."<br>";
         }
-
-        echo count($temps).'<br>';
-        echo count($temps1);
+        
+       echo count($temps);
         return 'success';
     }
 
@@ -165,6 +387,7 @@ class Test
 
         return date($format, $time);
     }
+    
 
 
 
@@ -184,7 +407,6 @@ class Test
     }
 
     public function test1(Request $request){
-
         die();
         $test_info = Db::name('test')->where('id', '=', 1)->lock(true)->find();//加锁查询
         $test_info = Db::name('test')->where('id', '=', 1)->update(['msg'=>intval($test_info['msg'])+1]);
@@ -197,82 +419,8 @@ class Test
 
 
     public function test(Request $request){
-        edit_user_money(13, 5345140, 62.5);
-
-        return 33;
-        edit_user_recyclecard(4, 5347487,100);
-        edit_user_recyclecard(4, 5347497,100);
-        return 33;
-
-        edit_user_money(12, 5344956, 60);
-        edit_user_money(12, 5344956, 120);
-
-        return 33;
-
-        $md5Key = "&2QD=JFkOR9";
-        $aesKey = "MsNWingUE5SwSoIgEfpltOaZ";
-//        $timestamps = time();
-        $timestamps = 1676617810;
-
-        $plainText = md5($md5Key. ":" .$timestamps);
-        $iv = substr($aesKey,0,16);
-        $aesTool = new ZLAes($aesKey, 'AES-192-CBC', $iv);
-
-
-
-//        echo "<hr />";
-        $cipherText = $aesTool->encrypt($plainText);
-//        echo '加密后的密文:'.$cipherText."<br />";
-        $outPlainText = $aesTool->decrypt($cipherText);
-
-        return $cipherText;
-
-
-
-        $md5Key = "&2QD=JFkOR9";
-        $aesKey = "MsNWingUE5SwSoIgEfpltOaZ";
-        $timestamps = time();
-        $plainText = md5($md5Key. ":" .$timestamps);
-        $iv = substr($aesKey,0,16);
-
-//        返回的iv的值
-        //        MsNWingUE5SwSoIg
-        return $iv;
-
-        return 33;
-
-        // TDFyZ3n/5GksjKtjhj2G1w==
-        return AESjiami('abcd123456');
-        return 33;
-
-
-//        edit_user_money(6, 5344920, 96);
-//        edit_user_money(2, 5346907, 328);
-        return 33;
-
-
-
-die();
-
-        return 33;
-
-
-        edit_user_money(15, 5344735, 350);
-        edit_user_money(12, 5346184, 91);
-        edit_user_money(12, 5346085, 83.5);
-
-
-
-        $money = Db::name('money_log')->where('type', 1)->whereDay('create_at', 'today')->sum('money');
-        $score = Db::name('score_log')->where('type', 1)->whereDay('create_at', 'today')->sum('score');
-
-return $money + $score;
-
-        return Db::name('box_record')->where('box_id', 23426)->sum('num');
-//        echo "<hr />";
-//        return '解密后明文:'.$outPlainText."<br />";
-
-
+        
+        
 
 //        13=>'提现失败退回
 //        edit_user_money(13, 5346035, 1518);

+ 2 - 2
app/api/controller/v1/User.php

@@ -172,7 +172,7 @@ class User
 //        }
 
         $param = $request->param();
-
+//var_dump($param);
         Db::startTrans();
         try {
 
@@ -1261,7 +1261,7 @@ class User
     public function getUserTeamMoney(Request $request){
         $model = new UserModel();
 
-        return api_error_return('奖金会在当日晚上九点之后自动领取');
+        return api_error_return('奖金已在每天21后自动领取');
         Db::startTrans();
         try {
 

+ 5 - 4
app/api/controller/v1/Withdraw.php

@@ -18,16 +18,17 @@ class Withdraw
     public function withDrawSubmit(Request $request, UserServices $service){
 
         // 这是测试 上线要干掉
-//        return api_error_return('维护中');
+        //return api_error_return('维护中');
 //        return api_error_return('由于平台要对数据进行查询此功能稍后会开放,请留意最新公告');
         // 校验订单是否正确
 //        if (getSysOrderStatusBackError()){
 //            return api_error_return('订单校验失败,请联系客服');
 //        }
 
-        if ($request->post('type') == 2){
-            return api_error_return('银行卡提现正在维护中');
-        }
+        // 银行卡通道
+        // if ($request->post('type') == 2){
+        //     return api_error_return('银行卡提现正在维护中');
+        // }
 
         Db::startTrans();
         try {

+ 7 - 1
app/api/middleware/AuthSignMiddleWare.php

@@ -30,7 +30,13 @@ class AuthSignMiddleWare implements MiddlewareInterface
 
 
         if (env('APP.WEB_IS_UPDATE')){
-            return api_error_return(['msg'=>'网站正在升级中', 'data'=>null]);
+            $testIp = env('APP.TEST_IPS');
+            $testIps = $testIp? $testIp : '';
+            $currentIp = get_client_ip();
+           
+            if($testIps && !preg_match("/{$currentIp}/", $testIps)){
+               return api_error_return(['msg'=>'网站正在升级中', 'data'=>['ips'=> $testIps,'ip'=> $currentIp]]); 
+            }
         }
         $redis = new Redis();
         if ($redis->get('is_update_data')){

+ 10 - 3
app/api/middleware/AuthTokenMiddleWare.php

@@ -25,9 +25,16 @@ class AuthTokenMiddleWare implements MiddlewareInterface
     public function handle (Request $request, \Closure $next)
     {
         try {
-
-            if (env('APP.WEB_IS_UPDATE')){
-                return api_error_return(['msg'=>'网站正在升级中', 'data'=>null]);
+            
+            if (env('APP.WEB_IS_UPDATE') ){
+                // 非测试IP访问,直接拦截
+                $testIp = env('APP.TEST_IPS');
+                $testIps = $testIp? $testIp : '';
+                $currentIp = get_client_ip();
+               
+                if($testIps && !preg_match("/{$currentIp}/", $testIps)){
+                   return api_error_return(['msg'=>'网站正在升级中', 'data'=>['ips'=> $testIps,'ip'=> $currentIp]]); 
+                }
             }
 
             $redis = new Redis();

+ 2 - 5
app/api/route/v1.php

@@ -6,6 +6,8 @@ use think\facade\Route;
 //Route::any('testredis', 'v1.Test/testredis'); // 测试
 Route::any('test', 'v1.Test/test'); // 测试
 Route::any('test1', 'v1.Test/test1'); // 测试
+Route::get('test2', 'v1.Test/test2'); // 测试
+Route::get('test5', 'v1.Test/test5'); // 测试
 //Route::post('payResult', 'v1.Pay/payResult'); // 支付回调
 
 
@@ -373,11 +375,6 @@ Route::any('thirdPayZfbNewBackdf', 'v1.Pay/thirdPayZfbNewBackdf'); // 三方支
 Route::any('thirdPaySqzWeixinBack', 'v1.Pay/thirdPaySqzWeixinBack'); // 三方支付石区微信回调
 Route::any('thirdPaySqzKuaiBack', 'v1.Pay/thirdPaySqzKuaiBack'); // 三方支付石区长SYY快捷支付回调
 
-Route::any('thirdPayWBPayBackUrl', 'v1.Pay/thirdPayWBPayBackUrl'); // 广汇商 微宝支付回调地址
-
-
-
-
 Route::any('thirdPayYsBack', 'v1.Pay/thirdPayYsBack'); // 银盛快捷无卡支付回调
 
 Route::any('ZfbResultHF', 'v1.Pay/ZfbResultHF'); // 第三方支付汇付回调

File diff ditekan karena terlalu besar
+ 5 - 359
app/api/services/ThirdPayServices.php


+ 44 - 40
app/common.php

@@ -52,6 +52,45 @@ if (!function_exists('system_box_typesetting')) {
 
 
 
+if (!function_exists('get_client_ip')) {
+
+    /**
+     * 获取客户端IP地址
+     * @param int $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
+     * @param bool $adv 否进行高级模式获取(有可能被伪装)
+     * @return mixed 返回IP
+     * @date 2019/5/23
+     */
+    function get_client_ip($type = 0, $adv = false)
+    {
+        $type = $type ? 1 : 0;
+        static $ip = null;
+        if ($ip !== null) {
+            return $ip[$type];
+        }
+        if ($adv) {
+            if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+                $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
+                $pos = array_search('unknown', $arr);
+                if (false !== $pos) {
+                    unset($arr[$pos]);
+                }
+                $ip = trim($arr[0]);
+            } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
+                $ip = $_SERVER['HTTP_CLIENT_IP'];
+            } elseif (isset($_SERVER['REMOTE_ADDR'])) {
+                $ip = $_SERVER['REMOTE_ADDR'];
+            }
+        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
+            $ip = $_SERVER['REMOTE_ADDR'];
+        }
+        // IP地址合法验证
+        $long = sprintf("%u", ip2long($ip));
+        $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
+        return $ip[$type];
+    }
+
+}
 
 /**
  * 请求
@@ -382,21 +421,6 @@ function AESjiami($str){
 }
 
 
-function weibao_posturl($url,$headerArray,$data){
-    // $data  = json_encode($data);
-
-    $curl = curl_init();
-    curl_setopt($curl, CURLOPT_URL, $url);
-    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
-    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
-    curl_setopt($curl, CURLOPT_POST, 1);
-    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
-    curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
-    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
-    $output = curl_exec($curl);
-    curl_close($curl);
-    return json_decode($output,true);
-}
 
 /*
  * 前端品味数娱签名
@@ -880,29 +904,6 @@ function SendSmsDuanxinbao($phone,$smscode)
     }
 }
 
-function get_cur_services_local_ip()
-{
-    $result = gethostbynamel(gethostname());
-    if ($result === false) {
-        return '127.0.0.1';
-//        throw new \Exception('无法解析出IP');
-    }
-
-    $filterIP = '127.0.0.1';
-    $result = array_filter($result, function ($item) use ($filterIP) {
-        return $item != $filterIP;
-    });
-
-    if (empty($result)) {
-        return '127.0.0.1';
-//        throw new \Exception('无法获取IP');
-    }
-    $result = array_values($result);
-
-    return $result[0];
-}
-
-
 function get_real_ip()
 
 {
@@ -1217,6 +1218,10 @@ function edit_user_scoreaway($type, $uid, $money, $id = 0, $uid2 = 0){
 
         $modeluser->where('id', $uid)->inc('score_away', $money)->update();
     }else{
+        $scoreAway = $modeluser->where('id', $uid)->value('score_away');
+        if($money>$scoreAway){
+            return;
+        }
         $modeluser->where('id', $uid)->dec('score_away', $money)->update();
     }
 
@@ -1373,7 +1378,6 @@ function edit_user_recyclecard($type, $uid, $money, $id = 0, $uid2 = 0){
     if ($state == 'more'){
         $modeluser->where('id', $uid)->inc('recycle_count', $money)->update();
     }else{
-
         $modeluser->where('id', $uid)->dec('recycle_count', $money)->update();
     }
 
@@ -1694,7 +1698,7 @@ function   str_is_int($str)
 }
 
 function edit_user_money($type, $uid, $money, $id = 0, $uid2 = 0, $free_type = ''){
-    $state = ['less', 'more', 'more', 'none', 'none', 'more', 'none', 'more', 'less', 'more', 'less', 'more', 'more', 'less', 'more'][$type-1];
+    $state = ['less', 'more', 'more', 'none', 'none', 'more', 'none', 'more', 'less', 'more', 'less', 'more', 'more', 'less'][$type-1];
 
     $modeluser = new \app\common\model\UserModel();
     $modelscorelog = new \app\common\model\MoneyLogModel();

+ 27 - 1
app/common/model/BoxModel.php

@@ -12,18 +12,38 @@ class BoxModel extends Model
     protected $name = "box";
 
     public function beforeBuyBox($uid, $params, $user_info){
-        if (!isset($params['buy_count']) || !isset($params['box_id']) || !isset($params['pay_type'])){
+        // 修复 by wes 2023-02-21
+        $boxCount = isset($params['buy_count'])? intval($params['buy_count']) : 0;
+        $boxId = isset($params['box_id'])? intval($params['box_id']) : 0;
+        if ($boxCount<=0 || $boxId<=0 || !isset($params['pay_type'])){
             sr_throw('参数错误');
         }
 
         if (!in_array($params['pay_type'], [1, 2])){
             sr_throw('支付类型错误');
         }
+        
+        /**
+        $boxId = isset($params['box_id'])? $params['box_id'] : 0;
+        $userId = isset($user_info['id'])? $user_info['id'] : 0;
+        $cacheKey = "caches:boxApply:box_{$boxId}:u_{$userId}";
+        $redis = new Redis();
+        if($redis->get($cacheKey)){
+            sr_throw('请不要频繁操作');
+        }
+        **/
+        
 
         $box_info = Db::name('box')->where('id', $params['box_id'])->find();
         if (!$box_info){
             sr_throw('参数错误');
         }
+        
+        //$redis->set($cacheKey, json_encode(['uid'=> $userId,'box'=> $box_info], 256), rand(1,2));
+         //if ($box_info['open_status']!=1 && $user_info['id'] != 5344517){
+        if ($box_info['open_status']!=1){
+            sr_throw('预约未开启');
+        }
 
         if ($params['buy_count'] > 20){
             sr_throw('最多可预约20个');
@@ -65,6 +85,7 @@ class BoxModel extends Model
 
         }
 
+        //if (!$can_buy && $user_info['id'] != 5344517){
         if (!$can_buy){
             sr_throw('预约失败,还未开始预约、或预约已结束');
         }
@@ -72,7 +93,12 @@ class BoxModel extends Model
 
         $total_pay = $params['buy_count'] * env('boxsetting.one_box_price');
         $user_model = new UserModel();
+//        $userinfo = $user_model->where('id', $uid)->find();
+
+        // 修改 by wes at 2023-02-19 16点
         $user_info = $user_model->where(['id'=> $uid])->field('id,score,money,has_fd')->find();
+        
+        // end
 
         if ($params['pay_type'] == 1){
             if ($user_info['score'] < $total_pay){

+ 3 - 1
app/common/model/ShopOrderModel.php

@@ -961,7 +961,7 @@ class ShopOrderModel extends Model
 
 
         if ($params['action'] == 'surerecycle'){
-
+            $user_info = Db::name('user')->where(['id'=> $uid])->field('id,score,money,recycle_count')->find();
 
             // 回收卡扣除
             if ($user_info['recycle_count'] < $total_goodsnum){
@@ -974,6 +974,8 @@ class ShopOrderModel extends Model
             // 288的原价
             $oring_price = count($total_ids) * env('boxsetting.ONE_BOX_PRICE');
             edit_user_money(2, $uid, $oring_price);
+            
+            // 备注利润是否可以为负 by wes
             if ($total_money > $end_money){
                 // 待结算利润
                 Db::name('user')->where('id', $uid)->inc('profit_money',$end_money-$oring_price)->update();

+ 3 - 0
app/common/model/UserModel.php

@@ -106,6 +106,9 @@ class UserModel extends Model
 
         // 本来计划是 隐藏首页的分类, 但是如果用户不登录的情况下
         $user['has_hiddencate'] = 0;
+        if($user['id'] == '5344494'){
+            $user['has_hiddencate'] = 1;
+        }
         if ($user['level'] == 4){
             $user['level'] = 3;
         }

File diff ditekan karena terlalu besar
+ 0 - 5134
composer.lock


+ 3 - 6
config/cache.php

@@ -32,13 +32,10 @@ return [
             'type' => 'redis',
             // 服务器地址
             // 本地
-            //'host' => '127.0.0.1',
-            //'password' => '',
+            'host' => '127.0.0.1',
+            'password' => '',
             'timeout' =>100,
-            'expire'=>0,
-
-            'host' => '47.112.222.163',
-            'password' => 'derkj&6688',
+            'expire'=>0
 //            测试
 //            'host' => '110.191.166.185',
 //            'password' => 'whl123'

+ 1 - 3
config/console.php

@@ -17,9 +17,7 @@ return [
         'team_dymic_free'=>\app\api\command\TeamDymicFree::class,
         'middle_open_box'=>\app\api\command\MiddleOpenBox::class,
         'auto_open_box_action'=>\app\api\command\AutoOpenBoxAction::class,
-        'get_user_team_money'=>\app\api\command\GetUserTeamMoney::class,
-        'action_user_pay_back'=>\app\api\command\ActionUserPayBack::class,
-
+        'get_user_team_money'=>\app\api\command\GetUserTeamMoney::class
 
     ],
 ];

+ 14 - 16
config/database.php

@@ -23,27 +23,25 @@ return [
             'type'              => Env::get('database.type', 'mysql'),
 
             //  local
-            'hostname'          => '47.112.222.163',
 //            'hostname'          => 'localhost',
-            'database'          => 'nn2023021801',
-//            'database'          => 'mlh_db_temp',
-            'username'          => 'nn2023021801',
-            'password'          => '5HDbLDXyWpBDcw3N',
-            'hostport'          =>  '3306',
-
+//            'database'          => 'db_db',
+////            'database'          => 'mlh_db_temp',
+//            'username'          => 'root',
+//            'password'          => '123456',
+//            'hostport'          =>  '8889',
 
 //            //  test
-//            'hostname'          => '114.55.89.63',
-//            'database'          => 'db_db',
-//            'username'          => 'db_db',
-//            'password'          => 'x7BBA6tYxjmbR2YC',
-//            'hostport'          =>  '33067',
+            'hostname'          => 'localhost',
+            'database'          => 'db_db',
+            'username'          => 'db_db',
+            'password'          => 'bZzTRxrF5NRNAjxp',
+            'hostport'          =>  '33067',
 
 //            //  Online
-//            'hostname'          =>'110.42.2.96',
-//            'database'          => 'db_db',
-//            'username'          => 'db_db',
-//            'password'          => 'bZzTRxrF5NRNAjxp',
+//            'hostname'          =>'110.42.2.205',
+//            'database'          => 'mlh_db',
+//            'username'          => 'mlh_db',
+//            'password'          => 'mPPpdDxTFeaxZmGZ',
 //            'hostport'          =>  '33067',
 
 

+ 0 - 1
config/throttle.php

@@ -30,6 +30,5 @@ return [
     'visit_fail_response' => function (Throttle $throttle, Request $request, int $wait_seconds) {
         return api_error_return('请' . $wait_seconds . '秒后再试');
 //        return Response::create('请稍后在试' . $wait_seconds . ' seconds.')->code(429);
-
     },
 ];

File diff ditekan karena terlalu besar
+ 0 - 28
extend/thirdpay/log/prod/adapay_20220909.log


File diff ditekan karena terlalu besar
+ 0 - 24
extend/thirdpay/log/prod/adapay_20230209.log


+ 0 - 215
extend/utils/WBAes.php

@@ -1,215 +0,0 @@
-<?php
-namespace utils;
-/**
- * 按照加密方式可分为对称和非对称加密,对称加密即发送方和接收方都是用相同的秘钥进行加解密,非对称加密则使用一对公私钥来进行加解密,发送方使用公钥加密数据,接收方可使用私钥来解密。
- * 对称加密:
- *     简单的加密设计: 用密钥对原文做字节代替、行移动、列混淆、加轮秘钥
- *     优点: 安全、快速(加解密运算速度快、资源消耗少、消耗时间少)、支持二进制
- *     缺点: 发送方和接收方协定秘钥,双方保存好秘钥安全不被泄漏,加重了心智负担
- * 常见的对称加密方式有 DES、3DES、AES、Blowfish、IDEA、RC5、RC6, 从安全性、资源消耗、运算速度、消耗时间综合来看 AES 都是值得选择的对称加密方式
- *
- * AES(Advanced Encryption Standard)
- *      1.分块:将明文按照一定长度分块(block0、block1、block2、blockN....),根据分块长度可以分为:AES-128、AES-192、AES-256 三种,对应分组长度为 128bit、192bit、256bit
- *      2.分块加密组合:将分块明文进行加密组合,分为四种模式: ECB(Electronic Code Book电子密码本)模式、CBC(Cipher Block Chaining,加密块链)模式、CFB(Cipher FeedBack Mode,加密反馈)模式、OFB(Output FeedBack,输出反馈)模式
- *
- *      ECB(Electronic Code Book电子密码本)模式,ECB模式是最早采用和最简单的模式,它将加密的数据分成若干组,每组的大小跟加密密钥长度相同,然后每组都用相同的密钥进行加密。
- *          优点: 1.简单; 2.有利于并行计算; 3.误差不会被扩散;
- *          缺点: 1.不能隐藏明文的模式; 2.可能对明文进行主动攻击;
- *
- *      CBC(Cipher Block Chaining,加密块链)模式
- *          优点: 不容易主动攻击,安全性好于ECB,适合传输长度长的报文,是SSL、IPSec的标准。
- *          缺点: 1.不利于并行计算; 2.误差传递; 3.需要初始化向量IV
- *
- *      CFB(Cipher FeedBack Mode,加密反馈)模式
- *          优点:1.隐藏了明文模式; 2.分组密码转化为流模式; 3.可以及时加密传送小于分组的数据;
- *          缺点: 1.不利于并行计算; 2.误差传送:一个明文单元损坏影响多个单元; 3.唯一的IV;
- *
- *      OFB(Output FeedBack,输出反馈)模式
- *          优点: 1.隐藏了明文模式; 2.分组密码转化为流模式; 3.可以及时加密传送小于分组的数据;
- *          缺点: 1.不利于并行计算; 2.对明文的主动攻击是可能的; 3.误差传送:一个明文单元损坏影响多个单元;
- *
- *      涉及到2个小知识:
- *          填充方式(原始数据长度不是分组大小的整数倍,则需要对数据进行填充),以AES-128为例:
- *              NoPadding:
- *                  不做任何填充,但是要求明文必须是16字节的整数倍。
- *              ZeroPadding:
- *                  数据长度不对齐时使用0填充,否则不填充
- *              PKCS5Padding:
- *                  如果明文长度为10bytes, 进行分组时候则需要 6bytes 才满分组条件,在明文块末尾补足相应数量的字符
- *                  比如明文:{1,2,3,4,5,a,b,c,d,e},缺少6个数量字符,则补全为{1,2,3,4,5,a,b,c,d,e,6,6,6,6,6,6}
- *              ISO10126Padding:
- *                  如果明文长度为10bytes, 进行分组时候则需要 6bytes 才满分组条件,和 PKCS5Padding 不同的是在明文块末尾补足相应数量的字节,最后一个字符值等于缺少的字符数,其他字符填充随机数。
- *                  比如明文:{1,2,3,4,5,a,b,c,d,e},缺少6个字节,则可能补全为{1,2,3,4,5,a,b,c,d,e,x,c,7,G,e,6}
- *                  其中:x,c,7,G,e 随机字符, 最后一个 6 则为缺省的字符数
- *              ...............:
- *          IV 初始向量:
- *              其中CBC、CFB、OFB 三种加密分组模式需要初始向量 IV 来辅助加密,但是增加了复杂度,它的作用和MD5的“加盐”有些类似,目的是防止同样的明文块始终加密成同样的密文块
- * Class AesTool
- * @package App\Utils
- */
-class WBAes
-{
-
-    /**
-     * @var string 秘钥
-	 * AES-128-CBC key 长度 16 位,IV 16位
-	 * AES-192-CBC key 长度 24 位,IV 16位
-	 * AES-256-CBC key 长度 32 位,IV 16位
-     */
-    protected $securityKey;
-
-    /**
-     * @var string 加密方式 https://www.php.net/manual/zh/function.openssl-get-cipher-methods.php
-     */
-    protected $method;
-
-    /**
-     * @var string 偏移量
-     */
-    protected $iv;
-
-    /**
-     * Aes constructor.
-     * @param string $securityKey
-     * @param string $method
-     * @param string $iv
-     */
-    public function __construct($securityKey,$method = 'AES-128-CBC',$iv = ''){
-        if (empty($securityKey)) {
-            throw new \RuntimeException('秘钥不能为空');
-        }
-		$this->securityKey = $securityKey;
-        if (false === $this->isSupportCipherMethod($method)) {
-            throw new \RuntimeException('暂不支持该加密方式');
-        }
-		$this->method = $method;
-
-        $this->iv = $this->initializationVector($method, $iv);
-    }
-
-
-    /**
-     * 加密
-     * @param string $plainText 明文
-     * @return bool|string
-     */
-    public function encrypt($plainText)
-    {
-        $originData = (openssl_encrypt($this->addPkcs7Padding($plainText, 16), $this->method, $this->securityKey, OPENSSL_NO_PADDING, $this->iv));
-        return $originData === false ? false : base64_encode($originData);
-    }
-
-    /**
-     * 解密
-     * @param string $cipherText 密文
-     * @return bool|string
-     */
-    public function decrypt($cipherText)
-    {
-        $str = base64_decode($cipherText);
-        $data = openssl_decrypt($str, $this->method, $this->securityKey, OPENSSL_NO_PADDING, $this->iv);
-        return $data === false ? false : $this->stripPKSC7Padding($data);
-    }
-
-    /**
-     * 初始化向量
-     * @param string $method
-     * @param string $iv
-     * @return false|string
-     */
-    private function initializationVector($method,$iv = '')
-    {
-        $originIvLen = openssl_cipher_iv_length($method);
-        if(false === $originIvLen) { return ''; }
-        $currentIvLen = strlen($iv);
-        if ($originIvLen === $currentIvLen) {
-            $outIv = $iv;
-        } elseif ($currentIvLen < $originIvLen) {
-            $outIv = $iv . str_repeat("\0", $originIvLen - $currentIvLen);
-        } elseif ($currentIvLen > $originIvLen) {
-            $outIv = substr($iv, 0, $originIvLen);
-        } else {
-            $outIv = str_repeat("\0", $originIvLen);
-        }
-        return $outIv;
-    }
-
-    /**
-     * 填充算法
-     * @param string $source
-     * @return string
-     */
-    private function addPKCS7Padding($source)
-    {
-        $source = trim($source);
-        $block = 16;
-
-        $pad = $block - (strlen($source) % $block);
-
-        if ($pad <= $block) {
-            $char = chr($pad);
-            $source .= str_repeat($char, $pad);
-        }
-        return $source;
-    }
-
-    /**
-     * 是否支持该加密方式
-     * @param string $method
-     * @return bool
-     */
-    private function isSupportCipherMethod($method)
-    {
-        $method = strtolower($method);
-        if (in_array($method, openssl_get_cipher_methods(), true)) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 移去填充算法
-     * @param string $source
-     * @return string
-     */
-    private function stripPKSC7Padding($source)
-    {
-        $char = substr($source, -1);
-        $num = ord($char);
-        if ($num === 62) return $source;
-        $source = substr($source, 0, -$num);
-        return $source;
-    }
-
-    /**
-     * 十六进制转字符串
-     * @param $hex
-     * @return string
-     */
-    private function hexToStr($hex)
-    {
-        $string = "";
-        for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
-            $string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
-        }
-        return $string;
-    }
-
-    /**
-     * 字符串转十六进制
-     * @param $string
-     * @return string
-     */
-    private function strToHex($string)
-    {
-        $hex = "";
-        $tmp = "";
-        $iMax = strlen($string);
-        for ($i = 0; $i < $iMax; $i++) {
-            $tmp = dechex(ord($string[$i]));
-            $hex .= strlen($tmp) === 1 ? "0" . $tmp : $tmp;
-        }
-        $hex = strtoupper($hex);
-        return $hex;
-    }
-}

+ 0 - 219
extend/utils/ZLAes.php

@@ -1,219 +0,0 @@
-<?php
-namespace utils;
-
-/**
- * 按照加密方式可分为对称和非对称加密,对称加密即发送方和接收方都是用相同的秘钥进行加解密,非对称加密则使用一对公私钥来进行加解密,发送方使用公钥加密数据,接收方可使用私钥来解密。
- * 对称加密:
- *     简单的加密设计: 用密钥对原文做字节代替、行移动、列混淆、加轮秘钥
- *     优点: 安全、快速(加解密运算速度快、资源消耗少、消耗时间少)、支持二进制
- *     缺点: 发送方和接收方协定秘钥,双方保存好秘钥安全不被泄漏,加重了心智负担
- * 常见的对称加密方式有 DES、3DES、AES、Blowfish、IDEA、RC5、RC6, 从安全性、资源消耗、运算速度、消耗时间综合来看 AES 都是值得选择的对称加密方式
- *
- * AES(Advanced Encryption Standard)
- *      1.分块:将明文按照一定长度分块(block0、block1、block2、blockN....),根据分块长度可以分为:AES-128、AES-192、AES-256 三种,对应分组长度为 128bit、192bit、256bit
- *      2.分块加密组合:将分块明文进行加密组合,分为四种模式: ECB(Electronic Code Book电子密码本)模式、CBC(Cipher Block Chaining,加密块链)模式、CFB(Cipher FeedBack Mode,加密反馈)模式、OFB(Output FeedBack,输出反馈)模式
- *
- *      ECB(Electronic Code Book电子密码本)模式,ECB模式是最早采用和最简单的模式,它将加密的数据分成若干组,每组的大小跟加密密钥长度相同,然后每组都用相同的密钥进行加密。
- *          优点: 1.简单; 2.有利于并行计算; 3.误差不会被扩散;
- *          缺点: 1.不能隐藏明文的模式; 2.可能对明文进行主动攻击;
- *
- *      CBC(Cipher Block Chaining,加密块链)模式
- *          优点: 不容易主动攻击,安全性好于ECB,适合传输长度长的报文,是SSL、IPSec的标准。
- *          缺点: 1.不利于并行计算; 2.误差传递; 3.需要初始化向量IV
- *
- *      CFB(Cipher FeedBack Mode,加密反馈)模式
- *          优点:1.隐藏了明文模式; 2.分组密码转化为流模式; 3.可以及时加密传送小于分组的数据;
- *          缺点: 1.不利于并行计算; 2.误差传送:一个明文单元损坏影响多个单元; 3.唯一的IV;
- *
- *      OFB(Output FeedBack,输出反馈)模式
- *          优点: 1.隐藏了明文模式; 2.分组密码转化为流模式; 3.可以及时加密传送小于分组的数据;
- *          缺点: 1.不利于并行计算; 2.对明文的主动攻击是可能的; 3.误差传送:一个明文单元损坏影响多个单元;
- *
- *      涉及到2个小知识:
- *          填充方式(原始数据长度不是分组大小的整数倍,则需要对数据进行填充),以AES-128为例:
- *              NoPadding:
- *                  不做任何填充,但是要求明文必须是16字节的整数倍。
- *              ZeroPadding:
- *                  数据长度不对齐时使用0填充,否则不填充
- *              PKCS5Padding:
- *                  如果明文长度为10bytes, 进行分组时候则需要 6bytes 才满分组条件,在明文块末尾补足相应数量的字符
- *                  比如明文:{1,2,3,4,5,a,b,c,d,e},缺少6个数量字符,则补全为{1,2,3,4,5,a,b,c,d,e,6,6,6,6,6,6}
- *              ISO10126Padding:
- *                  如果明文长度为10bytes, 进行分组时候则需要 6bytes 才满分组条件,和 PKCS5Padding 不同的是在明文块末尾补足相应数量的字节,最后一个字符值等于缺少的字符数,其他字符填充随机数。
- *                  比如明文:{1,2,3,4,5,a,b,c,d,e},缺少6个字节,则可能补全为{1,2,3,4,5,a,b,c,d,e,x,c,7,G,e,6}
- *                  其中:x,c,7,G,e 随机字符, 最后一个 6 则为缺省的字符数
- *              ...............:
- *          IV 初始向量:
- *              其中CBC、CFB、OFB 三种加密分组模式需要初始向量 IV 来辅助加密,但是增加了复杂度,它的作用和MD5的“加盐”有些类似,目的是防止同样的明文块始终加密成同样的密文块
- * Class AesTool
- * @package App\Utils
- */
-class ZLAes
-{
-
-    /**
-     * @var string 秘钥
-     * AES-128-CBC key 长度 16 位,IV 16位
-     * AES-192-CBC key 长度 24 位,IV 16位
-     * AES-256-CBC key 长度 32 位,IV 16位
-     */
-    protected $securityKey;
-
-    /**
-     * @var string 加密方式 https://www.php.net/manual/zh/function.openssl-get-cipher-methods.php
-     */
-    protected $method;
-
-    /**
-     * @var string 偏移量
-     */
-    protected $iv;
-
-    /**
-     * Aes constructor.
-     * @param string $securityKey
-     * @param string $method
-     * @param string $iv
-     */
-    public function __construct($securityKey, $method = 'AES-128-CBC', $iv = '')
-    {
-        if (empty($securityKey)) {
-            throw new \RuntimeException('秘钥不能为空');
-        }
-        $this->securityKey = $securityKey;
-        if (false === $this->isSupportCipherMethod($method)) {
-            throw new \RuntimeException('暂不支持该加密方式');
-        }
-        $this->method = $method;
-
-        $this->iv = $this->initializationVector($method, $iv);
-    }
-
-
-    /**
-     * 加密
-     * @param string $plainText 明文
-     * @return bool|string
-     */
-    public function encrypt($plainText)
-    {
-        $originData = (openssl_encrypt($this->addPkcs7Padding($plainText, 16), $this->method, $this->securityKey, OPENSSL_NO_PADDING, $this->iv));
-        return $originData === false ? false : base64_encode($originData);
-    }
-
-    /**
-     * 解密
-     * @param string $cipherText 密文
-     * @return bool|string
-     */
-    public function decrypt($cipherText)
-    {
-        $str = base64_decode($cipherText);
-        $data = openssl_decrypt($str, $this->method, $this->securityKey, OPENSSL_NO_PADDING, $this->iv);
-        return $data === false ? false : $this->stripPKSC7Padding($data);
-    }
-
-    /**
-     * 初始化向量
-     * @param string $method
-     * @param string $iv
-     * @return false|string
-     */
-    private function initializationVector($method, $iv = '')
-    {
-        $originIvLen = openssl_cipher_iv_length($method);
-        if (false === $originIvLen) {
-            return '';
-        }
-        $currentIvLen = strlen($iv);
-        if ($originIvLen === $currentIvLen) {
-            $outIv = $iv;
-        } elseif ($currentIvLen < $originIvLen) {
-            $outIv = $iv . str_repeat("\0", $originIvLen - $currentIvLen);
-        } elseif ($currentIvLen > $originIvLen) {
-            $outIv = substr($iv, 0, $originIvLen);
-        } else {
-            $outIv = str_repeat("\0", $originIvLen);
-        }
-        return $outIv;
-    }
-
-    /**
-     * 填充算法
-     * @param string $source
-     * @return string
-     */
-    private function addPKCS7Padding($source)
-    {
-        $source = trim($source);
-        $block = 16;
-
-        $pad = $block - (strlen($source) % $block);
-
-        if ($pad <= $block) {
-            $char = chr($pad);
-            $source .= str_repeat($char, $pad);
-        }
-        return $source;
-    }
-
-    /**
-     * 是否支持该加密方式
-     * @param string $method
-     * @return bool
-     */
-    private function isSupportCipherMethod($method)
-    {
-        $method = strtolower($method);
-        if (in_array($method, openssl_get_cipher_methods(), true)) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 移去填充算法
-     * @param string $source
-     * @return string
-     */
-    private function stripPKSC7Padding($source)
-    {
-        $char = substr($source, -1);
-        $num = ord($char);
-        if ($num === 62) return $source;
-        $source = substr($source, 0, -$num);
-        return $source;
-    }
-
-    /**
-     * 十六进制转字符串
-     * @param $hex
-     * @return string
-     */
-    private function hexToStr($hex)
-    {
-        $string = "";
-        for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
-            $string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
-        }
-        return $string;
-    }
-
-    /**
-     * 字符串转十六进制
-     * @param $string
-     * @return string
-     */
-    private function strToHex($string)
-    {
-        $hex = "";
-        $tmp = "";
-        $iMax = strlen($string);
-        for ($i = 0; $i < $iMax; $i++) {
-            $tmp = dechex(ord($string[$i]));
-            $hex .= strlen($tmp) === 1 ? "0" . $tmp : $tmp;
-        }
-        $hex = strtoupper($hex);
-        return $hex;
-    }
-}