PayRechargeController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Facade\TableName;
  4. use App\Game\Services\OuroGameService;
  5. use App\Http\Controllers\Controller;
  6. use App\Http\Controllers\Game\LoginController;
  7. use App\Http\helper\NumConfig;
  8. use App\Http\logic\api\PayRechargeLogic;
  9. use App\Models\AccountsInfo;
  10. use App\Models\Treasure\GameScoreInfo;
  11. use App\Services\OrderServices;
  12. use App\Services\PayMent;
  13. use App\Utility\SetNXLock;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Redis;
  17. use Yansongda\Pay\Pay;
  18. class PayRechargeController extends Controller
  19. {
  20. // 充值记录
  21. public function orderList(Request $request)
  22. {
  23. $user_id = $request->get('user_id', 1);
  24. if (!is_numeric($user_id)) {
  25. return apiReturnFail(['web.payment.invalid_params',__('messages.api.pay.invalid_params')]);
  26. }
  27. $page = $request->get('page', 1);
  28. $pageSize = $request->get('pageSize', 7);
  29. $redisKey = 'PayRecharge_orderList_'.$user_id;
  30. if (!SetNXLock::getExclusiveLock($redisKey)) {
  31. return apiReturnFail(['web.withdraw.try_again_later',__('messages.api.withdraw_info.try_again_later')]);
  32. }
  33. $list = (new PayRechargeLogic())->orderList($user_id, $pageSize);
  34. return apiReturnSuc($list);
  35. }
  36. // 首充
  37. public function firstPay()
  38. {
  39. $OrderServices = new OrderServices();
  40. // 充值金额
  41. $price = $OrderServices->FirstCharge;
  42. $give = $OrderServices->FirstChargeGive;
  43. // 首充
  44. $firstCharge = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  45. ->where('StatusName', 'FirstChargeGiftBag')
  46. ->first();
  47. $payConfigID = $firstCharge->StatusValue;
  48. $payConfigs = DB::table('agent.dbo.admin_configs')->where('id', $payConfigID)->select('id', 'name', 'new_pay_type')->first();
  49. $first_pay = [];
  50. if ($payConfigs) {
  51. if ($payConfigs->new_pay_type <= 1) {
  52. $first_pay = ['id' => $payConfigs->id, 'name' => $payConfigs->name, 'status' => 1, 'type' => 3, 'new_pay_type' => $payConfigs->new_pay_type];
  53. } else {
  54. $first_pay = ['id' => $payConfigs->id, 'name' => $payConfigs->name, 'status' => 1, 'type' => 0, 'new_pay_type' => $payConfigs->new_pay_type];
  55. }
  56. }
  57. return apiReturnSuc(compact('price', 'give','first_pay'));
  58. }
  59. public function timeBonus(Request $request)
  60. {
  61. $UserID=$request->UserID;
  62. if(empty($UserID)||!intval($UserID))return apiReturnFail();
  63. $user = AccountsInfo::find($UserID);
  64. if(!$user)return apiReturnFail();
  65. $user = $user->toArray();
  66. // if(env('VALID_COUNTRY')=='PK') {
  67. // $RechargeTimes = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->value('RechargeTimes') ?? 0;
  68. // if($RechargeTimes<4)return apiReturnFail();
  69. // }
  70. $data=['UserID'=>$user['UserID'],'Channel'=>$user['Channel'],'Score'=>GameScoreInfo::query()->select(['Score'])->where('UserID', $UserID)->first()->Score];
  71. LoginController::CheckTimeBonus($data);
  72. return apiReturnSuc($data);
  73. }
  74. public function firstPayMulti(Request $request)
  75. {
  76. $UserID=$request->UserID;
  77. if($UserID){
  78. $fpkey='Firstpay_'.$UserID;
  79. if(Redis::exists($fpkey)){
  80. $data=Redis::get($fpkey);
  81. $data=json_decode($data,true);
  82. $data['timeleft']=86400-(time()-$data['buytime']);
  83. return apiReturnSuc(['leftitem'=>$data]);
  84. }
  85. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  86. ->where('UserID', $UserID)
  87. ->value('Recharge') ?: 0;
  88. if($user_recharge)return apiReturnFail();
  89. }
  90. $fmkey='FirstMultiData1';
  91. $items=[];
  92. for($i=0;$i<5;$i++) {
  93. if (!Redis::exists($fmkey)) {
  94. $data = [];
  95. $names = DB::table('agent.dbo.admin_configs')
  96. ->where('type', 'pay_method')
  97. ->where('status', 1)
  98. ->select('id', 'name', 'new_pay_type')->orderByDesc('sort')->get()->toArray();
  99. foreach ($names as $k => $va) {
  100. $type = $va->new_pay_type == 1 ? 3 : 2;
  101. if ($va->new_pay_type == 4) {
  102. $type = 0;
  103. }
  104. // type = 1 sdk跳转 type=2 外跳链接 type=0 默认 type=3 复制信息到APP支付
  105. $data[] = ['id' => $va->id, 'name' => $va->name, 'status' => 1, 'type' => $type];
  106. }
  107. $gear = array_values($data);
  108. $items = DB::table('agent.dbo.recharge_gear')
  109. ->where('status', 1)
  110. // ->where('second_give', '>', 0)
  111. ->where('first_pay', '>=', 1)
  112. ->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')->get()->each(function ($item) use ($gear) {
  113. $item->id = 28;
  114. $item->gear = \GuzzleHttp\json_encode($gear);
  115. })->toArray();
  116. Redis::setex($fmkey, 600, json_encode($items));
  117. } else {
  118. $items = json_decode(Redis::get($fmkey), true);
  119. }
  120. if(count($items))break;
  121. }
  122. $default=count($items)-1;
  123. return apiReturnSuc(compact('items','default'));
  124. }
  125. public function getSecondGive(Request $request)
  126. {
  127. $UserID=$request->UserID;
  128. $fpkey='Firstpay_'.$UserID;
  129. if(Redis::exists($fpkey)){
  130. $data=Redis::get($fpkey);
  131. $data=json_decode($data,true);
  132. $data['timeleft']=86400-(time()-$data['buytime']);
  133. if($data['timeleft']<=0) {
  134. Redis::del($fpkey);
  135. //加钱
  136. if($data['second_give']){
  137. $czReason=$data['czReason'];
  138. $cjReason=$data['cjReason'];
  139. [$OrgScore,$NowScore]=OuroGameService::AddScore($UserID,$data['second_give']*NumConfig::NUM_VALUE,$cjReason);
  140. //更新二次领钱记录
  141. DB::table(TableName::agent() . 'guide_payment')->where('UserID',$UserID)->update([
  142. 'GetSecondTime' => now(),
  143. 'SecondScoreNum'=>$data['second_give']*NumConfig::NUM_VALUE
  144. ]);
  145. return apiReturnSuc(compact('OrgScore','NowScore'));
  146. }
  147. return apiReturnSuc();
  148. }
  149. }
  150. return apiReturnFail(['web.withdraw.try_again_later',__('messages.api.withdraw_info.try_again_later')]);
  151. }
  152. }