HomeController.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/11/27
* Time: 11:31
*/
namespace api\index\controller;
use api\index\model\HomeModel;
use cmf\controller\RestBaseController;
use think\Db;
/**
* @title 家政服务
* @description
*/
class HomeController extends RestBaseController
{
/**
* @title 家政服务首页轮播图
* @description
* @author GuoSheng
* @url /index/Home/photo
* @method GET
*
* @return id:ID
* @return thumbnail:图片
* @return url:链接地址
*
*/
public function photo(){
$where['delete_time'] = ['eq',0];
$data = Db::name('homepic')
->where($where)
->order('id desc')
->select();
foreach ($data as &$v){
$v['thumbnail'] = cmf_get_image_url($v['thumbnail']);
}
$this->success('SUCCESS',$data);
}
/**
* @title 家政公司列表
* @description
* @author GuoSheng
* @url /index/Home/home
* @method GET
*
* @return id:ID
* @return home_name:名称
* @return thumbnail:缩略图
*
*/
public function home(){
$where['delete_time'] = ['eq',0];
$data = Db::name('home')
->where($where)
->field('id,home_name,thumbnail')
->order('id desc')
->select();
foreach ($data as &$v){
$v['thumbnail'] = cmf_get_image_url($v['thumbnail']);
}
$this->success('SUCCESS',$data);
}
/**
* @title 家政公司详情
* @description 家政公司详情
* @author GuoSheng
* @url /index/Home/homeDetail
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:家政服务公司ID
*
* @return id:ID
* @return home_name:名称
* @return home_address:地址
* @return home_phone:联系电话
* @return images:轮播图
* @return content:公司介绍
* @return scver_name:服务名称
*
*/
public function homeDetail()
{
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error(['code'=>40001,'msg'=>'缺少必要参数']);
}
$where['id'] = ['eq',$id];
$homeModel = new HomeModel();
$data = $homeModel->findData($where)->toArray();
$data['sever_name'] = Db::name('service')->where('home_id',$id)->field('id as sever_id,sever_name')->select();
$this->success('SUCCESS',$data);
}
/**
* @title 家政服务服务评价列表
* @description 家政服务服务评价列表
* @author GuoSheng
* @url /index/Home/comment
* @method GET
*
* @param name:home_id type:int require:1 other: desc:家政公司id
* @param name:page type:int require:0 other: desc:当前页(默认1)
* @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
*
* @return id:评价id
* @return user_id:用户ID
* @return user_nickname:用户名
* @return num:评价星数
* @return content:评价内容
*
*/
public function comment()
{
$home_id = $this->request->param('home_id',0,'intval');
if(empty($home_id)){
$this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
}
$page = $this->request->param('page',1,'intval');
$pageNum = $this->request->param('pageNum',10,'intval');
$res = Db::name('shopcomment')
->alias('a')
->join('user b','a.user_id = b.id')
->field('a.*,b.user_nickname')
->where('shopgood_id',$home_id)
->page($page,$pageNum)
->select()
->toArray();
foreach ($res as &$v){
$v['num'] = ceil(($v['speed']+$v['service']+$v['recycle'])/3);
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
}
$this->success('SUCCESS',$res);
}
}