Hot.php
5.1 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
148
149
150
151
152
153
154
155
156
157
158
159
<?php
namespace app\api\controller;
use app\api\model\Deposit;
use app\api\model\DepositOrder;
use app\api\model\Industry;
use app\api\model\StoreComment;
use app\api\model\StoreInform;
use app\api\model\StoreInformGood;
use app\api\model\UserHouse;
use app\api\validate\HotValidate;
use app\common\controller\Api;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\Request;
/**
* 周边热点接口
*/
class Hot extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
protected $store_model;
protected $store_inform_model;
protected $store_inform_good_model;
protected $user_house_model;
protected $industry_model;
protected $favorite_model;
protected $comment_model;
protected $good_model;
protected $follow_model;
protected $user_id;
public function __construct(Request $request,\app\api\model\Store $store,Industry $industry,StoreInform $store_inform,UserHouse $user_house,StoreInformGood $store_inform_good)
{
parent::__construct($request);
$this->industry_model = $industry;
$this->store_model = $store;
$this->store_inform_model = $store_inform;
$this->store_inform_good_model = $store_inform_good;
$this->user_house_model = $user_house;
$this->user_id = $this->auth->id;
}
/**
* 商圈信息列表
* @ApiWeigh (80)
*
* @ApiTitle (商圈信息列表)
* @ApiSummary (商圈信息列表)
* @ApiMethod (POST)
* @ApiRoute (/api/hot/store_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function store_list()
{
if($this->request->isPost()){
$page = $this->request->param('page',1,'intval');
$house_ids = $this->user_house_model->where('user_id',$this->user_id)->column('house_id');
$query = function ($query) use ($house_ids){
foreach ($house_ids as $k=>$v){
$w = ['house_ids'=>['like','%,'.$v.',%']];
if($k == 0) {
$query->where($w);
} else {
$query->whereOr($w);
}
}
};
$where = [
'where' => $query
];
$order = ['number'=>'DESC','createtime'=>'DESC'];
$inform = $this->store_inform_model->pageSelect($page,$where,'*',$order,config('option.num'));
$list = $inform->items();
foreach ($list as &$v) {
// 获取点赞数及是否点赞
$where_g = [
'object_id' => $v['id']
];
$v['good_count'] = $this->store_inform_good_model->getCount($where_g);
$where_g['user_id'] = $this->user_id;
$v['is_good'] = $this->store_inform_good_model->getCount($where_g);
}
$return = [
'list' => $list,
'this_page' => $inform->currentPage(),
'total_page' => $inform->lastPage()
];
$this->success('请求成功',$return);
}
}
/**
* 留言提交
* @ApiWeigh (50)
*
* @ApiTitle (留言提交)
* @ApiSummary (留言提交)
* @ApiMethod (POST)
* @ApiRoute (/api/hot/comment_add)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="store_id", type="integer", required=true, description="店铺id")
* @ApiParams (name="content", type="string", required=true, description="留言内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function comment_add()
{
$param = (new HotValidate())->goCheck('comment_add');
$where = [
'where' => ['id' => $param['store_id']]
];
$store = $this->store_model->findOrFail($where);
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$param['store_user_id'] = $store['user_id'];
$model = new StoreComment();
$result = $model->add($param);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('留言失败');
}
$this->success('留言成功');
}
}