RechargeController.php 18 KB

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