|
@@ -395,24 +395,23 @@ class NewsService implements NewsServiceInterface
|
|
public function getWebsiteArticleList(array $data): array
|
|
public function getWebsiteArticleList(array $data): array
|
|
{
|
|
{
|
|
|
|
|
|
- $where[] = ['status', '=', 1];
|
|
|
|
-
|
|
|
|
|
|
+ $where[] = ['status', '=', 1];
|
|
if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
}
|
|
}
|
|
if(isset($data['catid']) && !empty($data['catid'])){
|
|
if(isset($data['catid']) && !empty($data['catid'])){
|
|
if(is_array($data['catid'])){
|
|
if(is_array($data['catid'])){
|
|
$category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
|
|
$category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
|
|
- $where[] = ['catid', 'in', $data['catid']];
|
|
|
|
|
|
+ array_push($where,['catid', 'in', $data['catid']]);
|
|
}else{
|
|
}else{
|
|
$category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
|
|
$category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
|
|
- $where[] = ['catid', '=', $data['catid']];
|
|
|
|
|
|
+ array_push($where,['catid', '=', $data['catid']]);
|
|
}
|
|
}
|
|
if(empty($category)){
|
|
if(empty($category)){
|
|
return Result::error("此网站暂无此栏目",0);
|
|
return Result::error("此网站暂无此栏目",0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // return Result::success($category);
|
|
|
|
|
|
+ // return Result::success($where);
|
|
$rep = Article::where(function ($query) use ($where) {
|
|
$rep = Article::where(function ($query) use ($where) {
|
|
foreach ($where as $condition) {
|
|
foreach ($where as $condition) {
|
|
if ($condition[1] === 'in') {
|
|
if ($condition[1] === 'in') {
|
|
@@ -549,13 +548,14 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
- * 前端-调查问卷投票 --------未完待续-------
|
|
|
|
|
|
+ * 前端-调查问卷投票
|
|
* @param array $data
|
|
* @param array $data
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
public function addWebsiteSurveyVote(array $data): array
|
|
public function addWebsiteSurveyVote(array $data): array
|
|
{
|
|
{
|
|
- if(isset($data['website_id']) &&!empty($data['website_id'])){
|
|
|
|
|
|
+
|
|
|
|
+ if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
$website = Website::where('id',$data['website_id'])->first();
|
|
$website = Website::where('id',$data['website_id'])->first();
|
|
if(empty($website)){
|
|
if(empty($website)){
|
|
return Result::error("暂无此网站",0);
|
|
return Result::error("暂无此网站",0);
|
|
@@ -565,36 +565,54 @@ class NewsService implements NewsServiceInterface
|
|
if(empty($survey)){
|
|
if(empty($survey)){
|
|
return Result::error("此调查问卷不存在",0);
|
|
return Result::error("此调查问卷不存在",0);
|
|
}
|
|
}
|
|
|
|
+ // return Result::success($survey);
|
|
// 调查问卷类型 0:单选 1:多选
|
|
// 调查问卷类型 0:单选 1:多选
|
|
$type = Article::where('survey_id',$data['sur_id'])->pluck('survey_type');
|
|
$type = Article::where('survey_id',$data['sur_id'])->pluck('survey_type');
|
|
// return Result::success($type);
|
|
// return Result::success($type);
|
|
- if(empty($type) || (!in_array($type, [0, 1], true))){
|
|
|
|
|
|
+ if(empty($type) || ($type[0]!= 1 && $type[0]!= 0)){
|
|
return Result::error("此调查问卷不可投票",0);
|
|
return Result::error("此调查问卷不可投票",0);
|
|
}
|
|
}
|
|
- return Result::success($type[0]);
|
|
|
|
|
|
+ // return Result::success($type[0]);
|
|
if(isset($data['choice_id']) &&!empty($data['choice_id'])){
|
|
if(isset($data['choice_id']) &&!empty($data['choice_id'])){
|
|
if($type[0] == 0){
|
|
if($type[0] == 0){
|
|
- $choice = ArticleSurvey::where('id',$data['choice_id'])->where('website_id',$data['website_id'])->first();
|
|
|
|
|
|
+ if(is_array($data['choice_id'])){
|
|
|
|
+ return Result::error("请选择一个选项!",0);
|
|
|
|
+ }
|
|
|
|
+ $data['choice_id'] = [$data['choice_id']];
|
|
}else{
|
|
}else{
|
|
- $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->get()->all();
|
|
|
|
|
|
+ if(!is_array($data['choice_id'])){
|
|
|
|
+ return Result::error("请传递数组!",0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // return Result::success($data['choice_id']);
|
|
|
|
+ $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
|
|
|
|
+ ->where('website_id',$data['website_id'])
|
|
|
|
+ ->where('is_other',1)
|
|
|
|
+ ->where('other_id','!=',0)
|
|
|
|
+ ->first();
|
|
|
|
+ // return Result::success($data);
|
|
|
|
+ if(!empty($choice['other'])){
|
|
|
|
+ array_push($data['choice_id'],$choice['other']['other_id']);
|
|
|
|
+ // return Result::success($data['choice_id']);
|
|
}
|
|
}
|
|
|
|
+ // return Result::success($data);
|
|
|
|
+ $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
|
|
|
|
+ ->where('website_id',$data['website_id'])
|
|
|
|
+ ->increment('results', 1);
|
|
if(empty($choice)){
|
|
if(empty($choice)){
|
|
return Result::error("请选择已有的选项!",0);
|
|
return Result::error("请选择已有的选项!",0);
|
|
}
|
|
}
|
|
|
|
+
|
|
return Result::success($choice);
|
|
return Result::success($choice);
|
|
- $where = [
|
|
|
|
- 'website_id'=>$data['website_id'],
|
|
|
|
- 'sur_id'=>$data['sur_id'],
|
|
|
|
- 'choice_id'=>$data['choice_id']
|
|
|
|
- ];
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
- return Result::success("111");
|
|
|
|
|
|
+ return Result::error("参数必填!");
|
|
// if(isset($data['choice_id']) && !empty($data['choice_id'])){
|
|
// 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();
|
|
// $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("此调查问卷不存在",0);
|
|
return Result::error("此调查问卷不存在",0);
|
|
}
|
|
}
|
|
- return Result::success("2222");
|
|
|
|
|
|
+ return Result::error("参数必填!");
|
|
}
|
|
}
|
|
}
|
|
}
|