model = new \app\api\model\app\exchange\Code; $this->batchModel = new \app\api\model\app\exchange\Batch; $this->goodsModel = new \app\api\model\app\exchange\Goods; } /** * 兑换 * @return void */ public function exchange(){ $code = $this->request->post('code'); //判断code是否可用 $codeInfo = $this->model->checkCode($code); if(!$codeInfo){ $this->error("该兑换码暂不可用"); } if(!$this->batchModel->checkLimit($this->auth->id,$codeInfo['batch_id'])){ $this->error("已超出兑换次数限制"); } //发放权益 $this->model->exchange($this->auth->id,$codeInfo['batch_id'],$code); $this->success("兑换成功,可在我的订阅中查看兑换的课程"); } }