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('使用成功'); } }