123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\Wallet;
- use app\utils\CurlUtil;
- use think\Db;
- use addons\epay\library\Service;
- class Pay extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
-
- public function vip_config()
- {
- $list = Db::name('payvip_config')->order('weigh asc,id asc')->select();
- $data['vipconfig'] = $list;
- $data['vip_endtime'] = model('wallet')->getWallet($this->auth->id, 'vip_endtime');
- $data['is_vip'] = $data['vip_endtime'] > time() ? 1 : 0;
- $data['avatar'] = localpath_to_netpath($this->auth->avatar);
- $this->success('success', $data);
- }
-
- public function vip_recharge()
- {
- $rc_id = input('rc_id', 0);
- $pay_type = input('pay_type', 'wechat');
- $platform = 'app';
- $uid = $this->auth->id;
- if (!$rc_id) {
- $this->error('请选择会员套餐');
- }
- if (!$this->user_auth_limit()) {
- $this->error('请先完成实名认证');
- }
-
- $recharge_config = Db::name('payvip_config')->where('id', $rc_id)->find();
- $money = $recharge_config['money'];
- if ($money <= 0) {
- $this->error('支付金额必须大于0');
- }
- if ($money > 10000) {
- $this->error('支付金额太大');
- }
-
- $data = [];
- $data['user_id'] = $uid;
- $data['out_trade_no'] = createUniqueNo('P', $uid);
- $data['order_amount'] = $money;
- $data['createtime'] = time();
- $data['pay_type'] = $pay_type;
- $data['platform'] = $platform;
- $data['order_status'] = 0;
- $data['table_name'] = 'vip_recharge';
- $data['table_id'] = 0;
- $data['args'] = json_encode(['days' => $recharge_config['days']]);
- $orderid = Db::name('pay_order')->insertGetId($data);
-
- $params = [
- 'type' => $pay_type,
- 'orderid' => $data['out_trade_no'],
- 'title' => '支付订单',
- 'amount' => $data['order_amount'],
- 'method' => $platform,
- 'notifyurl' => config('pay_notify_url') . '/api/notify/vip_notify_base/paytype/' . $pay_type,
- 'returnurl' => '',
- ];
- $res = Service::submitOrder($params);
- if ($pay_type == 'wechat') {
- $this->success('success', json_decode($res, true));
- } else {
- $this->success('success', $res);
- }
- }
-
- public function money_config()
- {
- $wallet = (new Wallet())->getWallet($this->auth->id);
- $data['wallet'] = $wallet;
- $data['recharge_explain'] = config('site.recharge_explain');
- $list = Db::name('paymoney_config')->order('weigh asc,id asc')->where('is_show', 1)->select();
- $data['config'] = $list;
- $this->success('success', $data);
- }
-
- public function money_recharge()
- {
- $rc_id = input('rc_id', 0);
- $pay_type = input('pay_type', 'wechat');
- $platform = input('platform', 'app');
- $free_money = input('free_money', 0);
- $user_id = $this->auth->id;
- if (!$rc_id && !$free_money) {
- $this->error('请选择或填写充值金额');
- }
- if ($rc_id) {
-
- $recharge_config = Db::name('paymoney_config')->where('id', $rc_id)->find();
- $money = $recharge_config['money'] ?: 0;
- } else {
-
- $money = floatval($free_money);
- }
- if ($money <= 0) {
- $this->error('支付金额必须大于0');
- }
- if ($money > 10000) {
- $this->error('支付金额太大');
- }
-
- $remark = '充值订单';
- $orderData = [
- 'user_id' => $user_id,
- 'out_trade_no' => createUniqueNo('M', $user_id),
- 'order_amount' => $money,
- 'pay_type' => $pay_type,
- 'platform' => $platform,
- 'table_name' => 'money_recharge',
- 'table_id' => 0,
- 'createtime' => time(),
- 'args' => json_encode([
- 'table_id' => 0,
- 'money' => $money,
- 'remark' => $remark
- ], JSON_UNESCAPED_UNICODE),
- ];
- if (!Db::name('pay_order')->insert($orderData)) {
- return $this->error('订单创建失败');
- }
-
- $params = [
- 'type' => $orderData['pay_type'],
- 'orderid' => $orderData['out_trade_no'],
- 'title' => $remark,
- 'amount' => $orderData['order_amount'],
- 'method' => $orderData['platform'],
- 'notifyurl' => CurlUtil::getHttp("/api/notify/recharge/pay_type/{$pay_type}"),
- 'returnurl' => '',
- ];
-
- if ($pay_type == 'wechat' && $platform == 'miniapp') {
- $params['openid'] = $this->auth->mini_openid;
- }
- $res = Service::submitOrder($params);
- if ($pay_type == 'wechat') {
- $this->success('success', json_decode($res, true));
- } else {
- $this->success('success', $res);
- }
- }
- }
|