优化内容库
This commit is contained in:
@@ -1297,10 +1297,11 @@ class ContentLibraryController extends Controller
|
||||
// 从s2_wechat_moments表获取朋友圈数据
|
||||
$query = Db::table('s2_wechat_moments')
|
||||
->where([
|
||||
//'wechatAccountId' => $friend['wechatAccountId'],
|
||||
'userName' => $friend['wechatId'],
|
||||
'wechatAccountId' => $friend['wechatAccountId']
|
||||
])
|
||||
->order('createTime', 'desc');
|
||||
->order('createTime', 'desc')
|
||||
->group('snsId');
|
||||
|
||||
// 如果启用了时间限制
|
||||
if ($library['timeEnabled'] && $library['timeStart'] > 0 && $library['timeEnd'] > 0) {
|
||||
@@ -1313,8 +1314,7 @@ class ContentLibraryController extends Controller
|
||||
}*/
|
||||
|
||||
// 获取最近20条朋友圈
|
||||
$moments = $query->page(1, 20)->select();
|
||||
|
||||
$moments = $query->page(1, 100)->select();
|
||||
if (empty($moments)) {
|
||||
continue;
|
||||
}
|
||||
@@ -1804,9 +1804,6 @@ class ContentLibraryController extends Controller
|
||||
->where('snsId', $moment['snsId'] ?? '')
|
||||
->find();
|
||||
|
||||
if ($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 解析资源URL (可能是JSON字符串)
|
||||
$resUrls = $moment['resUrls'];
|
||||
@@ -1892,30 +1889,37 @@ class ContentLibraryController extends Controller
|
||||
}
|
||||
|
||||
// 如果不存在,则创建新的内容项目
|
||||
$item = new ContentItem();
|
||||
$item->libraryId = $libraryId;
|
||||
$item->type = 'moment'; // 朋友圈类型
|
||||
$item->title = '来自 ' . $nickname . ' 的朋友圈';
|
||||
$item->contentData = json_encode($moment, JSON_UNESCAPED_UNICODE);
|
||||
$item->snsId = $moment['snsId'] ?? ''; // 存储snsId便于后续查询
|
||||
$item->createTime = time();
|
||||
$item->wechatId = $friend['wechatId'];
|
||||
$item->friendId = $friend['id'];
|
||||
$item->createMomentTime = $moment['createTime'] ?? 0;
|
||||
$item->content = $moment['content'] ?? '';
|
||||
$item->contentAi = $moment['contentAi'] ?? '';
|
||||
$item->coverImage = $coverImage;
|
||||
$item->contentType = $contentType; // 设置内容类型
|
||||
|
||||
if(empty($exists)){
|
||||
$exists = new ContentItem();
|
||||
}
|
||||
|
||||
$exists->libraryId = $libraryId;
|
||||
$exists->type = 'moment'; // 朋友圈类型
|
||||
$exists->title = '来自 ' . $nickname . ' 的朋友圈';
|
||||
$exists->contentData = json_encode($moment, JSON_UNESCAPED_UNICODE);
|
||||
$exists->snsId = $moment['snsId'] ?? ''; // 存储snsId便于后续查询
|
||||
$exists->createTime = time();
|
||||
$exists->wechatId = $friend['wechatId'];
|
||||
$exists->friendId = $friend['id'];
|
||||
$exists->createMomentTime = $moment['createTime'] ?? 0;
|
||||
$exists->content = $moment['content'] ?? '';
|
||||
$exists->contentAi = $moment['contentAi'] ?? '';
|
||||
$exists->coverImage = $coverImage;
|
||||
$exists->contentType = $contentType; // 设置内容类型
|
||||
$exists->ossUrls = $moment['ossUrls'] ?? json_decode([]);
|
||||
|
||||
// 独立存储resUrls和urls字段
|
||||
$item->resUrls = is_string($moment['resUrls']) ? $moment['resUrls'] : json_encode($resUrls, JSON_UNESCAPED_UNICODE);
|
||||
$item->urls = is_string($moment['urls']) ? $moment['urls'] : json_encode($urls, JSON_UNESCAPED_UNICODE);
|
||||
$exists->resUrls = is_string($moment['resUrls']) ? $moment['resUrls'] : json_encode($resUrls, JSON_UNESCAPED_UNICODE);
|
||||
$exists->urls = is_string($moment['urls']) ? $moment['urls'] : json_encode($urls, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 保存地理位置信息
|
||||
$item->location = $moment['location'] ?? '';
|
||||
$item->lat = $moment['lat'] ?? 0;
|
||||
$item->lng = $moment['lng'] ?? 0;
|
||||
$item->save();
|
||||
$exists->location = $moment['location'] ?? '';
|
||||
$exists->lat = $moment['lat'] ?? 0;
|
||||
$exists->lng = $moment['lng'] ?? 0;
|
||||
$exists->save();
|
||||
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
|
||||
Reference in New Issue
Block a user