NeedController.php
8.3 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-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\UserNeedModel;
use cmf\controller\AdminBaseController;
use app\portal\model\NeedAnswerModel;
use app\portal\model\MemberModel;
use app\portal\model\UserModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
* @title 保证金内容管理
* @description 接口说明
* @group 接口分组
*/
class NeedController extends AdminBaseController
{
// 列表
public function index(Request $request)
{
$where_coo['n.status'] = array('neq',9);
// $where_coo['type'] = 2;
// $where_coo = array();
$status = 0;
$arr = array();
if($request->param()){
$search = $request->param();
if(!empty($search['start_time'])){
$arr['start_time'] = $search['start_time'];
$start = strtotime($search['start_time']);
if(!empty($search['end_time'])){
$arr['end_time'] = $search['end_time'];
$end = strtotime($search['end_time']);
}else{
$end = time();
}
$where_coo['n.update_time'] = array('between',"$start,$end");
$this->assign('start_time',date('Y-m-d H:i',$start));
$this->assign('end_time',date('Y-m-d H:i',$end));
}else{
if(!empty($search['end_time'])){
$arr['end_time'] = $search['end_time'];
$end = strtotime($search['end_time']);
$where_coo['n.update_time'] = array('elt',$end);
$this->assign('end_time',date('Y-m-d H:i',$end));
}
}
if(!empty($search['name'])){
$arr['name'] = $search['name'];
$where_coo['m.name'] = array('like',"%".$search['name']."%");
$this->assign('name',$search['name']);
}
if(!empty($search['tel'])){
$tel = $search['tel'];
$arr['tel'] = $tel;
$where_coo['m.tel'] = array('like',"%".$search['tel']."%");
$this->assign('tel',$search['tel']);
}
if(!empty($search['status'])){
$where_coo['n.status'] = $search['status'];
$status = $search['status'];
$arr['status'] = $status;
}
}
$this->assign('status',$status);
$coo_list = Db::name('UserNeed')->alias('n')
->join("Member m",'m.id = n.user_id')
->where($where_coo)
->field("m.name as user_name,m.tel as user_tel,n.*")
->order('create_time desc')
->paginate(10,false,['query'=>$arr]);
$page = $coo_list->render();
$this->assign('page',$page);
$this->assign('list',$coo_list);
return $this->fetch('index');
}
// 详情
public function detail(){
$data = $this->request->param();
$where_need['n.id'] = $data['id'];
$where_need['n.status'] = array('neq',9);
$need = Db::name('UserNeed')->alias('n')
->join("Member m",'m.id = n.user_id')
->where($where_need)
->field('m.name as user_name,n.*')
->find();
if(!$need){
$this->error('需求错误');
}
$this->assign('list',$need);
return $this->fetch();
}
// 修改信息
public function change(Request $request)
{
$data = $request->Post();
$validate = Loader::validate('UserNeed');
if(!$validate->check($data)){
return json(array('code'=>0,'msg'=>$validate->getError()));
}
// 加数据库
// 保证金
$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->error('保证金获取失败');
}
}else{
$data['pay_money'] = $money['money'];
}
$model = new UserNeedModel();
// 修改
$where_need['id'] = $request->param('id');
$where_need['status'] = array('neq',9);
$need = Db::name('UserNeed')->where($where_need)->find();
$data['user_id'] = $need['user_id'];
if(!$need){
$this->error('该需求不可修改');
}else{
// $data['id'] = $data['need_id'];
if($need['status'] == 2){
unset($data['pay_money']);
}
$data['create_time'] = strtotime($data['create_time']);
$data['update_time'] = strtotime($data['update_time']);
$data['pay_time'] = strtotime($data['pay_time']);
$data['choose_time'] = strtotime($data['choose_time']);
$save = $model->isUpdate(true)->allowField(true)->save($data);
}
if($save){
$final['need_id'] = $model->id;
$this->success('修改成功',url('Need/index'));
}else{
$this->error('修改失败');
}
}
// 删除
public function del(Request $request){
$ids = $this->request->post();
$id = $request->param('id');
if($ids){
$add_del['id'] = array('in',$ids['ids']);
}else if($id){
$add_del['id'] = $request->param('id');
}else{
$this->error('删除失败');
}
$add_del['status'] = 9;
$model = new UserNeedModel();
$del = $model->isUpdate(true)->allowField(true)->save($add_del);
if($del){
$this->success('删除成功',url('index'));
}else{
$this->error('删除失败');
}
}
// 返回上一級狀態
public function level(){
$data = $this->request->param();
// 判断是否状态正确
$where_need['id'] = $data['need_id'];
$where_need['status'] = 7;
$need = Db::name('UserNeed')->where($where_need)->find();
if($need){
// 修改需求状态
$save_need['status'] = 5;
$save_need['update_time'] = time();
$save_need['choose_time'] = time();
$save_need['next_choose_time'] = '';
$save_need['complaint_time'] = '';
$changeNeed = Db::name('UserNeed')->where($where_need)->update($save_need);
// 修改报价状态
$where_agency['need_id'] = $data['need_id'];
$save_agency['status'] = 4;
$save_agency['update_time'] = time();
$save_agency['choose_time'] = '';
$save_agency['complaint_time'] = '';
$changeAgency = Db::name('Agency')->where($where_agency)->update($save_agency);
if(!$changeAgency || !$changeNeed){
$this->error('修改失败');
}else{
$this->success('修改成功');
}
}else{
$this->error('当前状态不支持修改');
}
}
}