|
@@ -555,8 +555,8 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteArticlett(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
+
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
$result = [];
|
|
|
if ($category) {
|
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
@@ -565,7 +565,8 @@ class NewsService implements NewsServiceInterface
|
|
|
];
|
|
|
var_dump($data, 'data-----------------');
|
|
|
|
|
|
- //如果是4:热点资讯 5:资讯推荐;
|
|
|
+ //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
|
|
|
+ // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
|
|
|
var_dump($where, 'where-----------------');
|
|
|
|
|
|
$result = Article::where($where)
|
|
@@ -580,13 +581,13 @@ class NewsService implements NewsServiceInterface
|
|
|
//updated_at最近三十天;
|
|
|
->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
|
})
|
|
|
- ->when($data['level'] != 5, function ($query) {
|
|
|
+ ->when($data['level'] == 4, function ($query) {
|
|
|
$query->orderBy("updated_at", "desc");
|
|
|
})
|
|
|
->when(!empty($data['level']), function ($query) use ($data) {
|
|
|
if ($data['level'] != 4 && $data['level'] != 5) {
|
|
|
$query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
- ->orWhereNull("level");
|
|
|
+ ->orderBy("updated_at", "desc");
|
|
|
}
|
|
|
})
|
|
|
->offset($placeid)
|
|
@@ -617,43 +618,13 @@ class NewsService implements NewsServiceInterface
|
|
|
'catid' => $catid,
|
|
|
];
|
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
- // 级别:0:未分类 1:头条 2:轮播图 3:推荐图 4:热点资讯 5:资讯推荐
|
|
|
+ // 1:文字新闻;2:轮播图;3:图文;
|
|
|
+ // 级别:0:未分类
|
|
|
+ // 3:推荐图片
|
|
|
if ($data['level'] == 1) {
|
|
|
-
|
|
|
- $result = Article::where($where)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
- ->orWhereNull("level")
|
|
|
- ->orWhereRaw("level = '[]'");
|
|
|
- })
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])
|
|
|
- ->get();
|
|
|
- } elseif ($data['level'] == 2) {
|
|
|
- $level = '2';
|
|
|
- $result = Article::where($where)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
- ->orWhereNull("level")
|
|
|
- ->orWhereRaw("level = '[]'");
|
|
|
- })
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])
|
|
|
- ->get();
|
|
|
-
|
|
|
- } else {
|
|
|
- $level = '3';
|
|
|
- $result = Article::where($where)
|
|
|
+ $data['level'] = 0;
|
|
|
+ }
|
|
|
+ $result = Article::where($where)
|
|
|
->where(function ($query) use ($data) {
|
|
|
$query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
->orWhereNull("level")
|
|
@@ -667,7 +638,6 @@ class NewsService implements NewsServiceInterface
|
|
|
->offset($placeid)
|
|
|
->limit($data['pagesize'])
|
|
|
->get();
|
|
|
- }
|
|
|
if (empty($result)) {
|
|
|
return Result::error("此栏目暂无相关新闻", 0);
|
|
|
}
|
|
@@ -676,9 +646,7 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
*获取新闻列表
|
|
|
* @param array $data
|
|
@@ -807,14 +775,19 @@ class NewsService implements NewsServiceInterface
|
|
|
$where['sur_id'] = $survey['sur_id'];
|
|
|
// $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
|
|
|
}
|
|
|
- $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
|
|
|
+ $result = ArticleSurvey::where($where)
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('is_other', 0)
|
|
|
+ ->orWhere(function ($subQuery) {
|
|
|
+ $subQuery->where('is_other', 1)
|
|
|
+ ->where('other_id', 0);
|
|
|
+ });
|
|
|
+ })
|
|
|
->leftJoin('article', 'article_survey.art_id', 'article.id')
|
|
|
->select('article_survey.*', 'article.survey_type')
|
|
|
->get()->all();
|
|
|
- $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
|
|
|
- $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("此文章暂无调查问卷", 0);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("此文章暂无调查问卷",0);
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -850,7 +823,7 @@ class NewsService implements NewsServiceInterface
|
|
|
if (empty($result)) {
|
|
|
return Result::error("添加失败", 0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+ return Result::success($data);
|
|
|
}
|
|
|
}
|
|
|
return Result::error("添加失败", 0);
|
|
@@ -865,10 +838,18 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function addWebsiteSurveyVote(array $data): array
|
|
|
{
|
|
|
- if (isset($data['website_id']) && !empty($data['website_id'])) {
|
|
|
- $website = Website::where('id', $data['website_id'])->first();
|
|
|
- if (empty($website)) {
|
|
|
- return Result::error("暂无此网站", 0);
|
|
|
+ // $choice_id = $data['choice_id'];
|
|
|
+ // return Result::success($data);
|
|
|
+ if(is_array($data['choice_id'])){
|
|
|
+ if (!is_array($data['choice_id'])) {
|
|
|
+ $data['choice_id'] = [$data['choice_id']];
|
|
|
+ }
|
|
|
+ $data['choice_id'] = array_map('intval', $data['choice_id']);
|
|
|
+ }
|
|
|
+ if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
+ $website = Website::where('id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("暂无此网站",0);
|
|
|
}
|
|
|
if (isset($data['sur_id']) && !empty($data['sur_id'])) {
|
|
|
$survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
|
|
@@ -876,32 +857,23 @@ class NewsService implements NewsServiceInterface
|
|
|
return Result::error("此调查问卷不存在", 0);
|
|
|
}
|
|
|
// return Result::success($survey);
|
|
|
- // 调查问卷类型 0:单选 1:多选
|
|
|
- $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
|
|
|
- // return Result::success($type);
|
|
|
- if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
|
|
|
- return Result::error("此调查问卷不可投票", 0);
|
|
|
- }
|
|
|
- // return Result::success($type[0]);
|
|
|
- if (isset($data['choice_id']) && !empty($data['choice_id'])) {
|
|
|
- if ($type[0] == 0) {
|
|
|
- if (is_array($data['choice_id'])) {
|
|
|
- return Result::error("请选择一个选项!", 0);
|
|
|
- }
|
|
|
- $data['choice_id'] = [$data['choice_id']];
|
|
|
+ // 调查问卷类型
|
|
|
+ if(isset($data['choice_id']) &&!empty($data['choice_id'])){
|
|
|
+ //多选 若是json型则转化成数组类型
|
|
|
+ if (strpos($data['choice_id'], '[') === 0) {
|
|
|
+ $data['choice_id'] = json_decode($data['choice_id'], true);
|
|
|
} else {
|
|
|
- if (!is_array($data['choice_id'])) {
|
|
|
- return Result::error("请传递数组!", 0);
|
|
|
- }
|
|
|
+ // 单选 也转换成数组
|
|
|
+ $data['choice_id'] = [$data['choice_id']];
|
|
|
}
|
|
|
- // return Result::success($data['choice_id']);
|
|
|
- $other = ArticleSurvey::whereIn('id', $data['choice_id'])
|
|
|
- ->where('website_id', $data['website_id'])
|
|
|
- ->where('is_other', 1)
|
|
|
- ->where('other_id', 0)
|
|
|
- ->first();
|
|
|
- if (!empty($other)) {
|
|
|
- return Result::error("请选择已有的选项!", 0);
|
|
|
+ $data['choice_id'] = array_map('intval', $data['choice_id']);
|
|
|
+ $other = ArticleSurvey::whereIn('id',$data['choice_id'])
|
|
|
+ ->where('website_id',$data['website_id'])
|
|
|
+ ->where('is_other',1)
|
|
|
+ ->where('other_id',0)
|
|
|
+ ->first();
|
|
|
+ if(!empty($other)){
|
|
|
+ return Result::error("请选择已有的选项!",0);
|
|
|
}
|
|
|
$choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
|
|
|
->where('website_id', $data['website_id'])
|
|
@@ -920,17 +892,13 @@ class NewsService implements NewsServiceInterface
|
|
|
if (empty($choice)) {
|
|
|
return Result::error("请选择已有的选项!", 0);
|
|
|
}
|
|
|
- $retult_survey = ArticleSurvey::where('website_id', $data['website_id'])
|
|
|
- ->where('sur_id', $data['sur_id'])
|
|
|
- ->get();
|
|
|
-
|
|
|
+ $retult_survey['data'] = ArticleSurvey::where('website_id', $data['website_id'])
|
|
|
+ ->where('sur_id', $data['sur_id'])
|
|
|
+ ->get();
|
|
|
+ $retult_survey['choice'] = $data['choice_id'];
|
|
|
return Result::success($retult_survey);
|
|
|
-
|
|
|
}
|
|
|
- return Result::error("参数必填!");
|
|
|
- // if(isset($data['choice_id']) && !empty($data['choice_id'])){
|
|
|
- // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
|
|
|
- // }
|
|
|
+ return Result::error("参数必填!");
|
|
|
}
|
|
|
return Result::error("此调查问卷不存在", 0);
|
|
|
}
|