IntermediaryneedController.php
13.9 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?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\AgencyModel;
use api\portal\model\OrderModel;
use api\portal\model\UserNeedModel;
use api\portal\model\MemberModel;
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 IntermediaryneedController extends CommonController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* @title 中介报价时保证金金额(填完房价调用;每次修改重新调用)
* @description 接口说明
* @author 开发者
* @url /api/portal/Intermediaryneed/payMoney
* @method POST
* @param name:housing_price type:int require:1 default: other: desc:房价
* @param name:token type:int require:1 default: other: desc:token
*/
public function payMoney($housing_price){
$where_inteRule['status'] = 1;
$where_inteRule['low'] = array('elt',$housing_price);
$where_inteRule['height'] = array('egt',$housing_price);
$inte_money = Db::name('IntermediaryRule')->where($where_inteRule)->field('money')->find();
if(!$inte_money){
$this->apiResponse('0','保证金获取失败');
}else{
$this->apiResponse('1','成功',$inte_money['money']);
}
}
/**
* @title 匹配需求
* @description 接口说明
* @author 开发者
* @url /api/portal/Intermediaryneed/sendNeed
* @method POST
* @param name:token type:int require:1 default: other: desc:token
* @param name:page type:int require:1 default: other: desc:分页
* @return data:''@
* @data city:'地区'
* @data quarters:'小区'
* @data room:'具体房号'
* @data floor:'楼层'
* @data house_type:'户型'
* @data renovation:'装修'
* @data quotation_time:'报价时间(天)'
* @data create_time:'发布时间'
* @data people:'报价人数'
*/
public function sendNeed(Request $request){
$data = $request->param();
$page = $data['page'];
$size = 4;
$final_list = array();
$getPageList = array();
$is_send = array();
$where_member['token'] = $data['token'];
// 查询,匹配:省市区县精确匹配,小区名模糊匹配(只要有连续字匹配,就算匹配)
$member_find = Db::name('Member')->where($where_member)->field("id,city,quarters")->find();
if(!$member_find){
$this->apiResponse('0','用户信息错误');
}
$where_need['city'] = $member_find['city'];
$where_need['status'] = 3;
$need_list = Db::name('UserNeed')->where($where_need)->field("id,city,quarters,room,floor,house_type,renovation,quotation_time,create_time,people,pay_time")->order('pay_time desc')->select()->toArray();
if($need_list){
foreach ($need_list as $nek=>$nev){
$is_match = strpos($member_find['quarters'],$nev['quarters']);
if($is_match !== false){
// 筛除已报价
$where_age['need_id'] = $nev['id'];
$where_age['agency_id'] = $member_find['id'];
$where_age['status'] = array('not in','1,9');
$is_agen = Db::name('Agency')->where($where_age)->field('id,need_id')->find();
$k[] = $is_agen['need_id'];
if(!$is_agen){
$final_list[] = $nev;
}else{
$c[] = $nev['id'];
}
}
}
$begin_page = $page*$size-$size;
$end_page = $page*$size;
if(!empty($final_list)){
foreach ($final_list as $fink=>$finv){
if($fink >= $begin_page && $fink < $end_page){
$getPageList[] = $finv;
}
}
}
$final['need_list'] = $getPageList;
$count = count($final_list);
$final['all_page'] = ceil($count/$size);
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','该地区暂无匹配需求');
}
}
// 匹配需求 按用户匹配(旧版)
public function sendNeedold(Request $request){
$data = $request->param();
$page = $data['page'];
$size = 4;
$where_member['token'] = $data['token'];
// 查询,匹配:省市区县精确匹配,小区名模糊匹配(只要有连续字匹配,就算匹配)
$member_find = Db::name('Member')->where($where_member)->field("id,city,quarters")->find();
if(!$member_find){
$this->apiResponse('0','用户信息错误');
}
$where_need['city'] = $member_find['city'];
$where_need['status'] = 3;
$quarters = explode('+',$member_find['quarters']);
if($quarters){
foreach ($quarters as $quartersk=>$quartersv){
$quarters[$quartersk] = '%'.$quartersv.'%';
}
}
$where_need['quarters'] = array('like',$quarters,'OR');
$need_list = Db::name('UserNeed')->where($where_need)->field("id,city,quarters,room,floor,house_type,renovation,quotation_time,create_time,people,pay_time")->order('pay_time desc')->limit($size)->page($page)->select()->toArray();
$count = count($need_list);
$final['all_page'] = ceil($count/$size);
$final_list = array();
if($need_list){
// 筛除已报价
foreach ($need_list as $nek=>$nev){
$where_age['need_id'] = $nev['id'];
$where_age['agency_id'] = $member_find['id'];
$where_age['status'] = array('not in','1,9');
$is_agen = Db::name('Agency')->where($where_age)->field('id')->find();
if(!$is_agen){
$final_list[] = $nev;
}
}
$final['need_list'] = $final_list;
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','该地区暂无匹配需求');
}
}
/**
* @title 中介报价(sure)
* @description 接口说明
* @author 开发者
* @url /api/portal/Intermediaryneed/send
* @method POST
* @param name:need_id type:varchar require:1 default: other: desc:需求id
* @param name:housing_price type:varchar require:1 default: other: desc:房价
* @param name:assessment_tax type:varchar require:1 default: other: desc:评估税
* @param name:value_added_tax type:int require:1 default: other: desc:增值税
* @param name:security_tax type:varchar require:1 default: other: desc:贷款担保税
* @param name:deed_tax type:varchar require:1 default: other: desc:契税
* @param name:else_tax type:varchar require:1 default: other: desc:其他税费
* @param name:personal_income_tax type:tinyint require:1 default: other: desc:个税
* @param name:service_charge type:tinyint 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 is_loan:'全款'
* @data is_contract:'非包干价'
*/
public function send(Request $request)
{
// header('Access-Control-Allow-Origin:*');
if($request->Post('token') && $request->Post('housing_price')){
// 判空,处理
Db::startTrans();
$validate = Loader::validate('IntermediaryNeed');
if(!$validate->scene('offer')->check($_POST)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
$data = $request->Post();
$token = $data['token'];
$model = new AgencyModel();
$where_mem['token'] = $data['token'];
$mem_id = Db::name('Member')->where($where_mem)->field('id')->find();
$data['agency_id'] = $mem_id['id'];
// 判断是否已发布过
$where_isIsset['need_id'] = $data['need_id'];
$where_isIsset['agency_id'] = $mem_id['id'];
$where_isIsset['status'] = array('not in','1,9');
$find_isset = $model->where($where_isIsset)->find();
if($find_isset){
Db::rollback();
$middle_final['need_id'] = $data['need_id'];
$this->apiResponse('0','该房屋您已参与报价',$middle_final);
}
// 判断是否存在
$where_issetNeed['id'] = $data['need_id'];
$where_issetNeed['status'] = 3;
$issetNeed = Db::name('UserNeed')->where($where_issetNeed)->find();
if(!$issetNeed){
Db::rollback();
$this->apiResponse('0','需求错误');
}
if(empty($data['assessment_tax'])){
$data['assessment_tax'] = 0;
}
if(empty($data['value_added_tax'])){
$data['value_added_tax'] = 0;
}
if(empty($data['security_tax'])){
$data['security_tax'] = 0;
}
if(empty($data['deed_tax'])){
$data['deed_tax'] = 0;
}
if(empty($data['else_tax'])){
$data['else_tax'] = 0;
}
if(empty($data['personal_income_tax'])){
$data['personal_income_tax'] = 0;
}
if(empty($data['service_charge'])){
$data['service_charge'] = 0;
}
$data['all_price'] = $data['housing_price'] + $data['assessment_tax'] + $data['value_added_tax'] + $data['security_tax'] + $data['deed_tax'] + $data['else_tax'] + $data['personal_income_tax'] + $data['service_charge'];
// 查询中介保证金
// $where_inteRule['status'] = 1;
$where_inteRule['low'] = array('lt',$data['housing_price']);
$where_inteRule['height'] = array('egt',$data['housing_price']);
$inte_money = Db::name('IntermediaryRule')->where($where_inteRule)->field('money')->find();
if(!$inte_money){
Db::rollback();
$this->apiResponse('0','保证金获取失败');
}else{
$data['deposit'] = $inte_money['money'];
$final['pay_money'] = $data['deposit'];
}
unset($data['token']);
$save = $model->save($data);
$final['intermediaryNeed_id'] = $model->getLastInsID();
if($save){
$where_addCount['token'] = $token;
$add_count = Db::name('member')->where($where_addCount)->setInc('count_agency',1);
if(!$add_count){
Db::rollback();
}else{
Db::commit();
$this->apiResponse('1','添加成功',$final);
}
}else{
Db::rollback();
$this->apiResponse('0','添加失败');
}
}else{
// 问答内容
$where_pro['status'] = 1;
$where_pro['type'] = 2;
$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['content'] = $list;
// 查询用户发布需求
if(!$request->param('need_id')){
$this->apiResponse('0','请选择报价房屋');
}
$where_need['id'] = $request->param('need_id');
$where_need['status'] = 3;
$need = Db::name('UserNeed')->where($where_need)->field("loan,contract")->find();
if(!$need){
$this->apiResponse('0','该需求暂不可报价');
}
// 全款
if($need['loan'] == 2 ){
$final['is_loan'] = 1;
}
// 包干价
if($need['contract'] == 2 ){
$final['is_contract'] = 1;
}
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','暂无内容');
}
}
}
/**
* @title 中介报价字段筛选
* @description 接口说明
* @author 开发者
* @url /api/portal/Intermediaryneed/choose
* @method POST
* @param name:need_id type:varchar require:1 default: other: desc:需求id
* @param name:token type:varchar require:1 default: other: desc:token
* @return data:''@
* @data is_loan:'全款'
* @data is_contract:'非包干价'
*/
public function choose(){
$data = $this->request->param();
$where_need['status'] = array('neq',9);
$where_need['id'] = $data['need_id'];
$need = Db::name('UserNeed')->where($where_need)->field('loan,contract')->find();
if($need){
$final['need'] = $need;
$this->apiResponse('1','成功',$final);
}else{
$this->apiResponse('0','需求错误');
}
}
}