Files
amb_wechatapp/application/api/controller/user/Collect.php
T

93 lines
2.0 KiB
PHP

<?php
namespace app\api\controller\user;
use app\common\controller\Api;
use think\Db;
/**
* 用户shocking
*/
class Collect extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['getIsCollect'];
protected $noNeedRight = '*';
protected $courseModel;
protected $model;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\common\model\user\Collect();
$this->courseModel = new \app\admin\model\course\Course;
}
public function getIsCollect()
{
if(!$this->auth->isLogin()){
$this->success('未登录',false);
}
$itemId = input('item_id','');
$type = input('type','course');
if($type != 'course'){
$this->error('参数错误');
}
$result = $this->model->where([
'user_id'=>$this->auth->id,
'item_id'=>$itemId,
'type'=>$type
])->find();
if($result){
$result = true;
}else{
$result = false;
}
$this->success('获取成功',$result);
}
/**
* 设置收藏状态
* @return void
*/
public function setCollect(){
$itemId = input('item_id','');
$type = input('type','course');
if($type != 'course'){
$this->error('参数错误');
}
$courseInfo = $this->courseModel->get($itemId);
if(!$courseInfo){
$this->error('获取课程信息失败');
}
$this->model->setCollect($this->auth->id,$itemId,$type);
$this->success('操作成功');
}
/**
* 获取我的订阅
* @return void
*/
public function getMyCollect(){
$limit = input('limit',10);
$page = input('page',1);
$type = input('type','all');
$list = $this->model->getMyCollect($this->auth->id,[
'limit'=>$limit,
'page'=>$page,
'type'=>$type
]);
$this->success('获取成功',$list);
}
}