|
@@ -12,7 +12,7 @@ use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
use App\Tools\Result;
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
use Hyperf\Utils\Random;
|
|
|
-
|
|
|
+use App\Model\ArticleSurvey;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -562,25 +562,24 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteArticleList(array $data): array
|
|
|
{
|
|
|
-
|
|
|
$where[] = ['status', '=', 1];
|
|
|
-
|
|
|
- if (isset($data['keyword']) && !empty($data['keyword'])) {
|
|
|
- array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
|
|
|
- }
|
|
|
- if (isset($data['catid']) && !empty($data['catid'])) {
|
|
|
- if (is_array($data['catid'])) {
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
|
|
|
- $where[] = ['catid', 'in', $data['catid']];
|
|
|
- } else {
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
|
|
|
- $where[] = ['catid', '=', $data['catid']];
|
|
|
+ if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
+ array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
|
+ }
|
|
|
+ if(isset($data['catid']) && !empty($data['catid'])){
|
|
|
+ if(is_array($data['catid'])){
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
|
|
|
+ array_push($where,['catid', 'in', $data['catid']]);
|
|
|
+ }else{
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
|
|
|
+ array_push($where,['catid', '=', $data['catid']]);
|
|
|
}
|
|
|
if (empty($category)) {
|
|
|
return Result::error("此网站暂无此栏目", 0);
|
|
|
}
|
|
|
}
|
|
|
- // return Result::success($category);
|
|
|
+ // return Result::success($where);
|
|
|
+
|
|
|
$rep = Article::where(function ($query) use ($where) {
|
|
|
foreach ($where as $condition) {
|
|
|
if ($condition[1] === 'in') {
|
|
@@ -590,11 +589,12 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- ->orderBy("created_at", "desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->get();
|
|
|
- $count = Article::where(function ($query) use ($where) {
|
|
|
+ ->orderBy("created_at", "desc")
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $count = Article::where(function ($query) use ($where) {
|
|
|
foreach ($where as $condition) {
|
|
|
if ($condition[1] === 'in') {
|
|
|
$query->whereIn($condition[0], $condition[2]);
|
|
@@ -603,14 +603,17 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
})->count();
|
|
|
+
|
|
|
$data = [
|
|
|
'rows' => $rep->toArray(),
|
|
|
'count' => $count,
|
|
|
];
|
|
|
- if (empty($rep)) {
|
|
|
+
|
|
|
+ if(empty($rep)){
|
|
|
return Result::error("没有信息数据");
|
|
|
}
|
|
|
return Result::success($data);
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* 前端-获取新闻详情
|
|
@@ -635,25 +638,153 @@ class NewsService implements NewsServiceInterface
|
|
|
$result['cat_name'] = $category['name'];
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * 验证导航名称是否重复
|
|
|
- * @return void
|
|
|
+ * 前端-获取网站调查问卷
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function checkCategoryName(array $data): array
|
|
|
+ public function getWebsiteSurvey(array $data): array
|
|
|
{
|
|
|
- $result = Category::when($data, function ($query) use ($data) {
|
|
|
- if (isset($data['name']) && $data['name']) {
|
|
|
- $query->where("name", $data['name']);
|
|
|
+ if(isset($data['survey_id']) && !empty($data['survey_id'])){
|
|
|
+ $website = Website::where('id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("暂无此网站",0);
|
|
|
}
|
|
|
- if (isset($data['id']) && $data['id']) {
|
|
|
- $query->where("id", "!=", $data['id']);
|
|
|
+ }
|
|
|
+ if(isset($data['art_id']) && !empty($data['art_id'])){
|
|
|
+ $article = Article::where('id',$data['art_id'])->first();
|
|
|
+ if(empty($article)){
|
|
|
+ return Result::error("暂无此文章",0);
|
|
|
}
|
|
|
- })->first();
|
|
|
- if ($result) {
|
|
|
- return Result::error("已存在");
|
|
|
- } else {
|
|
|
- return Result::success();
|
|
|
+ // return Result::error($data,0);
|
|
|
+ $where['art_id'] = $data['art_id'];
|
|
|
+ // $query = ArticleSurvey::where('art_id',$data['art_id']);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $survey = ArticleSurvey::where('website_id',$data['website_id'])->orderBy('created_at')->first();
|
|
|
+ if(empty($survey)){
|
|
|
+ return Result::error("暂无调查问卷",0);
|
|
|
+ }
|
|
|
+ $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['others'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
|
|
|
+ $result['other'] = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->first();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("此文章暂无调查问卷",0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 前端-添加网站调查问卷选项
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function addWebsiteSurveyOption(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);
|
|
|
+ }
|
|
|
+ if(isset($data['sur_id']) && !empty($data['sur_id'])){
|
|
|
+ $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
|
|
|
+ if(empty($survey)){
|
|
|
+ return Result::error("此调查问卷不可添加选项",0);
|
|
|
+ }
|
|
|
+ if(isset($data['choice_name']) &&!empty($data['choice_name'])){
|
|
|
+ $choice = [
|
|
|
+ 'art_id'=>$survey['art_id'],
|
|
|
+ 'website_id'=>$data['website_id'],
|
|
|
+ 'survey_name'=>$survey['survey_name'],
|
|
|
+ 'choice_name'=>$data['choice_name'],
|
|
|
+ 'sur_id'=>$survey['sur_id'],
|
|
|
+ 'is_other'=>1,
|
|
|
+ 'other_id'=>$survey['id'],
|
|
|
+
|
|
|
+ ];
|
|
|
+ $result = ArticleSurvey::insertGetId($choice);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("添加失败",0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result::error("添加失败",0);
|
|
|
+ }
|
|
|
+ return Result::error("添加失败",0);
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 前端-调查问卷投票
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ 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');
|
|
|
+ if(empty($survey)){
|
|
|
+ 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']];
|
|
|
+ }else{
|
|
|
+ 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)){
|
|
|
+ return Result::error("请选择已有的选项!",0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result::success($choice);
|
|
|
+
|
|
|
+ }
|
|
|
+ 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("此调查问卷不存在",0);
|
|
|
}
|
|
|
+ return Result::error("参数必填!");
|
|
|
}
|
|
|
-}
|
|
|
+}
|