|
|
@@ -802,10 +802,10 @@ class NewsService implements NewsServiceInterface
|
|
|
->select('website_id',
|
|
|
Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core'))
|
|
|
->get();
|
|
|
- // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
|
|
|
- // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
|
|
|
- $websiteIds = $web->pluck('website_id')->toArray();
|
|
|
- $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
|
|
|
+ // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
|
|
|
+ // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
|
|
|
+ $websiteIds = $web->pluck('website_id')->toArray();
|
|
|
+ $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
|
|
|
if($user_type == 0){
|
|
|
throw new \Exception("用户类型不能为空");
|
|
|
}
|
|
|
@@ -1088,27 +1088,7 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
|
|
|
$result = Article::where(['id' => $data['id']])->update($data);
|
|
|
-
|
|
|
- if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
|
|
|
- //article_ignore 表插入数据 db操作
|
|
|
- //转成数组
|
|
|
- //删掉数据重新写入
|
|
|
- // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
|
|
|
-
|
|
|
- $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
|
|
|
- // $insert_data = [];
|
|
|
- // foreach ($website_ids as $key => $value) {
|
|
|
- // $insert_data[] = [
|
|
|
- // 'article_id' => $data['id'],
|
|
|
- // 'website_id' => $value,
|
|
|
- // 'is_ignore' => 1
|
|
|
- // ];
|
|
|
- // }
|
|
|
- DB::table('article_ignore')->where('article_id', $data['id'])
|
|
|
- ->when(!empty($website_ids), function ($query) use ($website_ids) {
|
|
|
- $query->whereIn('website_id', $website_ids);
|
|
|
- })
|
|
|
- ->update(['is_ignore' => !empty($website_ids) ? 1 : 0]);
|
|
|
+
|
|
|
// ------c_show_time********up_status*******
|
|
|
// 若是审核通过 则更新c_show_time
|
|
|
if($data['status'] == 1){
|
|
|
@@ -1130,36 +1110,51 @@ class NewsService implements NewsServiceInterface
|
|
|
// 直接使用当前系统时间,不再强制添加8小时
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
$article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
|
|
|
- // 检查 $item 对象是否有 is_core 属性
|
|
|
- if (!isset($item['is_core'])) {
|
|
|
- throw new \Exception('$item 对象缺少 is_core 属性');
|
|
|
- }
|
|
|
- // 当 is_core 为 2 时,则表示此网站不存在
|
|
|
- if ($item['is_core'] == 2) {
|
|
|
- return null;
|
|
|
- }else if($item['is_core'] == 1){
|
|
|
- // 当 is_core 为 1 时,则表示此网站是核心站
|
|
|
- $c_show_time = date('Y-m-d H:i:s', strtotime($now));
|
|
|
- }else{
|
|
|
- // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
|
|
|
- $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
|
|
|
- if ($item['is_core'] == 0) {
|
|
|
- $time += $waiting_interval;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ if(isset($data['ignore_ids'])){
|
|
|
+ $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
|
|
|
+ if(in_array($item['website_id'], $ignore_website_ids)){
|
|
|
+ $is_ignore = 1;
|
|
|
+ }else{
|
|
|
+ $is_ignore = 0;
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'article_id' => $data['id'],
|
|
|
+ 'website_id' => $item['website_id'],
|
|
|
+ 'is_ignore' => $is_ignore,
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ // 检查 $item 对象是否有 is_core 属性
|
|
|
+ if (!isset($item['is_core'])) {
|
|
|
+ throw new \Exception('$item 对象缺少 is_core 属性');
|
|
|
+ }
|
|
|
+ // 当 is_core 为 2 时,则表示此网站不存在
|
|
|
+ if ($item['is_core'] == 2) {
|
|
|
+ return null;
|
|
|
+ }else if($item['is_core'] == 1){
|
|
|
+ // 当 is_core 为 1 时,则表示此网站是核心站
|
|
|
+ $c_show_time = $now;
|
|
|
+ }else{
|
|
|
+ // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
|
|
|
+ $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
|
|
|
+ if ($item['is_core'] == 0) {
|
|
|
+ $time += $waiting_interval;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- return [
|
|
|
- 'article_id' => $data['id'],
|
|
|
- 'website_id' => $item['website_id'],
|
|
|
- 'c_show_time' => $c_show_time,
|
|
|
- ];
|
|
|
+ return [
|
|
|
+ 'article_id' => $data['id'],
|
|
|
+ 'website_id' => $item['website_id'],
|
|
|
+ 'c_show_time' => $c_show_time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
}, array_keys($webArray), $webArray)));
|
|
|
-
|
|
|
- if(!empty($article_ignore)){
|
|
|
+ if(!empty($article_ignore) && !isset($data['ignore_ids'])){
|
|
|
// 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
|
|
|
// 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
|
|
|
- $article_ignores = ArticleIgnore::upsert(
|
|
|
+ $websiteIds = $web->pluck('website_id')->toArray();
|
|
|
+ $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
|
|
|
+ $article_ignores = ArticleIgnore::upsert(
|
|
|
$article_ignore,
|
|
|
['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
|
|
|
['c_show_time'] // 需要更新的字段
|
|
|
@@ -1168,9 +1163,22 @@ class NewsService implements NewsServiceInterface
|
|
|
throw new \Exception('c端展示时间插入失败');
|
|
|
}
|
|
|
}
|
|
|
+ if(!empty($data['ignore_ids'])){
|
|
|
+ // return Result::success($article_ignore);
|
|
|
+ // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
|
|
|
+ if(!empty($article_ignore)){
|
|
|
+ $article_ignores = ArticleIgnore::upsert(
|
|
|
+ $article_ignore,
|
|
|
+ ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
|
|
|
+ ['is_ignore'] // 需要更新的字段
|
|
|
+ );
|
|
|
+ // if(!$article_ignores){
|
|
|
+ // throw new \Exception('屏蔽网站更新失败');
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// ------c_show_time********up_status*******
|
|
|
- }
|
|
|
|
|
|
if ($result) {
|
|
|
return Result::success();
|