| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace app\api\controller\service;
- use app\common\controller\Api;
- use fast\Random;
- use think\Db;
- /**
- * 首页接口
- */
- class Recharge extends Api
- {
- protected $noNeedLogin = [''];
- protected $noNeedRight = ['*'];
- /**
- * 用户充值余额
- * @return void
- */
- public function recharge11()
- {
- $uid = $this->auth->id;
- $money = model('app\api\model\service\User')->where('id',$uid)->value('money');
- $type = input('type','');
- if($type == 'recharge')
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $price = sprintf("%.2f",input('price',''));
- $price <=0 && $this->error('充值金额错误');
- $orderId = 'Recharge'.Random::alnum(5).'-'.$uid.'-'.time();
- $paytype = input('paytype/d',0);
- $re = '';
- Db::startTrans();
- try{
- $recharge = new \app\api\model\service\Recharge(['user_id'=>$uid,'price'=>$price,'orderId'=>$orderId,'paytype'=>$paytype]);
- $recharge->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);
- }
- $this->success('信息返回成功',$money);
- }
- public function recharge()
- {
- $uid = $this->auth->id;
- $money = model('app\api\model\service\User')->where('id',$uid)->value('money');
- $packageList = model('app\api\model\service\RechargePackage')->where('state',1)->field('id,price,gift_price')->order('price desc')->select();
- $type = input('type','');
- if($type == 'recharge')
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $packageId = input('recharge_package_id','');
- $package = model('app\api\model\service\RechargePackage')->where(['state'=>1,'id'=>$packageId])->field('id,price,gift_price')->find();
- !$package && $this->error('充值套餐信息异常,请联系管理员');
- $price = sprintf("%.2f",$package['price']);
- $price <=0 && $this->error('充值金额错误');
- $gift_price = sprintf("%.2f",$package['gift_price']);
- $orderId = 'Recharge'.Random::alnum(5).'-'.$uid.'-'.time();
- $paytype = input('paytype/d',0);
- $re = '';
- Db::startTrans();
- try{
- $recharge = new \app\api\model\service\Recharge(['user_id'=>$uid,'recharge_package_id'=>$package['id'],'price'=>$price,'gift_price'=>$gift_price,'orderId'=>$orderId,'paytype'=>$paytype]);
- $recharge->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);
- }
- $this->success('信息返回成功',['money'=>$money,'packageList'=>$packageList]);
- }
- /**
- * 充值记录列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function list()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $page = input('page/d',1);
- $list = model('app\api\model\service\Recharge')
- ->where(['user_id'=>$uid,'state'=>1])
- ->field('id,price,gift_price,orderId,paytype,createtime')
- ->order('id desc')
- ->page($page)
- ->limit(10)
- ->select();
- $this->success('信息返回成功',$list);
- }
- }
|