作者 郭盛
1 个管道 的构建 通过 耗费 5 秒

编写老师端接口

... ... @@ -110,11 +110,13 @@ class Index extends Api
}
/**
* @ApiTitle (首页今日推荐/更多老师列表)
* @ApiSummary (首页今日推荐/更多老师列表)
* @ApiTitle (首页今日推荐/更多老师列表(带搜索))
* @ApiSummary (首页今日推荐/更多老师列表(带搜索))
* @ApiMethod (POST)
* @ApiRoute (/api/index/today)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="type", type="int", required=false, description="类型(如果为空或者为1是今日推荐列表 2是更多老师列表)")
* @ApiParams (name="keyword", type="string", required=false, description="关键字")
*
... ... @@ -149,6 +151,7 @@ class Index extends Api
public function today()
{
$token = $this->request->header('token');
//未登录的状态下
if(empty($token)){
$type = $this->request->param('type');
$keyword = $this->request->param('keyword');
... ... @@ -205,6 +208,8 @@ class Index extends Api
}
$this->success('success',$data);
}
//登录的状态下
$user_id = $this->getUserId();
$type = $this->request->param('type');
$keyword = $this->request->param('keyword');
if($type == '' || $type == 1){
... ... @@ -215,7 +220,29 @@ class Index extends Api
->select();
}else{
if(!empty($keyword)){
$history['user_id'] = $user_id;
$history['keyword'] = $keyword;
$history['createtime'] = time();
//查询关键字是否已经存在
$sel = Db::name('keyword')
->where('user_id',$history['user_id'])
->where('keyword',$history['keyword'])
->find();
if(empty($sel)){
Db::name('keyword')->insertGetId($history);
}
//将内容添加进热门搜索表去判断
$hotword['keyword'] = $keyword;
$hotword['createtime'] = time();
$hot = Db::name('hotword')
->where('keyword',$keyword)
->find();
if(!empty($hot)){
Db::name('hotword')->where('id',$hot['id'])->setInc('num');
}else{
Db::name('hotword')->insertGetId($hotword);
}
$contype = Db::name('contype')
->where('title',$keyword)
->field('id,title')
... ... @@ -260,4 +287,175 @@ class Index extends Api
}
$this->success('success',$data);
}
/**
* @ApiTitle (历史记录)
* @ApiSummary (历史记录)
* @ApiMethod (POST)
* @ApiRoute (/api/index/history)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
* "list":[
"id"://记录id,
"keyword"://搜索的内容
],
"hotlist":[
"id"://记录id,
"keyword"://搜索的内容
* ]
}
})
*/
public function history()
{
$user_id = $this->getUserId();
$data['list'] = Db::name('keyword')
->where('user_id',$user_id)
->field('id,keyword')
->limit(4)
->order('id desc')
->select();
$data['hotlist'] = Db::name('hotword')
->field('num,createtime',true)
->order('num desc')
->limit(10)
->select();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (老师详情)
* @ApiSummary (老师详情)
* @ApiMethod (POST)
* @ApiRoute (/api/index/detail)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="id", type="string", required=true, description="老师ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id": //老师id,
"user_id"://用户ID
"name"://老师名字
"sex"://性别
"birth"://出生日期
"idcard"://身份证号
"before"://身份证正面照
"behind"://身份证反面照
"phone"://手机号
"thumbnail"://头像
"address"://常住地
"honor"://头衔
"content"://个人履历
"show"://展示在最前
"desc"://个人简历
"online"://在线时段
"territory_id"://擅长领域ID
"help_num"://帮助人数
"level"://星级
"createtime"://创建时间
"is_guan"://是否关注(1已关注2还未关注)
}
})
*/
public function detail()
{
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('teacher')
->where('id',$id)
->find();
$qiniu = get_addon_config('qiniu');
$http = $qiniu['cdnurl'];
if($data['sex'] == 1){
$data['sex'] = '男';
}else{
$data['sex'] = '女';
}
//查看用户是否已经关注该老师
$good = Db::name('good')
->where('user_id',$user_id)
->where('teacher_id',$id)
->find();
if(empty($good)){
$data['is_guan'] = 2;
}else{
$data['is_guan'] = 1;
}
$data['before'] = $http.$data['before'];
$data['behind'] = $http.$data['behind'];
$data['thumbnail'] = $http.$data['thumbnail'];
$territory_id = explode(',',$data['territory_id']);
$data['territory_id'] = Db::name('territory')
->alias('a')
->join('contype b','a.contype_id = b.id')
->field('a.id,a.money,a.content,b.title')
->whereIn('a.id',$territory_id)
->select();
$this->success('success',$data);
}
/**
* @ApiTitle (老师关注/取消关注接口)
* @ApiSummary (老师关注/取消关注接口)
* @ApiMethod (POST)
* @ApiRoute (/api/index/good)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="id", type="int", required=false, description="老师ID")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function good()
{
$user_id = $this->getUserId();
$param['teacher_id'] = $this->request->param('id');
if(empty($param['teacher_id'])){
$this->error('缺少必要参数');
}
$param['user_id'] = $user_id;
$info = Db::name('good')
->where('user_id',$param['user_id'])
->where('teacher_id',$param['teacher_id'])
->find();
if(empty($info)){
$param['createtime'] = time();
$data = Db::name('good')
->insertGetId($param);
if(!empty($data)){
$this->success('关注成功');
}else{
$this->error('关注失败');
}
}else{
$data = Db::name('good')->where('teacher_id',$param['teacher_id'])->where('user_id',$param['user_id'])->delete();
if(!empty($data)){
$this->success('取消关注成功');
}else{
$this->error('关注失败');
}
}
}
}
... ...
... ... @@ -259,5 +259,56 @@ class Teacher extends Api
}
}
/**
* @ApiTitle (评价老师)
* @ApiSummary (评价老师)
* @ApiMethod (POST)
* @ApiRoute (/api/teacher/comment)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="teacher_id", type="int", required=true, description="老师ID")
* @ApiParams (name="service", type="int", required=true, description="服务态度评分")
* @ApiParams (name="ability", type="int", required=true, description="专业能力评分")
* @ApiParams (name="effect", type="int", required=true, description="解决效果评分")
* @ApiParams (name="content", type="string", required=true, description="评价内容")
* @ApiParams (name="desc", type="string", required=false, description="平台建议")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
'id':评价ID
}
})
*/
public function comment()
{
$param = $this->request->param();
$param['user_id'] = $this->getUserId();
$validate = new Validate([
'teacher_id' => 'require',
'service' => 'require',
'ability'=>'require',
'effect'=>'require',
'content' => 'require',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$param['level'] = ceil(($param['service'] + $param['ability'] + $param['effect'])/3);
$param['createtime'] = time();
$data = Db::name('comment')
->insertGetId($param);
$teacher = Db::name('teacher')->where('id',$param['teacher_id'])->find();
// Db::name('teacher')->where('id',$param['teacher_id'])
if(empty($data)){
$this->error('失败');
}else{
$this->success('成功');
}
}
}
\ No newline at end of file
... ...
此 diff 太大无法显示。