wesmiler 1 vuosi sitten
vanhempi
commit
d992cf24b8
100 muutettua tiedostoa jossa 346 lisäystä ja 1285 poistoa
  1. 10 18
      .env
  2. 1 1
      app/Console/Commands/SwooleTask.php
  3. 1 1
      app/Helpers/common.php
  4. 10 16
      app/Http/Controllers/Api/LoginController.php
  5. 14 28
      app/Http/Controllers/Api/v1/TestController.php
  6. 18 66
      app/Services/Api/FinanceService.php
  7. 36 68
      app/Services/Api/MemberService.php
  8. 0 755
      app/Services/Api/PledgeOrderService-back.php
  9. 222 271
      app/Services/Api/PledgeOrderService.php
  10. 2 2
      app/Services/Api/TeamService.php
  11. 1 7
      app/Services/Common/AccountLogService.php
  12. 17 21
      app/Services/Common/BalanceLogService.php
  13. 5 18
      app/Services/Common/MemberService.php
  14. 1 1
      app/Services/Common/MenuService.php
  15. 4 7
      app/Services/Common/UserService.php
  16. 0 1
      app/Services/Common/WalletLogService.php
  17. 4 4
      app/Services/CregisPayService.php
  18. BIN
      public/uploads/images/google/C_202407290177EE59C2E04A19A68B3EEF605F04E3.png
  19. BIN
      public/uploads/images/google/C_202407290437B7FF3CF02571819239DFF4D0694A.png
  20. BIN
      public/uploads/images/google/C_2024072904483500F3DB55C4816D71A453F4A5D1.png
  21. BIN
      public/uploads/images/google/C_20240729064E4E098B53BA698ABADB63623C0295.png
  22. BIN
      public/uploads/images/google/C_2024072906DC44E385A000C1D8651585DC248302.png
  23. BIN
      public/uploads/images/google/C_20240729092294E174A5D6693F40BB142890E4FD.png
  24. BIN
      public/uploads/images/google/C_20240729097835DD803FFA102F0CA26E275A7E0D.png
  25. BIN
      public/uploads/images/google/C_2024072909BFA5861857246E375EBB88BB19DA73.png
  26. BIN
      public/uploads/images/google/C_2024072909FEFA8CC9FF33EEDFDD3266F7467C46.png
  27. BIN
      public/uploads/images/google/C_202407290C997E3220A814ABDF56AFC1C1303EF2.png
  28. BIN
      public/uploads/images/google/C_202407290EB9A6F8F6EA44F097C3440F41497485.png
  29. BIN
      public/uploads/images/google/C_202407290F73569591BBC24A7B23734D0865F89D.png
  30. BIN
      public/uploads/images/google/C_20240729109C701C4F0055CA908EFE569B9DBC6B.png
  31. BIN
      public/uploads/images/google/C_202407291390BC2E66A234D399256CFDE749E9EC.png
  32. BIN
      public/uploads/images/google/C_202407291491746270392DE84DBAC3CE304F4F34.png
  33. BIN
      public/uploads/images/google/C_2024072914FE20A3601D71928F8AE7FE4C6832AE.png
  34. BIN
      public/uploads/images/google/C_202407291544C7E1EFE23FC38A5163229A0BD895.png
  35. BIN
      public/uploads/images/google/C_202407291BF92B0A94F748DC87DCB5CA09DBEC6E.png
  36. BIN
      public/uploads/images/google/C_202407291C0CA29999041E76B8344C7890197E5A.png
  37. BIN
      public/uploads/images/google/C_202407291E8E4DCC99D303AAEA8AE7A870644E7F.png
  38. BIN
      public/uploads/images/google/C_202407291F0CA81BDAF4D4FCF6E54FF408EDBD56.png
  39. BIN
      public/uploads/images/google/C_2024072920447525153F433DABA4381957DEFF25.png
  40. BIN
      public/uploads/images/google/C_20240729233674312AA5D379189B2CA205BDF695.png
  41. BIN
      public/uploads/images/google/C_20240729239B22CADC831345430596B3AFE19621.png
  42. BIN
      public/uploads/images/google/C_2024072924F4E8CF1553A4614338E900FD0B7F37.png
  43. BIN
      public/uploads/images/google/C_2024072925E63E8FDE512F4621BDDA988E1BF559.png
  44. BIN
      public/uploads/images/google/C_2024072926AE8D883B5412667B46050F78870BD0.png
  45. BIN
      public/uploads/images/google/C_202407292835AA945AF52CBCB2994D78BC59D7DE.png
  46. BIN
      public/uploads/images/google/C_2024072928C30529FC3F1E3F4000D7376A536FBF.png
  47. BIN
      public/uploads/images/google/C_202407292A3B0D627F4D72A03639298875E5A840.png
  48. BIN
      public/uploads/images/google/C_202407292C9DAA6F5B71CAB73843B43350515546.png
  49. BIN
      public/uploads/images/google/C_20240729312B572D7D26CF3C790B48B742C132B9.png
  50. BIN
      public/uploads/images/google/C_20240729333A44821E6C81269028BBC9C5F25C8C.png
  51. BIN
      public/uploads/images/google/C_20240729352EEC120ECD4EA98230EF6DDC99C0BF.png
  52. BIN
      public/uploads/images/google/C_202407293567CE0DFC6C4883796EA752E38235A4.png
  53. BIN
      public/uploads/images/google/C_202407293A09ECA76C56D5795AF57809E53971C1.png
  54. BIN
      public/uploads/images/google/C_202407293DA906E6C92DDEEBBA51CB4771C71CAA.png
  55. BIN
      public/uploads/images/google/C_202407294116E4A0A16B5560306F3AA313AC80B5.png
  56. BIN
      public/uploads/images/google/C_2024072942BF6D74E1E35A74578038CEBB2548F7.png
  57. BIN
      public/uploads/images/google/C_2024072942E024E770A61096D65D4619182FE34A.png
  58. BIN
      public/uploads/images/google/C_2024072947A54AA66280D552A730540C36A27D0F.png
  59. BIN
      public/uploads/images/google/C_2024072948B8186DC135023E073ABEB46A03FF1E.png
  60. BIN
      public/uploads/images/google/C_2024072949352503E2EDE514C4DB61006C0FF3BB.png
  61. BIN
      public/uploads/images/google/C_202407294B839AA3386F5AE340A0FF2DC4EB373F.png
  62. BIN
      public/uploads/images/google/C_202407294CF6C437776F5FB70FFF768CEE963F5E.png
  63. BIN
      public/uploads/images/google/C_202407294F03FCCBDC480498E9321D3098AA82A6.png
  64. BIN
      public/uploads/images/google/C_202407294F124CD563BCB816E3EEEEFA206B3706.png
  65. BIN
      public/uploads/images/google/C_202407294FDD165F3EA09EB008D77DD994D33759.png
  66. BIN
      public/uploads/images/google/C_202407295125746499980DDFF1B553621DC39A46.png
  67. BIN
      public/uploads/images/google/C_20240729517F09638FCA30057B1C2ACF18D8ECE7.png
  68. BIN
      public/uploads/images/google/C_20240729527D277B5F87B76F7BBD3A6577BDE90C.png
  69. BIN
      public/uploads/images/google/C_2024072953C84E92DF17CA96ED0AA1E4B2EE3A2A.png
  70. BIN
      public/uploads/images/google/C_2024072954388DB20C1C10D135BC6EAEBDC01554.png
  71. BIN
      public/uploads/images/google/C_202407295479B81BAEFAF5E2115454D98B2DCDA7.png
  72. BIN
      public/uploads/images/google/C_2024072955C779F957909578479505AE31651C5B.png
  73. BIN
      public/uploads/images/google/C_20240729573BFB34AE858C00DA0C2FC75E940823.png
  74. BIN
      public/uploads/images/google/C_20240729579E503387DC0E9AD30F85D130089D8F.png
  75. BIN
      public/uploads/images/google/C_20240729599D4A6E20499C08CD8D0CA55821BECB.png
  76. BIN
      public/uploads/images/google/C_2024072959F93840F7E69888CECC480278CEE89F.png
  77. BIN
      public/uploads/images/google/C_202407295ADBDFE490DDAD35E6AF275A90EDAA8F.png
  78. BIN
      public/uploads/images/google/C_202407295E08D9A56209E89BE3100FE87C3B434C.png
  79. BIN
      public/uploads/images/google/C_2024072961CC3CF71952DBCF471227F98A5AB64E.png
  80. BIN
      public/uploads/images/google/C_2024072962BDF477D89ECE43D67B969A0544DB53.png
  81. BIN
      public/uploads/images/google/C_202407296705782DBEBC9CE1F975351E175DB240.png
  82. BIN
      public/uploads/images/google/C_20240729673A0CA38AE42F5163C56EFD5E5D43AC.png
  83. BIN
      public/uploads/images/google/C_20240729680BE917CC7A5C48B96BFF8E878EBDCD.png
  84. BIN
      public/uploads/images/google/C_202407296D1617649DA04A58B2DE5F5417DF818B.png
  85. BIN
      public/uploads/images/google/C_202407296D8494A5BA23718967845B5B53F8E0BA.png
  86. BIN
      public/uploads/images/google/C_202407296DE118C308D86430344CDB2E0541057D.png
  87. BIN
      public/uploads/images/google/C_202407296F7610D800B6C047CE66EFB1D0C84A03.png
  88. BIN
      public/uploads/images/google/C_202407296FB065E60FCFBDDB9E8C4D17AE3C0F20.png
  89. BIN
      public/uploads/images/google/C_2024072971824A3BC21873C02587B9562151E411.png
  90. BIN
      public/uploads/images/google/C_2024072975B46002F0AD5A7B47642915E2B2D1E0.png
  91. BIN
      public/uploads/images/google/C_2024072976AE52A97384DAD85D0B5EB7DACB694A.png
  92. BIN
      public/uploads/images/google/C_20240729771F64236EAE67C907817DEE887A5F7B.png
  93. BIN
      public/uploads/images/google/C_20240729776B216F88E596184E541595B21765E7.png
  94. BIN
      public/uploads/images/google/C_202407297795B35463748B757CDE9EB72098F978.png
  95. BIN
      public/uploads/images/google/C_2024072977C9FC8DC5A885375B7DC9E9099D5A94.png
  96. BIN
      public/uploads/images/google/C_2024072978F35EDAC29FB862DA97CD107B94C626.png
  97. BIN
      public/uploads/images/google/C_202407297B851E10467012FCC1C99F2E6C979E41.png
  98. BIN
      public/uploads/images/google/C_202407297C5C0CB4C772CDF3D636A354C7C63708.png
  99. BIN
      public/uploads/images/google/C_202407297C9236FF0DD7BD748EB5B9048EF0D838.png
  100. 0 0
      public/uploads/images/google/C_202407297CA0A7FD0D6BF4711A3BB9C6C0A20F76.png

+ 10 - 18
.env

@@ -5,18 +5,17 @@ APP_KEY=base64:5c43a8wcR8LOQtT3fxxtJ/Y4Hf4y4KdLsGF5Gi6v7SY=
 API_KEY=SBTDAPPE4CE092C8
 APP_DEBUG=true
 API_RATE_LIMIT=120
-APP_URL=https://sbt-api.mp.dongerkj.com/
-WEB_URL=https://sbt-dapp.mp.dongerkj.com/
+APP_URL=https://sapi.sbtsolana.com/
+WEB_URL=https://dapp.sbtsolana.com/
 LOG_CHANNEL=stack
 
 DB_CONNECTION=mysql
-#DB_HOST=127.0.0.1
-DB_HOST=47.112.222.163
+DB_HOST=127.0.0.1
 DB_PORT=63306
 DB_PREFIX=lev_
-DB_DATABASE=nn2024071001
-DB_USERNAME=NN2024071001
-DB_PASSWORD=FDs2nyikpWM3M67N
+DB_DATABASE=sbtsolana
+DB_USERNAME=sbtsolana
+DB_PASSWORD=STZ88qvy788*Cc89Zc66
 
 
 FILESYSTEM_DRIVER=public # 文件系统
@@ -27,18 +26,11 @@ QUEUE_CONNECTION=redis
 SESSION_DRIVER=file
 SESSION_LIFETIME=120
 
-#REDIS_PREFIX=null
-#REDIS_HOST=127.0.0.1
-#REDIS_PASSWORD=null
-#REDIS_PORT=6379
-#REDIS_DB=1
-
 CACHE_DRIVER=redis
 REDIS_PREFIX=null
-#REDIS_HOST=127.0.0.1
-REDIS_HOST=47.112.222.163
-REDIS_PASSWORD=derkj&6688
-REDIS_PORT=16379
+REDIS_HOST=127.0.0.1
+REDIS_PASSWORD=78STWh&TwA5GaX5MQokb
+REDIS_PORT=56379
 REDIS_DB=1
 
 #socket
@@ -65,4 +57,4 @@ SITE_NAME = UTC
 NICK_NAME = UTC
 VERSION = v1.2.0
 
-IMG_URL = https://sbt-api.mp.dongerkj.com/uploads
+IMG_URL = https://sapi.sbtsolana.com/uploads

+ 1 - 1
app/Console/Commands/SwooleTask.php

@@ -241,7 +241,7 @@ class SwooleTask extends Command
         });
 
         // TODO 自动质押监控
