|
@@ -834,7 +834,7 @@ class NewsService implements NewsServiceInterface
|
|
|
if (empty($result)) {
|
|
|
return Result::error("添加失败", 0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+ return Result::success($data);
|
|
|
}
|
|
|
}
|
|
|
return Result::error("添加失败", 0);
|
|
@@ -849,11 +849,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');
|
|
@@ -861,32 +868,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'])
|
|
@@ -905,9 +903,10 @@ class NewsService implements NewsServiceInterface
|
|
|
if (empty($choice)) {
|
|
|
return Result::error("请选择已有的选项!", 0);
|
|
|
}
|
|
|
- $retult_survey = ArticleSurvey::where('website_id', $data['website_id'])
|
|
|
+ $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("参数必填!");
|