作者 董瑞恩
1 个管道 的构建 通过 耗费 1 秒

order

@@ -45,7 +45,7 @@ class AdminStatisticsController extends AdminBaseController{ @@ -45,7 +45,7 @@ class AdminStatisticsController extends AdminBaseController{
45 45
46 echo strtotime('10:15:30'); 46 echo strtotime('10:15:30');
47 47
48 - $where['start_time']=['between',[strtotime(date('Y-m-d 7:i:s')),strtotime(date('Y-m-d 12:i:s'))]]; 48 + $where['start_time']=['between',[strtotime(date('7:i:s')),strtotime(date('Y-m-d 12:i:s'))]];
49 $num=Db::name('order')->where($where)->count(); 49 $num=Db::name('order')->where($where)->count();
50 50
51 dump($num); 51 dump($num);
@@ -174,7 +174,28 @@ class AesController extends HomeBaseController{ @@ -174,7 +174,28 @@ class AesController extends HomeBaseController{
174 */ 174 */
175 public function state($name,$key,$type){ 175 public function state($name,$key,$type){
176 if ($type==1){ 176 if ($type==1){
  177 + //判断命令是否合法
177 if($key[0]=='0xff' && $key[4]=='0xef'){ 178 if($key[0]=='0xff' && $key[4]=='0xef'){
  179 + $this->open_deal_with($name,$key);
  180 + }else{
  181 + $this->apiResponse(2,'返回指令错误');
  182 + }
  183 + }else if($type==2){
  184 + //判断命令是否合法
  185 + if($key[0]=='0xff' && $key[7]=='0xef'){
  186 + $this->lock_deal_with($name,$key);
  187 + }else{
  188 + $this->apiResponse(2,'返回指令错误');
  189 + }
  190 + }
  191 + }
  192 +
  193 + //开锁状态处理
  194 + public function open_deal_with($name,$key){
  195 + $use=Db::name('equipment')->where('name',$name)->find()['use'];
  196 + if ($use==1){
  197 + $this->apiResponse(303,'此锁已被使用');
  198 + }
178 if ($key[3]=='0x01'){ 199 if ($key[3]=='0x01'){
179 //修改数据库设备状态 200 //修改数据库设备状态
180 try{ 201 try{
@@ -182,38 +203,37 @@ class AesController extends HomeBaseController{ @@ -182,38 +203,37 @@ class AesController extends HomeBaseController{
182 }catch (\Exception $exception){ 203 }catch (\Exception $exception){
183 $this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage()); 204 $this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());
184 } 205 }
185 - $this->apiResponse(1,'锁已开'); 206 + $this->apiResponse(200,'锁已开');
186 }else if($key[3]=='0x00'){ 207 }else if($key[3]=='0x00'){
187 - $this->apiResponse(0,'开锁失败'); 208 + $this->apiResponse(302,'锁未开');
188 } 209 }
189 - }else{  
190 - $this->apiResponse(2,'返回指令错误');  
191 } 210 }
192 - }else if($type==2){  
193 - if($key[0]=='0xff' && $key[7]=='0xef'){ 211 + //关锁
  212 + public function lock_deal_with($name,$key){
  213 + //查看数据库中设备状态
  214 + $use=Db::name('equipment')->where('name',$name)->find()['use'];
  215 + if ($use==0){
  216 + $this->apiResponse(303,'此锁未被使用');
  217 + }
  218 + //电量过低,修改数据库状态
194 if ($key[5]=='0x01'){ 219 if ($key[5]=='0x01'){
195 Db::name('equipment')->where('name',$name)->update(['electricity'=>0]); 220 Db::name('equipment')->where('name',$name)->update(['electricity'=>0]);
196 } 221 }
197 if ($key[6]=='0x01'){ 222 if ($key[6]=='0x01'){
198 //修改数据库设备状态 223 //修改数据库设备状态
199 - $this->apiResponse(1,'状态为开锁');//开着 224 + $this->apiResponse(301,'锁状态:开锁');//开着
200 }else if($key[6]=='0x00'){ 225 }else if($key[6]=='0x00'){
201 //修改数据库设备状态 226 //修改数据库设备状态
202 try{ 227 try{
203 Db::name('equipment')->where('name',$name)->update(['use'=>0]); 228 Db::name('equipment')->where('name',$name)->update(['use'=>0]);
204 }catch (\Exception $exception){ 229 }catch (\Exception $exception){
205 - $this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());  
206 - }  
207 - $this->apiResponse(0,'状态为关锁');//关了  
208 - }  
209 -  
210 -  
211 - }else{  
212 - $this->apiResponse(2,'返回指令错误'); 230 + $this->apiResponse(302,'数据库状态更改失败,错误信息:'.$exception->getMessage());
213 } 231 }
  232 + $this->apiResponse(200,'关锁成功');//关了
214 } 233 }
215 } 234 }
216 235
  236 +
217 //转成数组 237 //转成数组
218 private function ToArray($data){ 238 private function ToArray($data){
219 $array = array(); 239 $array = array();