RechargeController.php 18 KB

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