超管后台 - 新建项目返工
This commit is contained in:
@@ -14,7 +14,7 @@ Route::group('v1/', function () {
|
||||
Route::get(':id/handle-logs', 'app\\cunkebao\\controller\\device\\GetDeviceHandleLogsV1Controller@index'); // 获取设备操作记录
|
||||
Route::get('', 'app\\cunkebao\\controller\\device\\GetDeviceListV1Controller@index'); // 获取设备列表
|
||||
Route::get(':id', 'app\\cunkebao\\controller\\device\\GetDeviceDetailV1Controller@index'); // 获取设备详情
|
||||
Route::post('', 'app\\cunkebao\\controller\\Device@save'); // 添加设备
|
||||
Route::post('', 'app\\cunkebao\\controller\\device\\PostAddDeviceV1Controller@index'); // 添加设备
|
||||
Route::put('refresh', 'app\\cunkebao\\controller\\device\\RefreshDeviceDetailV1Controller@index'); // 刷新设备状态
|
||||
Route::delete(':id', 'app\\cunkebao\\controller\\Device@delete'); // 删除设备
|
||||
Route::post('task-config', 'app\\cunkebao\\controller\\device\\UpdateDeviceTaskConfigV1Controller@index'); // 更新设备任务配置
|
||||
|
||||
@@ -171,97 +171,5 @@ class Device extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备操作记录
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function handleLogs()
|
||||
{
|
||||
try {
|
||||
// 获取登录用户信息
|
||||
$userInfo = request()->userInfo;
|
||||
|
||||
// 获取设备ID
|
||||
$deviceId = $this->request->param('id/d');
|
||||
if (empty($deviceId)) {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '设备ID不能为空'
|
||||
]);
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该设备
|
||||
if ($userInfo['isAdmin'] != 1) {
|
||||
// 非管理员需要检查是否有权限访问该设备
|
||||
$hasPermission = \app\common\model\DeviceUser::checkUserDevicePermission(
|
||||
$userInfo['id'],
|
||||
$deviceId,
|
||||
$userInfo['companyId']
|
||||
);
|
||||
|
||||
if (!$hasPermission) {
|
||||
return json([
|
||||
'code' => 403,
|
||||
'msg' => '您没有权限查看该设备'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取设备信息,确认设备存在
|
||||
$device = DeviceModel::where('id', $deviceId)
|
||||
->where('isDeleted', 0)
|
||||
->find();
|
||||
|
||||
if (!$device) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '设备不存在或已删除'
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取分页参数
|
||||
$page = (int)Request::param('page', 1);
|
||||
$limit = (int)Request::param('limit', 10);
|
||||
|
||||
// 查询设备操作记录,并关联用户表获取操作人信息
|
||||
$logs = Db::table('tk_device_handle_log')
|
||||
->alias('l')
|
||||
->join('tk_users u', 'l.userId = u.id', 'left')
|
||||
->where('l.imei', $device['imei'])
|
||||
->where('l.companyId', $userInfo['companyId'])
|
||||
->field([
|
||||
'l.id',
|
||||
'l.content',
|
||||
'l.createTime',
|
||||
'u.username'
|
||||
])
|
||||
->order('l.createTime desc')
|
||||
->paginate($limit, false, ['page' => $page]);
|
||||
|
||||
// 格式化返回数据
|
||||
$items = [];
|
||||
foreach ($logs as $log) {
|
||||
$items[] = [
|
||||
'id' => $log['id'],
|
||||
'content' => $log['content'],
|
||||
'username' => $log['username'] ? $log['username'] : '未知用户',
|
||||
'createTime' => $log['createTime']
|
||||
];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'total' => $logs->total(),
|
||||
'list' => $items
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '获取失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -154,7 +153,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
{
|
||||
try {
|
||||
// 获取设备ID
|
||||
$id = Request::param('id/d');
|
||||
$id = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
$this->checkUserDevicePermission($id);
|
||||
|
||||
@@ -88,10 +88,10 @@ class GetDeviceListV1Controller extends BaseController
|
||||
/**
|
||||
* 统计微信好友
|
||||
*
|
||||
* @param object $list
|
||||
* @param \think\Paginator $list
|
||||
* @return array
|
||||
*/
|
||||
protected function countFriend(object $list): array
|
||||
protected function countFriend(\think\Paginator $list): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
|
||||
use app\library\s2\CurlHandle;
|
||||
use Couchbase\ViewOptions;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
*/
|
||||
class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* 验证IMEI是否已存在
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function checkDeviceIsExist(): void
|
||||
{
|
||||
if ($this->request->param('imei')) {
|
||||
$where = [
|
||||
'imei' => $this->request->param('imei'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
];
|
||||
|
||||
$exist = DeviceModel::where($where)->count() > 0;
|
||||
|
||||
if ($exist) {
|
||||
throw new \Exception('设备IMEI已存在', 400);
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('设备IMEI不能为空', 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function addDeviceToS2()
|
||||
{
|
||||
$curl = CurlHandle::getInstant();
|
||||
|
||||
// $curl->setMethod()
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addDevice()
|
||||
{
|
||||
|
||||
$id = DeviceModel::addDevice(
|
||||
$this->request->post()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备操作记录
|
||||
*
|
||||
* @param int $deviceId
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function addDeviceHandleLog(int $deviceId): void
|
||||
{
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'content' => '添加设备',
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据验证
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function dataValidate(): self
|
||||
{
|
||||
$validate = Validate::make([
|
||||
'imei' => 'require|length:32',
|
||||
'memo' => 'require|/\S+/'
|
||||
]);
|
||||
|
||||
if (!$validate->check($this->request->post())) {
|
||||
throw new \Exception($validate->getError(), 400);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$this->dataValidate()->checkDeviceIsExist();
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$deviceId = $this->addDevice();
|
||||
$this->addDeviceHandleLog($deviceId);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,12 +67,17 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
protected function addHandleLog(int $deviceId): void
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$content = null;
|
||||
|
||||
if (isset($data['autoAddFriend']))/**/$content = $data['autoAddFriend'] ? '开启自动添加好友' : '关闭自动添加好友';
|
||||
if (isset($data['autoReply']))/* */$content = $data['autoReply'] ? '开启自动回复' : '关闭自动回复';
|
||||
if (isset($data['momentsSync']))/* */$content = $data['momentsSync'] ? '开启朋友圈同步' : '关闭朋友圈同步';
|
||||
if (isset($data['aiChat']))/* */$content = $data['aiChat'] ? '开启AI会话' : '关闭AI会话';
|
||||
|
||||
if (empty($content)) {
|
||||
throw new \Exception('参数错误', '400');
|
||||
}
|
||||
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
@@ -109,7 +114,7 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$id = Request::param('deviceId/d');
|
||||
$id = $this->request->param('deviceId/d');
|
||||
|
||||
$this->checkDeviceExists($id);
|
||||
|
||||
@@ -120,8 +125,8 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$this->setTaskconf($id);
|
||||
$this->addHandleLog($id);
|
||||
$this->setTaskconf($id);
|
||||
|
||||
Db::commit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user