Coin.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\api\controller\v2;
  3. use app\api\controller\Api;
  4. use app\common\model\Members;
  5. use app\common\model\PayType;
  6. use app\service\MemberCoinService;
  7. use think\Config;
  8. class Coin extends Api
  9. {
  10. /**
  11. * 支付方式
  12. */
  13. public function payType()
  14. {
  15. // return $this->jsonResult('', 0, '平台币充值维护中');
  16. $checkResult = $this->validate($this->input,
  17. [
  18. ['version', 'require', '版本号不能为空'],
  19. ]
  20. );
  21. if (true !== $checkResult) {
  22. $this->jsonResult('', 0, $checkResult, 'json');
  23. }
  24. $game_id = $this->input('gameid'); //游戏ID
  25. $version = $this->input('version'); //sdk版本号 [v3.0.2 参数]
  26. $device = $this->input('device'); // 设备类型
  27. if($device == 4){
  28. $payTypeList = [
  29. ["paytype" => "wx_h5", "payname" => "微信", "pay_scene" => "wx_h5", "sort" => 1],
  30. ["paytype" => "ali_h5", "payname" => "支付宝", "pay_scene" => "ali_h5", "sort" => 2],
  31. // ["paytype" => "wx_h5", "payname" => "微信(扫码)", "pay_scene" => "wx_h5_qr", "sort" => 1],
  32. // ["paytype" => "ali_h5", "payname" => "支付宝(扫码)", "pay_scene" => "ali_h5_qr", "sort" => 2],
  33. ];
  34. $this->jsonResult($payTypeList, 1, '成功!');
  35. }
  36. $handleVersion = trim(config('pay_handle_version'));
  37. $handleQrVersion = trim(config('pay_qr_handle_version'));
  38. if (version_compare(trim($version), $handleVersion, '>')) {
  39. $payTypeList = [
  40. ["paytype" => "ybzf_wxmp_h5", "payname" => "微信", "pay_scene" => "wx_h5", "sort" => 1],
  41. ["paytype" => "zfb", "payname" => "支付宝(快捷)", "pay_scene" => "ali_app", "sort" => 2],
  42. ["paytype" => "zfb", "payname" => "支付宝", "pay_scene" => "ali_app", "sort" => 5],
  43. ];
  44. if(version_compare(trim($version), $handleQrVersion, '>=') && $device == 2){
  45. $payTypeNew = [
  46. ["paytype" => "old-zfb-wap", "payname" => "支付宝(扫码)", "pay_scene" => "ali_h5_qr", "sort" => 3],
  47. ["paytype" => "ybzf_wxmp_h5", "payname" => "微信(扫码)", "pay_scene" => "wx_h5_qr", "sort" => 4],
  48. ];
  49. $payTypeList = array_merge($payTypeList, $payTypeNew);
  50. usort($payTypeList, function($a, $b) {
  51. return $a['sort'] <=> $b['sort'];
  52. });
  53. }
  54. $this->jsonResult($payTypeList, 1, '成功!!');
  55. }
  56. $payTypeModel = new PayType;
  57. $sdkModel = model('common/AndroidSdk');
  58. // TODO:萌战无双游戏微信支付申请-01.02
  59. if ($game_id == Config::get('gb_game')) {
  60. $this->jsonResult([["paytype" => "ybzf_wxmp_h5", "payname" => "微信"]], 1, '成功');
  61. }
  62. $denyPayType = ['ptb', 'coinpay'];
  63. $android_sdk_id = $sdkModel->where(['version' => $version])->value('id');
  64. if (empty($android_sdk_id)) {
  65. $this->jsonResult('', 0, 'sdk版本信息不存在');
  66. }
  67. $arrPayType = $payTypeModel->field('paytype,payname')->where(['status' => 1, 'paytype' => ['not in', $denyPayType], 'used_sdk_id' => ['like', '%,' . $android_sdk_id . ',%']])->order('sort asc')->select();
  68. $this->jsonResult($arrPayType, 1, '成功!!!');
  69. }
  70. public function pay()
  71. {
  72. // return $this->jsonResult('', 0, '平台币充值维护中');
  73. $data['paytype'] = $this->input['paytype']; //支付类型
  74. $data['amount'] = $this->input['amount']; //支付金额
  75. $data['accountType'] = $this->input['accountType']; // 账号类型:1=当前账号, 2=其他账号
  76. $data['username'] = $this->input['username'];
  77. $data['ip'] = request()->ip();
  78. $data['version'] = $this->input['version'];
  79. $checkResult = $this->validate($data,
  80. [
  81. ['paytype', 'require', '支付类型不能为空'],
  82. ['amount', 'require|integer|egt:0', '支付金额不能为空|支付金额必须为整型|支付金额大于等于0的整型'],
  83. ['accountType', 'require|in:1,2', '账号类型不能为空|账号类型错误'],
  84. ['username', 'requireIf:accountType,2', '账号必填'],
  85. ['version', 'require', '版本号必填'],
  86. ]);
  87. if (true !== $checkResult) {
  88. $this->jsonResult('', 0, $checkResult, 'json');
  89. }
  90. // $data['type'] = $this->input['type']; //类型 1充值平台币 2 充值游戏
  91. // TODO:萌战无双游戏微信支付申请-01.02
  92. if ($this->input['gameid'] == Config::get('gb_game')) {
  93. $this->jsonResult('', 0, '接入中...');
  94. }
  95. // 封禁IOS老版本的支付方式
  96. if(version_compare($this->input('version'), 'v3.2.6') < 1){
  97. if(in_array($this->input('paytype'), ['ybzf_wxmp_h5', 'zfb']) && in_array($this->input('gameid'), ['20', '245', '248', '258', '259', '261', '263'])){
  98. $this->jsonResult('', 0, "请下载最新游戏包,或选择【支付宝(旧)】进行支付。");
  99. }
  100. }
  101. if ($data['accountType'] == 2) {
  102. if (empty($this->input['user_name'])) {
  103. $this->jsonResult('', 0, '账号不存在');
  104. }
  105. $data['username'] = $this->input['user_name'];
  106. if (!$user = (new Members())->getUseridByName($data)) {
  107. $this->jsonResult('', 0, '账号不存在');
  108. }
  109. $data['member_id'] = $user['id'];
  110. } else {
  111. $data['member_id'] = $this->input['userid'];
  112. if (!$user = (new Members())->getUseridById($data)) {
  113. $this->jsonResult('', 0, '当前账号异常!');
  114. }
  115. }
  116. $data['place_user_id'] = $this->input['userid'];
  117. $data['gameid'] = $this->input['gameid']; // 微信H5支付时需要用到
  118. $data['device'] = $this->input['device']??'';
  119. $result = (new MemberCoinService())->payCoin($data);
  120. if ($result['code'] == 1) {
  121. $this->jsonResult($result['data'], 1, (isset($result['data']['pay_status']) && $result['data']['pay_status'] == 1) ? '付款成功' : '订单生成成功', true);
  122. } else {
  123. $this->jsonResult('', 0, $result['msg']);
  124. }
  125. }
  126. }