Recharge.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if(!$recharge_config){
  36. $this->error('请选择充值金额');
  37. }
  38. $money = $recharge_config['money'];
  39. $gold = $recharge_config['gold'];
  40. //创建订单
  41. $data = [];
  42. $data['status'] = 0;
  43. $pay_no = createUniqueNo('P',$user_info['id']);
  44. $data['pay_no'] = $pay_no;
  45. $data['money'] = $money;
  46. $data['payment_class'] = $pay_type;
  47. $data['user_id'] = $user_info['id'];
  48. $data['ext_info'] = json_encode(['subject'=>'充值金币支付']);
  49. $data['memo'] = '充值金币支付';
  50. $data['createtime'] = time();
  51. $data['payment'] = $pay_type == 'alipay' ? 'web' : 'scan';
  52. $orderid = Db::name('pay_order')->insertGetId($data);
  53. //创建回调
  54. $even_data = [];
  55. $even_data['event'] = 'success';
  56. $even_data['class'] = 'app\common\model\Recharge';
  57. $even_data['method'] = 'rechargepaysucc';
  58. $even_data['args'] = json_encode(['user_id'=>$user_info['id'],'gold'=>$gold,'money'=>$money,'pg_id'=>$rc_id]);
  59. $even_data['pay_no'] = $pay_no;
  60. Db::name('pay_event')->insertGetId($even_data);
  61. //下单
  62. $params = [
  63. 'type' => $pay_type,
  64. 'orderid' => $pay_no,
  65. 'title' => $data['memo'],
  66. 'amount' => $data['money'],
  67. // 'amount' => 0.01,
  68. 'method' => $pay_type == 'alipay' ? 'web' : 'scan',
  69. 'notifyurl' => $this->request->root(true) . '/notify.php/paytype/'.$pay_type,
  70. 'returnurl' => $this->request->root(true) . '/index/recharge',
  71. ];
  72. $res = Service::submitOrder($params);
  73. if($pay_type == 'wechat'){
  74. $code_url = $res['cod_url'];
  75. $code_img = \EasyWeChat\OfficialAccount\Card\createQrCode();
  76. }else{
  77. return $res;
  78. }
  79. }
  80. }