53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\app\exchange;
|
|
|
|
use app\common\controller\Api;
|
|
|
|
/**
|
|
* 兑换码
|
|
*/
|
|
class Code extends Api
|
|
{
|
|
|
|
protected $noNeedLogin = [];
|
|
// 无需鉴权的接口,*表示全部
|
|
protected $noNeedRight = ['*'];
|
|
|
|
protected $model;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
|
|
$this->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("兑换成功,可在我的订阅中查看兑换的课程");
|
|
}
|
|
|
|
} |