2
0

RechargeController.php 18 KB

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