Recharge.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use think\Db;
  5. use addons\epay\library\Service;
  6. class Recharge extends Frontend
  7. {
  8. protected $noNeedLogin = '*';
  9. protected $noNeedRight = '*';
  10. protected $layout = '';
  11. public function index()
  12. {
  13. return $this->view->fetch();
  14. }
  15. //创建订单
  16. public function recharge_pc(){
  17. $rc_id = input('rc_id',0);
  18. $pay_type = input('pay_type','alipay');
  19. $mobile = input('mobile',0);
  20. if(!$rc_id){
  21. $this->error('请选择充值金额');
  22. }
  23. if(!$mobile){
  24. $this->error('请输入用户手机号');
  25. }
  26. //查找用户
  27. $user_info = Db::name('user')->field('id')->where('mobile',$mobile)->find();
  28. if (empty($user_info)) {
  29. $this->error('用户信息不存在');
  30. }
  31. //赋值money
  32. $recharge_config = Db::name('paygold_webcon')->where('id',$rc_id)->find();
  33. $money = $recharge_config['money'];
  34. $gold = $recharge_config['gold'];
  35. //创建订单
  36. $data = [];
  37. $data['status'] = 0;
  38. $pay_no = createUniqueNo('P',$user_info['id']);
  39. $data['pay_no'] = $pay_no;
  40. $data['money'] = $money;
  41. $data['payment_class'] = $pay_type;
  42. $data['user_id'] = $user_info['id'];
  43. $data['ext_info'] = json_encode(['subject'=>'充值金币支付']);
  44. $data['memo'] = '充值金币支付';
  45. $data['createtime'] = time();
  46. $data['payment'] = $pay_type == 'alipay' ? 'web' : 'scan';
  47. $orderid = Db::name('pay_order')->insertGetId($data);
  48. //创建回调
  49. $even_data = [];
  50. $even_data['event'] = 'success';
  51. $even_data['class'] = 'app\common\model\Recharge';
  52. $even_data['method'] = 'rechargepaysucc';
  53. $even_data['args'] = json_encode(['user_id'=>$user_info['id'],'gold'=>$gold,'money'=>$money,'pg_id'=>$rc_id]);
  54. $even_data['pay_no'] = $pay_no;
  55. Db::name('pay_event')->insertGetId($even_data);
  56. //下单
  57. $params = [
  58. 'type' => $pay_type,
  59. 'orderid' => $pay_no,
  60. 'title' => $data['memo'],
  61. 'amount' => $data['money'],
  62. // 'amount' => 0.01,
  63. 'method' => $pay_type == 'alipay' ? 'web' : 'scan',
  64. 'notifyurl' => $this->request->root(true) . '/notify.php/paytype/'.$pay_type,
  65. // 'returnurl' => $this->request->root(true) . '/index/index/paysuccess',
  66. ];
  67. $res = Service::submitOrder($params);
  68. if($pay_type == 'wechat'){
  69. exit;
  70. }else{
  71. return $res;
  72. }
  73. }
  74. }