Pay.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use addons\epay\library\Service;
  6. /**
  7. * 充值配置与充值订单
  8. */
  9. class Pay extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //vip用的
  14. public function vip_config(){
  15. $list = Db::name('payvip_config')->order('weigh asc,id asc')->select();
  16. $data['vipconfig'] = $list;
  17. $data['vip_endtime'] = model('wallet')->getWallet($this->auth->id,'vip_endtime');
  18. $data['is_vip'] = $data['vip_endtime'] > time() ? 1 : 0;
  19. $data['avatar'] = localpath_to_netpath($this->auth->avatar);
  20. $this->success('success',$data);
  21. }
  22. //vip用的,创建订单
  23. public function vip_recharge(){
  24. $rc_id = input('rc_id',0);
  25. $pay_type = input('pay_type','wechat');
  26. $platform = 'app';
  27. $uid = $this->auth->id;
  28. if(!$rc_id){
  29. $this->error('请选择会员套餐');
  30. }
  31. if(!$this->user_auth_limit()){
  32. $this->error('请先完成实名认证');
  33. }
  34. //赋值money
  35. $recharge_config = Db::name('payvip_config')->where('id',$rc_id)->find();
  36. $money = $recharge_config['money'];
  37. if($money<=0)
  38. {
  39. $this->error('支付金额必须大于0');
  40. }
  41. if($money > 10000){
  42. $this->error('支付金额太大');
  43. }
  44. //创建订单
  45. $data = [];
  46. $data['user_id'] = $uid;
  47. $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
  48. $data['order_amount'] = $money;
  49. $data['createtime'] = time();
  50. $data['pay_type'] = $pay_type;
  51. $data['platform'] = $platform;
  52. $data['order_status'] = 0;
  53. $data['table_name'] = 'vip_recharge';
  54. $data['table_id'] = 0;
  55. $data['args'] = json_encode(['days'=>$recharge_config['days']]);
  56. $orderid = Db::name('pay_order')->insertGetId($data);
  57. // $openid = $this->auth->mini_openid;
  58. //下单
  59. $params = [
  60. 'type' => $pay_type,
  61. 'orderid' => $data['out_trade_no'],
  62. 'title' => '支付订单',
  63. 'amount' => $data['order_amount'],
  64. 'method' => $platform,
  65. // 'openid' => $openid,
  66. 'notifyurl' => config('pay_notify_url').'/api/notify/vip_notify_base/paytype/'.$pay_type,
  67. 'returnurl' => '',
  68. ];
  69. $res = Service::submitOrder($params);
  70. if($pay_type == 'wechat'){
  71. $this->success('success',json_decode($res,true));
  72. }else{
  73. $this->success('success',$res);
  74. }
  75. }
  76. //人民币充值
  77. public function money_config(){
  78. $list = Db::name('paymoney_config')->order('weigh asc,id asc')->where('is_show',1)->select();
  79. $data['config'] = $list;
  80. $wallet = model('wallet')->getWallet($this->auth->id);
  81. $data['wallet'] = $wallet;
  82. $this->success('success',$data);
  83. }
  84. //充值金币 创建订单
  85. public function money_recharge(){
  86. $rc_id = input('rc_id',0);
  87. $pay_type = input('pay_type','wechat');
  88. $platform = 'app';
  89. $freemoney = input('freemoney',0);
  90. $uid = $this->auth->id;
  91. if(!$rc_id && !$freemoney){
  92. $this->error('请选择或填写充值金额');
  93. }
  94. //赋值money
  95. if($rc_id){
  96. $recharge_config = Db::name('paymoney_config')->where('id',$rc_id)->find();
  97. $money = $recharge_config['money'] ?: 0;
  98. }
  99. //自由输入覆盖
  100. if(!empty($freemoney)){
  101. $rc_id = 0;
  102. $money = floatval($freemoney);
  103. }
  104. //
  105. if($money<=0)
  106. {
  107. $this->error('支付金额必须大于0');
  108. }
  109. if($money > 10000){
  110. $this->error('支付金额太大');
  111. }
  112. //创建订单
  113. $data = [];
  114. $data['user_id'] = $uid;
  115. $data['out_trade_no'] = createUniqueNo('M',$uid); // 数据库订单号加密
  116. $data['order_amount'] = $money;
  117. $data['createtime'] = time();
  118. $data['pay_type'] = $pay_type;
  119. $data['platform'] = $platform;
  120. $data['order_status'] = 0;
  121. $data['table_name'] = 'money_recharge';
  122. $data['table_id'] = 0;
  123. $data['args'] = '';
  124. $orderid = Db::name('pay_order')->insertGetId($data);
  125. // $openid = $this->auth->mini_openid;
  126. //下单
  127. $params = [
  128. 'type' => $pay_type,
  129. 'orderid' => $data['out_trade_no'],
  130. 'title' => '充值订单',
  131. 'amount' => $data['order_amount'],
  132. 'method' => $platform,
  133. // 'openid' => $openid,
  134. 'notifyurl' => config('pay_notify_url').'/api/notify/recharge_notify_base/paytype/'.$pay_type,
  135. 'returnurl' => '',
  136. ];
  137. $res = Service::submitOrder($params);
  138. if($pay_type == 'wechat'){
  139. $this->success('success',json_decode($res,true));
  140. }else{
  141. $this->success('success',$res);
  142. }
  143. }
  144. }