RentController.php
7.4 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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
use think\Session;
//租车商品
class RentController extends CommentController
{
// session取货日期
public function insertSession(){
$data = $this->request->param();
if(!empty($data['start_time'])){
Session::set('start_time',$data['start_time']);
// $_SESSION['start_time'] = $data['start_time'];
}
if(!empty($data['end_time'])){
Session::set('end_time',$data['end_time']);
// $_SESSION['end_time'] = $data['end_time'];
}
}
// 一级分类(over)
public function index()
{
$data = $this->request->param();
if($data['type'] == 1){
$where_comm['type'] = array('like','%1%');
}else{
$where_comm['type'] = array('like','%2%');
}
$where_comm['grade'] = 1;
$where_comm['parent_id'] = 0;
$cate = Db::name('CommodityCate')->where($where_comm)->order('score desc,create_time desc')->select()->toArray();
$this->assign('cate',$cate);
$this->assign('type',$data['type']);
return $this->fetch('Rent/index');
}
// 二级分类
public function nextGrade()
{
$data = $this->request->param();
// 图片
$where_banner['type'] = $data['type'];
$where_banner['status'] = array('neq',9);
$banner = Db::name('Banner')->where($where_banner)->order('score desc,create_time desc')->limit(1)->find();
$this->assign('banner',$banner);
// 二级分类
$where_comm['parent_id'] = $data['pid'];
$where_comm['grade'] = 2;
if($data['type'] == 1){
$where_comm['type'] = array('like','%1%');
}else{
$where_comm['type'] = array('like','%2%');
}
$cate = Db::name('CommodityCate')->where($where_comm)->order('score desc,create_time desc')->select()->toArray();
$this->assign('cate',$cate);
// 分类下商品
// $where_vehicle['cate_id'] = $data['cate_id'];
// $where_vehicle['type'] = $data['type'];
// $where_vehicle['status'] = array('neq',9);
// $vehicle = Db::name('Vehicle')->where($where_vehicle)->order('score desc')->select()->toArray();
// $this->assign('vehicle',$vehicle);
return $this->fetch('Rent/rent');
}
// 租商品详情
public function rentDetail()
{
$data = $this->request->param();
$pic = array();
$where_vehicle['type'] = $data['type'];
$where_vehicle['id'] = $data['vehicle_id'];
$where_vehicle['status'] = array('neq',9);
$art = Db::name('Vehicle')->where($where_vehicle)->find();
if($art){
$art['pic'] = cmf_get_image_url($art['pic']);
$art['content'] = htmlspecialchars_decode($art['content']);
$art['pic_banner'] = json_decode($art['pic_banner'],true);
if($art['pic_banner']){
foreach ($art['pic_banner'] as $k=>$v){
$pic[] = $v['url'];
}
}
}
$this->assign('pic',$pic);
$this->assign('art',$art);
return $this->fetch('Rent/detail');
}
// 买商品详情
public function vehicleDetail()
{
$data = $this->request->param();
$pic = array();
$where_vehicle['type'] = $data['type'];
$where_vehicle['id'] = $data['vehicle_id'];
$where_vehicle['status'] = array('neq',9);
$art = Db::name('Vehicle')->where($where_vehicle)->find();
if($art){
$art['pic'] = cmf_get_image_url($art['pic']);
$art['content'] = htmlspecialchars_decode($art['content']);
$art['pic_banner'] = json_decode($art['pic_banner'],true);
if($art['pic_banner']){
foreach ($art['pic_banner'] as $k=>$v){
$pic[] = $v['url'];
}
}
}
$this->assign('pic',$pic);
$this->assign('art',$art);
// 购物车
$where_shopping['user_id'] = Session::get('uid');
$where_shopping['status'] = array('neq',9);
$cart = Db::name('Shopping')->where($where_shopping)->count();
$this->assign('cart',$cart);
return $this->fetch('Rent/buy_detail');
}
// 租车确认
public function rentSure(){
// 时间处理
$start_time = Session::get('start_time');
$end_time = Session::get('end_time');
$middle_start = empty($start_time)?time():strtotime(Session::get('start_time'));
$middle_end = empty($end_time)?time():strtotime(Session::get('end_time'));
$time['start_time'] = date('Y-m-d',$middle_start);
$time['end_time'] = date('Y-m-d',$middle_end);
$time['time_num'] = ceil((strtotime($time['end_time']) - strtotime($time['start_time']))/86400)+1;
$this->assign('time',$time);
return $this->fetch('Rent/rent_sure');
}
// 我要免押金
public function free(){
$where_art['status'] = array('neq',9);
$where_art['type'] = 3;
$art = Db::name('Art')->where($where_art)->order('score desc')->find();
$art['content'] = htmlspecialchars_decode($art['content']);
$this->assign('art',$art);
return $this->fetch();
}
// 搜索页
public function find(){
$data = $this->request->param();
$where_find['type'] = $data['type'];
if(empty($data['find'])){
$type = 1;
$where_history['user_id'] = $_SESSION['uid'];
$where_history['status'] = array('neq',9);
$res_history = Db::name('History')->where($where_history)->select()->toArray();
$vehicle = array();
}else{
$res_history = array();
$type = 2;
// 查找是否有重复
$where_history['user_id'] = $_SESSION['uid'];
$where_history['keyword'] = $data['find'];
$is_set = Db::name('History')->where($where_history)->find();
if(!$is_set){
$history['user_id'] = $_SESSION['uid'];
$history['keyword'] = $data['find'];
$history['create_time'] = time();
$history['update_time'] = time();
$res = Db::name('History')->insertGetId($history);
}
$where_find['name'] = array('like','%'.$data['find'].'%');
$vehicle = Db::name('Vehicle')->where($where_find)->select()->toArray();
}
$this->assign('history',$res_history);
$this->assign('vehicle',$vehicle);
$this->assign('type',$type);
return $this->fetch();
}
// 清空搜索
public function clear(){
$where_history['user_id'] = $_SESSION['uid'];
$update['status'] = 9;
$update['update_time'] = time();
$res_history = Db::name('History')->where($where_history)->update($update);
if($res_history){
// 成功
}else{
// 失败
}
}
}