Merge branch 'develop' of https://e.coding.net/g-xtcy5189/cunkebao/cunkebao_v3 into develop
This commit is contained in:
@@ -10,6 +10,7 @@ Route::group('v1/', function () {
|
||||
|
||||
// 设备管理相关
|
||||
Route::group('devices', function () {
|
||||
Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedDevicesController@index'); // 更新设备任务配置
|
||||
Route::get(':id/related-accounts', 'app\cunkebao\controller\device\GetRelatedAccountsV1Controller@index'); // 设备关联微信账号路由
|
||||
Route::get(':id/handle-logs', 'app\cunkebao\controller\device\GetDeviceHandleLogsV1Controller@index'); // 获取设备操作记录
|
||||
Route::get('', 'app\cunkebao\controller\device\GetDeviceListV1Controller@index'); // 获取设备列表
|
||||
@@ -18,7 +19,6 @@ Route::group('v1/', function () {
|
||||
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');
|
||||
Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedDevicesController@index'); // 更新设备任务配置
|
||||
});
|
||||
|
||||
// 设备微信相关
|
||||
@@ -35,6 +35,7 @@ Route::group('v1/', function () {
|
||||
// 获客场景相关
|
||||
Route::group('plan/scenes', function () {
|
||||
Route::get('', 'app\cunkebao\controller\Scene@index'); // 获取场景列表
|
||||
Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表
|
||||
});
|
||||
|
||||
// 流量标签相关
|
||||
@@ -80,4 +81,14 @@ Route::group('v1/', function () {
|
||||
|
||||
});
|
||||
|
||||
})->middleware(['jwt']);
|
||||
// 计划任务相关路由
|
||||
Route::group('plan', function () {
|
||||
// 添加计划任务
|
||||
Route::post('add', 'app\cunkebao\controller\Plan@index');
|
||||
// 获取计划任务列表
|
||||
Route::get('list', 'app\cunkebao\controller\Plan@getList');
|
||||
});
|
||||
|
||||
})->middleware(['jwt']);
|
||||
|
||||
return [];
|
||||
254
Server/application/cunkebao/controller/Plan.php
Normal file
254
Server/application/cunkebao/controller/Plan.php
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\facade\Request;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 获客场景控制器
|
||||
*/
|
||||
class Plan extends Controller
|
||||
{
|
||||
/**
|
||||
* 添加计划任务
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
// 获取表单数据
|
||||
$data = [
|
||||
'name' => Request::post('name', ''),
|
||||
'sceneId' => Request::post('sceneId', 0),
|
||||
'status' => Request::post('status', 0),
|
||||
'reqConf' => Request::post('reqConf', ''),
|
||||
'msgConf' => Request::post('msgConf', ''),
|
||||
'tagConf' => Request::post('tagConf', ''),
|
||||
'createTime' => time(),
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 验证必填字段
|
||||
if (empty($data['name'])) {
|
||||
return ResponseHelper::error('计划名称不能为空', 400);
|
||||
}
|
||||
|
||||
if (empty($data['sceneId'])) {
|
||||
return ResponseHelper::error('场景ID不能为空', 400);
|
||||
}
|
||||
|
||||
// 验证数据格式
|
||||
if (!$this->validateJson($data['reqConf'])) {
|
||||
return ResponseHelper::error('好友申请设置格式不正确', 400);
|
||||
}
|
||||
|
||||
if (!$this->validateJson($data['msgConf'])) {
|
||||
return ResponseHelper::error('消息设置格式不正确', 400);
|
||||
}
|
||||
|
||||
if (!$this->validateJson($data['tagConf'])) {
|
||||
return ResponseHelper::error('标签设置格式不正确', 400);
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
$result = Db::name('friend_plan')->insert($data);
|
||||
|
||||
if ($result) {
|
||||
return ResponseHelper::success([], '添加计划任务成功');
|
||||
} else {
|
||||
return ResponseHelper::error('添加计划任务失败', 500);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::error('系统错误: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划任务列表
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
try {
|
||||
// 获取分页参数
|
||||
$id = Request::param('id', 1);
|
||||
$page = Request::param('page', 1);
|
||||
$pageSize = Request::param('pageSize', 10);
|
||||
|
||||
// 构建查询条件
|
||||
$where = [];
|
||||
|
||||
// 过滤已删除的记录
|
||||
$where[] = ['deleteTime', 'null'];
|
||||
|
||||
// 查询总数
|
||||
$total = Db::name('friend_plan')->where('sceneId', $id)->count();
|
||||
|
||||
// 查询列表数据
|
||||
$list = Db::name('friend_plan')
|
||||
->where('sceneId', $id)
|
||||
->field('id, name, status, createTime, updateTime, sceneId')
|
||||
->order('createTime desc')
|
||||
->page($page, $pageSize)
|
||||
->select();
|
||||
// 遍历列表,获取每个计划的统计信息
|
||||
foreach ($list as &$item) {
|
||||
// 获取计划的统计信息
|
||||
$stats = $this->getPlanStats($item['id']);
|
||||
|
||||
// 合并统计信息到结果中
|
||||
$item = array_merge($item, $stats);
|
||||
|
||||
// 格式化状态为文字描述
|
||||
$item['statusText'] = $item['status'] == 1 ? '进行中' : '已暂停';
|
||||
|
||||
// 格式化时间
|
||||
$item['createTimeFormat'] = date('Y-m-d H:i', $item['createTime']);
|
||||
|
||||
// 获取最近一次执行时间
|
||||
$lastExecution = $this->getLastExecution($item['id']);
|
||||
$item['lastExecutionTime'] = $lastExecution['lastTime'] ?? '';
|
||||
$item['nextExecutionTime'] = $lastExecution['nextTime'] ?? '';
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'list' => $list,
|
||||
'page' => $page,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
return ResponseHelper::success($result);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::error('获取数据失败: ' . $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划的统计信息
|
||||
*
|
||||
* @param int $planId 计划ID
|
||||
* @return array
|
||||
*/
|
||||
private function getPlanStats($planId)
|
||||
{
|
||||
try {
|
||||
// 获取设备数
|
||||
$deviceCount = $this->getDeviceCount($planId);
|
||||
|
||||
// 获取已获客数
|
||||
$customerCount = $this->getCustomerCount($planId);
|
||||
|
||||
// 获取已添加数
|
||||
$addedCount = 1; //$this->getAddedCount($planId);
|
||||
|
||||
// 计算通过率
|
||||
$passRate = $customerCount > 0 ? round(($addedCount / $customerCount) * 100) : 0;
|
||||
|
||||
return [
|
||||
'deviceCount' => $deviceCount,
|
||||
'customerCount' => $customerCount,
|
||||
'addedCount' => $addedCount,
|
||||
'passRate' => $passRate
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'deviceCount' => 0,
|
||||
'customerCount' => 0,
|
||||
'addedCount' => 0,
|
||||
'passRate' => 0
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划使用的设备数
|
||||
*
|
||||
* @param int $planId 计划ID
|
||||
* @return int
|
||||
*/
|
||||
private function getDeviceCount($planId)
|
||||
{
|
||||
try {
|
||||
// 获取计划
|
||||
$plan = Db::name('friend_plan')->where('id', $planId)->find();
|
||||
if (!$plan) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 解析reqConf
|
||||
$reqConf = json_decode($plan['reqConf'], true);
|
||||
|
||||
// 返回设备数量
|
||||
return isset($reqConf['selectedDevices']) ? count($reqConf['selectedDevices']) : 0;
|
||||
} catch (\Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划的已获客数
|
||||
*
|
||||
* @param int $planId 计划ID
|
||||
* @return int
|
||||
*/
|
||||
private function getCustomerCount($planId)
|
||||
{
|
||||
// 模拟数据,实际应从相关表获取
|
||||
return rand(10, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划的已添加数
|
||||
*
|
||||
* @param int $planId 计划ID
|
||||
* @return int
|
||||
*/
|
||||
private function getAddedCount($planId)
|
||||
{
|
||||
// 模拟数据,实际应从相关表获取
|
||||
$customerCount = $this->getCustomerCount($planId);
|
||||
return rand(5, $customerCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计划的最近一次执行时间
|
||||
*
|
||||
* @param int $planId 计划ID
|
||||
* @return array
|
||||
*/
|
||||
private function getLastExecution($planId)
|
||||
{
|
||||
// 模拟数据,实际应从执行记录表获取
|
||||
$now = time();
|
||||
$lastTime = $now - rand(3600, 86400);
|
||||
$nextTime = $now + rand(3600, 86400);
|
||||
|
||||
return [
|
||||
'lastTime' => date('Y-m-d H:i', $lastTime),
|
||||
'nextTime' => date('Y-m-d H:i:s', $nextTime)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证JSON格式是否正确
|
||||
*
|
||||
* @param string $string
|
||||
* @return bool
|
||||
*/
|
||||
private function validateJson($string)
|
||||
{
|
||||
if (empty($string)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
json_decode($string);
|
||||
return (json_last_error() == JSON_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,14 @@ namespace app\cunkebao\controller\device;
|
||||
use app\api\controller\DeviceController as ApiDeviceController;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 设备控制器
|
||||
*/
|
||||
class GetAddResultedDevicesController extends Controller
|
||||
class GetAddResultedDevicesController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 通过账号id 获取项目id。
|
||||
@@ -85,7 +85,7 @@ class GetAddResultedDevicesController extends Controller
|
||||
[
|
||||
'accountId' => $accountId,
|
||||
'pageIndex' => 0,
|
||||
'pageSize' => 1
|
||||
'pageSize' => 1
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
@@ -6,8 +6,11 @@ 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\User as UserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use Eison\Utils\Helper\ArrHelper;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -23,15 +26,15 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
$hasPermission = DeviceUserModel::where($where)->count() > 0;
|
||||
|
||||
if (!$hasPermission) {
|
||||
throw new \Exception('您没有权限查看该设备', '403');
|
||||
throw new \Exception('您没有权限查看该设备', 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,19 +67,23 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function getTaskConfig(int $deviceId): array
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
];
|
||||
|
||||
$conf = DeviceTaskconfModel::where($where)->field('autoAddFriend,autoReply,contentSync,aiChat')->find();
|
||||
$conf = DeviceTaskconfModel::alias('c')
|
||||
->field([
|
||||
'c.autoAddFriend', 'c.autoReply', 'c.momentsSync', 'c.aiChat'
|
||||
])
|
||||
->where($where)
|
||||
->find();
|
||||
|
||||
return $conf ? $conf->toArray() : [
|
||||
'autoAddFriend' => 0,
|
||||
'autoReply' => 0,
|
||||
'contentSync' => 0,
|
||||
'aiChat' => 0
|
||||
];
|
||||
if (!is_null($conf)) {
|
||||
return $conf->toArray();
|
||||
}
|
||||
|
||||
// 未配置时赋予默认关闭的状态
|
||||
return ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +96,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function getTotalFriend(int $deviceId): int
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
];
|
||||
|
||||
@@ -124,11 +131,10 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
->field([
|
||||
'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.updateTime as lastUpdateTime', 'd.extra'
|
||||
])
|
||||
->where('d.deleteTime', 0)
|
||||
->find($id);
|
||||
|
||||
if (empty($device)) {
|
||||
throw new \Exception('设备不存在', '404');
|
||||
throw new \Exception('设备不存在', 404);
|
||||
}
|
||||
|
||||
$device['battery'] = $this->parseExtraForBattery($device['extra']);
|
||||
@@ -152,25 +158,17 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
// 获取设备ID
|
||||
$id = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($id);
|
||||
}
|
||||
|
||||
$info = $this->getDeviceInfo($id);
|
||||
$resultSet = $this->getDeviceInfo($id);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $info
|
||||
]);
|
||||
return ResponseHelper::success($resultSet);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => $e->getMessage(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceHandleLog;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -20,15 +22,15 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
$hasPermission = DeviceUserModel::where($where)->count() > 0;
|
||||
|
||||
if (!$hasPermission) {
|
||||
throw new \Exception('您没有权限查看该设备', '403');
|
||||
throw new \Exception('您没有权限查看该设备', 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +44,7 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
{
|
||||
return DeviceHandleLog::alias('l')
|
||||
->field([
|
||||
'l.id',
|
||||
'l.content',
|
||||
'l.createTime',
|
||||
'l.id', 'l.content', 'l.createTime',
|
||||
'u.username'
|
||||
])
|
||||
->leftJoin('users u', 'l.userId = u.id')
|
||||
@@ -63,25 +63,20 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
try {
|
||||
$deviceId = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($deviceId);
|
||||
}
|
||||
|
||||
$logs = $this->getHandleLogs($deviceId);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'total' => $logs->total(),
|
||||
'list' => $logs->items()
|
||||
'list' => $logs->items()
|
||||
]
|
||||
]);
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -32,7 +35,6 @@ class GetDeviceListV1Controller extends BaseController
|
||||
}
|
||||
|
||||
$where['d.companyId'] = $this->getUserInfo('companyId');
|
||||
$where['d.deleteTime'] = 0;
|
||||
|
||||
return array_merge($params, $where);
|
||||
}
|
||||
@@ -70,7 +72,11 @@ class GetDeviceListV1Controller extends BaseController
|
||||
protected function getDeviceList(array $where, int $page = 1, int $limit = 10): \think\Paginator
|
||||
{
|
||||
$query = DeviceModel::alias('d')
|
||||
->field(['d.id', 'd.imei', 'd.memo', 'l.wechatId', 'd.alive','wa.nickname','wa.alias', '0 totalFriend'])
|
||||
->field([
|
||||
'd.id', 'd.imei', 'd.memo', 'd.alive',
|
||||
'l.wechatId',
|
||||
'wa.nickname', 'wa.alias', '0 totalFriend'
|
||||
])
|
||||
->leftJoin('device_wechat_login l', 'd.id = l.deviceId')
|
||||
->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId')
|
||||
->order('d.id desc');
|
||||
@@ -117,7 +123,7 @@ class GetDeviceListV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
if ($this->getUserInfo('isAdmin') == 1) {
|
||||
if ($this->getUserInfo('isAdmin') == UserModel::ADMIN_STP) {
|
||||
$where = $this->makeWhere();
|
||||
$result = $this->getDeviceList($where);
|
||||
} else {
|
||||
@@ -125,19 +131,14 @@ class GetDeviceListV1Controller extends BaseController
|
||||
$result = $this->getDeviceList($where);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $this->countFriend($result),
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->countFriend($result),
|
||||
'total' => $result->total(),
|
||||
]
|
||||
]);
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -22,15 +24,15 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
$hasPermission = DeviceUserModel::where($where)->count() > 0;
|
||||
|
||||
if (!$hasPermission) {
|
||||
throw new \Exception('您没有权限查看该设备', '403');
|
||||
throw new \Exception('您没有权限查看该设备', 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +45,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
protected function getDeviceWechatIds(int $deviceId): array
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
@@ -68,18 +70,18 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过微信id获取微信最后活跃时间
|
||||
* TODO 通过微信id获取微信最后活跃时间
|
||||
*
|
||||
* @param int $wechatId
|
||||
* @param int $time
|
||||
* @return string
|
||||
*/
|
||||
protected function getWechatLastActiveTime($wechatId): string
|
||||
protected function getWechatLastActiveTime(int $time): string
|
||||
{
|
||||
return date('Y-m-d H:i:s', $wechatId ?: time());
|
||||
return date('Y-m-d H:i:s', $time ?: time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 加友状态
|
||||
* TODO 加友状态
|
||||
*
|
||||
* @param string $wechatId
|
||||
* @return string
|
||||
@@ -90,7 +92,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号状态
|
||||
* TODO 账号状态
|
||||
*
|
||||
* @param string $wechatId
|
||||
* @return string
|
||||
@@ -147,27 +149,22 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
try {
|
||||
$deviceId = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($deviceId);
|
||||
}
|
||||
|
||||
// 获取设备关联的微信账号
|
||||
$wechatAccounts = $this->getDeviceRelatedAccounts($deviceId);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'accounts' => $wechatAccounts,
|
||||
'total' => count($wechatAccounts)
|
||||
'total' => count($wechatAccounts)
|
||||
]
|
||||
]);
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use library\s2\CurlHandle;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
@@ -23,9 +25,8 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
if ($this->request->param('imei')) {
|
||||
$where = [
|
||||
'imei' => $this->request->param('imei'),
|
||||
'imei' => $this->request->param('imei'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
];
|
||||
|
||||
$exist = DeviceModel::where($where)->count() > 0;
|
||||
@@ -43,7 +44,7 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
$curl = CurlHandle::getInstant();
|
||||
|
||||
// $curl->setMethod()
|
||||
// $curl->setMethod()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,9 +71,9 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'content' => '添加设备',
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'content' => '添加设备',
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
]
|
||||
);
|
||||
@@ -114,17 +115,10 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
|
||||
Db::commit();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功'
|
||||
]);
|
||||
return ResponseHelper::success();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -17,16 +18,9 @@ class RefreshDeviceDetailV1Controller extends BaseController
|
||||
{
|
||||
try {
|
||||
// TODO: 实现实际刷新设备状态的功能
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '刷新成功',
|
||||
]);
|
||||
return ResponseHelper::success();
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceTaskconf;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
|
||||
use app\common\model\DeviceTaskconf;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -24,15 +26,14 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
protected function checkDeviceExists(int $deviceId)
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
];
|
||||
|
||||
$device = DeviceModel::find($where);
|
||||
|
||||
if (!$device) {
|
||||
throw new \Exception('设备不存在或已删除', '404');
|
||||
throw new \Exception('设备不存在或已删除', 404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,15 +46,15 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
$hasPermission = DeviceUserModel::where($where)->count() > 0;
|
||||
|
||||
if (!$hasPermission) {
|
||||
throw new \Exception('您没有权限操作该设备', '403');
|
||||
throw new \Exception('您没有权限操作该设备', 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +70,20 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
$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 (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');
|
||||
throw new \Exception('参数错误', 400);
|
||||
}
|
||||
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'content' => $content,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'content' => $content,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
]
|
||||
);
|
||||
@@ -118,7 +119,7 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
|
||||
$this->checkDeviceExists($id);
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($id);
|
||||
}
|
||||
|
||||
@@ -130,17 +131,10 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
|
||||
Db::commit();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '更新任务配置成功'
|
||||
]);
|
||||
return ResponseHelper::success();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
return json([
|
||||
'code' => $e->getCode(),
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user