Reservation.php
11.6 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
<?php
/**
* Created by PhpStorm.
* User: wxd1061
* Date: 2017-05-02
* Time: 11:31
*/
namespace app\mobile\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\response\Json;
use think\Session;
use think\Cookie;
class Reservation extends MobileBase
{
public $user_id = 0;
public $user = array();
/**
* 析构流函数
*/
public function __construct()
{
$address = urlencode(curHostURL() . $_SERVER['REQUEST_URI']);
parent::__construct();
if (session('?user')) {
$user = session('user');
$reuser = M('users')->where("user_id", $user['user_id'])->find();
session('user', $reuser); //覆盖session 中的 user
$this->user = $reuser;
$this->user_id = $reuser['user_id'];
$this->assign('user', $reuser); //存储用户信息
} else {
$uid = Cookie::get('user_id');
if ($uid) {
$user = M('users')->where("user_id", $uid)->where("store_id", getMobileStoId())->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}
}
if (empty($this->user_id)) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId(), "oldurl" => $address)));
exit;
}
if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId(), "oldurl" => $address)));
exit;
}
}
// wxd.pos.vipreservation.list.get 查询预约
// wxd.pos.vipreservation.add 添加预约
// wxd.pos.vipreservation.edit 編輯预约
// wxd.pos.vipreproject.list.get 预约項目
// wxd.pos.vvipreservation.list 预约详情视图
/** 预约页面**/
public function index()
{
$getstoid=getMobileStoId();
$getsotinfo=tpCache('shop_info',$getstoid);
$user_info['api_token'] =$getsotinfo['api_token'];
$user_info['store_logo'] = $getsotinfo['store_logo'];
$user_info['store_name'] = $getsotinfo['store_name'];
$user_info['ERPId'] = $getsotinfo['ERPId'];
$user_info['erpvipid']= $this->user['erpvipid'];
if ($user_info) {
$mapuser['VIPID'] = $user_info['erpvipid'];
$where = array(
'VIPID' => $mapuser['VIPID'],
'State' => '0',
);
$vip_ord = getApiData('wxd.pos.vvipreservation.list', $user_info['api_token'], null, $where);//查询是否有预约项目
$vip_ord = json_decode($vip_ord, 'true');
if ($vip_ord && $vip_ord['code'] == 1 && $vip_ord['data']) {
//已有预约单,调取这条订单,显示详情
$state = 'see';
$see_data = $vip_ord['data'][0];
} else {
//没有预约单,跳转添加
$state = 'add';
$where = array(
'IsStop' => 0,//项目:0启用,1未启用
);
//获取当前时间以及往后一个月的时间
$thistime = array(
'open' => date("Y-m-d"),
'end' => date('Y-m-d', strtotime("+1 month"))
);
$accdb = $user_info['ERPId'] ;
$project=getApiData_java("api/erp/vip/reservation/project/list",$accdb,$where,1,1000); //预约项目
// $project = getApiData('wxd.pos.vipreproject.list.get', $user_info['api_token'], null, $where);
$project = json_decode($project,true);
if ($project && $project['code'] == 0 && $project['data']['pageData']) {
$projectdata = $project['data']['pageData'];
}
}
$this->assign('state', $state);//传递状态add||see
$this->assign('see_data', $see_data);//查看信息
$this->assign('project', $projectdata);//预约项目
// $this->assign('stores', $storesdata);//门店
$this->assign('thistime', $thistime);//渲染时间
}
return $this->fetch();
}
//获取门店
public function storelist()
{
$data = I('post.');
if (empty($data['WareId']))
{
return json(["code" => -1, "msg" => "请选择项目"]);
}
$where = array(
'WareId' => $data['WareId'],
);
$accdb = tpCache('shop_info.ERPId', getMobileStoId());
$selectnum=getApiData_java("api/erp/vip/reservation/storage/list",$accdb,$where,1,1000); //查询门店
$selectnum = json_decode($selectnum, true);
if ($selectnum && $selectnum['code'] == 0 && $selectnum['data']) {
return json(["code" => 1, "msg" => "ok", "data" => $selectnum['data']]);
} else {
return json(["code" => -1, "msg" => "接口出错"]);
}
}
/** 预约提交**/
public function makeinfo()
{
$getstoid=getMobileStoId();
$getsotinfo=tpCache('shop_info',$getstoid);
$user_info['api_token'] =$getsotinfo['api_token'];
$user_info['store_logo'] = $getsotinfo['store_logo'];
$user_info['store_name'] = $getsotinfo['store_name'];
$user_info['ERPId'] = $getsotinfo['ERPId'];
$user_info['erpvipid']= $this->user['erpvipid'];
$user_info['vipname']= $this->user['vipname'];
$user_info['store_id']= $this->user['store_id'];
if ($user_info) {
$yyh = 'yyfw' . date("YmdHis", time()) . get_total_millisecond();
$mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
$data = I('post.');
$data1 = I('post.');
$shoppers = $data['shoppers'];//导购ID
// $shoppers = $user_info['erpvipid'].",".$user_info['erpvipid'];
$data['VIPID'] = $user_info['erpvipid'];
$data['State'] = 0;
$data['number'] = $yyh;
unset($data['StorageName']);
unset($data['StorageAddress']);
unset($data['WareName']);
unset($data['WareName']);
unset($data['shoppers']);
//获取预约人数
$selmap = array(
'WareId' => $data['WareId'],
'StorageId' => $data['StorageId'],
'RsDate' => $data['RSDate'],
);
$selectnum = getApiData('wxd.vip.reservation.peopleqty', $user_info['api_token'], null, $selmap);//查询剩余预约数
$selectnum = json_decode($selectnum, 'true');
if ($selectnum){
if ($selectnum['data']['0']['PeopleQty'] < $data['PeopleQty']) {
return json(["code" => -2, "msg" => "预约人数超过可预约人数", "data" => $selectnum['data']['0']['PeopleQty']]);
} else {
//预约
$add_data = getApiData('wxd.pos.vipreservation.add', $user_info['api_token'], array($data));//预约项目
mlog("返回1:" . $add_data, "makeinfo/" . $user_info['store_id']);
$add_data = json_decode($add_data, true);
if ($add_data && $add_data['code'] == 1) {
//推送消息
$url = curHostURL() . "/home/api/poswxcode?typeid=1011&Acc=" . $user_info['ERPId'] . "&ErpVipid=" . $user_info['erpvipid'] . "&title=恭喜您成功预约,您的预约号是" . $yyh . "&key1=" . $user_info['vipname'] . "&key2=" . $data1['StorageName'] . "&key3=" . $data1['StorageAddress'] . "&key4=" . $data1['RSDate'] . "&key5=" . $data1['WareName'] . "&remark=" . $data1['Remrak'] . "&backurl=" . curHostURL() . "/mobile/reservation/index/stoid/" . $user_info['store_id'];
$resp = httpRequest($url, "GET");
if ($shoppers) {
$shoppers = explode(",", $shoppers);
foreach ($shoppers as $key => $vo) {
$url1 = curHostURL() . "/home/api/poswxcode?typeid=1011&Acc=" . $user_info['ERPId'] . "&ErpVipid=" . $shoppers[$key] . "&title=恭喜您成功预约,您的预约号是" . $yyh . "&key1=" . $user_info['vipname'] . "&key2=" . $data1['StorageName'] . "&key3=" . $data1['StorageAddress'] . "&key4=" . $data1['RSDate'] . "&key5=" . $data1['WareName'] . "&remark=" . $data1['Remrak'] . "&backurl=" . curHostURL() . "/mobile/reservation/index/stoid/" . $user_info['store_id'];
$resp1 = httpRequest($url1, "GET");
}
}
return json(["code" => 1, "msg" => "预约成功"]);
} else {
return json(["code" => -1, "msg" => "服务器繁忙,请稍后再试"]);
}
}
}else{
return json(["code" => -1, "msg" => "服务器繁忙,请稍后再试"]);
}
return $this->fetch();
}
}
/**取消預約**/
public
function cancel()
{
$ID = I('ID');
$getstoid=getMobileStoId();
$getsotinfo=tpCache('shop_info',$getstoid);
$user_info['api_token'] =$getsotinfo['api_token'];
$user_info['store_logo'] = $getsotinfo['store_logo'];
$user_info['store_name'] = $getsotinfo['store_name'];
$user_info['ERPId'] = $getsotinfo['ERPId'];
$user_info['erpvipid']= $this->user['erpvipid'];
if ($user_info) {
// $mapuser['VIPNo'] = $user_info['erpvipno'];//token验证
$edit = array(
'Id' => $ID,
'State' => '-1'
);
mlog("取消预约数据1:" . json_encode($edit), "reservation/" . getMobileStoId());
$edit_state = getApiData('wxd.pos.vipreservation.edit', $user_info['api_token'], array($edit));//预约项目
$edit_state = json_decode($edit_state, 'true');
mlog("取消预约接口返回2:" . json_encode($edit_state), "reservation/" . getMobileStoId());
if ($edit_state && $edit_state['code'] == 1) {
return json(["code" => 1, "msg" => "取消预约"]);
} else {
return json(["code" => -1, "msg" => "服务器繁忙,请稍后再试"]);
}
}
return $this->fetch();
}
/**判断预约人数**/
public function resernum()
{
$getstoid=getMobileStoId();
$getsotinfo=tpCache('shop_info',$getstoid);
$user_info['api_token'] =$getsotinfo['api_token'];
$user_info['store_logo'] = $getsotinfo['store_logo'];
$user_info['store_name'] = $getsotinfo['store_name'];
$user_info['ERPId'] = $getsotinfo['ERPId'];
$user_info['erpvipid']= $this->user['erpvipid'];
if ($user_info) {
$data = I('post.');
$where = array(
'WareId' => $data['WareId'],
'StorageId' => $data['StorageId'],
'RsDate' => $data['RSDate'],
);
$selectnum = getApiData('wxd.vip.reservation.peopleqty', $user_info['api_token'], null, $where);//查询剩余预约数
$selectnum = json_decode($selectnum, true);
if ($selectnum && $selectnum['code'] == 1) {
return json(["code" => 1, "msg" => "返回预约名额", "peopledata" => $selectnum['data']['0']]);
} else {
return json(["code" => -1, "msg" => "接口出错"]);
}
}
return $this->fetch();
}
}