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

interface

... ... @@ -127,16 +127,16 @@ class AesController extends HomeBaseController{
* @url /portal/Aes/getState
* @method GET
*
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
* @param name:name type:String require:1 default:无 other: desc:设备名称
*
*
* @return lockKey:获取电压、开关状态的指令(数组)
*/
public function getState(){
$MACAddress=$this->request->param('MACAddress');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
$name=$this->request->param('name');
$equipment=Db::name('equipment')->where('mac_address',$name)->find();
if (!empty($equipment)){
$key="ff05a301ef";
$StateKey=$this->ToArray($key);
$this->apiResponse(200,'success',$StateKey);
... ... @@ -180,24 +180,26 @@ class AesController extends HomeBaseController{
* @url /portal/Aes/decryption
* @method GET
*
* @param name:users_id type:String require:1 default:无 other: desc:用户id
* @param name:name type:String require:1 default:无 other: desc:设备名称
* @param name:key type:String require:1 default:无 other: desc:设备返回状态(未加密)
* @param name:type type:String require:1 default:无 other:1开锁返回指令,2状态返回指令 desc:命令类型
*
* @return code:1锁已开,0位锁已关,2为数据异常
* @return name:设备锁名称
*/
public function state($name,$key,$type){
public function state($users_id,$name,$key,$type){
if ($type==1){
//判断命令是否合法
if($key[0]=='0xff' && $key[4]=='0xef'){
$this->open_deal_with($name,$key);
$this->open_deal_with($users_id,$name,$key);
}else{
$this->apiResponse(2,'返回指令错误');
}
}else if($type==2){
//判断命令是否合法
if($key[0]=='0xff' && $key[7]=='0xef'){
$this->lock_deal_with($name,$key);
$this->lock_deal_with($users_id,$name,$key);
}else{
$this->apiResponse(2,'返回指令错误');
}
... ... @@ -205,29 +207,33 @@ class AesController extends HomeBaseController{
}
//开锁状态处理
public function open_deal_with($name,$key){
$use=Db::name('equipment')->where('name',$name)->find()['use'];
if ($use==1){
$this->apiResponse(303,'此锁已被使用');
}
public function open_deal_with($users_id,$name,$key){
if ($key[3]=='0x01'){
//修改数据库设备状态
try{
Db::startTrans();
//用户状态
Db::name('users')->where('id',$users_id)->update(['is_use'=>1]);
Db::name('equipment')->where('name',$name)->update(['use'=>1]);
}catch (\Exception $exception){
Db::rollback();
$this->apiResponse(301,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(200,'锁已开');
Db::commit();
//生成订单
$this->apiResponse(200,'锁已开',['设备名称'=>$name]);
}else if($key[3]=='0x00'){
$this->apiResponse(302,'锁未开');
$this->apiResponse(302,'锁未开',['设备名称'=>$name]);
}
}
//关锁
public function lock_deal_with($name,$key){
public function lock_deal_with($users_id,$name,$key){
//查看数据库中设备状态
$use=Db::name('equipment')->where('name',$name)->find()['use'];
if ($use==0){
$this->apiResponse(303,'此锁未被使用');
$this->apiResponse(303,'此锁未打开,还床失败',['设备名称'=>$name]);
}
//电量过低,修改数据库状态
if ($key[5]=='0x01'){
... ... @@ -235,15 +241,20 @@ class AesController extends HomeBaseController{
}
if ($key[6]=='0x01'){
//修改数据库设备状态
$this->apiResponse(301,'锁状态:开锁');//开着
$this->apiResponse(301,'锁未关,当前锁状态为:开锁',['设备名称'=>$name]);//开着
}else if($key[6]=='0x00'){
//修改数据库设备状态
try{
Db::startTrans();
Db::name('users')->where('id',$users_id)->update(['is_use'=>0]);
Db::name('equipment')->where('name',$name)->update(['use'=>0]);
}catch (\Exception $exception){
Db::rollback();
$this->apiResponse(302,'数据库状态更改失败,错误信息:'.$exception->getMessage());
}
$this->apiResponse(200,'关锁成功');//关了
Db::commit();
$this->apiResponse(200,'关锁成功',['设备名称'=>$name]);//关了
}
}
... ...
... ... @@ -38,25 +38,27 @@ class UsersController extends HomeBaseController{
* @method GET
*
* @param name:users_id type:String require:1 default:无 other: desc:用户id
*
* @return is_use:是否在使用设备
* @return is_deposit:是否交付押金
* @return is_order:是否有未支付订单
*/
public function lock_check(){
$users_id=$this->request->param('users_id');
//获取提交押金的状态
$users=Db::name('users')->where('id',$users_id)->find();
if ($users['is_deposit']===1){
if ($users['is_use']==1){
$this->apiResponse(303,'用户正在使用设备');
}else{
$data=[
'is_use'=>$users['use'],
'is_deposit' => $users['is_deposit']
];
$order=Db::name('order')->where(['users_id'=>$users_id,'state'=>2])->find();
if (empty($order)){
$this->apiResponse(200,'验证通过');
$data['is_order']=0;
}else{
$this->apiResponse(302,'有未支付订单');
}
}
}else{
$this->apiResponse(301,'未支付押金');
$data['is_order']=1;
}
$this->apiResponse(200,'success',$data);
}
/**
... ...