| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\api\controller\service;
- use app\common\controller\Api;
- use fast\Random;
- use think\Db;
- /**
- * 首页接口
- */
- class Plus extends Api
- {
- protected $noNeedLogin = [''];
- protected $noNeedRight = ['*'];
- public function plus()
- {
- $uid = $this->auth->id;
- $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_plus,plusname,plustime')->find();
- $type = input('type','');
- if($type == 'pay')
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $id = input('id/d','');
- $paytype = input('paytype/d',0);
- $info = model('app\api\model\service\PlusConfig')->where(['id'=>$id])->field('id,price,name')->find();
- !$info && $this->error('参数错误');
- $price = sprintf("%.2f",$info['price']);
- $orderId = 'PlusPay'.Random::alnum(4).'-'.$uid.'-'.time();
- $re = '';
- Db::startTrans();
- try{
- $skillEnsurePay = new \app\api\model\service\PlusPay(['user_id'=>$uid,'price'=>$price,'plus_id'=>$id,'orderId'=>$orderId,'paytype'=>$paytype]);
- $skillEnsurePay->allowField(true)->save();
- $re = \addons\service\library\Pay::payOrder(['amount'=>$price,'orderid'=>$orderId,'title'=>'充值会员'],$paytype,$uid,0);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error('支付拉起失败',$e->getMessage());
- }
- $this->success('支付信息返回成功',$re);
- }
- $list = model('app\api\model\service\PlusConfig')->field('id,name,price,original_price,daynums,discount')->order('price asc')->select();
- $this->success('信息返回成功',$list);
- }
- }
|