Recharge.php 2.8 KB

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