RechargeController.php 18 KB

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