-        \swoole_timer_tick(60000, function ($timer) use ($serv, &$time) { // 启用定时器,每1分钟执行一次
+        \swoole_timer_tick(180000, function ($timer) use ($serv, &$time) { // 启用定时器,每3分钟执行一次
             $date = date('Y-m-d H:i:s');
             if ($time > 7200 && file_exists($this->options['log_file'])) {
                 $time = 0;

+ 1 - 1
app/Helpers/common.php

@@ -865,7 +865,7 @@ if (!function_exists('get_image_url')) {
         } else {
             $host = request()->header('HOST');
             $https = request()->secure();
-            $host = ($https ? 'https://' : '//') . $host . '/uploads';
+            $host = ($https ? 'https://' : 'http://') . $host . '/uploads';
         }
 
         return strpos($image_url, 'http') === false ? $host . '/' . ltrim($image_url, '/') : $image_url;

+ 10 - 16
app/Http/Controllers/Api/LoginController.php

@@ -3,7 +3,6 @@
 namespace App\Http\Controllers\Api;
 
 use App\Services\Api\MemberService;
-use App\Services\RedisService;
 
 /**
  * 授权登录控制器基类
@@ -18,22 +17,17 @@ class LoginController extends webApp
      */
     public function dapp(){
         $walletUrl = request()->post('wallet_url','');
-        try {
-            $scode = request()->post('scode','');
-            if(empty($walletUrl)){
-                return showJson('钱包授权失败',false);
-            }
+        $scode = request()->post('scode','');
+        if(empty($walletUrl)){
+            return showJson('钱包授权失败',false);
+        }
 
-            // 钱包账号登录
-            if($result = MemberService::make()->loginOrRegister($walletUrl, $scode)){
-                return showJson(2004, true, $result);
-            }else{
-                $code = MemberService::make()->getError();
-                return showJson($code, false,'',$code==2015? 403: 0);
-            }
-        }catch (\Exception $exception){
-            RedisService::set("caches:login:{$walletUrl}", ['error'=>$exception->getMessage(),'line'=>$exception->getLine(),'data'=>$exception->getTrace()],600);
-            return showJson(1018, false);
+        // 钱包账号登录
+        if($result = MemberService::make()->loginOrRegister($walletUrl, $scode)){
+            return showJson(2004, true, $result);
+        }else{
+            $code = MemberService::make()->getError();
+            return showJson($code, false,'',$code==2015? 403: 0);
         }
     }
 }

+ 14 - 28
app/Http/Controllers/Api/v1/TestController.php

@@ -4,13 +4,11 @@ namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
 use App\Models\MemberModel;
-use App\Models\PledgeOrderModel;
 use App\Services\Api\FinanceService;
 use App\Services\Api\MemberService;
 use App\Services\Api\PledgeOrderService;
 use App\Services\Api\PriceLogService;
 use App\Services\Common\InstitutionalService;
-use App\Services\ConfigService;
 use App\Services\CregisPayService;
 use App\Services\WalletService;
 use Earnp\GoogleAuthenticator\GoogleAuthenticator;
@@ -25,32 +23,20 @@ class TestController extends webApp
 
     public function check()
     {
-//        $order = PledgeOrderModel::where(['id'=>29])->first();
-//        $result = FinanceService::make()->settleShareAward(10042,'10001,10034,10035,10036,10037,10038,10039,10040,',$order);
-//        var_dump(make_wallet_token('58YsXE527EojowwqSFDV1V7tCWUGVFbEqnD1f3TUUALQ',10001));
-//        $result = CregisPayService::make()->withdraw('58YsXE527EojowwqSFDV1V7tCWUGVFbEqnD1f3TUUALQ', 1, 'TS2024080201010234', '1000', '', '测试');
-//        $result = FinanceService::make()->developerSettle(1,'FD3JJToc92rxabSuuYWEqttEtDj9wwQFz79mCtPixHtL');
-//        $result = MemberService::make()->upgradeUpdate(11056);
-//        var_dump($result);
-//        var_dump(lang(FinanceService::make()->getError()));
+        $result = CregisPayService::make()->withdraw('58YsXE527EojowwqSFDV1V7tCWUGVFbEqnD1f3TUUALQ', 0.66, 'TS'.date('YmdHis'), '1000', '', '手动测试');
+//        $result = FinanceService::make()->developerSettle(2,'58YsXE527EojowwqSFDV1V7tCWUGVFbEqnD1f3TUUALQ');
+var_dump(CregisPayService::make()->getError());
+        var_dump($result);
 //        $result = CregisPayService::make()->withdraw('58YsXE527EojowwqSFDV1V7tCWUGVFbEqnD1f3TUUALQ',1,'TS'.date('YmdHis'),1000);
 //        $result = MemberService::make()->pledgeUserList();
 //        $result = PledgeOrderService::make()->orderSettle(4,'PD20240729105659045786',10023);
 //        var_dump($result);
 //
-//        $userInfo = MemberModel::where(['id'=> 13300])->first()->toArray();
-//        $result = PledgeOrderService::make()->autoMakeOrder($userInfo);
-//        var_dump($result);
-//        var_dump(lang(PledgeOrderService::make()->getError()));
+//        $userInfo = MemberModel::where(['id'=> 10023])->first()->toArray();
 //        var_dump($userInfo);
-        $sbtPrice = PriceLogService::make()->getSbtPrice();
-        $sbtUsdtFee = ConfigService::make()->getConfigByCode('pledge_sbt_usdt_fee', 0);
-        $sbtUsdtFee = $sbtUsdtFee > 0 ? floatval($sbtUsdtFee) : 0;
-        $sbtFee = $sbtUsdtFee && $sbtPrice > 0 ? moneyFormat($sbtUsdtFee / $sbtPrice, 2) : 0;
-        var_dump($sbtFee);
-//          $result = MemberService::make()->pledgeUserList();
-//        $result = [];
-        return message('获取结果', true, $sbtFee);
+//        $result = PledgeOrderService::make()->autoMakeOrder($userInfo);
+        var_dump(lang(PledgeOrderService::make()->getError()));
+        return message('获取结果', true, $result);
     }
 
     /**
@@ -59,12 +45,12 @@ class TestController extends webApp
      */
     public function sbtPrice()
     {
-//        $sdate = '2024-07-10';
-//        for($i = 1; $i <=11; $i++){
-//            $date = date('Y-m-d', strtotime($sdate)  + $i * 86400);
-//            $result = PriceLogService::make()->updateSbtPrice($date);
-//            var_dump($result);
-//        }
+        $sdate = '2024-07-10';
+        for($i = 1; $i <=11; $i++){
+            $date = date('Y-m-d', strtotime($sdate)  + $i * 86400);
+            $result = PriceLogService::make()->updateSbtPrice($date);
+            var_dump($result);
+        }
 
         return message('获取结果');
     }

+ 18 - 66
app/Services/Api/FinanceService.php

@@ -12,7 +12,6 @@
 namespace App\Services\Api;
 
 use App\Models\AccountLogModel;
-use App\Models\BalanceLogModel;
 use App\Models\DeveloperModel;
 use App\Models\FinanceModel;
 use App\Models\MemberModel;
@@ -244,7 +243,6 @@ class FinanceService extends BaseService
         $bonusPerformance = isset($userInfo['bonus_performance']) ? floatval($userInfo['bonus_performance']) : 0;
         DB::beginTransaction();
         try {
-            $logs = [];
             if ($bonusRate > 0 && $bonusRate < 100) {
                 $teamPerformance = TeamService::make()->getTeamPerformanceByType($userId, 2, true);
                 $teamPerformance = round($teamPerformance + $userPerformance, 2); // 用户团队业绩
@@ -294,8 +292,6 @@ class FinanceService extends BaseService
                             $this->error = "用户[{$userId}]质押订单[{$orderNo}]的团队分红结算失败";
                             return false;
                         }
-
-                        $logs[$userId] = ['error'=>"质押用户[{$userId}]团队分红结算成功",'orderNo'=>$orderNo,'bonusUsdt'=>$bonusAwardUsdt,'bonusRate'=>$bonusRate,'log'=>$data];
                     }
 
                 }
@@ -303,6 +299,7 @@ class FinanceService extends BaseService
 
 
             // TODO 上级分红结算
+            $logs = [];
             if($parentIds){
                 $lastUserId = $userId;
                 $lastUserInfo = [];
@@ -318,7 +315,6 @@ class FinanceService extends BaseService
                     foreach($parentIds as $pid){
                         $info = isset($parents[$pid])? $parents[$pid] : [];
                         if(empty($info)){
-                            $lastUserId = $pid;
                             $logs[$pid] = ['error'=>"分红用户[{$userId}]上级用户[{$pid}]信息不存在",'orderNo'=>$orderNo,'info'=>$info];
                             continue;
                         }
@@ -327,13 +323,12 @@ class FinanceService extends BaseService
                             $lastUserInfo = $userInfo;
                         }else{
                             $lastUserInfo = isset($parents[$lastUserId])?$parents[$lastUserId] : [];
-//                            $lastUserId = isset($lastUserInfo['id'])? $lastUserInfo['id'] : 0;
+                            $lastUserId = isset($lastUserInfo['id'])? $lastUserInfo['id'] : 0;
                         }
 
                         // 当前节点线下级直推用户
                         if(empty($lastUserInfo)){
-                            $lastUserId = $pid;
-                            $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]直推线用户信息不存在",'orderNo'=>$orderNo,'lastUserId'=>$lastUserId,'parents'=>$parents,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
+                            $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]直推线用户信息不存在",'orderNo'=>$orderNo,'lastUserId'=>$lastUserId,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
                             continue;
                         }
 
@@ -343,7 +338,6 @@ class FinanceService extends BaseService
                         $parentBonusRate = isset($info['bonus_rate']) ? floatval($info['bonus_rate']) : 0;
                         $realBonusRate = max(0,round($parentBonusRate - $bonusTotalRate));
                         if($realBonusRate <=0 || $realBonusRate >= 100){
-                            $lastUserId = $pid;
                             $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]无实际分红比例",'orderNo'=>$orderNo,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
                             continue;
                         }
@@ -400,7 +394,7 @@ class FinanceService extends BaseService
                                     'coin_type' => 3,
                                     'money' => $bonusAwardUsdt,
                                     'before_money' => $parentProfit,
-                                    'create_time' => time()+1,
+                                    'create_time' => time(),
                                     'action_ip' => get_client_ip(),
                                     'remark' => "团队分红",
                                     'status' => 1,
@@ -413,17 +407,9 @@ class FinanceService extends BaseService
                                     return false;
                                 }
 
-                                $lastUserId = $pid;
-                                $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]团队分红成功",'orderNo'=>$orderNo,'bonusUsdt'=>$bonusAwardUsdt,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
-                                $bonusTotalRate += $realBonusRate;
-                            }else{
-                                $lastUserId = $pid;
-                                $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]团队分红无结算金额",'orderNo'=>$orderNo,'bonusUsdt'=>0,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
+                                $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]团队分红结算成功",'orderNo'=>$orderNo,'bonusUsdt'=>$bonusAwardUsdt,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
                             }
 
-                        }else{
-                            $lastUserId = $pid;
-                            $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]团队分红业绩不足",'orderNo'=>$orderNo,'teamPerformance'=>$teamPerformance,'bonusTeamPerformance'=>$bonusTeamPerformance,'bonusUsdt'=>0,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
                         }
                     }
                 }
@@ -602,7 +588,6 @@ class FinanceService extends BaseService
                                 }
 
                                 $logs[$pid] = ['error'=>"质押用户[{$userId}]上级用户[{$pid}]工作室分红结算成功",'orderNo'=>$orderNo,'bonusUsdt'=>$bonusAwardUsdt,'bonusRateTotal'=>$bonusTotalRate,'info'=>$info];
-                                $bonusTotalRate += $realBonusRate;
                             }
 
                         }
@@ -925,7 +910,7 @@ class FinanceService extends BaseService
         }
 
         $parentIds = get_parents($parentIds);
-//        $parentIds = array_slice($parentIds, 0, 10);
+        $parentIds = array_slice($parentIds, 0, 10);
         if (empty($parentIds)) {
             $this->error = lang(4511, ['uid' => $userId, 'order_no' => $orderNo]);
             return true;
@@ -935,33 +920,20 @@ class FinanceService extends BaseService
         try {
             $count = 0;
             $logs = [];
-            $floor = 0;
             $shareRates = InstitutionalService::make()->getAwardByFloor();
             DB::beginTransaction();
             foreach ($parentIds as $key => $pid) {
-                if($floor>7){
-                    $logs[$pid] = ['error' => "该推荐人[{$pid}]超过结算层级,不结算", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor];
-                    continue;
-                }
-
-                // 验证用户是否有效
-                if (!PledgeOrderService::make()->checHasPledge($pid)) {
-                    $logs[$pid] = ['error' => "该推荐人[{$pid}]是无效用户,不计算奖励不计算层级", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1];
-                    continue;
-                }
-
-                $rateInfo = isset($shareRates[$floor+1]) ? $shareRates[$floor+1] : [];
+                $floor = $key + 1;
+                $rateInfo = isset($shareRates[$floor]) ? $shareRates[$floor] : [];
                 $rate = isset($rateInfo['value']) && $rateInfo['value'] > 0 && $rateInfo['value'] < 100 ? floatval($rateInfo['value']) : 0;
                 if (empty($rateInfo) || $rate <= 0) {
-                    $floor++;
-                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐收益比例参数未配置,算层级不结算", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1];
+                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐收益比例参数未配置", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor];
                     continue;
                 }
 
                 $shareAwardUsdt = moneyFormat($pledgeUsdt * $rate / 100, 2);
                 if ($shareAwardUsdt <= 0) {
-                    $floor++;
-                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐无推荐收益,算层级不结算", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1, 'rate' => $rate];
+                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐无推荐收益", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor, 'rate' => $rate];
                     continue;
                 }
 
@@ -971,14 +943,13 @@ class FinanceService extends BaseService
                 $userInfo = $userInfo ? $userInfo->toArray() : [];
                 $userProfit = isset($userInfo['profit']) ? $userInfo['profit'] : 0;
                 if (empty($userInfo) || $pid <= 0) {
-                    $logs[$pid] = ['error' => "该推荐人[{$pid}]信息不存在,不算层级", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1, 'rate' => $rate];
+                    $logs[$pid] = ['error' => "该推荐人[{$pid}]信息不存在", 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor, 'rate' => $rate];
                     continue;
                 }
 
                 // 验证是否结算过
                 if ($logId = AccountLogModel::where(['user_id' => $pid, 'order_no' => $orderNo, 'type' => 8, 'status' => 1, 'mark' => 1])->value('id')) {
-                    $floor++;
-                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐奖励已结算过,算层级", 'logId' => $logId, 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1, 'rate' => $rate];
+                    $logs[$pid] = ['error' => "该层推荐人[{$pid}]推荐奖励已结算过", 'logId' => $logId, 'orderNo' => $orderNo, 'uid' => $userId, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor, 'rate' => $rate];
                     continue;
                 }
 
@@ -1008,19 +979,18 @@ class FinanceService extends BaseService
                     'before_money' => $userProfit,
                     'create_time' => time(),
                     'action_ip' => get_client_ip(),
-                    'remark' => ($floor+1)."层推荐奖励",
+                    'remark' => "{$floor}层推荐奖励",
                     'status' => 1,
                     'mark' => 1,
                 ];
 
                 if (!AccountLogModel::insertGetId($data)) {
                     DB::rollBack();
-                    $this->error = "用户[{$userId}]质押订单[{$orderNo}]的[".($floor+1)."]层推荐人[{$pid}]推荐收益[{$shareAwardUsdt}]结算错误";
+                    $this->error = "用户[{$userId}]质押订单[{$orderNo}]的[{$floor}]层推荐人[{$pid}]推荐收益[{$shareAwardUsdt}]结算错误";
                     return false;
                 }
-                $logs[$pid] = ['error' => "推荐人[{$pid}]奖励结算成功", 'orderNo' => $orderNo, 'uid' => $userId, 'profit' => $userProfit, 'awardUsdt' => $shareAwardUsdt, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor+1, 'rate' => $rate];
+                $logs[$pid] = ['error' => "推荐人[{$pid}]奖励结算成功", 'orderNo' => $orderNo, 'uid' => $userId, 'profit' => $userProfit, 'awardUsdt' => $shareAwardUsdt, 'pledgeUsdt' => $pledgeUsdt, 'floor' => $floor, 'rate' => $rate];
                 $count++;
-                $floor++;
             }
 
             DB::commit();
@@ -1054,7 +1024,6 @@ class FinanceService extends BaseService
         $info = $info? $info->toArray() : [];
         $userId = isset($info['user_id'])? intval($info['user_id']) : 0;
         $userProfit = isset($info['profit'])? floatval($info['profit']) : 0;
-        $profitRate = isset($info['maintenance_rate'])? floatval($info['maintenance_rate']) : 0;
         if(empty($info) || $userId<=0){
             $this->error = 2001;
             return false;
@@ -1074,29 +1043,12 @@ class FinanceService extends BaseService
 
         DB::beginTransaction();
         try {
-            // 最近七天充提差
-            $rechargeTotal = BalanceLogModel::where(['type'=>1,'status'=>2,'mark'=>1])->where(function($query) use($lastSettleAt){
-                if($lastSettleAt){
-                    $query->where('pay_at','>=',$lastSettleAt)->where('pay_at','<',date('Y-m-d H:i:s'));
-                }else{
-                    $query->where('pay_at','<',date('Y-m-d H:i:s'));
-                }
-            })->sum('money');
-            $withdrawTotal = BalanceLogModel::where(['type'=>2,'pay_status'=>20,'status'=>2,'mark'=>1])->where(function($query) use($lastSettleAt){
-                if($lastSettleAt){
-                    $query->where('pay_at','>=',$lastSettleAt)->where('pay_at','<',date('Y-m-d H:i:s'));
-                }else{
-                    $query->where('pay_at','<',date('Y-m-d H:i:s'));
-                }
-            })->sum('money');
-
-            $pledgeTotal = $rechargeTotal>$withdrawTotal?round($rechargeTotal - $withdrawTotal, 2) : 0;
-
+            // 全网流水
+            $pledgeTotal = PledgeOrderService::make()->getGlobalTotal();
 
             // 结算比例
             $settleRate = ConfigService::make()->getConfigByCode('developer_settle_rate', 3);
             $settleRate = $settleRate>0 && $settleRate <= 20? $settleRate : 3;
-            $settleRate = $profitRate>0 && $profitRate< 50? $profitRate : $settleRate;
 
             $settleMoney = round($pledgeTotal * $settleRate/100, 2);
             if($settleMoney>0){
@@ -1148,7 +1100,7 @@ class FinanceService extends BaseService
 
             DB::commit();
             $this->error = 1046;
-            return ['id'=>$developerId,'user_id'=>$userId,'money'=>$settleMoney,'recharge'=>$rechargeTotal,'withdraw'=>$withdrawTotal];
+            return ['id'=>$developerId,'user_id'=>$userId,'money'=>$settleMoney];
 
         }catch (\Exception $exception){
             $this->error = $exception->getMessage();

+ 36 - 68
app/Services/Api/MemberService.php

@@ -200,7 +200,7 @@ class MemberService extends BaseService
                 'bonus_rate' => $info['bonus_rate'],
                 'pledge_auto' => $info['pledge_auto'],
                 'recharge_url' => $info['recharge_url'],
-                'parent_url' => format_str($parentWalletUrl,24,6),
+                'parent_url' => $parentWalletUrl,
             ],
         ];
     }
@@ -232,7 +232,7 @@ class MemberService extends BaseService
         $parentWalletUrl = isset($parentInfo['wallet_url']) ? $parentInfo['wallet_url'] : '';
         $walletUrl = isset($info['wallet_url']) ? $info['wallet_url'] : '';
         $walletToken = isset($info['wallet_token']) ? $info['wallet_token'] : '';
-        if ($type == 3 && $walletUrl && $walletToken && $walletToken != make_wallet_token($walletUrl, $userId)) {
+        if ($type == 3 && $walletUrl && $walletToken != make_wallet_token($walletUrl, $userId)) {
             $info['error'] = '钱包地址已被修改';
         }
 
@@ -245,7 +245,7 @@ class MemberService extends BaseService
             }
         }
         $rechargeToken = isset($info['recharge_token']) ? $info['recharge_token'] : '';
