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

order

... ... @@ -45,7 +45,7 @@ class AdminStatisticsController extends AdminBaseController{
echo strtotime('10:15:30');
$where['start_time']=['between',[strtotime(date('Y-m-d 7:i:s')),strtotime(date('Y-m-d 12:i:s'))]];
$where['start_time']=['between',[strtotime(date('7:i:s')),strtotime(date('Y-m-d 12:i:s'))]];
$num=Db::name('order')->where($where)->count();
dump($num);
... ...
... ... @@ -174,46 +174,66 @@ class AesController extends HomeBaseController{
*/
public function state($name,$key,$type){
if ($type==1){
//判断命令是否合法
if($key[0]=='0xff' && $key[4]=='0xef'){
if ($key[3]=='0x01'){
//修改数据库设备状态
try{
Db::name('equipment')->where('name',$name)->update(['use'=>1]);
}catch (\Exception $exception){
$this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(1,'锁已开');
}else if($key[3]=='0x00'){
$this->apiResponse(0,'开锁失败');
}
$this->open_deal_with($name,$key);
}else{
$this->apiResponse(2,'返回指令错误');
}
}else if($type==2){
//判断命令是否合法
if($key[0]=='0xff' && $key[7]=='0xef'){
if ($key[5]=='0x01'){
Db::name('equipment')->where('name',$name)->update(['electricity'=>0]);
}
if ($key[6]=='0x01'){
//修改数据库设备状态
$this->apiResponse(1,'状态为开锁');//开着
}else if($key[6]=='0x00'){
//修改数据库设备状态
try{
Db::name('equipment')->where('name',$name)->update(['use'=>0]);
}catch (\Exception $exception){
$this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(0,'状态为关锁');//关了
}
$this->lock_deal_with($name,$key);
}else{
$this->apiResponse(2,'返回指令错误');
}
}
}
//开锁状态处理
public function open_deal_with($name,$key){
$use=Db::name('equipment')->where('name',$name)->find()['use'];
if ($use==1){
$this->apiResponse(303,'此锁已被使用');
}
if ($key[3]=='0x01'){
//修改数据库设备状态
try{
Db::name('equipment')->where('name',$name)->update(['use'=>1]);
}catch (\Exception $exception){
$this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(200,'锁已开');
}else if($key[3]=='0x00'){
$this->apiResponse(302,'锁未开');
}
}
//关锁
public function lock_deal_with($name,$key){
//查看数据库中设备状态
$use=Db::name('equipment')->where('name',$name)->find()['use'];
if ($use==0){
$this->apiResponse(303,'此锁未被使用');
}
//电量过低,修改数据库状态
if ($key[5]=='0x01'){
Db::name('equipment')->where('name',$name)->update(['electricity'=>0]);
}
if ($key[6]=='0x01'){
//修改数据库设备状态
$this->apiResponse(301,'锁状态:开锁');//开着
}else if($key[6]=='0x00'){
//修改数据库设备状态
try{
Db::name('equipment')->where('name',$name)->update(['use'=>0]);
}catch (\Exception $exception){
$this->apiResponse(302,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(200,'关锁成功');//关了
}
}
//转成数组
private function ToArray($data){
$array = array();
... ...