RechargeController.php 18 KB

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