初始化项目:添加后端代码、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("兑换成功,可在我的订阅中查看兑换的课程");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\app\exchange;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* 兑换记录
|
||||
*/
|
||||
class UseLog extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = [];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
$this->model = new \app\api\model\app\exchange\UseLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function getLog()
|
||||
{
|
||||
$limit = input('limit',10);
|
||||
$page = input('page',1);
|
||||
|
||||
$where = [
|
||||
'user_id'=>$this->auth->id
|
||||
];
|
||||
$list = $this->model
|
||||
->with(['batch','course'])
|
||||
->where($where)
|
||||
->limit($limit)
|
||||
->page($page)
|
||||
->order('createtime','desc')
|
||||
->select();
|
||||
|
||||
if(!empty($list)){
|
||||
foreach ($list as $item){
|
||||
$item->batch->visible(['name']);
|
||||
$item->course->visible(['name','type']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('获取成功', $list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user