Plus.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. use fast\Random;
  5. use think\Db;
  6. /**
  7. * 首页接口
  8. */
  9. class Plus extends Api
  10. {
  11. protected $noNeedLogin = [''];
  12. protected $noNeedRight = ['*'];
  13. public function plus()
  14. {
  15. $uid = $this->auth->id;
  16. $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_plus,plusname,plustime')->find();
  17. $type = input('type','');
  18. if($type == 'pay')
  19. {
  20. if (!$this->request->isPost()) {
  21. $this->error('请求方式异常');
  22. }
  23. $id = input('id/d','');
  24. $paytype = input('paytype/d',0);
  25. $info = model('app\api\model\service\PlusConfig')->where(['id'=>$id])->field('id,price,name')->find();
  26. !$info && $this->error('参数错误');
  27. $price = sprintf("%.2f",$info['price']);
  28. $orderId = 'PlusPay'.Random::alnum(4).'-'.$uid.'-'.time();
  29. $re = '';
  30. Db::startTrans();
  31. try{
  32. $skillEnsurePay = new \app\api\model\service\PlusPay(['user_id'=>$uid,'price'=>$price,'plus_id'=>$id,'orderId'=>$orderId,'paytype'=>$paytype]);
  33. $skillEnsurePay->allowField(true)->save();
  34. $re = \addons\service\library\Pay::payOrder(['amount'=>$price,'orderid'=>$orderId,'title'=>'充值会员'],$paytype,$uid,0);
  35. Db::commit();
  36. } catch (Exception $e) {
  37. Db::rollback();
  38. $this->error('支付拉起失败',$e->getMessage());
  39. }
  40. $this->success('支付信息返回成功',$re);
  41. }
  42. $list = model('app\api\model\service\PlusConfig')->field('id,name,price,original_price,daynums,discount')->order('price asc')->select();
  43. $this->success('信息返回成功',$list);
  44. }
  45. }