136 lines
3.9 KiB
PHP
136 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace app\storeapi\logic;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\teastore\TeaStore;
|
|
use app\common\model\teastore\TeaStoreRoom;
|
|
use app\common\model\teastore\TeaStoreRoom as roomModel;
|
|
use app\common\service\iot\IotService;
|
|
use app\common\service\iot\DoorService;
|
|
|
|
class DeviceLogic extends BaseLogic
|
|
{
|
|
/**
|
|
* Class SmsLogic
|
|
* @package app\api\logic
|
|
* 设备管理逻辑
|
|
*/
|
|
|
|
public static function getDeviceLists($params){
|
|
try {
|
|
$store_id = $params['store_id'];
|
|
$data =[];
|
|
$store = TeaStore::where([
|
|
'id'=>$store_id,
|
|
'del'=>0
|
|
])->find();
|
|
if(!$store){
|
|
throw new \Exception('门店不存在或已删除');
|
|
}
|
|
$roomList = roomModel::where('store_id',$store_id)
|
|
->where('del',0)
|
|
->select()->toArray();
|
|
$data['store_id'] = $store_id;
|
|
$data['is_lock'] = $store->is_lock;
|
|
$data['lock_no']= $store->lock_no;
|
|
$data['roomDevice'] = array();
|
|
if($roomList){
|
|
$roomDevice = [];
|
|
foreach ($roomList as $key=>$item){
|
|
$data['roomDevice'][$key]['room_id'] = $item['id'];
|
|
$data['roomDevice'][$key]['title'] = $item['title'];
|
|
$data['roomDevice'][$key]['device_id']= $item['device_id'];
|
|
$data['roomDevice'][$key]['lock_no'] = $item['lock_no'];
|
|
$data['roomDevice'][$key]['is_open'] = $item['is_open'];
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
|
|
}catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static function deviceOff_On($params){
|
|
try {
|
|
$device_id = $params['device_id'];
|
|
$state = $params['state'];
|
|
$device = TeaStoreRoom::where('device_id',$device_id)->find();
|
|
|
|
if(!$device){
|
|
throw new \Exception('空开id错误');
|
|
}
|
|
// 使用服务类
|
|
$iotService = new IotService();
|
|
$result = $iotService->controlDevice($device_id, $state);
|
|
|
|
TeaStoreRoom::where('id',$device['id'])->update(['is_open'=>$state]);
|
|
|
|
if($result['code']!==200){
|
|
throw new \Exception('空开操作失败');
|
|
}
|
|
return [];
|
|
|
|
|
|
}catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public static function lockOff_On($params){
|
|
try {
|
|
$type = $params['type'];
|
|
$lock_no = $params['lock_no'];
|
|
$store_id = $params['store_id'];
|
|
$room_id = $params['room_id'];
|
|
|
|
|
|
if (!in_array($type, [1, 2])) {
|
|
throw new \Exception('门锁类型不存在');
|
|
}
|
|
if($type == 1){
|
|
$store = TeaStore::where([
|
|
'lock_no'=>$lock_no,
|
|
'id'=>$store_id,
|
|
'del'=>0
|
|
])->find();
|
|
if(!$store){
|
|
throw new \Exception('门店不存在或大门门锁编号不匹配');
|
|
}
|
|
}else{
|
|
$room = TeaStoreRoom::where([
|
|
'id'=>$room_id,
|
|
'lock_no'=>$lock_no,
|
|
'del'=>0
|
|
])->find();
|
|
|
|
if(!$room){
|
|
throw new \Exception('包间不存在或包间门锁编号不匹配');
|
|
}
|
|
}
|
|
|
|
$doorService = new DoorService();
|
|
$result = $doorService->unlockByNetwork($lock_no);
|
|
if($result['errcode'] !==0){
|
|
throw new \Exception('开锁失败');
|
|
}
|
|
return [];
|
|
|
|
}catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |