PayCoin.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * 支付接口控制器
  4. *
  5. */
  6. namespace app\api\controller\v1;
  7. use app\api\controller\Api;
  8. use app\common\model\Members;
  9. use app\common\model\Game;
  10. use app\common\model\ChannelFrozen;
  11. use app\common\model\Cpurl;
  12. use app\common\model\Pay as PayModel;
  13. use app\common\model\PayCpinfo;
  14. use app\common\model\MemberChannelGame;
  15. use app\common\logic\PayCallback;
  16. use app\common\logic\Pay as PayLogic;
  17. use app\common\library\WeixinPay;
  18. use app\service\GamePayService;
  19. use app\service\MemberCoinService;
  20. use think\Db;
  21. use think\Config;
  22. use app\common\model\Setting;
  23. class PayCoin extends Api {
  24. protected $nowTime;
  25. protected $payRequestLimit = 15; //重复下单的限制时间
  26. protected $redis; //redis的句柄对象
  27. /**
  28. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  29. */
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. $this->nowTime = NOW_TIMESTAMP;
  34. $this->redis = \think\Cache::store('default')->handler();
  35. }
  36. /**
  37. * 支付处理 新整理
  38. */
  39. public function index(){
  40. $data['type'] = 1; //类型 1充值平台币 2 充值游戏
  41. $data['paytype'] = input('paytype'); //支付类型
  42. $data['amount'] = input('amount'); //支付金额
  43. $data['accountType'] = 1; //账号类型1当前账号2其他账号
  44. $data['username'] = input('username');
  45. $data['gameid'] = input('gameid');
  46. $data['serverid'] = input('serverid');
  47. $data['roleid'] = input('roleid');
  48. $data['ip'] = request()->ip();
  49. $data['member_id'] = $this->input('userid'); //用户ID
  50. $checkResult = $this->validate($data,
  51. [
  52. ['type', 'require|integer|in:1,2', '类型不能为空|必须为整型'],
  53. ['paytype', 'require', '支付类型不能为空'],
  54. ['amount', 'require|integer|egt:0', '支付金额不能为空|支付金额必须为整型|支付金额大于等于0的整型'],
  55. ['accountType', 'require|in:1,2', '账号类型不能为空|账号类型错误'],
  56. ['username', 'requireIf:accountType,2', '账号必填'],
  57. ['gameid', 'requireIf:type,2|integer', '游戏必填|游戏必须为整型'],
  58. ['serverid', 'requireIf:type,2', '区服必填'],
  59. ['roleid', 'requireIf:type,2', '角色必填'],
  60. ['coin_amt', 'float|egt:0', '金额必须为数字|支付金额大于等于0'],
  61. ]);
  62. if (true !== $checkResult) {
  63. $this->result('', 0, $checkResult, 'json');
  64. }
  65. $data['coin_amt'] = 0;
  66. $result = (new MemberCoinService())->payCoin($data);
  67. if ($result['code'] == 1) {
  68. $this->jsonResult($result['data'], 1, (isset($result['data']['pay_status'])&&$result['data']['pay_status'] == 1) ? '付款成功' : '订单生成成功', false);
  69. } else {
  70. $this->jsonResult('', 0, $result['msg']);
  71. }
  72. }
  73. }