UserneedController.php
13.5 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\portal\model\UserNeedModel;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
use think\Db;
use think\Request;
use think\Loader;
use think\Config;
use think\captcha\Captcha;
use think\Url;
use SmsDemo;
//use think\Route;
/**
* @title 用户需求接口
* @description 接口说明
* @group 接口分组
*/
class UserneedController extends CommonController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* @title 用户发布需求时保证金金额(填完地区,小区调用;每次修改重新调用)(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/payMoney
* @method POST
* @param name:city type:int require:1 default: other: desc:地区
* @param name:area type:int require:1 default: other: desc:面积
*/
public function payMoney(Request $request){
$data = $request->param();
if(!$data['city'] || !$data['area'] ){
$this->apiResponse('0','城市、面积不能为空');
}
$city = $data['city'];
$area = $data['area'];
// 查询地区
$where_area['area_name'] = array('like',"%$city%");
// $where_area['parent_id'] = 0;
$city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
$where_money['city'] = array('like',"%".$city_id['area_id'].'%');
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if(!$money){
$where_elsemoney['city'] = 0;
$where_elsemoney['status'] = 1;
$where_elsemoney['low_area'] = array('lt',$area);
$where_elsemoney['height_area'] = array('egt',$area);
$elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
if($elsemoney){
$this->apiResponse('1','成功',$elsemoney['money']);
}else{
$this->apiResponse('0','保证金获取失败');
}
}else{
$this->apiResponse('1','成功',$money['money']);
}
}
/**
* @title 用户发布需求(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/send
* @method POST
* @param name:city type:varchar require:1 default: other: desc:地区(省-市-区)
* @param name:quarters type:varchar require:1 default: other: desc:小区
* @param name:room type:varchar require:1 default: other: desc:具体房号(1-1-1)
* @param name:floor type:int require:1 default: other: desc:楼层
* @param name:house_type type:varchar require:1 default: other: desc:户型
* @param name:renovation type:varchar require:1 default: other: desc:装修
* @param name:area type:varchar require:1 default: other: desc:建筑面积
* @param name:is_first type:tinyint require:1 default: other: desc:是否首套房(1->首套房,2->两套及以上)
* @param name:loan type:tinyint require:1 default: other: desc:贷款(1->贷款,2->全款)
* @param name:contract type:tinyint require:1 default: other: desc:是否是包干价(1->是,2->否)
* @param name:quotation_time type:int require:1 default: other: desc:报价时间
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:else type:int require:1 default: other: desc:备注
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data type:'1->包干价,2->问答'
* @data need_id:'需求id'
*/
public function send(Request $request)
{
Db::startTrans();
if($request->Post('token') && $request->Post('area')){
// $data = $request->param();
// 判空,处理
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
$data = $request->Post();
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$where_area['area_name'] = array('like',"%$city%");
$city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
$where_money['city'] = array('like',"%".$city_id['area_id'].'%');
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if(!$money){
$where_elsemoney['city'] = 0;
$where_elsemoney['status'] = 1;
$where_elsemoney['low_area'] = array('lt',$area);
$where_elsemoney['height_area'] = array('egt',$area);
$elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
if($elsemoney){
$data['pay_money'] = $elsemoney['money'];
}else{
Db::rollback();
$this->apiResponse('0','保证金获取失败');
}
}else{
$data['pay_money'] = $money['money'];
}
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['user_id'] = $mem_id['id'];
$model = new UserNeedModel();
// 添加
unset($data['code']);
unset($data['connect']);
unset($data['token']);
$save = $model->save($data);
if($save){
$final['userNeed_id'] = $model->getLastInsID();
Db::commit();
$this->apiResponse('1','添加成功',$final);
}else{
Db::rollback();
$this->apiResponse('0','添加失败');
}
}else{
// 问答内容
$where_pro['status'] = 1;
$list = Db::name('NeedAnswer')->where($where_pro)->order("update_time desc")->field("title,content,id,type")->select()->toArray();
foreach ($list as $lk=>$lv){
$list[$lk]['content'] = htmlspecialchars_decode($lv['content']);
}
if($list){
$final['answer'] = $list;
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
/**
* @title 用户修改需求(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/UserNeed/changesend
* @method POST
* @param name:city type:varchar require:1 default: other: desc:地区(省-市-区)
* @param name:quarters type:varchar require:1 default: other: desc:小区
* @param name:room type:varchar require:1 default: other: desc:具体房号(1-1-1)
* @param name:floor type:int require:1 default: other: desc:楼层
* @param name:house_type type:varchar require:1 default: other: desc:户型
* @param name:renovation type:varchar require:1 default: other: desc:装修
* @param name:area type:varchar require:1 default: other: desc:建筑面积
* @param name:is_first type:tinyint require:1 default: other: desc:是否首套房(1->首套房,2->两套及以上)
* @param name:loan type:tinyint require:1 default: other: desc:贷款(1->贷款,2->全款)
* @param name:contract type:tinyint require:1 default: other: desc:是否是包干价(1->是,2->否)
* @param name:quotation_time type:int require:1 default: other: desc:报价时间
* @param name:name type:varchar require:1 default: other: desc:联系人姓名
* @param name:tel type:varchar require:1 default: other: desc:联系人电话
* @param name:code type:int require:1 default: other: desc:验证码
* @param name:else type:int require:1 default: other: desc:备注
* @param name:need_id type:int require:1 default: other:修改需求时传 desc:需求id
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data type:'1->包干价,2->问答'
* @data need_id:'需求id'
*/
public function changeSend(Request $request)
{
if($request->Post('token') && $request->Post('name')){
// $data = $request->param();
// 判空,处理
$validate = Loader::validate('UserNeed');
if(!$validate->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
$data = $request->Post();
// 保证金
$city = $data['city'];
$area = $data['area'];
// 查询地区
$where_area['area_name'] = array('like',"%$city%");
$city_id = Db::name('Areas')->where($where_area)->field('area_id')->find();
$where_money['city'] = array('like',"%".$city_id['area_id'].'%');
$where_money['status'] = 1;
$where_money['low_area'] = array('lt',$area);
$where_money['height_area'] = array('egt',$area);
$money = Db::name('MoneyRule')->where($where_money)->field('money')->find();
if(!$money){
$where_elsemoney['city'] = 0;
$where_elsemoney['status'] = 1;
$where_elsemoney['low_area'] = array('lt',$area);
$where_elsemoney['height_area'] = array('egt',$area);
$elsemoney = Db::name('MoneyRule')->where($where_elsemoney)->field('money')->find();
if($elsemoney){
$data['pay_money'] = $elsemoney['money'];
}else{
$this->apiResponse('0','保证金获取失败');
}
}else{
$data['pay_money'] = $money['money'];
}
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['user_id'] = $mem_id['id'];
$model = new UserNeedModel();
// 修改
$where_need['id'] = $request->param('need_id');
$where_need['status'] = array('in','1,2');
$need = Db::name('UserNeed')->where($where_need)->find();
if(!$need){
$this->apiResponse('0','该需求不可修改');
}else{
unset($data['code']);
unset($data['connect']);
unset($data['token']);
$data['id'] = $data['need_id'];
if($need['status'] == 2){
unset($data['pay_money']);
}
$save = $model->isUpdate(true)->allowField(true)->save($data);
}
if($save){
$final['need_id'] = $model->id;
$this->apiResponse('1','修改成功',$final);
}else{
$this->apiResponse('0','修改失败');
}
}else{
$data = $request->param();
if(empty($data['need_id'])){
$this->apiResponse('0','需求id不可為空');
}
$where_need['id'] = $request->param('need_id');
$where_need['status'] = array('in','1,2');;
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$where_need['user_id'] = $mem_id['id'];
$list['need'] = Db::name('UserNeed')->where($where_need)->find();
if(!$list['need']){
$this->apiResponse('0','该需求不可修改');
}
// 问答内容
$where_pro['status'] = 1;
$answer = Db::name('NeedAnswer')->where($where_pro)->order("update_time desc")->field("title,content,id,type")->select()->toArray();
foreach ($answer as $lk=>$lv){
$answer[$lk]['content'] = htmlspecialchars_decode($lv['content']);
}
$list['answer'] = $answer;
if($list){
$this->apiResponse('1','成功',$list);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
}