Recharge.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 Recharge extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. //公众号支付完全放弃
  18. /*public function __construct(){
  19. echo __LINE__;
  20. exit;
  21. }*/
  22. //充值配置列表
  23. public function config(){
  24. $rs = Db::name('paygold_webcon')->field('id,money,gold')->order('id asc')->select();
  25. $this->success('success',$rs);
  26. }
  27. //根据uid检索人
  28. public function check_user()
  29. {
  30. $mobile = input('mobile');
  31. if(!$mobile){
  32. $this->error('请输入用户手机号');
  33. }
  34. //填充0
  35. $map = [
  36. 'mobile'=>$mobile,
  37. ];
  38. $user_info = Db::name('user')->field('username,nickname')->where($map)->find();
  39. if (empty($user_info)) {
  40. $this->error('用户信息不存在');
  41. }
  42. $this->success('success',$user_info);
  43. }
  44. //创建订单,公众号
  45. public function recharge(){
  46. $rc_id = input('rc_id',0);
  47. $pay_type = input('pay_type','wechat');
  48. $username = input('username',0);
  49. if(!$rc_id){
  50. $this->error('请选择充值金额');
  51. }
  52. if(!$username){
  53. $this->error('请输入用户手机号并选择');
  54. }
  55. //查找用户
  56. $user_info = Db::name('user')->field('id')->where('username',$username)->find();
  57. if (empty($user_info)) {
  58. $this->error('用户信息不存在');
  59. }
  60. //赋值money
  61. $recharge_config = Db::name('paygold_webcon')->where('id',$rc_id)->find();
  62. $money = $recharge_config['money'];
  63. $gold = $recharge_config['gold'];
  64. //创建订单
  65. $data = [];
  66. $data['status'] = 0;
  67. $pay_no = createUniqueNo('P',$user_info['id']);
  68. $data['pay_no'] = $pay_no;
  69. $data['money'] = $money;
  70. $data['payment_class'] = $pay_type;
  71. $data['user_id'] = $user_info['id'];
  72. $data['ext_info'] = json_encode(['subject'=>'充值金币支付']);
  73. $data['memo'] = '充值金币支付';
  74. $data['createtime'] = time();
  75. $data['payment'] = 'mp';
  76. $orderid = Db::name('pay_order')->insertGetId($data);
  77. //创建回调
  78. $data = [];
  79. $data['event'] = 'success';
  80. $data['class'] = 'app\common\model\Recharge';
  81. $data['method'] = 'rechargepaysucc';
  82. $data['args'] = json_encode(['user_id'=>$user_info['id'],'gold'=>$gold,'money'=>$money,'pg_id'=>$rc_id]);
  83. $data['pay_no'] = $pay_no;
  84. Db::name('pay_event')->insertGetId($data);
  85. $return = [
  86. 'pay_no'=>$pay_no,
  87. 'title' => '充值金币支付',
  88. ];
  89. $this->success('success',$return);
  90. }
  91. //公众号
  92. public function topay(){
  93. $openid = input('openid');
  94. $pay_no = input('pay_no');
  95. $pay_type = input_post('pay_type','wechat');
  96. $orderInfo = Db::name('pay_order')->where('pay_no',$pay_no)->find();
  97. //下单
  98. $params = [
  99. 'type' => $pay_type,
  100. 'orderid' => $pay_no,
  101. 'title' => $orderInfo['memo'],
  102. 'amount' => $orderInfo['money'],
  103. // 'amount' => 0.01,
  104. 'method' => 'mp',
  105. 'openid' => $openid,
  106. 'notifyurl' => $this->request->root(true) . '/notify.php',
  107. //'returnurl' => $this->request->root(true) . '/location.php',
  108. ];
  109. $res = Service::submitOrder($params);
  110. $this->success('请求成功',json_decode($res,true));
  111. }
  112. }