RechargeController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\dao\Pay\AccountPayInfo;
  4. use App\Facade\TableName;
  5. use App\Http\helper\NumConfig;
  6. use App\Http\logic\api\CashPayLogic;
  7. use App\Http\logic\api\RechargeLogic;
  8. use App\Models\AccountsInfo;
  9. use App\Models\Order;
  10. use App\Models\Platform\MonthCard;
  11. use App\Services\ApkService;
  12. use App\Util;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\Cache;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Redis;
  18. use function GuzzleHttp\Psr7\rewind_body;
  19. class RechargeController
  20. {
  21. protected $JumpOut = [2, 4, 9, 13, 12, 14];
  22. protected $Sdk = [];
  23. // 返回支付档位
  24. public function gear(Request $request)
  25. {
  26. $UserID = (int)$request->globalUser->UserID ?? 0;
  27. $vip = 0;
  28. if ($UserID > 0) {
  29. $vip = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  30. ->where('UserID', $UserID)
  31. ->value('Recharge') ?: 0;
  32. }
  33. $list = DB::table('agent.dbo.recharge_gear')
  34. ->where('in_shop', 1)
  35. ->select('id','money','favorable_price','give','recommend','gear')
  36. ->orderBy('money', 'asc')->where('status', 1)->get();
  37. foreach ($list as $item) {
  38. if (!empty($item->gear)) {
  39. $item->gear = Util::filterGearByDevice($item->gear, $vip);
  40. }
  41. }
  42. return apiReturnSuc(['list'=>$list,'bonus_show'=>false]);
  43. }
  44. // 根据支付档位获取渠道
  45. public function getPayChannel(Request $request)
  46. {
  47. $id = $request->id ?: '';
  48. $ChannelNumber = $request->ChannelNumber ?: '';
  49. if (empty($id)) {
  50. return apiReturnFail(['web.payment.payment_error','PayMent Error']);
  51. }
  52. $key="get_channel_{$id}_{$ChannelNumber}";
  53. // if(Redis::exists($key)) {
  54. // $result=json_decode(Redis::get($key));
  55. // }else {
  56. $first = DB::table('agent.dbo.recharge_gear')
  57. ->where('status', 1)
  58. ->where('id', $id)
  59. ->first();
  60. if (empty($first)) {
  61. return apiReturnFail(['web.payment.payment_error','PayMent Error']);
  62. }
  63. $first->favorable_price = $first->favorable_price + $first->give;
  64. $UserID=$request->UserID;
  65. if(env('MULTI_COUNTRY',0)==1){
  66. $names = DB::table('agent.dbo.admin_configs')
  67. ->where('type', 'pay_method')
  68. ->where('status', '1')
  69. ->where('country',$request->Country??AccountsInfo::select('BindCountry')->where('UserID',$UserID)->first()->BindCountry)
  70. ->select('id', 'name', 'new_pay_type')
  71. ->orderByDesc('sort')->get()
  72. ->map(function ($value) {
  73. return (array)$value;
  74. })->toArray();
  75. }else{
  76. $names = DB::table('agent.dbo.admin_configs')
  77. ->where('type', 'pay_method')
  78. ->where('status', '1')
  79. ->select('id', 'name', 'new_pay_type')
  80. ->orderByDesc('sort')->get()
  81. ->map(function ($value) {
  82. return (array)$value;
  83. })->toArray();
  84. }
  85. // 渠道
  86. if ($ChannelNumber != '') {
  87. $switch = Redis::get("recharge_config_switch_{$ChannelNumber}");
  88. if ($switch) {
  89. $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge as go')
  90. ->join('agent.dbo.admin_configs as cf', 'go.ConfigID', '=', 'cf.id')
  91. ->where('go.Channel', $ChannelNumber)
  92. ->where('go.Status', 1)
  93. ->where('cf.type', 'pay_method')
  94. ->orderByDesc('go.Sort')
  95. ->select('go.Sort', 'ConfigID')
  96. ->pluck('Sort', 'ConfigID')->toArray();
  97. }
  98. }
  99. if (!isset($list) || count($list) < 1) { // 默认配置
  100. $list = DB::connection('write')->table('agent.dbo.admin_configs')
  101. ->where('type', 'pay_method')
  102. ->where('status', 1)
  103. ->select('sort as Sort', 'id as ConfigID')
  104. ->pluck('Sort', 'ConfigID')->toArray();
  105. }
  106. $data = [];
  107. foreach ($names as $k => $va) {
  108. if (isset($list[$va['id']])) {
  109. $type = $va['new_pay_type'] == 1 ? 3 : 2;
  110. if ($va['new_pay_type'] == 4) {
  111. $type = 0;
  112. }
  113. // type = 1 sdk跳转 type=2 外跳链接 type=0 默认 type=3 复制信息到APP支付
  114. $data[] = ['id' => $va['id'],
  115. 'name' => $va['name'], 'status' => 1, 'type' => $type, 'sort' => $list[$va['id']]];
  116. }
  117. }
  118. // $first->cpf_first=0;
  119. // if($ChannelNumber==103)$first->cpf_first=1;
  120. $gear = array_values($data);
  121. $gear = collect($gear)->sortByDesc('sort')->toArray();
  122. $first->kefu_switch = 1;
  123. $gear = array_values($gear);
  124. $first->gear = \GuzzleHttp\json_encode($gear);
  125. $result = apiReturnSuc($first);
  126. // Redis::set($key,json_encode($result));
  127. // Redis::expire($key,60);
  128. // }
  129. // $dir = $path = app()->basePath() . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'cache';
  130. // if (!file_exists($dir)) {
  131. // mkdir($dir, 0777);
  132. // }
  133. // $path = $dir . DIRECTORY_SEPARATOR . "get_channel_{$id}_{$ChannelNumber}.json";
  134. // file_put_contents($path, json_encode($result));
  135. return $result;
  136. }
  137. // 返回支付渠道
  138. public function payChannel()
  139. {
  140. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay_method')
  141. ->where('status', 1)
  142. ->select('id', 'name', 'status')
  143. ->orderByDesc('sort')->get();
  144. foreach ($list as &$value) {
  145. if (in_array($value->id, $this->Sdk)) {
  146. $value->type = 0;
  147. } elseif (in_array($value->id, $this->JumpOut)) {
  148. $value->type = 2;
  149. } else {
  150. $value->type = 0;
  151. }
  152. }
  153. unset($value);
  154. return apiReturnSuc("$list");
  155. }
  156. // 首充可选择渠道
  157. public function firstPayfirstPayConfig(Request $request)
  158. {
  159. $origin = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
  160. if (strstr($origin, "52256") ) {
  161. return apiReturnSuc(null);
  162. }
  163. $user=$request->user();
  164. if($user){
  165. $firstPayExists = DB::table(TableName::QPAccountsDB().'UserRechargeActive')->where('UserID',$user->UserID)->first();
  166. if($firstPayExists){
  167. return apiReturnSuc(null);
  168. }
  169. }
  170. // 推荐充值档位
  171. $recomendar_recharge = DB::table(TableName::QPAccountsDB() . 'SystemStatusInfo')
  172. ->where('StatusName', 'RecomendarRecharge')
  173. ->value('StatusValue');
  174. $first_pay = DB::table('agent.dbo.recharge_gear')->where('status', 1)
  175. ->where('first_pay', 1)->first();
  176. if (!$first_pay) {
  177. return apiReturnSuc(compact('first_pay', 'recomendar_recharge'));
  178. }
  179. $names = DB::table('agent.dbo.admin_configs')
  180. ->where('type', 'pay_method')
  181. ->where('status', 1)
  182. ->select('id', 'name', 'new_pay_type')->orderByDesc('sort')->get()->toArray();
  183. $first_pay->favorable_price = $first_pay->favorable_price + $first_pay->give;
  184. $data = [];
  185. foreach ($names as $k => $va) {
  186. $type = $va->new_pay_type == 1 ? 3 : 2;
  187. if($va->new_pay_type == 4){
  188. $type = 0;
  189. }
  190. // type = 1 sdk跳转 type=2 外跳链接 type=0 默认 type=3 复制信息到APP支付
  191. $data[] = ['id' => $va->id, 'name' => $va->name, 'status' => 1, 'type' => $type];
  192. }
  193. $gear = array_values($data);
  194. $first_pay->gear = \GuzzleHttp\json_encode($gear);
  195. $ChannelNumber = $request->ChannelNumber ?: '';
  196. // $first_pay->cpf_first=0;
  197. // if($ChannelNumber==103)$first_pay->cpf_first=1;
  198. return apiReturnSuc(compact('first_pay', 'recomendar_recharge'));
  199. }
  200. // 引导付费
  201. public function guidePayment(Request $request)
  202. {
  203. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  204. // 引导付费标识
  205. // $guide_payment_exists = DB::table(TableName::agent() . 'guide_payment')->where('UserID', $UserID)->first();
  206. $flag = false;
  207. // 查看用户有没有充值过【只要充值过,引导付费就不能充值】
  208. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  209. ->where('UserID', $UserID)
  210. ->value('Recharge') ?: 0;
  211. if ($user_recharge > 0) {
  212. $flag = true;
  213. }
  214. // 引导付费礼包列表
  215. $guidePayment = (new RechargeLogic())->guidePayment($this->JumpOut);
  216. // 日期 -- 倒计时【小时】
  217. $countdown = 24;
  218. return apiReturnSuc(['is_pay' => $flag, 'countdown' => $countdown, 'guidePayment' => $guidePayment]);
  219. }
  220. // 充值Vip等级
  221. public function vipConfig(Request $request)
  222. {
  223. $res = DB::table('QPAccountsDB.dbo.ProtectLevel')
  224. ->orderBy('Recharge')->get();
  225. $list = [];
  226. foreach ($res as $v) {
  227. $list[] = [
  228. 'id' => $v->ID,
  229. 'money' => $v->Recharge,
  230. 'num' => $v->ID - 1,
  231. 'relief_money' => $v->GrantNum/100,
  232. 'vip' => $v->ID - 1,
  233. ];
  234. }
  235. // 充值礼包
  236. $monthCards = MonthCard::query()
  237. ->select('CardID', 'CardName', 'Price', 'FirstReward', 'DayReward', 'gear', 'CardState')
  238. ->where(['CardType' => 1,])
  239. ->get();
  240. // 充值渠道过滤
  241. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  242. $accountInfo = AccountsInfo::query()->where('UserID', $UserID)->first();
  243. $channel = $accountInfo->Channel ?? 0;
  244. $switch = Redis::get("recharge_config_switch_{$channel}");
  245. if ($channel && $switch) {
  246. $channels = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge as go')
  247. ->join('agent.dbo.admin_configs as cf', 'go.ConfigID', '=', 'cf.id')
  248. ->where('go.Channel', $channel)
  249. ->where('go.Status', 1)
  250. ->where('cf.type', 'pay_method')
  251. ->orderByDesc('go.Sort')
  252. ->select(
  253. DB::raw('cf.id as id'),
  254. 'name',
  255. 'config_value',
  256. 'new_pay_type',
  257. DB::raw('go.Sort as sort')
  258. )
  259. ->get()
  260. ->toArray();
  261. }
  262. if (empty($channels)) {
  263. $channels = DB::table('agent.dbo.admin_configs')
  264. ->select('id', 'name', 'config_value', 'new_pay_type', 'sort')
  265. ->where([
  266. 'type' => 'pay_method',
  267. 'status' => 1
  268. ])
  269. ->orderByDesc('sort')
  270. ->get()->toArray();
  271. }
  272. foreach ($monthCards as $k => $v) {
  273. $monthCards[$k]['CardID'] = $monthCards[$k]['CardID'] + 100;
  274. $monthCards[$k]['FirstReward'] = $v['FirstReward']/100;
  275. $monthCards[$k]['DayReward'] = $v['DayReward']/100;
  276. $cardChannels = [];
  277. foreach ($channels as $channel) {
  278. $channel->type = $channel->new_pay_type == 4?0: ($channel->new_pay_type == 1 ? 3 : 2);
  279. $cardChannels[] = [
  280. 'id' => $channel->id,
  281. 'name' => $channel->name,
  282. 'pic' => $channel->config_value,
  283. 'status' => 1,
  284. 'type' => $channel->new_pay_type == 4?0: ($channel->new_pay_type == 1 ? 3 : 2),
  285. 'new_pay_type' => $channel->new_pay_type,
  286. 'sort' => $channel->sort
  287. ];
  288. }
  289. usort($cardChannels, function ($a, $b) {
  290. return $a['sort'] > $b['sort'] ? -1 : 1;
  291. });
  292. $monthCards[$k]['gear'] = json_encode($cardChannels);
  293. }
  294. return apiReturnSuc(compact('list', 'monthCards'));
  295. }
  296. // 用户总充值
  297. public function userTotalRecharge(Request $request)
  298. {
  299. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  300. // Util::WriteLog('login_header',$request->header());
  301. try{
  302. $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  303. ->where('UserID', $UserID)
  304. ->first();
  305. if(isset($userInfo)) {
  306. //记录版本号
  307. $v = (int)$request->get('v');
  308. $cv = Util::getClientVer();
  309. // $CustomID = $v * 1000 + $cv;
  310. // DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  311. // ->where('UserID', $UserID)
  312. // ->update(['CustomID' => $CustomID]);
  313. $list = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreInfo')
  314. ->where('UserID', '=', $UserID)
  315. ->first();
  316. if ($list) {
  317. //下线的包
  318. if ($list->WinCount == 0 && $list->LostCount == 0 && in_array($userInfo->Channel, [103, 104, 101, 105, 123, 109, 121, 106])) {
  319. // ApkService::ControlOldUser($UserID);
  320. }
  321. if ($list->WinCount == 0 && $list->LostCount == 0 && strtotime($list->RegisterDate) < time() - 86400 * 2) {
  322. if ($userInfo->Channel == 100 || $userInfo->Channel == 103 || $userInfo->Channel == 104) {
  323. // ApkService::ControlOldUser($UserID);
  324. }
  325. }
  326. }
  327. }
  328. }catch (\Exception $exception){
  329. Util::WriteLog('control_old_user',$exception);
  330. }
  331. $user_total_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  332. ->where('UserID', $UserID)
  333. ->value('Recharge') ?: 0;
  334. // 引导付费标识
  335. // $guide_payment_exists = DB::table(TableName::agent() . 'guide_payment')->where('UserID', $UserID)->first();
  336. $flag = false;
  337. // 查看用户有没有充值过【只要充值过,引导付费就不能充值】
  338. if ($user_total_recharge > 0) {
  339. $flag = true;
  340. }
  341. // 引导付费礼包列表
  342. // $guidePayment = (new RechargeLogic())->guidePayment($this->JumpOut);
  343. // 日期 -- 倒计时【小时】
  344. $countdown = 24;
  345. return apiReturnSuc(['user_total_recharge'=>$user_total_recharge,'is_pay' => $flag, 'countdown' => $countdown, 'guidePayment' => []]);
  346. // $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  347. // ->lock('WITH(NOLOCK)')
  348. // ->where('UserID', $UserID)
  349. // ->first();
  350. //
  351. //
  352. // if (!$AccountWithDrawInfo) {
  353. // $cpf = $this->_getNewCpf($UserID);
  354. // if($cpf){
  355. // $dao = new AccountPayInfo();
  356. // $data = [
  357. // 'PixType' => 1,
  358. // 'BankUserName' => $dao->randUserName(0),
  359. // 'PixNum' => $cpf,
  360. // 'UserID' => $UserID,
  361. // 'Achieves' => 0,
  362. // 'HistoryWithDraw' => 0
  363. // ];
  364. //
  365. // try {
  366. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  367. // ->where('UserID', $UserID)
  368. // ->insert($data);
  369. //
  370. // try {
  371. // DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  372. // ->insert([
  373. // 'UserID' => $UserID,
  374. // 'BankCard' => $cpf,
  375. // 'BindDate' => now()
  376. // ]);
  377. // Util::WriteLog('update_pix',[
  378. // 'UserID' => $UserID,
  379. // 'BankCard' => $cpf,
  380. // 'BindDate' => now()
  381. // ]);
  382. // } catch (\Exception $e) {
  383. // Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  384. // }
  385. //
  386. // } catch (\Exception $e) {
  387. // Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  388. // }
  389. // }
  390. //
  391. // } else {
  392. // if(!$AccountWithDrawInfo->BankUserName || !$AccountWithDrawInfo->PixNum){
  393. //
  394. // $cpf = $this->_getNewCpf($UserID);
  395. //
  396. // if($cpf){
  397. // $dao = new AccountPayInfo();
  398. // $data = [
  399. // 'PixType' => 1,
  400. // 'BankUserName' => $dao->randUserName(0),
  401. // 'PixNum' => $cpf,
  402. // 'UserID' => $UserID,
  403. // 'Achieves' => 0,
  404. // 'HistoryWithDraw' => 0
  405. // ];
  406. //
  407. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  408. // ->where('UserID', $UserID)
  409. // ->update($data);
  410. // }
  411. //
  412. //
  413. // }
  414. // }
  415. }
  416. private function _getNewCpf($UserID){
  417. return 0;
  418. $where[] = ['payment_code', 'cashPay'];
  419. $where[] = ['pay_status', 1];
  420. $where[] = ['UserID', $UserID];
  421. $build_sql = DB::connection('write')->table('order')
  422. ->where($where)
  423. ->first();
  424. if($build_sql){
  425. $cashPay = new CashPayLogic();
  426. return $cashPay->search($build_sql->order_sn);
  427. }
  428. return 0;
  429. }
  430. }