初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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("兑换成功,可在我的订阅中查看兑换的课程");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user