正在显示
2 个修改的文件
包含
111 行增加
和
59 行删除
@@ -185,8 +185,9 @@ class AesController extends HomeBaseController{ | @@ -185,8 +185,9 @@ class AesController extends HomeBaseController{ | ||
185 | * @param name:key type:String require:1 default:无 other: desc:设备返回状态(未加密) | 185 | * @param name:key type:String require:1 default:无 other: desc:设备返回状态(未加密) |
186 | * @param name:type type:String require:1 default:无 other:1开锁返回指令,2状态返回指令 desc:命令类型 | 186 | * @param name:type type:String require:1 default:无 other:1开锁返回指令,2状态返回指令 desc:命令类型 |
187 | * | 187 | * |
188 | - * @return code:1锁已开,0位锁已关,2为数据异常 | ||
189 | - * @return name:设备锁名称 | 188 | + * @return state:1成功 0失败 |
189 | + * @return message:错误类型 | ||
190 | + * @return error:错误描述 | ||
190 | */ | 191 | */ |
191 | public function state($users_id,$name,$key,$type){ | 192 | public function state($users_id,$name,$key,$type){ |
192 | if ($type==1){ | 193 | if ($type==1){ |
@@ -194,14 +195,22 @@ class AesController extends HomeBaseController{ | @@ -194,14 +195,22 @@ class AesController extends HomeBaseController{ | ||
194 | if($key[0]=='0xff' && $key[4]=='0xef'){ | 195 | if($key[0]=='0xff' && $key[4]=='0xef'){ |
195 | $this->open_deal_with($users_id,$name,$key); | 196 | $this->open_deal_with($users_id,$name,$key); |
196 | }else{ | 197 | }else{ |
197 | - $this->apiResponse(2,'返回指令错误'); | 198 | + $data=[ |
199 | + 'state'=>0, | ||
200 | + 'message'=>'返回指令错误' | ||
201 | + ]; | ||
202 | + $this->apiResponse(200,'success',$data); | ||
198 | } | 203 | } |
199 | }else if($type==2){ | 204 | }else if($type==2){ |
200 | //判断命令是否合法 | 205 | //判断命令是否合法 |
201 | if($key[0]=='0xff' && $key[7]=='0xef'){ | 206 | if($key[0]=='0xff' && $key[7]=='0xef'){ |
202 | $this->lock_deal_with($users_id,$name,$key); | 207 | $this->lock_deal_with($users_id,$name,$key); |
203 | }else{ | 208 | }else{ |
204 | - $this->apiResponse(2,'返回指令错误'); | 209 | + $data=[ |
210 | + 'state'=>0, | ||
211 | + 'message'=>'返回指令错误' | ||
212 | + ]; | ||
213 | + $this->apiResponse(200,'success',$data); | ||
205 | } | 214 | } |
206 | } | 215 | } |
207 | } | 216 | } |
@@ -217,15 +226,39 @@ class AesController extends HomeBaseController{ | @@ -217,15 +226,39 @@ class AesController extends HomeBaseController{ | ||
217 | Db::name('equipment')->where('name',$name)->update(['use'=>1]); | 226 | Db::name('equipment')->where('name',$name)->update(['use'=>1]); |
218 | }catch (\Exception $exception){ | 227 | }catch (\Exception $exception){ |
219 | Db::rollback(); | 228 | Db::rollback(); |
220 | - $this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage()); | 229 | + $data=[ |
230 | + 'state'=>0, | ||
231 | + 'message'=>'数据库操作错误', | ||
232 | + 'error' => $exception->getMessage() | ||
233 | + ]; | ||
234 | + $this->apiResponse(200,'success',$data); | ||
221 | } | 235 | } |
222 | - Db::commit(); | ||
223 | //生成订单 | 236 | //生成订单 |
224 | - | ||
225 | - | ||
226 | - $this->apiResponse(200,'锁已开',['设备名称'=>$name]); | 237 | + $order=new OrderController(); |
238 | + $res=$order->createOrder($users_id,$name); | ||
239 | + if ($res['state'==true]){ | ||
240 | + Db::commit(); | ||
241 | + $data=[ | ||
242 | + 'state'=>1, | ||
243 | + 'name'=>$name, | ||
244 | + 'order_no' => $res['order_no'] | ||
245 | + ]; | ||
246 | + $this->apiResponse(200,'success',$data); | ||
247 | + }else{ | ||
248 | + Db::rollback(); | ||
249 | + $data=[ | ||
250 | + 'state'=>0, | ||
251 | + 'message'=>'订单生成错误', | ||
252 | + 'error' => $res['message'] | ||
253 | + ]; | ||
254 | + $this->apiResponse(200,'success',$data); | ||
255 | + } | ||
227 | }else if($key[3]=='0x00'){ | 256 | }else if($key[3]=='0x00'){ |
228 | - $this->apiResponse(302,'锁未开',['设备名称'=>$name]); | 257 | + $data=[ |
258 | + 'state'=>0, | ||
259 | + 'message'=>'开锁失败' | ||
260 | + ]; | ||
261 | + $this->apiResponse(200,'success',$data); | ||
229 | } | 262 | } |
230 | } | 263 | } |
231 | //关锁 | 264 | //关锁 |
@@ -233,7 +266,11 @@ class AesController extends HomeBaseController{ | @@ -233,7 +266,11 @@ class AesController extends HomeBaseController{ | ||
233 | //查看数据库中设备状态 | 266 | //查看数据库中设备状态 |
234 | $use=Db::name('equipment')->where('name',$name)->find()['use']; | 267 | $use=Db::name('equipment')->where('name',$name)->find()['use']; |
235 | if ($use==0){ | 268 | if ($use==0){ |
236 | - $this->apiResponse(303,'此锁未打开,还床失败',['设备名称'=>$name]); | 269 | + $data=[ |
270 | + 'state'=>0, | ||
271 | + 'message'=>'该设备为关闭状态,不能还锁' | ||
272 | + ]; | ||
273 | + $this->apiResponse(200,'success',$data); | ||
237 | } | 274 | } |
238 | //电量过低,修改数据库状态 | 275 | //电量过低,修改数据库状态 |
239 | if ($key[5]=='0x01'){ | 276 | if ($key[5]=='0x01'){ |
@@ -241,20 +278,15 @@ class AesController extends HomeBaseController{ | @@ -241,20 +278,15 @@ class AesController extends HomeBaseController{ | ||
241 | } | 278 | } |
242 | if ($key[6]=='0x01'){ | 279 | if ($key[6]=='0x01'){ |
243 | //修改数据库设备状态 | 280 | //修改数据库设备状态 |
244 | - $this->apiResponse(301,'锁未关,当前锁状态为:开锁',['设备名称'=>$name]);//开着 | 281 | + $data=[ |
282 | + 'state'=>0, | ||
283 | + 'message'=>'未还床' | ||
284 | + ]; | ||
285 | + $this->apiResponse(200,'success',$data); | ||
245 | }else if($key[6]=='0x00'){ | 286 | }else if($key[6]=='0x00'){ |
246 | //修改数据库设备状态 | 287 | //修改数据库设备状态 |
247 | - try{ | ||
248 | - Db::startTrans(); | ||
249 | - Db::name('users')->where('id',$users_id)->update(['is_use'=>0]); | ||
250 | - Db::name('equipment')->where('name',$name)->update(['use'=>0]); | ||
251 | - }catch (\Exception $exception){ | ||
252 | - Db::rollback(); | ||
253 | - $this->apiResponse(302,'数据库状态更改失败,错误信息:'.$exception->getMessage()); | ||
254 | - } | ||
255 | - Db::commit(); | ||
256 | - | ||
257 | - $this->apiResponse(200,'关锁成功',['设备名称'=>$name]);//关了 | 288 | + $order=new OrderController(); |
289 | + $order->order($users_id,$name); | ||
258 | } | 290 | } |
259 | } | 291 | } |
260 | 292 |
@@ -20,20 +20,18 @@ use wxapp\pay\WeixinPay; | @@ -20,20 +20,18 @@ use wxapp\pay\WeixinPay; | ||
20 | */ | 20 | */ |
21 | class OrderController extends HomeBaseController{ | 21 | class OrderController extends HomeBaseController{ |
22 | 22 | ||
23 | - /** | ||
24 | - * @title 生成订单 | ||
25 | - * @description 生成订单,加入开始时间和用户id | ||
26 | - * @author 董瑞恩 | ||
27 | - * @url /portal/order/createOrder | ||
28 | - * @method GET | ||
29 | - * | ||
30 | - * @param name:users_id type:String require:1 default:无 other: desc:用户id | ||
31 | - * @param name:name type:String require:1 default:无 other: desc:设备名称 | ||
32 | - * | ||
33 | - */ | ||
34 | - public function createOrder(){ | ||
35 | - $users_id=$this->request->param('users_id'); | ||
36 | - $name=$this->request->param('name'); | 23 | +// /** |
24 | +// * @title 生成订单 | ||
25 | +// * @description 生成订单,加入开始时间和用户id | ||
26 | +// * @author 董瑞恩 | ||
27 | +// * @url /portal/order/createOrder | ||
28 | +// * @method GET | ||
29 | +// * | ||
30 | +// * @param name:users_id type:String require:1 default:无 other: desc:用户id | ||
31 | +// * @param name:name type:String require:1 default:无 other: desc:设备名称 | ||
32 | +// * | ||
33 | +// */ | ||
34 | + public function createOrder($users_id,$name){ | ||
37 | $order=[ | 35 | $order=[ |
38 | 'order_no' => cmf_get_order_sn(), | 36 | 'order_no' => cmf_get_order_sn(), |
39 | 'eq_name' => $name, | 37 | 'eq_name' => $name, |
@@ -49,28 +47,31 @@ class OrderController extends HomeBaseController{ | @@ -49,28 +47,31 @@ class OrderController extends HomeBaseController{ | ||
49 | Db::rollback(); | 47 | Db::rollback(); |
50 | $data=[ | 48 | $data=[ |
51 | 'state'=>false, | 49 | 'state'=>false, |
52 | - 'message'=>$exception | 50 | + 'message'=>$exception->getMessage() |
53 | ]; | 51 | ]; |
52 | + return $data; | ||
54 | } | 53 | } |
55 | Db::commit(); | 54 | Db::commit(); |
56 | - $this->apiResponse(200,'success'); | 55 | + $data=[ |
56 | + 'state'=>true, | ||
57 | + 'order_no' => $order['order_no'] | ||
58 | + ]; | ||
59 | + return $data; | ||
57 | } | 60 | } |
58 | 61 | ||
59 | - /** | ||
60 | - * @title 完成订单 | ||
61 | - * @description 订单完成,加入结束时间和结算费用,并调用微信统一下单 | ||
62 | - * @author 董瑞恩 | ||
63 | - * @url /portal/order/order | ||
64 | - * @method GET | ||
65 | - * | ||
66 | - * @param name:users_id type:String require:1 default:无 other: desc:用户id | ||
67 | - * | ||
68 | - * @return data:返回用于调用支付的参数 | ||
69 | - */ | ||
70 | - public function order(){ | ||
71 | - $users_id=$this->request->param('users_id'); | ||
72 | - $users=Db::name('users')->where('id',$users_id)->find(); | ||
73 | - $order= Db::name('order')->where('order_no',$users['order_no'])->find(); | 62 | +// /** |
63 | +// * @title 完成订单 | ||
64 | +// * @description 订单完成,加入结束时间和结算费用,并调用微信统一下单 | ||
65 | +// * @author 董瑞恩 | ||
66 | +// * @url /portal/order/order | ||
67 | +// * @method GET | ||
68 | +// * | ||
69 | +// * @param name:users_id type:String require:1 default:无 other: desc:用户id | ||
70 | +// * | ||
71 | +// * @return data:返回用于调用支付的参数 | ||
72 | +// */ | ||
73 | + public function order($users_id,$name){ | ||
74 | + $order= Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find(); | ||
74 | $end_time=time(); | 75 | $end_time=time(); |
75 | $price=$this->getPrice($order['start_time'],$end_time); | 76 | $price=$this->getPrice($order['start_time'],$end_time); |
76 | $time=ceil(($end_time-$order['start_time'])/3600); | 77 | $time=ceil(($end_time-$order['start_time'])/3600); |
@@ -83,13 +84,20 @@ class OrderController extends HomeBaseController{ | @@ -83,13 +84,20 @@ class OrderController extends HomeBaseController{ | ||
83 | try{ | 84 | try{ |
84 | Db::startTrans(); | 85 | Db::startTrans(); |
85 | Db::name('users')->where('id',$users_id)->update(['is_use'=>0,'order_no'=>null]); | 86 | Db::name('users')->where('id',$users_id)->update(['is_use'=>0,'order_no'=>null]); |
86 | - Db::name('order')->where('order_no',$users['order_no'])->update($data); | 87 | + Db::name('equipment')->where('name',$name)->update(['use'=>0]); |
88 | + Db::name('order')->where('order_no',$order['order_no'])->update($data); | ||
87 | }catch (\Exception $exception){ | 89 | }catch (\Exception $exception){ |
88 | Db::rollback(); | 90 | Db::rollback(); |
89 | - $this->apiResponse(301,'订单生成失败,错误信息:'.$exception->getMessage()); | 91 | + $data=[ |
92 | + 'state'=>false, | ||
93 | + 'message'=>$exception->getMessage() | ||
94 | + ]; | ||
95 | + $this->apiResponse(200,'success',$data); | ||
90 | } | 96 | } |
91 | Db::commit(); | 97 | Db::commit(); |
98 | + //调起支付 | ||
92 | $this->pay($order['order_no']); | 99 | $this->pay($order['order_no']); |
100 | + | ||
93 | } | 101 | } |
94 | 102 | ||
95 | public function getPrice($start_time,$end_time){ | 103 | public function getPrice($start_time,$end_time){ |
@@ -133,10 +141,22 @@ class OrderController extends HomeBaseController{ | @@ -133,10 +141,22 @@ class OrderController extends HomeBaseController{ | ||
133 | $price=$order['price']*100;//订单价格 | 141 | $price=$order['price']*100;//订单价格 |
134 | $notify_url=url('order/notify','','',true);//回调地址 | 142 | $notify_url=url('order/notify','','',true);//回调地址 |
135 | $wxPay=new WeixinPay($openId,$order_no,$body,$price,$notify_url); | 143 | $wxPay=new WeixinPay($openId,$order_no,$body,$price,$notify_url); |
136 | - $data=$wxPay->pay(); | ||
137 | - if (isset($data['package'])){ | ||
138 | - $this->apiResponse(200,'下单成功',$data);//微信支付下单成功,返回调用支付的参数 | 144 | + $pay=$wxPay->pay(); |
145 | + if (isset($pay['package'])){ | ||
146 | + $data=[ | ||
147 | + 'state'=>1, | ||
148 | + 'pay'=>$pay | ||
149 | + ]; | ||
150 | + $this->apiResponse(200,'success',$data); | ||
151 | + }else{ | ||
152 | + $data=[ | ||
153 | + 'state'=>0, | ||
154 | + 'message'=>'统一下单失败', | ||
155 | + 'error' => $pay | ||
156 | + ]; | ||
157 | + $this->apiResponse(200,'success',$data); | ||
139 | } | 158 | } |
159 | + | ||
140 | } | 160 | } |
141 | 161 | ||
142 | //支付回调接口 | 162 | //支付回调接口 |
-
请 注册 或 登录 后发表评论