-        if ($type == 2 && $rechargeUrl && $rechargeToken && $rechargeToken != make_wallet_token($rechargeUrl, $userId)) {
+        if ($type == 2 && $rechargeUrl && $rechargeToken != make_wallet_token($rechargeUrl, $userId)) {
             $info['error'] = '钱包地址已被修改';
         }
 
@@ -269,14 +269,12 @@ class MemberService extends BaseService
             'bonus_rate' => $info['bonus_rate'],
             'pledge_auto' => $info['pledge_auto'],
             'error' => isset($info['error']) ? $info['error'] : '',
-            'parent_url' => format_str($parentWalletUrl,24,6),
+            'parent_url' => $parentWalletUrl,
             'recharge_url' => $rechargeUrl,
             'max_usdt_rate' => ConfigService::make()->getConfigByCode('usdt_withdraw_max_rate', 0),
             'sbt_fee' => ConfigService::make()->getConfigByCode('profit_withdraw_sbt_fee', 0),
             'recharge_min' => ConfigService::make()->getConfigByCode('recharge_min_money', 0.1),
             'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min_money', 0),
-            'recharge_open' => ConfigService::make()->getConfigByCode('recharge_open', 1),
-            'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 1),
         ];
 
         if ($type == 1) {
@@ -571,29 +569,25 @@ class MemberService extends BaseService
      */
     public function makeQrcode($str, $dir='qrcode', $refresh = false, $size = 4, $margin = 2, $level = 2)
     {
-        try {
-            $basePath = base_path() . '/public';
-            $qrFile = "/images/{$dir}/";
-            if (!is_dir($basePath . '/uploads' . $qrFile)) {
-                @mkdir($basePath . '/uploads' . $qrFile, 0755, true);
-            }
-
-            $key = date('Ymd') . strtoupper(md5($str . '_' . $size . $margin . $level));
-            $qrFile = $qrFile . "C_{$key}.png";
-            $cacheKey = "caches:qrcodes:member_" . $key;
-            if (RedisService::get($cacheKey) && is_file($basePath . '/uploads' . $qrFile) && !$refresh) {
-                return $qrFile;
-            }
+        $basePath = base_path() . '/public';
+        $qrFile = "/images/{$dir}/";
+        if (!is_dir($basePath . '/uploads' . $qrFile)) {
+            @mkdir($basePath . '/uploads' . $qrFile, 0755, true);
+        }
 
-            QRcode::png($str, $basePath . '/uploads' . $qrFile, $level, $size, $margin);
-            if (!file_exists($basePath . '/uploads' . $qrFile)) {
-                return false;
-            }
-            RedisService::set($cacheKey, ['str' => $str, 'qrcode' => $qrFile, 'date' => date('Y-m-d H:i:s')], 7 * 24 * 3600);
+        $key = date('Ymd') . strtoupper(md5($str . '_' . $size . $margin . $level));
+        $qrFile = $qrFile . "C_{$key}.png";
+        $cacheKey = "caches:qrcodes:member_" . $key;
+        if (RedisService::get($cacheKey) && is_file($basePath . '/uploads' . $qrFile) && !$refresh) {
             return $qrFile;
-        }catch (\Exception $exception){
+        }
+
+        QRcode::png($str, $basePath . '/uploads' . $qrFile, $level, $size, $margin);
+        if (!file_exists($basePath . '/uploads' . $qrFile)) {
             return false;
         }
+        RedisService::set($cacheKey, ['str' => $str, 'qrcode' => $qrFile, 'date' => date('Y-m-d H:i:s')], 7 * 24 * 3600);
+        return $qrFile;
     }
 
     /**
@@ -641,25 +635,17 @@ class MemberService extends BaseService
 
         // 可提金额或手续费验证
         try {
-            // 本金USDT余额提现
             DB::beginTransaction();
             RedisService::set($cacheKey . '_lock', date('Y-m-d H:i:s'), rand(3,5));
             if ($coinType == 1) {
-                if($money>$userUsdt){
-                    DB::rollBack();
-                    $this->error = 2026; // 本金余额不足
-                    $this->errorData = ['money' => $userUsdt];
-                    RedisService::clear($cacheKey . '_lock');
-                    return false;
-                }
-
                 $maxUsdtRate = ConfigService::make()->getConfigByCode('usdt_withdraw_max_rate', 0);
-                $maxUsdtRate = $maxUsdtRate>0 && $maxUsdtRate<100? floatval($maxUsdtRate) : 0;
-                $actualMoney = moneyFormat($money * $maxUsdtRate/100, 2);
-                $fee = round($money - $actualMoney, 2);
-                if($actualMoney>$money){
+                $withdrawTotal = BalanceLogService::make()->getCountByType($userId, 2, 1, 0);
+                $maxWithdrawMoney = ($withdrawTotal + $userUsdt);
+                $maxWithdrawMoney = $maxUsdtRate > 0 && $maxUsdtRate < 100 ? moneyFormat($maxWithdrawMoney * $maxUsdtRate / 100, 2) : $maxWithdrawMoney;
+                if (($withdrawTotal + floatval($money)) >= $maxWithdrawMoney) {
                     DB::rollBack();
-                    $this->error = 2033; // 提现处理失败
+                    $this->error = 2026; // 可提金额超出
+                    $this->errorData = ['money' => moneyFormat($maxWithdrawMoney - $withdrawTotal, 2)];
                     RedisService::clear($cacheKey . '_lock');
                     return false;
                 }
@@ -681,15 +667,14 @@ class MemberService extends BaseService
                     'user_type' => 1,
                     'coin_type' => 1,
                     'money' => $money,
-                    'actual_money' => $actualMoney,
-                    'fee' => $fee,
+                    'actual_money' => $money,
+                    'fee' => 0,
                     'pay_type' => 10,
                     'pay_status' => 10,
                     'wallet_url' => $info['wallet_url'],
                     'pt_wallet_url' => '',
                     'date' => date('Y-m-d'),
                     'create_time' => time(),
-                    'action_ip' => get_client_ip(),
                     'audit_remark' => '',
                     'status' => 1,
                     'mark' => 1,
@@ -775,7 +760,6 @@ class MemberService extends BaseService
                     'pt_wallet_url' => '',
                     'date' => date('Y-m-d'),
                     'create_time' => time(),
-                    'action_ip' => get_client_ip(),
                     'audit_remark' => '',
                     'status' => 1,
                     'mark' => 1,
@@ -1058,21 +1042,21 @@ class MemberService extends BaseService
             ->value('id');
         $nextLevel = $nextLevel>0? intval($nextLevel) : 0;
         // 是否只升不降
-        if ($upgradeStatus==2 && $nextLevel<=$memberLevel) {
+        if ($$upgradeStatus==2 && $nextLevel<=$memberLevel) {
             RedisService::clear($cacheKey);
             $this->error = lang(4302, ['uid' => $userId]);
             return false;
         }
 
         // 更新等级
-        if (!$this->model->where(['id' => $userId])->update(['member_level' => $nextLevel, 'old_level' => $memberLevel,'upgrade_at'=>date('Y-m-d H:i:s'),'upgrade_remark'=>"团队业绩[{$teamPerformance}]等级[S{$memberLevel}]自动升级为[S{$nextLevel}]", 'update_time' => time()])) {
+        if (!$this->model->where(['id' => $userId])->update(['member_level' => $nextLevel, 'old_level' => $memberLevel,'upgrade_at'=>date('Y-m-d H:i:s'), 'update_time' => time()])) {
             RedisService::clear($cacheKey);
-            $this->error = lang(4304, ['uid' => $userId,'old'=>$memberLevel, 'level' => $nextLevel]);
+            $this->error = lang(4302, ['uid' => $userId, 'level' => $nextLevel]);
             return false;
         }
 
-        $this->error = lang(4305, ['uid' => $userId, 'level' => $nextLevel, 'old' => $memberLevel]);
-        RedisService::set($cacheKey, ['level' => $nextLevel, 'old' => $memberLevel, 'date' => date('Y-m-d H:i:s')], rand(300, 600));
+        $this->error = lang(4302, ['uid' => $userId, 'level' => $nextLevel, 'old' => $memberLevel]);
+        RedisService::set($cacheKey, ['level' => $nextLevel, 'old' => $memberLevel, 'date' => date('Y-m-d H:i:s')], rand(30, 60));
         return ['msg' => '更新成功', 'uid' => $userId, 'level' => $nextLevel, 'old' => $memberLevel];
     }
 
@@ -1093,36 +1077,20 @@ class MemberService extends BaseService
             $sbtUsdtFee = $sbtUsdtFee > 0 ? floatval($sbtUsdtFee) : 0;
             $sbtFee = $sbtUsdtFee && $sbtPrice > 0 ? moneyFormat($sbtUsdtFee / $sbtPrice, 2) : 0;
 
-            $page = RedisService::get("caches:pledge:user_page_{$limit}");
-            $page = $page? $page : 1;
-
-            $time = ConfigService::make()->getConfigByCode('pledge_next_time', 2);
-            $time = $time>0 && $time<= 30 * 24 * 60? $time : 2;
-
             $datas = $this->model->from('member as a')
                 ->leftJoin('pledge_orders as b', 'b.user_id', '=', 'a.id')
                 ->where('a.usdt', '>=', $pledgeUsdt)
                 ->where('a.sbt', '>=', $sbtFee)
-                ->where(function($query) use($time){
-                    $query->where('b.id', '<=', 0)
-                        ->orWhere('a.pledge_count', '<=', 0)
-                        ->orWhere('a.last_pledge_at','<=', date('Y-m-d H:i:s', (time() - $time * 60)));
+                ->where(function($query){
+                    $query->where('b.id', '<=', 0)->orWhere('a.pledge_count', '<=', 0);
                 })
                 ->where(['a.pledge_auto' => 1, 'a.status' => 1, 'a.mark' => 1])
                 ->select(['a.id', 'a.pledge_auto', 'a.usdt', 'a.sbt', 'a.profit', 'a.trade_status','a.settle_status','a.status', 'a.parent_ids', 'b.id as pledge_id'])
-                ->offset(($page-1)* $limit)
                 ->limit($limit)
-//                ->orderByRaw('rand()')
+                ->orderByRaw('rand()')
                 ->orderBy('a.id', 'asc')
                 ->get();
-            $datas = $datas?$datas->toArray() : [];
-            if(empty($datas)){
-                RedisService::clear("caches:pledgeOrder:user_page_{$limit}");
-            }else{
-                RedisService::get("caches:pledgeOrder:user_page_{$limit}", $page +1, rand(3600, 7200));
-            }
-
-            return $datas;
+            return $datas?$datas->toArray() : [];
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             return false;

+ 0 - 755
app/Services/Api/PledgeOrderService-back.php

@@ -1,755 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Services\Api;
-
-use App\Models\AccountLogModel;
-use App\Models\MemberModel;
-use App\Models\PledgeOrderModel;
-use App\Services\BaseService;
-use App\Services\ConfigService;
-use App\Services\RedisService;
-use Illuminate\Support\Facades\DB;
-
-/**
- * 租赁订单-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
-class PledgeOrderService extends BaseService
-{
-
-    protected static $instance;
-
-    /**
-     * 构造函数
-     * @author laravel开发员
-     * @since 2020/11/11
-     */
-    public function __construct()
-    {
-        $this->model = new PledgeOrderModel();
-    }
-
-    /**
-     * 静态入口
-     */
-    public static function make()
-    {
-        if (!self::$instance) {
-            self::$instance = new static();
-        }
-        return self::$instance;
-    }
-
-    /**
-     * 质押订单统计
-     * @param $userId 用户ID
-     * @return array|mixed
-     */
-    public function getCountByUser($userId)
-    {
-        $cacheKey = "caches:pledge:counts_{$userId}";
-        $counts = RedisService::get($cacheKey);
-        if($counts){
-            $expiredTime = isset($counts['expired_time'])? intval($counts['expired_time']) : 0;
-            $settleTime = isset($counts['settle_time'])? intval($counts['settle_time']) : 0;
-            $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
-            $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
-            $counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
-            $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
-            return $counts;
-        }
-
-        $counts = [
-            "pledge_count" => 0,
-            "pledge_total" => "0.00",
-            "pledge_money" => "0.00",
-            "pledge_profit" => "0.00",
-            "pledge_destruction" => "0.00",
-            "pledge_end_time" => 0,
-            "pledge_settle_time" => 0,
-            "pledge_ent_text" => '00:00:00',
-            "pledge_settle_data" => [
-                'hour'=> '00',
-                'minute'=> '00',
-                'second'=> '00',
-            ],
-        ];
-
-        if($userId){
-            $counts['pledge_count'] = (int)$this->model->where(['user_id'=> $userId,'mark'=>1])->count('id');
-            $counts['pledge_destruction'] = (int)abs(AccountLogModel::where(['type'=>1,'coin_type'=>2,'status'=> 1,'mark'=>1])->sum('money'));
-            $counts['pledge_total'] = moneyFormat($this->model->where(['user_id'=> $userId,'mark'=>1])->sum('money'),2);
-            $info = $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->orderBy('id','desc')->first();
-            $info = $info? $info->toArray() : [];
-            if($info){
-                $counts['pledge_money'] = moneyFormat($info['money'],2);
-                $counts['pledge_profit'] = moneyFormat($info['profit'], 2);
-
-                $expiredTime = $info['expired_at']? strtotime($info['expired_at']) : 0;
-                $settleTime = $info['settle_at']? strtotime($info['settle_at']) : 0;
-                $counts['expired_time'] = $expiredTime;
-                $counts['settle_time'] = $settleTime;
-                $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
-                $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
-                $counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
-                $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
-            }
-        }
-
-        RedisService::set($cacheKey, $counts, rand(10, 30));
-        return $counts;
-    }
-
-    /**
-     * 检测是否质押过且超过了24小时退本(即是否有退本过)
-     * @param $userId 质押用户ID
-     * @return array|false|mixed
-     */
-    public function checkPledgeRefund($userId)
-    {
-        $cacheKey = "caches:pledge:checkRefund_{$userId}";
-        $data = RedisService::get($cacheKey);
-        if($data || RedisService::exists($cacheKey)){
-            return $data;
-        }
-
-        $data = $this->model->where(['user_id'=> $userId,'status'=> 2,'mark'=>1])->value('id');
-        if($data){
-            RedisService::set($cacheKey, $data, rand(3600,7200));
-        }
-        return $data;
-    }
-
-    /**
-     * 检测是否质押过
-     * @param $userId 质押用户ID
-     * @return array|false|mixed
-     */
-    public function checkPledge($userId)
-    {
-        $cacheKey = "caches:pledge:check_exists_{$userId}";
-        $data = RedisService::get($cacheKey);
-        if($data || RedisService::exists($cacheKey)){
-            return $data;
-        }
-
-        $data = $this->model->where(['user_id'=> $userId,'mark'=>1])->value('id');
-        if($data){
-            RedisService::set($cacheKey, $data, 600);
-        }
-        return $data;
-    }
-
-    /**
-     * 验证质押订单状态
-     * @param $userId 质押用户
-     * @return array|mixed
-     */
-    public function checHasPledge($userId)
-    {
-        $cacheKey = "caches:pledge:check_{$userId}";
-        $data = RedisService::get($cacheKey);
-        if($data){
-            return $data;
-        }
-
-        $data = $this->model->where(['user_id'=> $userId,'mark'=>1])
-            ->where(function($query){
-                $query->where('expired_at','>', date('Y-m-d H:i:s'))
-                    ->orWhere(['status'=>1]);
-            })
-            ->select(['id','user_id','order_no','money','expired_at','status'])
-            ->first();
-
-        $data = $data? $data->toArray() :[];
-        if($data){
-            RedisService::set($cacheKey, $data, rand(300, 600));
-        }
-
-        return $data;
-    }
-
-    /**
-     * 自动质押处理
-     * @param $userInfo 用户信息:id-用户ID,pledge_auto-质押状态,usdt-USDT余额,sbt-sbt余额,status-状态,parent_ids-上级团队ID(升级用)
-     * @return bool
-     */
-    public function autoMakeOrder($userInfo)
-    {
-        $userId = isset($userInfo['id'])? intval($userInfo['id']) : 0;
-        $pledgeAuto = isset($userInfo['pledge_auto'])? intval($userInfo['pledge_auto']) : 0;
-        $userUsdt = isset($userInfo['usdt'])? floatval($userInfo['usdt']) : 0;
-        $userSbt = isset($userInfo['sbt'])? floatval($userInfo['sbt']) : 0;
-        $tradeStatus = isset($userInfo['trade_status'])? intval($userInfo['trade_status']) : 0;
-        $userStatus = isset($userInfo['status'])? intval($userInfo['status']) : 0;
-        $parentIds = isset($userInfo['parent_ids'])? trim($userInfo['parent_ids']) : '';
-        $settleStatus = isset($userInfo['settle_status'])? intval($userInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus==2? 2 : 1; // 1-正常结算,2-不结算动态和个人业绩
-        if($userId<=0 || $userUsdt<=0 || $userStatus != 1){
-            $this->error = lang(4101,['uid'=>$userId,'usdt'=>$userUsdt,'status'=>$userStatus]);
-            return false;
-        }
-
-        // 检测是否已经开启了自动质押
-        if($pledgeAuto != 1 || $tradeStatus == 2){
-            $this->error = 4104;
-            return false;
-        }
-
-        // 质押所需USDT验证
-        $pledgeUsdt = ConfigService::make()->getConfigByCode('pledge_money', 500);
-        $pledgeUsdt = $pledgeUsdt>0?$pledgeUsdt: 500;
-        if($userUsdt < $pledgeUsdt){
-            $this->error = lang(4102,['usdt'=> $userUsdt,'money'=>$pledgeUsdt]);
-            return false;
-        }
-
-        // SBT 手续费
-        $sbtPrice = PriceLogService::make()->getSbtPrice();
-        $sbtUsdtFee = ConfigService::make()->getConfigByCode('pledge_sbt_usdt_fee', 0);
-        $sbtUsdtFee = $sbtUsdtFee>0? floatval($sbtUsdtFee): 0;
-        $sbtFee = $sbtUsdtFee && $sbtPrice>0? moneyFormat($sbtUsdtFee / $sbtPrice,2) : 0;
-        if($sbtUsdtFee>0 && $sbtFee>0 && $userSbt < $sbtFee){
-            $this->error = lang(4103,['sbt'=> $userSbt,'fee'=>$sbtFee]);
-            return false;
-        }
-
-        // 质押收益比例参数
-        $profitRate = ConfigService::make()->getConfigByCode('pledge_profit_rate',3);
-        $profitRate = $profitRate>0 && $profitRate<100? floatval($profitRate) : 3;
-        $bonusUsdtRate = ConfigService::make()->getConfigByCode('bonus_usdt_rate',80);
-        $bonusUsdtRate = $bonusUsdtRate>0 && $bonusUsdtRate<100? floatval($bonusUsdtRate) : 80;
-
-        // 检测是否有质押中订单
-        if($info = PledgeOrderService::make()->checHasPledge($userId)){
-            $orderNo = isset($info['order_no'])? $info['order_no'] : '';
-            $this->error = lang(4105,['order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 预计收益
-        $profit = moneyFormat($pledgeUsdt * $profitRate/100, 2); // 总收益
-        $profitUsdt = moneyFormat($profit * $bonusUsdtRate/100, 2); // USDT余额进账部分
-
-        // 质押有效期
-        $pledgeTime = ConfigService::make()->getConfigByCode('pledge_time', 24);
-        $pledgeTime = $pledgeTime>0 && $pledgeTime < 30 * 24? floatval($pledgeTime) : 24;
-        $expiredAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600));
-
-        // 结算时间
-        $pledgeSettleTime = ConfigService::make()->getConfigByCode('pledge_settle_time', 24);
-        $pledgeSettleTime = $pledgeSettleTime>0 && $pledgeSettleTime < 30 * 24? floatval($pledgeSettleTime) : 24;
-        $settleAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600) + intval($pledgeSettleTime * 3600));
-
-        // 质押轮次
-        $lastRound = $this->model->where(['user_id'=> $userId,'mark'=>1])
-            ->orderBy('round','desc')
-            ->orderBy('create_time','desc')
-            ->value('round');
-        $round = $lastRound>0? intval($lastRound) + 1 : 1;
-
-        // 缓存锁
-        if(RedisService::get("caches:pledge:lock_{$userId}_{$round}")){
-            $this->error = lang(4111,['uid'=> $userId,'round'=> $round]);
-            return false;
-        }
-
-        // 若满足自动质押条件
-        DB::beginTransaction();
-        RedisService::set("caches:pledge:lock_{$userId}_{$round}",rand(60,120));
-        try{
-            // TODO 质押订单
-            $order = [
-                'user_id'=> $userId,
-                'order_no'=> get_order_num('PD'),
-                'money'=> $pledgeUsdt,
-                'bonus_rate'=> $profitRate,
-                'profit'=> $profit,
-                'profit_usdt'=> $profitUsdt,
-                'sbt_price'=> $sbtPrice,
-                'time'=> $pledgeTime,
-                'round'=> $round,
-                'expired_at'=> $expiredAt,
-                'settle_at'=> $settleAt,
-                'settle_status'=> $settleStatus, // 1-正常结算,2-不结算动态和个人业绩
-                'create_time'=>time(),
-                'remark'=> '自动质押',
-                'status'=>1,
-                'mark'=>1,
-            ];
-            if(!$this->model->insertGetId($order)){
-                DB::rollBack();
-                $this->error = lang(4106,['uid'=> $userId,'round'=> $round]);
-                RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
-                return false;
-            }
-
-            // 扣除余额和手续费
-            $updateData = [
-                'usdt'=> DB::raw("usdt - {$pledgeUsdt}"),
-                'upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),
-                'pledge_count'=>DB::raw("pledge_count + 1"),
-                'sbt'=>DB::raw("sbt - {$sbtFee}"),
-                'update_time'=>time()
-            ];
-            // 正常结算业绩
-            if($settleStatus==1){
-                $updateData['performance'] = DB::raw("performance + {$pledgeUsdt}");
-            }
-            if(!MemberModel::where(['id'=> $userId])->update($updateData)){
-                DB::rollBack();
-                $this->error = lang(4107,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
-                RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
-                return false;
-            }
-
-            // USDT账单
-            $data = [
-                'user_id' => $userId,
-                'order_no' => $order['order_no'],
-                'type' => 1,
-                'user_type' => 1,
-                'round' => $round,
-                'coin_type' => 1,
-                'money' => -$pledgeUsdt,
-                'before_money' => $userUsdt,
-                'create_time' => time(),
-                'action_ip' => get_client_ip(),
-                'remark' => '质押交易',
-                'status' => 1,
-                'mark' => 1,
-            ];
-
-            if (!AccountLogModel::insertGetId($data)) {
-                DB::rollBack();
-                $this->error = lang(4108,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
-                RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
-                return false;
-            }
-
-            // SBT 手续费
-            if($sbtFee){
-                $data = [
-                    'user_id' => $userId,
-                    'order_no' => $order['order_no'],
-                    'type' => 1,
-                    'round' => $round,
-                    'user_type' => 1,
-                    'coin_type' => 2,
-                    'money' => -$sbtFee,
-                    'before_money' => $userSbt,
-                    'create_time' => time(),
-                    'action_ip' => get_client_ip(),
-                    'remark' => '质押交易手续费',
-                    'status' => 1,
-                    'mark' => 1,
-                ];
-
-                if (!AccountLogModel::insertGetId($data)) {
-                    DB::rollBack();
-                    $this->error = lang(4108,['uid'=> $userId,'round'=>$round]);
-                    RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
-                    return false;
-                }
-            }
-
-            DB::commit();
-
-            // 更新上级团队用户的等级更新时间
-            $parentIds = get_parents($parentIds);
-            if($parentIds){
-                MemberModel::whereIn('id', $parentIds)->update(['upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),'update_time'=>time()]);
-            }
-
-            // 质押轮次奖励
-            FinanceService::make()->pledgeAward($userId, $round, $order);
-
-            // TODO 是否结算动态收益
-            if($settleStatus==1) {
-                // 团队分红结算
-                if(!FinanceService::make()->settleTeamBonus($userId, $parentIds, $order)){
-                    RedisService::set("caches:pledgeOrder:team_bonus_{$order['order_no']}", ['uid'=>$userId,'parentIds'=>$parentIds,'order'=>$order,'error'=>FinanceService::make()->getError()], 600);
-                }
-
-                // 工作室分红结算
-                if(!FinanceService::make()->settleRoomBonus($userId, $parentIds, $order)){
-                    RedisService::set("caches:pledgeOrder:room_bonus_{$order['order_no']}", ['uid'=>$userId,'parentIds'=>$parentIds,'order'=>$order,'error'=>FinanceService::make()->getError()], 600);
-                }
-            }
-
-            $this->error =  $this->error = lang(4109,['uid'=> $userId,'round'=>$round]);
-            RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
-            RedisService::clear("caches:pledgeOrder:total_{$userId}");
-            RedisService::clear("caches:pledge:check_{$userId}");
-            RedisService::clear("caches:pledge:counts_{$userId}");
-            return ['user_id'=>$userId,'round'=>$round,'money'=>$pledgeUsdt,'settleStatus'=>$settleStatus,'msg'=>'自动质押成功'];
-        } catch (\Exception $exception){
-            DB::rollBack();
-            $this->error = lang(4110,['uid'=> $userId,'round'=>$round,'error'=> $exception->getMessage()]);
-            return false;
-        }
-    }
-
-    /**
-     * 获取需要退本的订单
-     * @return array|false
-     */
-    public function getRefundOrderList()
-    {
-        try {
-            $limit = ConfigService::make()->getConfigByCode('refund_pledge_count', 500);
-            $limit = $limit > 0 ? $limit : 500;
-            $datas = $this->model->where(function($query){
-                    $query->where('expired_at', '<=', date('Y-m-d H:i:s'));
-                })
-                ->where(['status' => 1, 'mark' => 1])
-                ->select(['id','user_id', 'order_no','money','status'])
-                ->limit($limit)
-                ->orderByRaw('rand()')
-                ->orderBy('expired_at', 'asc')
-                ->get();
-            return $datas?$datas->toArray() : [];
-        } catch (\Exception $exception) {
-            $this->error = $exception->getMessage();
-            return false;
-        }
-    }
-
-    /**
-     * 获取需要结算收益的订单
-     * @return array|false
-     */
-    public function getSettleOrderList()
-    {
-        try {
-            $limit = ConfigService::make()->getConfigByCode('settle_pledge_count', 500);
-            $limit = $limit > 0 ? $limit : 500;
-            $datas = $this->model->where(function($query){
-                    $query->where('settle_at', '<=', date('Y-m-d H:i:s'));
-                })
-                ->where(['status' => 2, 'mark' => 1])
-                ->select(['id','user_id', 'order_no','money','status'])
-                ->limit($limit)
-                ->orderByRaw('rand()')
-                ->orderBy('settle_at', 'asc')
-                ->get();
-            return $datas?$datas->toArray() : [];
-        } catch (\Exception $exception) {
-            $this->error = $exception->getMessage();
-            return false;
-        }
-    }
-
-    /**
-     * 自动退本
-     * @return bool
-     */
-    public function refund($orderId,$orderNo, $userId=0)
-    {
-        $cacheKey = "caches:pledgeOrder:refund_{$orderId}";
-        if(RedisService::get($cacheKey)){
-            $this->error = lang(4310,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 订单信息
-        $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
-            ->select(['id','user_id','order_no','money','round','bonus_rate','profit','profit_usdt','expired_at','status'])
-            ->first();
-        $orderInfo = $orderInfo? $orderInfo->toArray() : [];
-        if(empty($orderInfo)){
-            $this->error = lang(4311,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 状态验证
-        $expiredAt = isset($orderInfo['expired_at'])? $orderInfo['expired_at'] : '';
-        $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
-        $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0;
-        $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0;
-        $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
-        $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
-        if($expiredAt>date('Y-m-d H:i:s') || $status != 1 || $pledgeRound<=0){
-            $this->error = lang(4312,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 退本金额
-        if($pledgeUsdt<=0){
-            $this->error = lang(4316,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 质押用户信息
-        $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
-            ->select(['id','usdt','sbt','profit','performance','pledge_count','status'])
-            ->first();
-        $memberInfo = $memberInfo? $memberInfo->toArray() : [];
-        $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
-        $performance = isset($memberInfo['performance'])? $memberInfo['performance'] : 0;
-        $pledgeCount = isset($memberInfo['pledge_count'])? $memberInfo['pledge_count'] : 0;
-        if(empty($memberInfo) || $pledgeUserId != $userId){
-            $this->error = lang(4313,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 订单退本处理
-        DB::beginTransaction();
-        try{
-            // 更新订单状态
-            if(!$this->model->where(['id'=> $orderId])->update(['status'=>2,'refund_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
-                DB::rollBack();
-                $this->error = lang(4314,['uid'=>$userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            // 返还本金
-            $updateData = [
-                'usdt'=>DB::raw("usdt + {$pledgeUsdt}"),
-                'pledge_count'=>max(0,($pledgeCount - 1)),
-                'update_time'=>time()
-            ];
-            // 正常结算业绩
-            if($settleStatus == 1){
-                $updateData['performance'] = max(0,($performance - $pledgeUsdt));
-            }
-            if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
-                DB::rollBack();
-                $this->error = lang(4315,['uid'=>$userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            // 退本账单
-            $data = [
-                'user_id' => $userId,
-                'order_no' => $orderNo,
-                'type' => 12,
-                'round' => $pledgeRound,
-                'user_type' => 1,
-                'coin_type' => 1,
-                'money' => $pledgeUsdt,
-                'before_money' => $userUsdt,
-                'create_time' => time(),
-                'action_ip' => get_client_ip(),
-                'remark' => '质押到期退还',
-                'status' => 1,
-                'mark' => 1,
-            ];
-
-            if (!AccountLogModel::insertGetId($data)) {
-                DB::rollBack();
-                $this->error = lang(4317,['uid'=> $userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            DB::commit();
-            $this->error = lang(4318,['uid'=> $userId,'order_no'=>$orderNo,'performance'=>$pledgeUsdt]);
-            $order = ['user_id'=>$userId,'round'=>$pledgeRound,'performance'=>$pledgeUsdt,'order_no'=>$orderNo];
-            RedisService::set($cacheKey, $order, rand(300, 600));
-            RedisService::clear("caches:pledge:check_{$userId}");
-            return $order;
-        }catch (\Exception $exception){
-            DB::rollBack();
-            $this->error = $exception->getMessage();
-            return false;
-        }
-    }
-
-    /**
-     * 到期结算收益
-     * @return bool
-     */
-    public function orderSettle($orderId, $orderNo, $userId=0)
-    {
-        $cacheKey = "caches:pledgeOrder:settle_{$orderId}";
-        if(RedisService::get($cacheKey)){
-            $this->error = lang(4410,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 订单信息
-        $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
-            ->select(['id','user_id','order_no','money','round','bonus_rate','sbt_price','profit','profit_usdt','settle_at','settle_status','status'])
-            ->first();
-        $orderInfo = $orderInfo? $orderInfo->toArray() : [];
-        if(empty($orderInfo)){
-            $this->error = lang(4411,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 状态验证
-        $settleAt = isset($orderInfo['settle_at'])? $orderInfo['settle_at'] : '';
-        $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
-        $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0; // 质押用户
-        $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0; // 质押金额
-        $profit = isset($orderInfo['profit'])? floatval($orderInfo['profit']) : 0;  // 总收益
-        $profitUsdt = isset($orderInfo['profit_usdt'])? floatval($orderInfo['profit_usdt']) : 0; // USDT收益
-        $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
-        $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
-        if($settleAt>date('Y-m-d H:i:s') || $status != 2 || $pledgeRound<=0){
-            $this->error = lang(4412,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 质押收益金额
-        if($pledgeUsdt<=0 || $profit <=0 || ($profit < $profitUsdt)){
-            $this->error = lang(4416,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // 质押用户信息
-        $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
-            ->select(['id','usdt','sbt','profit','performance','parent_ids','status'])
-            ->first();
-        $memberInfo = $memberInfo? $memberInfo->toArray() : [];
-        $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
-        $userProfit = isset($memberInfo['profit'])? $memberInfo['profit'] : 0;
-        $userSbt = isset($memberInfo['sbt'])? $memberInfo['sbt'] : 0;
-        $parentIds = isset($memberInfo['parent_ids'])? $memberInfo['parent_ids'] : '';
-        if(empty($memberInfo) || $pledgeUserId != $userId){
-            $this->error = lang(4413,['uid'=>$userId,'order_no'=>$orderNo]);
-            return false;
-        }
-
-        // SBT 收益金额
-        $sbtPrice = PriceLogService::make()->getSbtPrice();
-        $profitSbt = moneyFormat(($profit - $profitUsdt)/$sbtPrice, 2); // 金本位计算
-
-
-        // 订单收益结算处理
-        DB::beginTransaction();
-        try{
-            // 更新订单状态
-            if(!$this->model->where(['id'=> $orderId])->update(['status'=>3,'bonus_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
-                DB::rollBack();
-                $this->error = lang(4414,['uid'=>$userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            // USDT收益和SBT收益
-            $updateData = [
-                'profit'=>DB::raw("profit + {$profitUsdt}"),
-                'profit_total'=>DB::raw("profit_total + {$profit}"),
-                'pledge_profit'=>DB::raw("pledge_profit + {$profit}"),
-                'sbt'=>DB::raw("sbt + {$profitSbt}"),
-                'update_time'=>time()
-            ];
-            if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
-                DB::rollBack();
-                $this->error = lang(4415,['uid'=>$userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            // USDT收益账单
-            $data = [
-                'user_id' => $userId,
-                'order_no' => $orderNo,
-                'type' => 7,
-                'round' => $pledgeRound,
-                'user_type' => 1,
-                'coin_type' => 1,
-                'money' => $profitUsdt,
-                'before_money' => $userUsdt,
-                'create_time' => time(),
-                'action_ip' => get_client_ip(),
-                'remark' => '质押收益',
-                'status' => 1,
-                'mark' => 1,
-            ];
-
-            if (!AccountLogModel::insertGetId($data)) {
-                DB::rollBack();
-                $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
-                return false;
-            }
-
-            // SBT收益账单
-            if($profitSbt>0){
-                $data = [
-                    'user_id' => $userId,
-                    'order_no' => $orderNo,
-                    'type' => 7,
-                    'round' => $pledgeRound,
-                    'user_type' => 1,
-                    'coin_type' => 2,
-                    'money' => $profitSbt,
-                    'before_money' => $userSbt,
-                    'create_time' => time(),
-                    'action_ip' => get_client_ip(),
-                    'remark' => '质押收益',
-                    'status' => 1,
-                    'mark' => 1,
-                ];
-
-                if (!AccountLogModel::insertGetId($data)) {
-                    DB::rollBack();
-                    $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
-                    return false;
-                }
-            }
-
-            // TODO 是否结算动态收益
-            if($settleStatus==1){
-                // TODO 推荐奖结算
-                if(!FinanceService::make()->settleShareAward($userId, $parentIds, $orderInfo)){
-                    DB::rollBack();
-                    $this->error = FinanceService::make()->getError();
-                    return false;
-                }
-
-
-                //  TODO 管理奖和平级奖结算
-                if(!FinanceService::make()->settleManageAndLevelAward($userId, $parentIds, $orderInfo)){
-                    DB::rollBack();
-                    $this->error = FinanceService::make()->getError();
-                    return false;
-                }
-            }
-
-            DB::commit();
-
-            $this->error = lang(4418,['uid'=> $userId,'order_no'=>$orderNo]);
-            $order = ['user_id'=>$userId,'round'=>$pledgeRound,'profit'=>$profit,'profit_usdt'=>$profitUsdt,'profit_sbt'=>$profitSbt,'order_no'=>$orderNo];
-            RedisService::set($cacheKey, $order, rand(300, 600));
-            return $order;
-        }catch (\Exception $exception){
-            DB::rollBack();
-            $this->error = '订单结算异常:'.$exception->getMessage();
-            return false;
-        }
-    }
-
-    /**
-     * 全网流水(质押中订单总金额)
-     * @return array|mixed
-     */
-    public function getGlobalTotal()
-    {
-        $cacheKey = "caches:pledgeOrder:globalTotal";
-        $data = RedisService::get($cacheKey);
-        if($data){
-            return $data;
-        }
-
-        $data = $this->model->where(['status'=>1,'mark'=>1])->sum('money');
-        if($data){
-            RedisService::set($cacheKey, $data, 600);
-        }
-
-        return $data;
-    }
-
-}

+ 222 - 271
app/Services/Api/PledgeOrderService.php

@@ -60,13 +60,13 @@ class PledgeOrderService extends BaseService
     {
         $cacheKey = "caches:pledge:counts_{$userId}";
         $counts = RedisService::get($cacheKey);
-        if ($counts) {
-            $expiredTime = isset($counts['expired_time']) ? intval($counts['expired_time']) : 0;
-            $settleTime = isset($counts['settle_time']) ? intval($counts['settle_time']) : 0;
-            $counts['pledge_end_time'] = $expiredTime > time() ? intval($expiredTime - time()) : 0;
-            $counts['pledge_settle_time'] = $settleTime > time() ? intval($settleTime - time()) : 0;
+        if($counts){
+            $expiredTime = isset($counts['expired_time'])? intval($counts['expired_time']) : 0;
+            $settleTime = isset($counts['settle_time'])? intval($counts['settle_time']) : 0;
+            $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
+            $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
             $counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
-            $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'], 2);
+            $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
             return $counts;
         }
 
@@ -75,35 +75,33 @@ class PledgeOrderService extends BaseService
             "pledge_total" => "0.00",
             "pledge_money" => "0.00",
             "pledge_profit" => "0.00",
-            "pledge_destruction" => "0.00",
             "pledge_end_time" => 0,
             "pledge_settle_time" => 0,
             "pledge_ent_text" => '00:00:00',
             "pledge_settle_data" => [
-                'hour' => '00',
-                'minute' => '00',
-                'second' => '00',
+                'hour'=> '00',
+                'minute'=> '00',
+                'second'=> '00',
             ],
         ];
 
-        if ($userId) {
-            $counts['pledge_count'] = (int)$this->model->where(['user_id' => $userId, 'mark' => 1])->count('id');
-            $counts['pledge_destruction'] = (int)abs(AccountLogModel::where(['type' => 1, 'coin_type' => 2, 'status' => 1, 'mark' => 1])->sum('money'));
-            $counts['pledge_total'] = moneyFormat($this->model->where(['user_id' => $userId, 'mark' => 1])->sum('money'), 2);
-            $info = $this->model->where(['user_id' => $userId, 'status' => 1, 'mark' => 1])->orderBy('create_time', 'desc')->orderBy('id', 'desc')->first();
-            $info = $info ? $info->toArray() : [];
-            if ($info) {
-                $counts['pledge_money'] = moneyFormat($info['money'], 2);
+        if($userId){
+            $counts['pledge_count'] = (int)$this->model->where(['user_id'=> $userId,'mark'=>1])->count('id');
+            $counts['pledge_total'] = moneyFormat($this->model->where(['user_id'=> $userId,'mark'=>1])->sum('money'),2);
+            $info = $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->orderBy('id','desc')->first();
+            $info = $info? $info->toArray() : [];
+            if($info){
+                $counts['pledge_money'] = moneyFormat($info['money'],2);
                 $counts['pledge_profit'] = moneyFormat($info['profit'], 2);
 
-                $expiredTime = $info['expired_at'] ? strtotime($info['expired_at']) : 0;
-                $settleTime = $info['settle_at'] ? strtotime($info['settle_at']) : 0;
+                $expiredTime = $info['expired_at']? strtotime($info['expired_at']) : 0;
+                $settleTime = $info['settle_at']? strtotime($info['settle_at']) : 0;
                 $counts['expired_time'] = $expiredTime;
                 $counts['settle_time'] = $settleTime;
-                $counts['pledge_end_time'] = $expiredTime > time() ? intval($expiredTime - time()) : 0;
-                $counts['pledge_settle_time'] = $settleTime > time() ? intval($settleTime - time()) : 0;
+                $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
+                $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
                 $counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
-                $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'], 2);
+                $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
             }
         }
 
@@ -120,13 +118,13 @@ class PledgeOrderService extends BaseService
     {
         $cacheKey = "caches:pledge:checkRefund_{$userId}";
         $data = RedisService::get($cacheKey);
-        if ($data || RedisService::exists($cacheKey)) {
+        if($data || RedisService::exists($cacheKey)){
             return $data;
         }
 
-        $data = $this->model->where(['user_id' => $userId, 'status' => 2, 'mark' => 1])->value('id');
-        if ($data) {
-            RedisService::set($cacheKey, $data, rand(3600, 7200));
+        $data = $this->model->where(['user_id'=> $userId,'status'=> 2,'mark'=>1])->value('id');
+        if($data){
+            RedisService::set($cacheKey, $data, rand(3600,7200));
         }
         return $data;
     }
@@ -140,12 +138,12 @@ class PledgeOrderService extends BaseService
     {
         $cacheKey = "caches:pledge:check_exists_{$userId}";
         $data = RedisService::get($cacheKey);
-        if ($data || RedisService::exists($cacheKey)) {
+        if($data || RedisService::exists($cacheKey)){
             return $data;
         }
 
-        $data = $this->model->where(['user_id' => $userId, 'mark' => 1])->value('id');
-        if ($data) {
+        $data = $this->model->where(['user_id'=> $userId,'mark'=>1])->value('id');
+        if($data){
             RedisService::set($cacheKey, $data, 600);
         }
         return $data;
@@ -160,52 +158,20 @@ class PledgeOrderService extends BaseService
     {
         $cacheKey = "caches:pledge:check_{$userId}";
         $data = RedisService::get($cacheKey);
-        if ($data) {
+        if($data){
             return $data;
         }
 
-        $data = $this->model->where(['user_id' => $userId, 'mark' => 1])
-            ->where(function ($query) {
-                $query->where('expired_at', '>', date('Y-m-d H:i:s'))
-                    ->orWhere(['status' => 1]);
+        $data = $this->model->where(['user_id'=> $userId,'mark'=>1])
+            ->where(function($query){
+                $query->where('expired_at','>', date('Y-m-d H:i:s'))
+                    ->orWhere(['status'=>1]);
             })
-            ->select(['id', 'user_id', 'order_no', 'money', 'expired_at', 'status'])
+            ->select(['id','user_id','order_no','money','expired_at','status'])
             ->first();
 
-        $data = $data ? $data->toArray() : [];
-        if ($data) {
-            RedisService::set($cacheKey, $data, rand(300, 600));
-        }
-
-        return $data;
-    }
-
-    /**
-     * 验证质押订单状态
-     * @param $userId 质押用户
-     * @param $time 时间间隔/分钟
-     * @return array|mixed
-     */
-    public function checLastPledge(int $userId, $time)
-    {
-        $cacheKey = "caches:pledge:last_{$userId}_{$time}";
-        $data = RedisService::get($cacheKey);
-        if ($data) {
-            return $data;
-        }
-
-        $data = $this->model->where(['user_id' => $userId, 'mark' => 1])
-            ->where(function ($query) {
-                $query->where('expired_at', '>', date('Y-m-d H:i:s'))
-                    ->orWhere(['status' => 1]);
-            })
-            ->where('create_time', '>', (time() - intval(floatval($time) * 60)))
-            ->select(['id', 'user_id', 'order_no', 'money', 'expired_at', 'status'])
-            ->orderBy('create_time', 'desc')
-            ->first();
-
-        $data = $data ? $data->toArray() : [];
-        if ($data) {
+        $data = $data? $data->toArray() :[];
+        if($data){
             RedisService::set($cacheKey, $data, rand(300, 600));
         }
 
@@ -219,137 +185,129 @@ class PledgeOrderService extends BaseService
      */
     public function autoMakeOrder($userInfo)
     {
-        $userId = isset($userInfo['id']) ? intval($userInfo['id']) : 0;
-        $pledgeAuto = isset($userInfo['pledge_auto']) ? intval($userInfo['pledge_auto']) : 0;
-        $userUsdt = isset($userInfo['usdt']) ? floatval($userInfo['usdt']) : 0;
-        $userSbt = isset($userInfo['sbt']) ? floatval($userInfo['sbt']) : 0;
-        $tradeStatus = isset($userInfo['trade_status']) ? intval($userInfo['trade_status']) : 0;
-        $userStatus = isset($userInfo['status']) ? intval($userInfo['status']) : 0;
-        $parentIds = isset($userInfo['parent_ids']) ? trim($userInfo['parent_ids']) : '';
-        $settleStatus = isset($userInfo['settle_status']) ? intval($userInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus == 2 ? 2 : 1; // 1-正常结算,2-不结算动态和个人业绩
-        if ($userId <= 0 || $userUsdt <= 0 || $userStatus != 1) {
-            $this->error = lang(4101, ['uid' => $userId, 'usdt' => $userUsdt, 'status' => $userStatus]);
-            return false;
-        }
-
-        if ($userUsdt <= 0) {
-            $this->error = lang(4112, ['uid' => $userId]);
+        $userId = isset($userInfo['id'])? intval($userInfo['id']) : 0;
+        $pledgeAuto = isset($userInfo['pledge_auto'])? intval($userInfo['pledge_auto']) : 0;
+        $userUsdt = isset($userInfo['usdt'])? floatval($userInfo['usdt']) : 0;
+        $userSbt = isset($userInfo['sbt'])? floatval($userInfo['sbt']) : 0;
+        $tradeStatus = isset($userInfo['trade_status'])? intval($userInfo['trade_status']) : 0;
+        $userStatus = isset($userInfo['status'])? intval($userInfo['status']) : 0;
+        $parentIds = isset($userInfo['parent_ids'])? trim($userInfo['parent_ids']) : '';
+        $settleStatus = isset($userInfo['settle_status'])? intval($userInfo['settle_status']) : 0;
+        $settleStatus = $settleStatus==2? 2 : 1; // 1-正常结算,2-不结算动态和个人业绩
+        if($userId<=0 || $userUsdt<=0 || $userStatus != 1){
+            $this->error = lang(4101,['uid'=>$userId,'usdt'=>$userUsdt,'status'=>$userStatus]);
             return false;
         }
 
         // 检测是否已经开启了自动质押
-        if ($pledgeAuto != 1 || $tradeStatus == 2) {
-            $this->error = lang(4104, ['uid' => $userId]);
+        if($pledgeAuto != 1 || $tradeStatus == 2){
+            $this->error = 4104;
             return false;
         }
 
         // 质押所需USDT验证
         $pledgeUsdt = ConfigService::make()->getConfigByCode('pledge_money', 500);
-        $pledgeUsdt = $pledgeUsdt > 0 ? $pledgeUsdt : 500;
-        if ($userUsdt < $pledgeUsdt) {
-            $this->error = lang(4102, ['uid' => $userId, 'usdt' => $userUsdt, 'money' => $pledgeUsdt]);
+        $pledgeUsdt = $pledgeUsdt>0?$pledgeUsdt: 500;
+        if($userUsdt < $pledgeUsdt){
+            $this->error = lang(4102,['usdt'=> $userUsdt,'money'=>$pledgeUsdt]);
             return false;
         }
 
         // SBT 手续费
         $sbtPrice = PriceLogService::make()->getSbtPrice();
         $sbtUsdtFee = ConfigService::make()->getConfigByCode('pledge_sbt_usdt_fee', 0);
-        $sbtUsdtFee = $sbtUsdtFee > 0 ? floatval($sbtUsdtFee) : 0;
-        $sbtFee = $sbtUsdtFee && $sbtPrice > 0 ? moneyFormat($sbtUsdtFee / $sbtPrice, 2) : 0;
-        if ($sbtUsdtFee > 0 && $sbtFee > 0 && $userSbt < $sbtFee) {
-            $this->error = lang(4103, ['uid' => $userId, 'sbt' => $userSbt, 'fee' => $sbtFee]);
+        $sbtUsdtFee = $sbtUsdtFee>0? floatval($sbtUsdtFee): 0;
+        $sbtFee = $sbtUsdtFee && $sbtPrice>0? moneyFormat($sbtUsdtFee / $sbtPrice,2) : 0;
+        if($sbtUsdtFee>0 && $sbtFee>0 && $userSbt < $sbtFee){
+            $this->error = lang(4103,['sbt'=> $userSbt,'fee'=>$sbtFee]);
             return false;
         }
 
         // 质押收益比例参数
-        $profitRate = ConfigService::make()->getConfigByCode('pledge_profit_rate', 3);
-        $profitRate = $profitRate > 0 && $profitRate < 100 ? floatval($profitRate) : 3;
-        $bonusUsdtRate = ConfigService::make()->getConfigByCode('bonus_usdt_rate', 80);
-        $bonusUsdtRate = $bonusUsdtRate > 0 && $bonusUsdtRate < 100 ? floatval($bonusUsdtRate) : 80;
-
-        // 校验是否可以下一轮
-        $time = ConfigService::make()->getConfigByCode('pledge_next_time', 2);
-        $time = $time > 0 && $time <= 30 * 24 * 60 ? $time : 2;
-        if ($lastInfo = $this->checLastPledge($userId, $time)) {
-            $orderNo = isset($lastInfo['order_no']) ? $lastInfo['order_no'] : '';
-            $this->error = lang(4105, ['uid' => $userId, 'time' => $time, 'order_no' => $orderNo]);
+        $profitRate = ConfigService::make()->getConfigByCode('pledge_profit_rate',3);
+        $profitRate = $profitRate>0 && $profitRate<100? floatval($profitRate) : 3;
+        $bonusUsdtRate = ConfigService::make()->getConfigByCode('bonus_usdt_rate',80);
+        $bonusUsdtRate = $bonusUsdtRate>0 && $bonusUsdtRate<100? floatval($bonusUsdtRate) : 80;
+
+        // 检测是否有质押中订单
+        if($info = PledgeOrderService::make()->checHasPledge($userId)){
+            $orderNo = isset($info['order_no'])? $info['order_no'] : '';
+            $this->error = lang(4105,['order_no'=>$orderNo]);
             return false;
         }
 
         // 预计收益
-        $profit = moneyFormat($pledgeUsdt * $profitRate / 100, 2); // 总收益
-        $profitUsdt = moneyFormat($profit * $bonusUsdtRate / 100, 2); // USDT余额进账部分
+        $profit = moneyFormat($pledgeUsdt * $profitRate/100, 2); // 总收益
+        $profitUsdt = moneyFormat($profit * $bonusUsdtRate/100, 2); // USDT余额进账部分
 
         // 质押有效期
         $pledgeTime = ConfigService::make()->getConfigByCode('pledge_time', 24);
-        $pledgeTime = $pledgeTime > 0 && $pledgeTime < 30 * 24 ? floatval($pledgeTime) : 24;
+        $pledgeTime = $pledgeTime>0 && $pledgeTime < 30 * 24? floatval($pledgeTime) : 24;
         $expiredAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600));
 
         // 结算时间
-        $pledgeSettleTime = ConfigService::make()->getConfigByCode('pledge_settle_time', 0);
-        $pledgeSettleTime = $pledgeSettleTime >= 0 && $pledgeSettleTime < 30 * 24 ? floatval($pledgeSettleTime) : 24;
+        $pledgeSettleTime = ConfigService::make()->getConfigByCode('pledge_settle_time', 24);
+        $pledgeSettleTime = $pledgeSettleTime>0 && $pledgeSettleTime < 30 * 24? floatval($pledgeSettleTime) : 24;
         $settleAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600) + intval($pledgeSettleTime * 3600));
 
         // 质押轮次
-        $lastRound = $this->model->where(['user_id' => $userId, 'mark' => 1])
-            ->orderBy('round', 'desc')
-            ->orderBy('create_time', 'desc')
+        $lastRound = $this->model->where(['user_id'=> $userId,'mark'=>1])
+            ->orderBy('round','desc')
+            ->orderBy('create_time','desc')
             ->value('round');
-        $round = $lastRound > 0 ? intval($lastRound) + 1 : 1;
+        $round = $lastRound>0? intval($lastRound) + 1 : 1;
 
         // 缓存锁
-        if (RedisService::get("caches:pledge:lock_{$userId}_{$round}")) {
-            $this->error = lang(4111, ['uid' => $userId, 'round' => $round]);
+        if(RedisService::get("caches:pledge:lock_{$userId}_{$round}")){
+            $this->error = lang(4111,['uid'=> $userId,'round'=> $round]);
             return false;
         }
 
         // 若满足自动质押条件
         DB::beginTransaction();
-        RedisService::set("caches:pledge:lock_{$userId}_{$round}", rand(60, 120));
-        try {
+        RedisService::set("caches:pledge:lock_{$userId}_{$round}",rand(60,120));
+        try{
             // TODO 质押订单
             $order = [
-                'user_id' => $userId,
-                'order_no' => get_order_num('PD'),
-                'money' => $pledgeUsdt,
-                'bonus_rate' => $profitRate,
-                'profit' => $profit,
-                'profit_usdt' => $profitUsdt,
-                'sbt_price' => $sbtPrice,
-                'time' => $pledgeTime,
-                'round' => $round,
-                'expired_at' => $expiredAt,
-                'settle_at' => $settleAt,
-                'settle_status' => $settleStatus, // 1-正常结算,2-不结算动态和个人业绩
-                'create_time' => time(),
-                'remark' => '自动质押',
-                'status' => 1,
-                'mark' => 1,
+                'user_id'=> $userId,
+                'order_no'=> get_order_num('PD'),
+                'money'=> $pledgeUsdt,
+                'bonus_rate'=> $profitRate,
+                'profit'=> $profit,
+                'profit_usdt'=> $profitUsdt,
+                'sbt_price'=> $sbtPrice,
+                'time'=> $pledgeTime,
+                'round'=> $round,
+                'expired_at'=> $expiredAt,
+                'settle_at'=> $settleAt,
+                'settle_status'=> $settleStatus, // 1-正常结算,2-不结算动态和个人业绩
+                'create_time'=>time(),
+                'remark'=> '自动质押',
+                'status'=>1,
+                'mark'=>1,
             ];
-            if (!$this->model->insertGetId($order)) {
+            if(!$this->model->insertGetId($order)){
                 DB::rollBack();
-                $this->error = lang(4106, ['uid' => $userId, 'round' => $round]);
+                $this->error = lang(4106,['uid'=> $userId,'round'=> $round]);
                 RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
                 return false;
             }
 
             // 扣除余额和手续费
             $updateData = [
-                'usdt' => DB::raw("usdt - {$pledgeUsdt}"),
-                'upgrade_at' => date('Y-m-d H:i:s', time() + 2 * 86400),
-                'pledge_count' => DB::raw("pledge_count + 1"),
-                'sbt' => DB::raw("sbt - {$sbtFee}"),
-                'last_pledge_at' => date('Y-m-d H:i:s'),
-                'update_time' => time()
+                'usdt'=> DB::raw("usdt - {$pledgeUsdt}"),
+                'upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),
+                'pledge_count'=>DB::raw("pledge_count + 1"),
+                'sbt'=>DB::raw("sbt - {$sbtFee}"),
+                'update_time'=>time()
             ];
             // 正常结算业绩
-            if ($settleStatus == 1) {
+            if($settleStatus==1){
                 $updateData['performance'] = DB::raw("performance + {$pledgeUsdt}");
             }
-            if (!MemberModel::where(['id' => $userId])->update($updateData)) {
+            if(!MemberModel::where(['id'=> $userId])->update($updateData)){
                 DB::rollBack();
-                $this->error = lang(4107, ['uid' => $userId, 'round' => $round, 'money' => $pledgeUsdt]);
+                $this->error = lang(4107,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
                 RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
                 return false;
             }
@@ -373,13 +331,13 @@ class PledgeOrderService extends BaseService
 
             if (!AccountLogModel::insertGetId($data)) {
                 DB::rollBack();
-                $this->error = lang(4108, ['uid' => $userId, 'round' => $round, 'money' => $pledgeUsdt]);
+                $this->error = lang(4108,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
                 RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
                 return false;
             }
 
             // SBT 手续费
-            if ($sbtFee) {
+            if($sbtFee){
                 $data = [
                     'user_id' => $userId,
                     'order_no' => $order['order_no'],
@@ -398,7 +356,7 @@ class PledgeOrderService extends BaseService
 
                 if (!AccountLogModel::insertGetId($data)) {
                     DB::rollBack();
-                    $this->error = lang(4108, ['uid' => $userId, 'round' => $round]);
+                    $this->error = lang(4108,['uid'=> $userId,'round'=>$round]);
                     RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
                     return false;
                 }
@@ -408,35 +366,28 @@ class PledgeOrderService extends BaseService
 
             // 更新上级团队用户的等级更新时间
             $parentIds = get_parents($parentIds);
-            if ($parentIds) {
-                MemberModel::whereIn('id', $parentIds)->update(['upgrade_at' => date('Y-m-d H:i:s', time() + 2 * 86400), 'update_time' => time()]);
+            if($parentIds){
+                MemberModel::whereIn('id', $parentIds)->update(['upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),'update_time'=>time()]);
             }
 
             // 质押轮次奖励
             FinanceService::make()->pledgeAward($userId, $round, $order);
 
-            // TODO 是否结算动态收益
-            if ($settleStatus == 1) {
-                // 团队分红结算
-                if (!FinanceService::make()->settleTeamBonus($userId, $parentIds, $order)) {
-                    RedisService::set("caches:pledgeOrder:team_bonus_{$order['order_no']}", ['uid' => $userId, 'parentIds' => $parentIds, 'order' => $order, 'error' => FinanceService::make()->getError()], 600);
-                }
+            // 团队分红结算
+            FinanceService::make()->settleTeamBonus($userId, $parentIds, $order);
 
-                // 工作室分红结算
-                if (!FinanceService::make()->settleRoomBonus($userId, $parentIds, $order)) {
-                    RedisService::set("caches:pledgeOrder:room_bonus_{$order['order_no']}", ['uid' => $userId, 'parentIds' => $parentIds, 'order' => $order, 'error' => FinanceService::make()->getError()], 600);
-                }
-            }
+            // 工作室分红结算
+            FinanceService::make()->settleRoomBonus($userId, $parentIds, $order);
 
-            $this->error = $this->error = lang(4109, ['uid' => $userId, 'round' => $round]);
+            $this->error =  $this->error = lang(4109,['uid'=> $userId,'round'=>$round]);
             RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
             RedisService::clear("caches:pledgeOrder:total_{$userId}");
             RedisService::clear("caches:pledge:check_{$userId}");
             RedisService::clear("caches:pledge:counts_{$userId}");
-            return ['user_id' => $userId, 'round' => $round, 'money' => $pledgeUsdt, 'settleStatus' => $settleStatus, 'msg' => '自动质押成功'];
-        } catch (\Exception $exception) {
+            return ['user_id'=>$userId,'round'=>$round,'money'=>$pledgeUsdt,'msg'=>'自动质押成功'];
+        } catch (\Exception $exception){
             DB::rollBack();
-            $this->error = lang(4110, ['uid' => $userId, 'round' => $round, 'error' => $exception->getMessage()]);
+            $this->error = lang(4110,['uid'=> $userId,'round'=>$round,'error'=> $exception->getMessage()]);
             return false;
         }
     }
@@ -450,16 +401,16 @@ class PledgeOrderService extends BaseService
         try {
             $limit = ConfigService::make()->getConfigByCode('refund_pledge_count', 500);
             $limit = $limit > 0 ? $limit : 500;
-            $datas = $this->model->where(function ($query) {
-                $query->where('expired_at', '<=', date('Y-m-d H:i:s'));
-            })
+            $datas = $this->model->where(function($query){
+                    $query->where('expired_at', '<=', date('Y-m-d H:i:s'));
+                })
                 ->where(['status' => 1, 'mark' => 1])
-                ->select(['id', 'user_id', 'order_no', 'money', 'status'])
+                ->select(['id','user_id', 'order_no','money','status'])
                 ->limit($limit)
                 ->orderByRaw('rand()')
                 ->orderBy('expired_at', 'asc')
                 ->get();
-            return $datas ? $datas->toArray() : [];
+            return $datas?$datas->toArray() : [];
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             return false;
@@ -475,16 +426,16 @@ class PledgeOrderService extends BaseService
         try {
             $limit = ConfigService::make()->getConfigByCode('settle_pledge_count', 500);
             $limit = $limit > 0 ? $limit : 500;
-            $datas = $this->model->where(function ($query) {
-                $query->where('settle_at', '<=', date('Y-m-d H:i:s'));
-            })
+            $datas = $this->model->where(function($query){
+                    $query->where('settle_at', '<=', date('Y-m-d H:i:s'));
+                })
                 ->where(['status' => 2, 'mark' => 1])
-                ->select(['id', 'user_id', 'order_no', 'money', 'status'])
+                ->select(['id','user_id', 'order_no','money','status'])
                 ->limit($limit)
                 ->orderByRaw('rand()')
                 ->orderBy('settle_at', 'asc')
                 ->get();
-            return $datas ? $datas->toArray() : [];
+            return $datas?$datas->toArray() : [];
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             return false;
@@ -495,79 +446,79 @@ class PledgeOrderService extends BaseService
      * 自动退本
      * @return bool
      */
-    public function refund($orderId, $orderNo, $userId = 0)
+    public function refund($orderId,$orderNo, $userId=0)
     {
         $cacheKey = "caches:pledgeOrder:refund_{$orderId}";
-        if (RedisService::get($cacheKey)) {
-            $this->error = lang(4310, ['uid' => $userId, 'order_no' => $orderNo]);
+        if(RedisService::get($cacheKey)){
+            $this->error = lang(4310,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 订单信息
-        $orderInfo = $this->model::where(['id' => $orderId, 'mark' => 1])
-            ->select(['id', 'user_id', 'order_no', 'money', 'round', 'bonus_rate', 'profit', 'profit_usdt', 'expired_at', 'status'])
+        $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
+            ->select(['id','user_id','order_no','money','round','bonus_rate','profit','profit_usdt','expired_at','status'])
             ->first();
-        $orderInfo = $orderInfo ? $orderInfo->toArray() : [];
-        if (empty($orderInfo)) {
-            $this->error = lang(4311, ['uid' => $userId, 'order_no' => $orderNo]);
+        $orderInfo = $orderInfo? $orderInfo->toArray() : [];
+        if(empty($orderInfo)){
+            $this->error = lang(4311,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 状态验证
-        $expiredAt = isset($orderInfo['expired_at']) ? $orderInfo['expired_at'] : '';
-        $status = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
-        $pledgeUserId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0;
-        $pledgeUsdt = isset($orderInfo['money']) ? floatval($orderInfo['money']) : 0;
-        $pledgeRound = isset($orderInfo['round']) ? intval($orderInfo['round']) : 0;
-        $settleStatus = isset($orderInfo['settle_status']) ? intval($orderInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus == 2 ? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
-        if ($expiredAt > date('Y-m-d H:i:s') || $status != 1 || $pledgeRound <= 0) {
-            $this->error = lang(4312, ['uid' => $userId, 'order_no' => $orderNo]);
+        $expiredAt = isset($orderInfo['expired_at'])? $orderInfo['expired_at'] : '';
+        $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
+        $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0;
+        $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0;
+        $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
+        $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
+        $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
+        if($expiredAt>date('Y-m-d H:i:s') || $status != 1 || $pledgeRound<=0){
+            $this->error = lang(4312,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 退本金额
-        if ($pledgeUsdt <= 0) {
-            $this->error = lang(4316, ['uid' => $userId, 'order_no' => $orderNo]);
+        if($pledgeUsdt<=0){
+            $this->error = lang(4316,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 质押用户信息
-        $memberInfo = MemberModel::where(['id' => $pledgeUserId, 'mark' => 1])
-            ->select(['id', 'usdt', 'sbt', 'profit', 'performance', 'pledge_count', 'status'])
+        $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
+            ->select(['id','usdt','sbt','profit','performance','pledge_count','status'])
             ->first();
-        $memberInfo = $memberInfo ? $memberInfo->toArray() : [];
-        $userUsdt = isset($memberInfo['usdt']) ? $memberInfo['usdt'] : 0;
-        $performance = isset($memberInfo['performance']) ? $memberInfo['performance'] : 0;
-        $pledgeCount = isset($memberInfo['pledge_count']) ? $memberInfo['pledge_count'] : 0;
-        if (empty($memberInfo) || $pledgeUserId != $userId) {
-            $this->error = lang(4313, ['uid' => $userId, 'order_no' => $orderNo]);
+        $memberInfo = $memberInfo? $memberInfo->toArray() : [];
+        $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
+        $performance = isset($memberInfo['performance'])? $memberInfo['performance'] : 0;
+        $pledgeCount = isset($memberInfo['pledge_count'])? $memberInfo['pledge_count'] : 0;
+        if(empty($memberInfo) || $pledgeUserId != $userId){
+            $this->error = lang(4313,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 订单退本处理
         DB::beginTransaction();
-        try {
+        try{
             // 更新订单状态
-            if (!$this->model->where(['id' => $orderId])->update(['status' => 2, 'refund_at' => date('Y-m-d H:i:s'), 'update_time' => time()])) {
+            if(!$this->model->where(['id'=> $orderId])->update(['status'=>2,'refund_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
                 DB::rollBack();
-                $this->error = lang(4314, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4314,['uid'=>$userId,'order_no'=>$orderNo]);
                 return false;
             }
 
             // 返还本金
             $updateData = [
-                'usdt' => DB::raw("usdt + {$pledgeUsdt}"),
-                'pledge_count' => max(0, ($pledgeCount - 1)),
-                'update_time' => time()
+                'usdt'=>DB::raw("usdt + {$pledgeUsdt}"),
+                'pledge_count'=>max(0,($pledgeCount - 1)),
+                'update_time'=>time()
             ];
             // 正常结算业绩
-            if ($settleStatus == 1) {
-                $updateData['performance'] = max(0, ($performance - $pledgeUsdt));
+            if($settleStatus == 1){
+                $updateData['performance'] = max(0,($performance - $pledgeUsdt));
             }
-            if (!MemberModel::where(['id' => $pledgeUserId])->update($updateData)) {
+            if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
                 DB::rollBack();
-                $this->error = lang(4315, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4315,['uid'=>$userId,'order_no'=>$orderNo]);
                 return false;
             }
 
@@ -590,17 +541,17 @@ class PledgeOrderService extends BaseService
 
             if (!AccountLogModel::insertGetId($data)) {
                 DB::rollBack();
-                $this->error = lang(4317, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4317,['uid'=> $userId,'order_no'=>$orderNo]);
                 return false;
             }
 
             DB::commit();
-            $this->error = lang(4318, ['uid' => $userId, 'order_no' => $orderNo, 'performance' => $pledgeUsdt]);
-            $order = ['user_id' => $userId, 'round' => $pledgeRound, 'performance' => $pledgeUsdt, 'order_no' => $orderNo];
+            $this->error = lang(4318,['uid'=> $userId,'order_no'=>$orderNo,'performance'=>$pledgeUsdt]);
+            $order = ['user_id'=>$userId,'round'=>$pledgeRound,'performance'=>$pledgeUsdt,'order_no'=>$orderNo];
             RedisService::set($cacheKey, $order, rand(300, 600));
             RedisService::clear("caches:pledge:check_{$userId}");
             return $order;
-        } catch (\Exception $exception) {
+        }catch (\Exception $exception){
             DB::rollBack();
             $this->error = $exception->getMessage();
             return false;
@@ -611,85 +562,85 @@ class PledgeOrderService extends BaseService
      * 到期结算收益
      * @return bool
      */
-    public function orderSettle($orderId, $orderNo, $userId = 0)
+    public function orderSettle($orderId, $orderNo, $userId=0)
     {
         $cacheKey = "caches:pledgeOrder:settle_{$orderId}";
-        if (RedisService::get($cacheKey)) {
-            $this->error = lang(4410, ['uid' => $userId, 'order_no' => $orderNo]);
+        if(RedisService::get($cacheKey)){
+            $this->error = lang(4410,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 订单信息
-        $orderInfo = $this->model::where(['id' => $orderId, 'mark' => 1])
-            ->select(['id', 'user_id', 'order_no', 'money', 'round', 'bonus_rate', 'sbt_price', 'profit', 'profit_usdt', 'settle_at', 'settle_status', 'status'])
+        $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
+            ->select(['id','user_id','order_no','money','round','bonus_rate','sbt_price','profit','profit_usdt','settle_at','settle_status','status'])
             ->first();
-        $orderInfo = $orderInfo ? $orderInfo->toArray() : [];
-        if (empty($orderInfo)) {
-            $this->error = lang(4411, ['uid' => $userId, 'order_no' => $orderNo]);
+        $orderInfo = $orderInfo? $orderInfo->toArray() : [];
+        if(empty($orderInfo)){
+            $this->error = lang(4411,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 状态验证
-        $settleAt = isset($orderInfo['settle_at']) ? $orderInfo['settle_at'] : '';
-        $status = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
-        $pledgeUserId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0; // 质押用户
-        $pledgeUsdt = isset($orderInfo['money']) ? floatval($orderInfo['money']) : 0; // 质押金额
-        $profit = isset($orderInfo['profit']) ? floatval($orderInfo['profit']) : 0;  // 总收益
-        $profitUsdt = isset($orderInfo['profit_usdt']) ? floatval($orderInfo['profit_usdt']) : 0; // USDT收益
-        $pledgeRound = isset($orderInfo['round']) ? intval($orderInfo['round']) : 0;
-        $settleStatus = isset($orderInfo['settle_status']) ? intval($orderInfo['settle_status']) : 0;
-        $settleStatus = $settleStatus == 2 ? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
-        if ($settleAt > date('Y-m-d H:i:s') || $status != 2 || $pledgeRound <= 0) {
-            $this->error = lang(4412, ['uid' => $userId, 'order_no' => $orderNo]);
+        $settleAt = isset($orderInfo['settle_at'])? $orderInfo['settle_at'] : '';
+        $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
+        $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0; // 质押用户
+        $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0; // 质押金额
+        $profit = isset($orderInfo['profit'])? floatval($orderInfo['profit']) : 0;  // 总收益
+        $profitUsdt = isset($orderInfo['profit_usdt'])? floatval($orderInfo['profit_usdt']) : 0; // USDT收益
+        $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
+        $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
+        $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
+        if($settleAt>date('Y-m-d H:i:s') || $status != 2 || $pledgeRound<=0){
+            $this->error = lang(4412,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 质押收益金额
-        if ($pledgeUsdt <= 0 || $profit <= 0 || ($profit < $profitUsdt)) {
-            $this->error = lang(4416, ['uid' => $userId, 'order_no' => $orderNo]);
+        if($pledgeUsdt<=0 || $profit <=0 || ($profit < $profitUsdt)){
+            $this->error = lang(4416,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // 质押用户信息
-        $memberInfo = MemberModel::where(['id' => $pledgeUserId, 'mark' => 1])
-            ->select(['id', 'usdt', 'sbt', 'profit', 'performance', 'parent_ids', 'status'])
+        $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
+            ->select(['id','usdt','sbt','profit','performance','parent_ids','status'])
             ->first();
-        $memberInfo = $memberInfo ? $memberInfo->toArray() : [];
-        $userUsdt = isset($memberInfo['usdt']) ? $memberInfo['usdt'] : 0;
-        $userProfit = isset($memberInfo['profit']) ? $memberInfo['profit'] : 0;
-        $userSbt = isset($memberInfo['sbt']) ? $memberInfo['sbt'] : 0;
-        $parentIds = isset($memberInfo['parent_ids']) ? $memberInfo['parent_ids'] : '';
-        if (empty($memberInfo) || $pledgeUserId != $userId) {
-            $this->error = lang(4413, ['uid' => $userId, 'order_no' => $orderNo]);
+        $memberInfo = $memberInfo? $memberInfo->toArray() : [];
+        $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
+        $userProfit = isset($memberInfo['profit'])? $memberInfo['profit'] : 0;
+        $userSbt = isset($memberInfo['sbt'])? $memberInfo['sbt'] : 0;
+        $parentIds = isset($memberInfo['parent_ids'])? $memberInfo['parent_ids'] : '';
+        if(empty($memberInfo) || $pledgeUserId != $userId){
+            $this->error = lang(4413,['uid'=>$userId,'order_no'=>$orderNo]);
             return false;
         }
 
         // SBT 收益金额
         $sbtPrice = PriceLogService::make()->getSbtPrice();
-        $profitSbt = moneyFormat(($profit - $profitUsdt) / $sbtPrice, 2); // 金本位计算
+        $profitSbt = moneyFormat(($profit - $profitUsdt)/$sbtPrice, 2); // 金本位计算
 
 
         // 订单收益结算处理
         DB::beginTransaction();
-        try {
+        try{
             // 更新订单状态
-            if (!$this->model->where(['id' => $orderId])->update(['status' => 3, 'bonus_at' => date('Y-m-d H:i:s'), 'update_time' => time()])) {
+            if(!$this->model->where(['id'=> $orderId])->update(['status'=>3,'bonus_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
                 DB::rollBack();
-                $this->error = lang(4414, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4414,['uid'=>$userId,'order_no'=>$orderNo]);
                 return false;
             }
 
             // USDT收益和SBT收益
             $updateData = [
-                'profit' => DB::raw("profit + {$profitUsdt}"),
-                'profit_total' => DB::raw("profit_total + {$profit}"),
-                'pledge_profit' => DB::raw("pledge_profit + {$profit}"),
-                'sbt' => DB::raw("sbt + {$profitSbt}"),
-                'update_time' => time()
+                'profit'=>DB::raw("profit + {$profitUsdt}"),
+                'profit_total'=>DB::raw("profit_total + {$profit}"),
+                'pledge_profit'=>DB::raw("pledge_profit + {$profit}"),
+                'sbt'=>DB::raw("sbt + {$profitSbt}"),
+                'update_time'=>time()
             ];
-            if (!MemberModel::where(['id' => $pledgeUserId])->update($updateData)) {
+            if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
                 DB::rollBack();
-                $this->error = lang(4415, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4415,['uid'=>$userId,'order_no'=>$orderNo]);
                 return false;
             }
 
@@ -712,12 +663,12 @@ class PledgeOrderService extends BaseService
 
             if (!AccountLogModel::insertGetId($data)) {
                 DB::rollBack();
-                $this->error = lang(4417, ['uid' => $userId, 'order_no' => $orderNo]);
+                $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
                 return false;
             }
 
             // SBT收益账单
-            if ($profitSbt > 0) {
+            if($profitSbt>0){
                 $data = [
                     'user_id' => $userId,
                     'order_no' => $orderNo,
@@ -736,15 +687,15 @@ class PledgeOrderService extends BaseService
 
                 if (!AccountLogModel::insertGetId($data)) {
                     DB::rollBack();
-                    $this->error = lang(4417, ['uid' => $userId, 'order_no' => $orderNo]);
+                    $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
                     return false;
                 }
             }
 
             // TODO 是否结算动态收益
-            if ($settleStatus == 1) {
+            if($settleStatus==1){
                 // TODO 推荐奖结算
-                if (!FinanceService::make()->settleShareAward($userId, $parentIds, $orderInfo)) {
+                if(!FinanceService::make()->settleShareAward($userId, $parentIds, $orderInfo)){
                     DB::rollBack();
                     $this->error = FinanceService::make()->getError();
                     return false;
@@ -752,7 +703,7 @@ class PledgeOrderService extends BaseService
 
 
                 //  TODO 管理奖和平级奖结算
-                if (!FinanceService::make()->settleManageAndLevelAward($userId, $parentIds, $orderInfo)) {
+                if(!FinanceService::make()->settleManageAndLevelAward($userId, $parentIds, $orderInfo)){
                     DB::rollBack();
                     $this->error = FinanceService::make()->getError();
                     return false;
@@ -761,13 +712,13 @@ class PledgeOrderService extends BaseService
 
             DB::commit();
 
-            $this->error = lang(4418, ['uid' => $userId, 'order_no' => $orderNo]);
-            $order = ['user_id' => $userId, 'round' => $pledgeRound, 'profit' => $profit, 'profit_usdt' => $profitUsdt, 'profit_sbt' => $profitSbt, 'order_no' => $orderNo];
+            $this->error = lang(4418,['uid'=> $userId,'order_no'=>$orderNo]);
+            $order = ['user_id'=>$userId,'round'=>$pledgeRound,'profit'=>$profit,'profit_usdt'=>$profitUsdt,'profit_sbt'=>$profitSbt,'order_no'=>$orderNo];
             RedisService::set($cacheKey, $order, rand(300, 600));
             return $order;
-        } catch (\Exception $exception) {
+        }catch (\Exception $exception){
             DB::rollBack();
-            $this->error = '订单结算异常:' . $exception->getMessage();
+            $this->error = '订单结算异常:'.$exception->getMessage();
             return false;
         }
     }
@@ -780,12 +731,12 @@ class PledgeOrderService extends BaseService
     {
         $cacheKey = "caches:pledgeOrder:globalTotal";
         $data = RedisService::get($cacheKey);
-        if ($data) {
+        if($data){
             return $data;
         }
 
-        $data = $this->model->where(['status' => 1, 'mark' => 1])->sum('money');
-        if ($data) {
+        $data = $this->model->where(['status'=>1,'mark'=>1])->sum('money');
+        if($data){
             RedisService::set($cacheKey, $data, 600);
         }
 

+ 2 - 2
app/Services/Api/TeamService.php

@@ -142,8 +142,8 @@ class TeamService extends BaseService
         ];
 
         if($type == 1){
-            $info['team_count'] = $this->getTeamUserCountByType($userId, 2); //
-            $info['share_count'] = $this->getTeamUserCountByType($userId, 1);
+            $info['share_count'] = $this->getTeamUserCountByType($userId, 1); //
+            $info['today_share_count'] = $this->getTeamUserCountByType($userId, 3);
 
             // 下一等级业绩,团队业绩
             $nextLevelData = MemberService::make()->getLevelData($info['member_level'], 2);

+ 1 - 7
app/Services/Common/AccountLogService.php

@@ -112,11 +112,6 @@ class AccountLogService extends BaseService
                     $query->where('a.hash', '=', trim($hash));
                 }
 
-                $actionIp = isset($params['action_ip'])? trim($params['action_ip']) : '';
-                if($actionIp){
-                    $query->where('a.action_ip', '=', trim($actionIp));
-                }
-
                 $walletUrl = isset($params['wallet_url']) ? trim($params['wallet_url']) : '';
                 if ($walletUrl) {
                     $query->where('b.wallet_url', $walletUrl);
@@ -190,7 +185,6 @@ class AccountLogService extends BaseService
         $type = isset($params['type'])? intval($params['type']) : 1;
         $accountId = isset($params['user_id'])? intval($params['user_id']) : 0;
         $amount = isset($params['amount'])? floatval($params['amount']) : 0;
-        $remark = isset($params['remark'])? trim($params['remark']) : '';
 
         if($amount<=0){
             $this->error = 4100;
@@ -251,7 +245,7 @@ class AccountLogService extends BaseService
             'create_time' => time(),
             'admin_id' => $adminId,
             'action_ip' => get_client_ip(),
-            'remark' => $remark? $remark : ($type==1?"链上充值":"链上扣除"),
+            'remark' => $type==1?"链上充值":"链上扣除",
             'status' => 1,
             'mark' => 1,
         ];

+ 17 - 21
app/Services/Common/BalanceLogService.php

@@ -229,11 +229,11 @@ class BalanceLogService extends BaseService
         }
 
         // 真实充提
-        $data = $this->model->where(['user_id'=>$userId,'type'=>$type,'mark'=>1])->whereIn('coin_type',[1,2])->whereIn('status',[1,2])->sum('money');
+        $data = $this->model->where(['user_id'=>$userId,'type'=>$type,'mark'=>1])->whereIn('status',[1,2])->sum('money');
 
         // 上下分
         $total = AccountLogModel::where(['user_id'=> $userId,'type'=>$type==1?5:6,'status'=>1,'mark'=>1])->sum('money');
-        $data = round(abs($total) + $data, 2);
+        $data = round($total + $data, 2);
         RedisService::set($cacheKey, $data, rand(5,10));
         return $data?$data:'0.00';
     }
@@ -381,7 +381,7 @@ class BalanceLogService extends BaseService
 
             // 用户钱包和提现地址验证
             $walletToken = isset($userInfo['wallet_token'])? $userInfo['wallet_token'] : '';
-            if($walletUrl!=$accountWalletUrl || ($walletToken && $walletToken != make_wallet_token($walletUrl, $userId))){
+            if($walletUrl!=$accountWalletUrl || $walletToken != make_wallet_token($walletUrl, $userId)){
                 DB::rollBack();
                 $this->error = 4009;
                 RedisService::clear($cacheKey);
@@ -407,28 +407,24 @@ class BalanceLogService extends BaseService
             // U盾出账
             try {
                 $payRemark = $coinType == 1 ? 'USDT余额提现' : '佣金收益提现';
-                $result = CregisPayService::make()->withdraw($walletUrl, $payMoney, $orderNo, '1000', '', $payRemark);
+                $count = 0;
+                while($count < 3){
+                    $result = CregisPayService::make()->withdraw($walletUrl, $payMoney, $orderNo, '1000', '', $payRemark);
+                    if($result){
+                        $count++;
+                        sleep(1);
+                    }else {
+                        break;
+                    }
+                }
                 // 平台钱包出账
-//                var_dump($result);
                 $data = isset($result['data'])? $result['data'] : [];
                 $tradeCid = isset($data['cid']) ? $data['cid'] : '';
-                $msg = isset($result['msg']) ? $result['msg'] : '';
-
                 if(empty($tradeCid)){
+                    DB::rollBack();
                     $this->error = CregisPayService::make()->getError();
-                    if(preg_match("/^Duplicate/",$this->error)){
-                        $updateData = ['status'=>2,'actual_money'=>$payMoney,'audit_remark'=>$remark, 'update_time' => time()];
-                        if(!$this->model->where(['id'=> $id])->update($updateData)){
-                            DB::rollBack();
-                            $this->error = 4006;
-                            RedisService::clear($cacheKey);
-                            return false;
-                        }
-                    }else{
-                        DB::rollBack();
-                        RedisService::clear($cacheKey);
-                        return false;
-                    }
+                    RedisService::clear($cacheKey);
+                    return false;
                 }
 
                 $updateData = ['trade_cid' => $tradeCid, 'update_time' => time()];
@@ -486,7 +482,7 @@ class BalanceLogService extends BaseService
                 }
             }
 
-            // 退回账户明细
+            // 账户明细
             $log = [
                 'user_id' => $accountUserId,
                 'order_no' => $orderNo,

+ 5 - 18
app/Services/Common/MemberService.php

@@ -76,11 +76,6 @@ class MemberService extends BaseService
                     $query->where('b.wallet_url','like',"%{$parentUrl}%");
                 }
 
-                $loginIp = isset($params['login_ip'])? trim($params['login_ip']) : '';
-                if($loginIp){
-                    $query->where('a.login_ip',$loginIp);
-                }
-
                 $parentId = isset($params['parent_id'])? intval($params['parent_id']) : 0;
                 if($parentId){
                     $query->where('a.parent_id',$parentId);
@@ -113,8 +108,8 @@ class MemberService extends BaseService
 
                 $pledge = isset($item['pledge'])? $item['pledge'] : [];
                 $item['is_pledge'] = $pledge? 1 : 0;
-                $item['recharge_total'] = BalanceLogService::make()->getTotalByUser($item['id'],1);
-                $item['withdraw_total'] = BalanceLogService::make()->getTotalByUser($item['id'],2);
+                $item['recharge_total'] = BalanceLogService::make()->getTotalByUser($item['id']);
+                $item['withdraw_total'] = BalanceLogService::make()->getTotalByUser($item['id']);
 
                 $rechargeData = BalanceLogService::make()->getTeamTotalByUser($item['id'], 1);
                 $ptRechargeData = BalanceLogService::make()->getTeamTotalByUser($item['id'], 2);
@@ -162,10 +157,9 @@ class MemberService extends BaseService
         try {
             // 判断团队分红比例
             $uid = isset($data['id'])? $data['id'] : 0;
-            $info = $this->model->where(['id'=> $uid,'mark'=>1])->select(['id','member_level','parent_ids','bonus_rate','room_bonus_rate'])->first();
+            $info = $this->model->where(['id'=> $uid,'mark'=>1])->select(['id','parent_ids','bonus_rate','room_bonus_rate'])->first();
             $info = $info? $info->toArray() : [];
             $userParentId = isset($info['parent_id'])? $info['parent_id'] : 0;
-            $memberLevel = isset($info['member_level'])? $info['member_level'] : 0;
             $userParentIds = isset($info['parent_ids'])? $info['parent_ids'] : '';
 
             // 最大设置比例
@@ -230,14 +224,6 @@ class MemberService extends BaseService
                         }
                     }
                 }
-                ActionLogModel::setTitle("修改用户推荐人");
-                ActionLogModel::record();
-            }
-
-            $level = isset($data['member_level'])? intval($info['member_level']) : 0;
-            if($level != $memberLevel){
-                ActionLogModel::setTitle("修改用户等级为[S{$level}]");
-                ActionLogModel::record();
             }
 
 
@@ -254,6 +240,7 @@ class MemberService extends BaseService
                 return $result;
             }
 
+
             ActionLogModel::setTitle("修改会员信息");
             ActionLogModel::record();
             RedisService::keyDel("caches:member:list*");
@@ -291,7 +278,7 @@ class MemberService extends BaseService
             })
             ->where(function($query) use($keyword){
                 if($keyword){
-                    $query->where('nickname','like',"%{$keyword}%")->orWhere('wallet_url','like',"%{$keyword}%");
+                    $query->where('nickname','like',"{$keyword}%")->orWhere('wallet_url','like',"{$keyword}%");
                 }
             })
             ->select(['id','wallet_url','code','nickname','status'])

+ 1 - 1
app/Services/Common/MenuService.php

@@ -298,7 +298,7 @@ class MenuService extends BaseService
             // 其他角色
             $menuModel = new MenuModel();
             $permissionList = $menuModel::from("menu as m")
-                ->select(['m.permission','m.pid','m.sort'])
+                ->select('m.permission')
                 ->join('role_menu as rm', 'rm.menu_id', '=', 'm.id')
                 ->join('user_role as ur', 'ur.role_id', '=', 'rm.role_id')
                 ->distinct(true)

+ 4 - 7
app/Services/Common/UserService.php

@@ -108,15 +108,12 @@ class UserService extends BaseService
 
         // 头像处理
         $avatar = isset($data['avatar']) ? trim($data['avatar']) : '';
-        if($avatar){
-            if (strpos($avatar, "temp")) {
-                $data['avatar'] = save_image($avatar, 'user');
-            } else {
-                $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
-            }
+        if (strpos($avatar, "temp")) {
+            $data['avatar'] = save_image($avatar, 'user');
+        } else {
+            $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
         }
 
-
         // 验证绑定谷歌验证码
         if(isset($data['google_code']) && $data['google_code']){
             $googleKey = $this->model->where(['username'=> $username])->value('google_key');

+ 0 - 1
app/Services/Common/WalletLogService.php

@@ -62,7 +62,6 @@ class WalletLogService extends BaseService
             ->from('wallet_log as a')
             ->where($where)
             ->select($field ? $field : ['a.*'])
-            ->orderBy('create_time','desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list ? $list->toArray() : [];
         if ($list) {

+ 4 - 4
app/Services/CregisPayService.php

@@ -45,7 +45,7 @@ class CregisPayService extends BaseService
             'project_no' => isset($config['cregis_project_no']['value']) ? $config['cregis_project_no']['value'] : '', //商户号
             'api_key' => isset($config['cregis_api_key']['value']) ? $config['cregis_api_key']['value'] : '', //apikey
             'endpoint' => isset($config['cregis_endpoint']['value']) ? $config['cregis_endpoint']['value'] : '', //节点
-            'callUrl' => trim(env('APP_URL'),'/').'/'.trim($notifyUrl,'/'), //回调地址
+            'callUrl' => env('APP_URL').'/'.trim($notifyUrl,'/'), //回调地址
             'debug' => false  //调试模式
         ];
 
@@ -109,7 +109,7 @@ class CregisPayService extends BaseService
     public function createAddress($mainCoinType = '1000')
     {
         try {
-            $callback = trim(env('APP_URL'),'/').'/'.trim(self::$rechargeNotifyUrl,'/');
+            $callback = env('APP_URL').'/'.trim(self::$rechargeNotifyUrl,'/');
             $result = $this->dispatch->createAddress(self::$config['project_no'], $mainCoinType, '', $callback);
             $code = isset($result['code']) ? trim($result['code']) : 0;
             $address = isset($result['data']['address']) ? trim($result['data']['address']) : '';
@@ -120,7 +120,7 @@ class CregisPayService extends BaseService
                 return '';
             }
         }catch (\Exception $exception){
-            RedisService::set("caches:cregisPay:createAddress:error_" . date('YmdHis'), ['error'=>$exception->getMessage(),'mainCoinType' => $mainCoinType], 7200);
+            RedisService::set("caches:cregisPay:createAddress:error_" . date('YmdHis'), ['error'=>$exception->getMessage(),'mainCoinType' => $mainCoinType, 'result' => $result], 7200);
             return '';
         }
 
@@ -215,7 +215,7 @@ class CregisPayService extends BaseService
         $sgin = $this->dispatch->generateSign(self::$config['api_key'], $params);
         if($getSign!=$sgin){
             RedisService::set("{$cacheKey}:sign",['params'=> request()->all(),'result'=> $params], 3600);
-            return 'Sign error';
+//            return 'Sign error';
         }
 
         $address = isset($params['address'])? trim($params['address']) : '';

BIN
public/uploads/images/google/C_202407290177EE59C2E04A19A68B3EEF605F04E3.png


BIN
public/uploads/images/google/C_202407290437B7FF3CF02571819239DFF4D0694A.png


BIN
public/uploads/images/google/C_2024072904483500F3DB55C4816D71A453F4A5D1.png


BIN
public/uploads/images/google/C_20240729064E4E098B53BA698ABADB63623C0295.png


BIN
public/uploads/images/google/C_2024072906DC44E385A000C1D8651585DC248302.png


BIN
public/uploads/images/google/C_20240729092294E174A5D6693F40BB142890E4FD.png


BIN
public/uploads/images/google/C_20240729097835DD803FFA102F0CA26E275A7E0D.png


BIN
public/uploads/images/google/C_2024072909BFA5861857246E375EBB88BB19DA73.png


BIN
public/uploads/images/google/C_2024072909FEFA8CC9FF33EEDFDD3266F7467C46.png


BIN
public/uploads/images/google/C_202407290C997E3220A814ABDF56AFC1C1303EF2.png


BIN
public/uploads/images/google/C_202407290EB9A6F8F6EA44F097C3440F41497485.png


BIN
public/uploads/images/google/C_202407290F73569591BBC24A7B23734D0865F89D.png


BIN
public/uploads/images/google/C_20240729109C701C4F0055CA908EFE569B9DBC6B.png


BIN
public/uploads/images/google/C_202407291390BC2E66A234D399256CFDE749E9EC.png


BIN
public/uploads/images/google/C_202407291491746270392DE84DBAC3CE304F4F34.png


BIN
public/uploads/images/google/C_2024072914FE20A3601D71928F8AE7FE4C6832AE.png


BIN
public/uploads/images/google/C_202407291544C7E1EFE23FC38A5163229A0BD895.png


BIN
public/uploads/images/google/C_202407291BF92B0A94F748DC87DCB5CA09DBEC6E.png


BIN
public/uploads/images/google/C_202407291C0CA29999041E76B8344C7890197E5A.png


BIN
public/uploads/images/google/C_202407291E8E4DCC99D303AAEA8AE7A870644E7F.png


BIN
public/uploads/images/google/C_202407291F0CA81BDAF4D4FCF6E54FF408EDBD56.png


BIN
public/uploads/images/google/C_2024072920447525153F433DABA4381957DEFF25.png


BIN
public/uploads/images/google/C_20240729233674312AA5D379189B2CA205BDF695.png


BIN
public/uploads/images/google/C_20240729239B22CADC831345430596B3AFE19621.png


BIN
public/uploads/images/google/C_2024072924F4E8CF1553A4614338E900FD0B7F37.png


BIN
public/uploads/images/google/C_2024072925E63E8FDE512F4621BDDA988E1BF559.png


BIN
public/uploads/images/google/C_2024072926AE8D883B5412667B46050F78870BD0.png


BIN
public/uploads/images/google/C_202407292835AA945AF52CBCB2994D78BC59D7DE.png


BIN
public/uploads/images/google/C_2024072928C30529FC3F1E3F4000D7376A536FBF.png


BIN
public/uploads/images/google/C_202407292A3B0D627F4D72A03639298875E5A840.png


BIN
public/uploads/images/google/C_202407292C9DAA6F5B71CAB73843B43350515546.png


BIN
public/uploads/images/google/C_20240729312B572D7D26CF3C790B48B742C132B9.png


BIN
public/uploads/images/google/C_20240729333A44821E6C81269028BBC9C5F25C8C.png


BIN
public/uploads/images/google/C_20240729352EEC120ECD4EA98230EF6DDC99C0BF.png


BIN
public/uploads/images/google/C_202407293567CE0DFC6C4883796EA752E38235A4.png


BIN
public/uploads/images/google/C_202407293A09ECA76C56D5795AF57809E53971C1.png


BIN
public/uploads/images/google/C_202407293DA906E6C92DDEEBBA51CB4771C71CAA.png


BIN
public/uploads/images/google/C_202407294116E4A0A16B5560306F3AA313AC80B5.png


BIN
public/uploads/images/google/C_2024072942BF6D74E1E35A74578038CEBB2548F7.png


BIN
public/uploads/images/google/C_2024072942E024E770A61096D65D4619182FE34A.png


BIN
public/uploads/images/google/C_2024072947A54AA66280D552A730540C36A27D0F.png


BIN
public/uploads/images/google/C_2024072948B8186DC135023E073ABEB46A03FF1E.png


BIN
public/uploads/images/google/C_2024072949352503E2EDE514C4DB61006C0FF3BB.png


BIN
public/uploads/images/google/C_202407294B839AA3386F5AE340A0FF2DC4EB373F.png


BIN
public/uploads/images/google/C_202407294CF6C437776F5FB70FFF768CEE963F5E.png


BIN
public/uploads/images/google/C_202407294F03FCCBDC480498E9321D3098AA82A6.png


BIN
public/uploads/images/google/C_202407294F124CD563BCB816E3EEEEFA206B3706.png


BIN
public/uploads/images/google/C_202407294FDD165F3EA09EB008D77DD994D33759.png


BIN
public/uploads/images/google/C_202407295125746499980DDFF1B553621DC39A46.png


BIN
public/uploads/images/google/C_20240729517F09638FCA30057B1C2ACF18D8ECE7.png


BIN
public/uploads/images/google/C_20240729527D277B5F87B76F7BBD3A6577BDE90C.png


BIN
public/uploads/images/google/C_2024072953C84E92DF17CA96ED0AA1E4B2EE3A2A.png


BIN
public/uploads/images/google/C_2024072954388DB20C1C10D135BC6EAEBDC01554.png


BIN
public/uploads/images/google/C_202407295479B81BAEFAF5E2115454D98B2DCDA7.png


BIN
public/uploads/images/google/C_2024072955C779F957909578479505AE31651C5B.png


BIN
public/uploads/images/google/C_20240729573BFB34AE858C00DA0C2FC75E940823.png


BIN
public/uploads/images/google/C_20240729579E503387DC0E9AD30F85D130089D8F.png


BIN
public/uploads/images/google/C_20240729599D4A6E20499C08CD8D0CA55821BECB.png


BIN
public/uploads/images/google/C_2024072959F93840F7E69888CECC480278CEE89F.png


BIN
public/uploads/images/google/C_202407295ADBDFE490DDAD35E6AF275A90EDAA8F.png


BIN
public/uploads/images/google/C_202407295E08D9A56209E89BE3100FE87C3B434C.png


BIN
public/uploads/images/google/C_2024072961CC3CF71952DBCF471227F98A5AB64E.png


BIN
public/uploads/images/google/C_2024072962BDF477D89ECE43D67B969A0544DB53.png


BIN
public/uploads/images/google/C_202407296705782DBEBC9CE1F975351E175DB240.png


BIN
public/uploads/images/google/C_20240729673A0CA38AE42F5163C56EFD5E5D43AC.png


BIN
public/uploads/images/google/C_20240729680BE917CC7A5C48B96BFF8E878EBDCD.png


BIN
public/uploads/images/google/C_202407296D1617649DA04A58B2DE5F5417DF818B.png


BIN
public/uploads/images/google/C_202407296D8494A5BA23718967845B5B53F8E0BA.png


BIN
public/uploads/images/google/C_202407296DE118C308D86430344CDB2E0541057D.png


BIN
public/uploads/images/google/C_202407296F7610D800B6C047CE66EFB1D0C84A03.png


BIN
public/uploads/images/google/C_202407296FB065E60FCFBDDB9E8C4D17AE3C0F20.png


BIN
public/uploads/images/google/C_2024072971824A3BC21873C02587B9562151E411.png


BIN
public/uploads/images/google/C_2024072975B46002F0AD5A7B47642915E2B2D1E0.png


BIN
public/uploads/images/google/C_2024072976AE52A97384DAD85D0B5EB7DACB694A.png


BIN
public/uploads/images/google/C_20240729771F64236EAE67C907817DEE887A5F7B.png


BIN
public/uploads/images/google/C_20240729776B216F88E596184E541595B21765E7.png


BIN
public/uploads/images/google/C_202407297795B35463748B757CDE9EB72098F978.png


BIN
public/uploads/images/google/C_2024072977C9FC8DC5A885375B7DC9E9099D5A94.png


BIN
public/uploads/images/google/C_2024072978F35EDAC29FB862DA97CD107B94C626.png


BIN
public/uploads/images/google/C_202407297B851E10467012FCC1C99F2E6C979E41.png


BIN
public/uploads/images/google/C_202407297C5C0CB4C772CDF3D636A354C7C63708.png


BIN
public/uploads/images/google/C_202407297C9236FF0DD7BD748EB5B9048EF0D838.png


+ 0 - 0
public/uploads/images/google/C_202407297CA0A7FD0D6BF4711A3BB9C6C0A20F76.png


Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä