内容库可以选择设备
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace app\cunkebao\controller;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\WechatCustomer as WechatCustomerModel;
|
||||
use app\cunkebao\model\ContentLibrary;
|
||||
use app\cunkebao\model\ContentItem;
|
||||
use library\s2\titleFavicon;
|
||||
@@ -64,6 +67,7 @@ class ContentLibraryController extends Controller
|
||||
|
||||
$keywordInclude = isset($param['keywordInclude']) ? json_encode($param['keywordInclude'], 256) : json_encode([]);
|
||||
$keywordExclude = isset($param['keywordExclude']) ? json_encode($param['keywordExclude'], 256) : json_encode([]);
|
||||
$devices = isset($param['devices']) ? json_encode($param['devices'], 256) : json_encode([]);
|
||||
$sourceType = isset($param['sourceType']) ? $param['sourceType'] : 1;
|
||||
|
||||
|
||||
@@ -75,6 +79,7 @@ class ContentLibraryController extends Controller
|
||||
'sourceGroups' => $sourceType == 2 && isset($param['wechatGroups']) ? json_encode($param['wechatGroups']) : json_encode([]), // 选择的微信群
|
||||
'groupMembers' => $sourceType == 2 && isset($param['groupMembers']) ? json_encode($param['groupMembers']) : json_encode([]), // 群组成员
|
||||
'catchType' => isset($param['catchType']) ? json_encode($param['catchType']) : json_encode([]), // 采集类型
|
||||
'devices' => $devices,
|
||||
// 关键词配置
|
||||
'keywordInclude' => $keywordInclude, // 包含的关键词
|
||||
'keywordExclude' => $keywordExclude, // 排除的关键词
|
||||
@@ -314,7 +319,7 @@ class ContentLibraryController extends Controller
|
||||
|
||||
// 查询内容库信息
|
||||
$library = ContentLibrary::where($where)
|
||||
->field('id,name,sourceType,sourceFriends,sourceGroups,keywordInclude,keywordExclude,aiEnabled,aiPrompt,timeEnabled,timeStart,timeEnd,status,userId,companyId,createTime,updateTime,groupMembers,catchType')
|
||||
->field('id,name,sourceType,devices ,sourceFriends,sourceGroups,keywordInclude,keywordExclude,aiEnabled,aiPrompt,timeEnabled,timeStart,timeEnd,status,userId,companyId,createTime,updateTime,groupMembers,catchType')
|
||||
->find();
|
||||
|
||||
if (empty($library)) {
|
||||
@@ -322,13 +327,14 @@ class ContentLibraryController extends Controller
|
||||
}
|
||||
|
||||
// 处理JSON字段转数组
|
||||
$library['friendsGroups'] = json_decode($library['sourceFriends'] ?: '[]', true);
|
||||
$library['wechatGroups'] = json_decode($library['sourceGroups'] ?: '[]', true);
|
||||
$library['keywordInclude'] = json_decode($library['keywordInclude'] ?: '[]', true);
|
||||
$library['keywordExclude'] = json_decode($library['keywordExclude'] ?: '[]', true);
|
||||
$library['groupMembers'] = json_decode($library['groupMembers'] ?: '[]', true);
|
||||
$library['catchType'] = json_decode($library['catchType'] ?: '[]', true);
|
||||
unset($library['sourceFriends'], $library['sourceGroups']);
|
||||
$library['friendsGroups'] = json_decode($library['sourceFriends'] ?: [], true);
|
||||
$library['wechatGroups'] = json_decode($library['sourceGroups'] ?: [], true);
|
||||
$library['keywordInclude'] = json_decode($library['keywordInclude'] ?: [], true);
|
||||
$library['keywordExclude'] = json_decode($library['keywordExclude'] ?: [], true);
|
||||
$library['groupMembers'] = json_decode($library['groupMembers'] ?: [], true);
|
||||
$library['catchType'] = json_decode($library['catchType'] ?: [], true);
|
||||
$library['deviceGroups'] = json_decode($library['devices'] ?: [], true);
|
||||
unset($library['sourceFriends'], $library['sourceGroups'],$library['devices']);
|
||||
|
||||
// 将时间戳转换为日期格式(精确到日)
|
||||
if (!empty($library['timeStart'])) {
|
||||
@@ -369,6 +375,32 @@ class ContentLibraryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
//获取设备信息
|
||||
if (!empty($library['deviceGroups'])) {
|
||||
$deviceList = DeviceModel::alias('d')
|
||||
->field([
|
||||
'd.id', 'd.imei', 'd.memo', 'd.alive',
|
||||
'l.wechatId',
|
||||
'a.nickname', 'a.alias', 'a.avatar', 'a.alias', '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')
|
||||
->whereIn('d.id', $library['deviceGroups'])
|
||||
->order('d.id desc')
|
||||
->select();
|
||||
|
||||
foreach ($deviceList as &$device) {
|
||||
$curstomer = WechatCustomerModel::field('friendShip')->where(['wechatId' => $device['wechatId']])->find();
|
||||
$device['totalFriend'] = $curstomer->friendShip->totalFriend ?? 0;
|
||||
}
|
||||
unset($device);
|
||||
$library['deviceGroupsOptions'] = $deviceList;
|
||||
} else {
|
||||
$library['deviceGroupsOptions'] = [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
@@ -401,7 +433,8 @@ class ContentLibraryController extends Controller
|
||||
|
||||
$where = [
|
||||
['companyId', '=', $this->request->userInfo['companyId']],
|
||||
['isDel', '=', 0] // 只查询未删除的记录
|
||||
['isDel', '=', 0], // 只查询未删除的记录
|
||||
['id', '=', $param['id']]
|
||||
];
|
||||
|
||||
if (empty($this->request->userInfo['isAdmin'])) {
|
||||
@@ -420,6 +453,7 @@ class ContentLibraryController extends Controller
|
||||
|
||||
$keywordInclude = isset($param['keywordInclude']) ? json_encode($param['keywordInclude'], 256) : json_encode([]);
|
||||
$keywordExclude = isset($param['keywordExclude']) ? json_encode($param['keywordExclude'], 256) : json_encode([]);
|
||||
$devices = isset($param['devices']) ? json_encode($param['devices'], 256) : json_encode([]);
|
||||
|
||||
// 更新内容库基本信息
|
||||
$library->name = $param['name'];
|
||||
@@ -428,6 +462,7 @@ class ContentLibraryController extends Controller
|
||||
$library->sourceGroups = $param['sourceType'] == 2 && isset($param['wechatGroups']) ? json_encode($param['wechatGroups']) : json_encode([]);
|
||||
$library->groupMembers = $param['sourceType'] == 2 && isset($param['groupMembers']) ? json_encode($param['groupMembers']) : json_encode([]);
|
||||
$library->catchType = isset($param['catchType']) ? json_encode($param['catchType']) : json_encode([]);// 采集类型
|
||||
$library->devices = $devices;
|
||||
$library->keywordInclude = $keywordInclude;
|
||||
$library->keywordExclude = $keywordExclude;
|
||||
$library->aiEnabled = isset($param['aiEnabled']) ? $param['aiEnabled'] : 0;
|
||||
@@ -437,8 +472,6 @@ class ContentLibraryController extends Controller
|
||||
$library->timeEnd = isset($param['endTime']) ? strtotime($param['endTime']) : 0;
|
||||
$library->status = isset($param['status']) ? $param['status'] : 0;
|
||||
$library->updateTime = time();
|
||||
|
||||
|
||||
$library->save();
|
||||
|
||||
Db::commit();
|
||||
@@ -597,8 +630,8 @@ class ContentLibraryController extends Controller
|
||||
$item['content'] = !empty($item['contentAi']) ? $item['contentAi'] : $item['content'];
|
||||
|
||||
// 处理JSON字段
|
||||
$item['resUrls'] = json_decode($item['resUrls'] ?: '[]', true);
|
||||
$item['urls'] = json_decode($item['urls'] ?: '[]', true);
|
||||
$item['resUrls'] = json_decode($item['resUrls'] ?: [], true);
|
||||
$item['urls'] = json_decode($item['urls'] ?: [], true);
|
||||
|
||||
// 格式化时间
|
||||
if (!empty($item['createMomentTime']) && is_numeric($item['createMomentTime'])) {
|
||||
@@ -798,8 +831,8 @@ class ContentLibraryController extends Controller
|
||||
}
|
||||
|
||||
// 处理JSON字段
|
||||
$item['resUrls'] = json_decode($item['resUrls'] ?: '[]', true);
|
||||
$item['urls'] = json_decode($item['urls'] ?: '[]', true);
|
||||
$item['resUrls'] = json_decode($item['resUrls'] ?: [], true);
|
||||
$item['urls'] = json_decode($item['urls'] ?: [], true);
|
||||
|
||||
// 添加内容类型的文字描述
|
||||
$contentTypeMap = [
|
||||
@@ -1083,12 +1116,12 @@ class ContentLibraryController extends Controller
|
||||
// 预处理内容库数据
|
||||
foreach ($libraries as &$library) {
|
||||
// 解析JSON字段
|
||||
$library['sourceFriends'] = json_decode($library['sourceFriends'] ?: '[]', true);
|
||||
$library['sourceGroups'] = json_decode($library['sourceGroups'] ?: '[]', true);
|
||||
$library['keywordInclude'] = json_decode($library['keywordInclude'] ?: '[]', true);
|
||||
$library['keywordExclude'] = json_decode($library['keywordExclude'] ?: '[]', true);
|
||||
$library['groupMembers'] = json_decode($library['groupMembers'] ?: '[]', true);
|
||||
$library['catchType'] = json_decode($library['catchType'] ?: '[]', true);
|
||||
$library['sourceFriends'] = json_decode($library['sourceFriends'] ?: [], true);
|
||||
$library['sourceGroups'] = json_decode($library['sourceGroups'] ?: [], true);
|
||||
$library['keywordInclude'] = json_decode($library['keywordInclude'] ?: [], true);
|
||||
$library['keywordExclude'] = json_decode($library['keywordExclude'] ?: [], true);
|
||||
$library['groupMembers'] = json_decode($library['groupMembers'] ?: [], true);
|
||||
$library['catchType'] = json_decode($library['catchType'] ?: [], true);
|
||||
}
|
||||
unset($library); // 解除引用
|
||||
|
||||
|
||||
Reference in New Issue
Block a user