|
@@ -289,30 +289,48 @@ class NewsService implements NewsServiceInterface
|
|
|
public function getWebsiteArticlett(array $data): array
|
|
|
{
|
|
|
|
|
|
- $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;
|
|
|
- $where = [
|
|
|
- 'status' => 1,
|
|
|
- 'level' => $data['level'],
|
|
|
- ];
|
|
|
- $result = Article::where($where)
|
|
|
- ->whereIn("catid", $category)
|
|
|
- ->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();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("暂无头条新闻",0);
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- return Result::error("本网站下暂无相关栏目",0);
|
|
|
+ $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;
|
|
|
+ $where = [
|
|
|
+ 'status' => 1,
|
|
|
+ ];
|
|
|
+ var_dump($data, 'data-----------------');
|
|
|
+
|
|
|
+ //如果是4:热点资讯 5:资讯推荐;
|
|
|
+ var_dump($where, 'where-----------------');
|
|
|
+
|
|
|
+ $result = Article::where($where)
|
|
|
+ ->whereIn("catid", $category)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ //$data['level'] == 4 || $data['level'] == 5 查询随机
|
|
|
+ ->when($data['level'] == 5, function ($query) {
|
|
|
+ $query->inRandomOrder()
|
|
|
+ //updated_at最近三十天;
|
|
|
+ ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
|
+ })
|
|
|
+ ->when($data['level'] != 5, 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");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无头条新闻", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("本网站下暂无相关栏目", 0);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -323,67 +341,75 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
public function getWebsiteModelArticles(array $data): array
|
|
|
{
|
|
|
- $catid=$data['catid'];
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$catid)->select('category_id')->get();
|
|
|
+ $catid = $data['catid'];
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
|
|
|
$category = $category->toArray();
|
|
|
- if(!empty($category)){
|
|
|
- $where=[
|
|
|
+ if (!empty($category)) {
|
|
|
+ $where = [
|
|
|
'status' => 1,
|
|
|
- 'catid' => $catid
|
|
|
+ 'catid' => $catid,
|
|
|
];
|
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
// 级别:0:未分类 1:头条 2:轮播图 3:推荐图 4:热点资讯 5:资讯推荐
|
|
|
if ($data['level'] == 1) {
|
|
|
- $level = [
|
|
|
- 0 => '1',
|
|
|
- 1 => '4',
|
|
|
- 2 => '5',
|
|
|
- 3 => '0',
|
|
|
- ];
|
|
|
+
|
|
|
$result = Article::where($where)
|
|
|
- ->whereIn('level',$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';
|
|
|
+ ->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('level',$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();
|
|
|
+ ->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';
|
|
|
+ } else {
|
|
|
+ $level = '3';
|
|
|
$result = Article::where($where)
|
|
|
- ->where('level',$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();
|
|
|
+ ->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();
|
|
|
}
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("此栏目暂无相关新闻",0);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("此栏目暂无相关新闻", 0);
|
|
|
}
|
|
|
- }else{
|
|
|
- return Result::error("此网站暂无此栏目",0);
|
|
|
-
|
|
|
+ } else {
|
|
|
+ return Result::error("此网站暂无此栏目", 0);
|
|
|
+
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+ return Result::success($result);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -511,12 +537,17 @@ 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)
|
|
|
- ->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();
|
|
|
+ $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();
|
|
|
if(empty($result)){
|
|
|
return Result::error("此文章暂无调查问卷",0);
|
|
|
}
|
|
@@ -624,14 +655,12 @@ class NewsService implements NewsServiceInterface
|
|
|
if(empty($choice)){
|
|
|
return Result::error("请选择已有的选项!",0);
|
|
|
}
|
|
|
-
|
|
|
- return Result::success($choice);
|
|
|
-
|
|
|
+ $retult_survey = ArticleSurvey::where('website_id', $data['website_id'])
|
|
|
+ ->where('sur_id', $data['sur_id'])
|
|
|
+ ->get();
|
|
|
+ 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);
|
|
|
}
|