ThirdsendController.php
8.7 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
<?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 cmf\controller\HomeBaseController;
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 30分钟后发布
* @description 接口说明
* @group 接口分组
*/
class ThirdsendController extends HomeBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
// 查询中介报价
// $need_id 需求id
public function Offer($user_id,$need_id){
$where_agency['status'] = 2;
$where_agency['create_time'] = array('lt',time());
$where_agency['need_id'] = $need_id;
$agency_list = Db::name('Agency')
->where($where_agency)
// ->field("id,housing_price,assessment_tax,security_tax,else_tax,service_charge")
->select()->toArray();
if($agency_list){
foreach ($agency_list as $agencyk=>$agencyv){
// $final_list[$agencyk] = $agencyv;
// $final_list[$agencyk]['agency_id'] = $agencyv['id'];
// $final_list[$agencyk]['user_id'] = $user_id;
$money = $agencyv['housing_price']*10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'] ;
$money_arr[] = $money;
$fianlMoney = substr($money, 0,-4);
$agency_list[$agencyk]['true_money'] = $money;
// $final_list[$agencyk]['money'] = $fianlMoney;
}
sort($money_arr);
if(count($money_arr) > 3 ){
foreach ($agency_list as $finalk=>$finalv){
foreach ($money_arr as $monryk=>$moneyv){
if($finalv['true_money'] == $moneyv){
$return[] = $finalv;
}
}
}
}else{
$save['status'] = 8;
}
return $return;
}
}
// 30分钟后发布
public function thirdSend(){
Db::startTrans();
$where_need['status'] = 1;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,create_time')->select()->toArray();
$time = time();
$change_arr = array();
foreach ($userNeedList as $userk=>$userv){
if($userv['create_time'] <= ($time+60) && $userv['create_time'] >= $time){
$change_arr[] = $userv['id'];
}
}
if($change_arr){
$where_save['id'] = array('in',$change_arr);
$save['status'] = 2;
$save['update_time'] = time();
$fianl_save = Db::name('UserNeed')->where($where_save)->update($save);
if($fianl_save){
Db::commit();
}else{
Db::rollback();
}
}
}
// 规定时间结束报价
public function over()
{
Db::startTrans();
// 查询用户发布需求信息
$where_need['status'] = 2;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,quotation_time,create_time')->select()->toArray();
$change_arr = array();
$time = time();
$time = '1529734985';
// 循环需求,查询相应报价
foreach ($userNeedList as $uNeedk => $uNeedv) {
$final_time = $uNeedv['create_time'] + $uNeedv['quotation_time'] * 86400;
if ($final_time <= ($time + 60) && $final_time >= $time) {
$us_middleid = $uNeedv['id'];
$where_agency['a.status'] = 2;
$where_agency['a.create_time'] = array('lt', time());
$where_agency['a.need_id'] = $uNeedv['id'];
$where_agency['m.type'] = 2;
$where_agency['m.status'] = 1;
$agency_list = Db::name('Agency')->alias('a')
->where($where_agency)
->join("hp_Member m", 'm.id = a.agency_id')
->field('a.*,m.company')
->select()->toArray();
// 查询品牌企业
$where_brand['status'] = 1;
$band_list = Db::name('Brand')->where($where_brand)->column('name');
$agen_arr = array();
$money_arr = array();
if ($agency_list) {
// 判断是否超过三个报价人
if (count($agency_list) >= 3) {
// 查询三人中是否有品牌中介
// 循环匹配品牌企业
foreach ($agency_list as $agencyk => $agencyv) {
foreach ($band_list as $brak => $brav) {
// 判断是否在品牌企业中
if (strstr($brav, $agencyv['company']) !== false) {
// 存在
$agen_money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
if (empty($agen_arr)) {
$agen_arr[0]['money'] = $agen_money;
$agen_arr[0]['id'] = $agencyv['id'];
} else {
// 判断大小
if ($agen_money < $agen_arr[0]['money']) {
$agen_arr[0]['money'] = $agen_money;
$agen_arr[0]['id'] = $agencyv['id'];
}
}
}
}
// 取出前三报价
$money = $agencyv['housing_price'] * 10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'];
$money_list[$agencyv['id']] = $money;
}
asort($money_list);
$k = 0;
foreach ($money_list as $mok => $mov) {
if ($k < 3) {
$fin_list[$k]['id'] = $mok;
$fin_list[$k]['money'] = $mov;
$fin_arr[] = $mok;
}
$k += 1;
}
$ag_id = implode(',', $fin_arr);
$userSave_status['status'] = 5;
$agencySave_status['status'] = 4;
} else {
// 报价小于3人,更改订单状态,报价失败
$userSave_status['status'] = 4;
$agencySave_status['status'] = 7;
}
} else {
// 没有报价
$userSave_status['status'] = 4;
$agencySave_status['status'] = 7;
}
$us_id = implode(',', $us_middleid);
// 插入数据库
// 用户需求表
$where_us['id'] = array('in', $us_id);
$fianl_Ussave = Db::name('UserNeed')->where($where_us)->update($userSave_status);
if(!$fianl_Ussave){
Db::rollback();
}
// 中介报价表
$where_ag['id'] = array('in', $ag_id);
$fianl_Agsave = Db::name('Agency')->where($where_ag)->update($agencySave_status);
if(!$fianl_Agsave){
Db::rollback();
}else{
Db::commit();
}
}
}
}
// 三天用户选择
public function userChoose(){
Db::startTrans();
// 查询用户发布需求信息
$where_need['status'] = 2;
$userNeedList = Db::name('UserNeed')->where($where_need)->field('id,quotation_time,create_time')->select()->toArray();
}
// 三天中介确认
public function intermediaryChoose(){
}
}