1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\PayOrderModel;
- use app\common\model\Wallet;
- use app\utils\CurlUtil;
- use think\Db;
- use addons\epay\library\Service;
- /**
- * 充值配置与充值订单
- */
- class Vip extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- // VIP抵扣券
- public function coupon()
- {
- $user_id = $this->auth->id;
- $list = Db::name('vip_coupon_user')
- ->field(['id','coupon_no','type','name','info','end_time','use_frequency_day','use_frequency_times','status','create_time'])
- ->where('user_id',$user_id)
- ->whereIn('status',[1,2])
- ->order('id desc')
- ->autopage()
- ->select();
- foreach ($list as $key=>$val){
- $list[$key]['end_time_text'] = date('Y-m-d H:i',$val['end_time']);
- $list[$key]['create_time_text'] = date('Y-m-d H:i',$val['create_time']);
- }
- $this->success('success', $list);
- }
- // 使用抵扣券
- public function coupon_use()
- {
- $user_id = $this->auth->id;
- $params = $this->request->param();
- if (empty($params['coupon_id'])){
- $this->error('请选择要使用的抵扣券');
- }
- $info = Db::name('vip_coupon_user')
- ->where('id',$params['coupon_id'])
- ->where('user_id',$user_id)
- ->whereIn('status',[1,2])
- ->find();
- if (!$info){
- $this->error('不存在的券');
- }
- if ($info['status'] != 1){
- $this->error('券已使用');
- }
- if (!Db::name('vip_coupon_user')->where(['id'=>$params['coupon_id'],'status'=>1])->update(['status'=>2])){
- $this->error('操作失败');
- }
- $this->error('使用成功');
- }
- }
|