设备管理新增删除及头像

This commit is contained in:
wong
2025-08-13 14:30:22 +08:00
parent 46ce2f7e8d
commit 5ef40510ce
3 changed files with 61 additions and 6 deletions

View File

@@ -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()]);
}
}
/************************ 设备分组相关接口 ************************/
/**

View File

@@ -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;
}
}
/**

View File

@@ -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')