diff --git a/Server/application/api/controller/DeviceController.php b/Server/application/api/controller/DeviceController.php index 287ecc14..df072c2c 100644 --- a/Server/application/api/controller/DeviceController.php +++ b/Server/application/api/controller/DeviceController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\api\model\DeviceModel; use app\api\model\DeviceGroupModel; +use think\Db; use think\facade\Request; use think\facade\Env; use Endroid\QrCode\QrCode; @@ -274,6 +275,53 @@ class DeviceController extends BaseController } } + + /** + * 删除设备 + * + * @param $deviceId + * @return false|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function delDevice($deviceId = '') + { + $authorization = $this->authorization; + if (empty($authorization)) { + return json_encode(['code'=>500,'msg'=>'缺少授权信息']); + } + + if (empty($deviceId)) { + return json_encode(['code'=>500,'msg'=>'删除的设备不能为空']); + } + + $device = Db::table('s2_device')->where('id', $deviceId)->find(); + if (empty($device)) { + return json_encode(['code'=>500,'msg'=>'设备不存在']); + } + + try { + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'json'); + // 发送请求 + $result = requestCurl($this->baseUrl . 'api/device/del/'.$deviceId, [], 'DELETE', $header,'json'); + if (empty($result)) { + Db::table('s2_device')->where('id', $deviceId)->update([ + 'isDeleted' => 1, + 'deleteTime' => time() + ]); + return json_encode(['code'=>200,'msg'=>'删除成功']); + }else{ + return json_encode(['code'=>200,'msg'=>'删除失败']); + } + } catch (\Exception $e) { + return json_encode(['code'=>500,'msg'=>'获取设备分组列表失败:' . $e->getMessage()]); + } + } + + /************************ 设备分组相关接口 ************************/ /** diff --git a/Server/application/cunkebao/controller/device/DeleteDeviceV1Controller.php b/Server/application/cunkebao/controller/device/DeleteDeviceV1Controller.php index a2b149ad..cb1b4a22 100644 --- a/Server/application/cunkebao/controller/device/DeleteDeviceV1Controller.php +++ b/Server/application/cunkebao/controller/device/DeleteDeviceV1Controller.php @@ -9,6 +9,7 @@ use app\common\model\User as UserModel; use app\cunkebao\controller\BaseController; use library\ResponseHelper; use think\Db; +use app\api\controller\DeviceController as apiDevice; /** * 设备管理控制器 @@ -83,11 +84,17 @@ class DeleteDeviceV1Controller extends BaseController */ protected function deleteCkbAbout(int $id): self { - $this->deleteDevice($id); - $this->deleteDeviceConf($id); - $this->deleteDeviceUser($id); - - return $this; + $apiDevice = new ApiDevice(); + $res = $apiDevice->delDevice($id); + $res = json_decode($res, true); + if ($res['code'] == 200){ + $this->deleteDevice($id); + $this->deleteDeviceConf($id); + $this->deleteDeviceUser($id); + return $this; + }else{ + return false; + } } /** diff --git a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php index 33410d13..78a21c1a 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php @@ -75,7 +75,7 @@ class GetDeviceListV1Controller extends BaseController ->field([ 'd.id', 'd.imei', 'd.memo', 'd.alive', 'l.wechatId', - 'a.nickname', 'a.alias', '0 totalFriend' + 'a.nickname', 'a.alias', 'a.avatar', '0 totalFriend' ]) ->leftJoin('device_wechat_login l', 'd.id = l.deviceId and l.alive =' . DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE . ' and l.companyId = d.companyId') ->leftJoin('wechat_account a', 'l.wechatId = a.wechatId')