|
@@ -4,11 +4,12 @@ namespace App\JsonRpc;
|
|
|
use App\Model\Article;
|
|
|
use App\Model\ArticleData;
|
|
|
use App\Model\Category;
|
|
|
+use App\Model\Website;
|
|
|
use App\Model\WebsiteCategory;
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
use App\Tools\Result;
|
|
|
-
|
|
|
+use App\Model\ArticleSurvey;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -274,23 +275,24 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
+ * 获取新闻详情
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
public function getArticleInfo(array $data): array
|
|
|
{
|
|
|
$where = [
|
|
|
- 'article.id'=>$data['id']
|
|
|
+ 'article.id'=>$data['id'],
|
|
|
+ 'article.status'=>1
|
|
|
];
|
|
|
$result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
|
|
|
- if($result){
|
|
|
- return Result::success($result->toArray());
|
|
|
- }else{
|
|
|
+ if(empty($result)){
|
|
|
return Result::error("查询失败",0);
|
|
|
}
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
|
- * 获取新闻
|
|
|
+ * 获取头条新闻
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
@@ -386,6 +388,7 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ *获取新闻列表
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
@@ -398,17 +401,40 @@ class NewsService implements NewsServiceInterface
|
|
|
array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
|
}
|
|
|
if(isset($data['catid']) && !empty($data['catid'])){
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->select('category_id')->first();
|
|
|
+ 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(empty($category)){
|
|
|
return Result::error("此网站暂无此栏目",0);
|
|
|
}
|
|
|
- array_push($where,['catid',$data['catid']]);
|
|
|
}
|
|
|
- $rep = Article::where($where)
|
|
|
- ->orderBy("created_at","desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
- $count = Article::where($where)->count();
|
|
|
+ // return Result::success($category);
|
|
|
+ $rep = Article::where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $condition) {
|
|
|
+ if ($condition[1] === 'in') {
|
|
|
+ $query->whereIn($condition[0], $condition[2]);
|
|
|
+ } else {
|
|
|
+ $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->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]);
|
|
|
+ } else {
|
|
|
+ $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })->count();
|
|
|
$data = [
|
|
|
'rows'=>$rep->toArray(),
|
|
|
'count'=>$count
|
|
@@ -418,4 +444,157 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
return Result::success($data);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 前端-获取新闻详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function selectWebsiteArticleInfo(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'article.id'=>$data['id'],
|
|
|
+ 'article.status'=>1
|
|
|
+ ];
|
|
|
+ $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("查询失败",0);
|
|
|
+ }
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("查询失败",0);
|
|
|
+ }
|
|
|
+ $result['category_id'] = $category['category_id'];
|
|
|
+ $result['cat_name'] = $category['name'];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 前端-获取网站调查问卷
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteSurvey(array $data): array
|
|
|
+ {
|
|
|
+ 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['art_id']) && !empty($data['art_id'])){
|
|
|
+ $article = Article::where('id',$data['art_id'])->first();
|
|
|
+ if(empty($article)){
|
|
|
+ return Result::error("暂无此文章",0);
|
|
|
+ }
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
+ // 调查问卷类型 0:单选 1:多选
|
|
|
+ $type = Article::where('survey_id',$data['sur_id'])->pluck('survey_type');
|
|
|
+ // return Result::success($type);
|
|
|
+ if(empty($type) || (!in_array($type, [0, 1], true))){
|
|
|
+ return Result::error("此调查问卷不可投票",0);
|
|
|
+ }
|
|
|
+ return Result::success($type[0]);
|
|
|
+ if(isset($data['choice_id']) &&!empty($data['choice_id'])){
|
|
|
+ if($type[0] == 0){
|
|
|
+ $choice = ArticleSurvey::where('id',$data['choice_id'])->where('website_id',$data['website_id'])->first();
|
|
|
+ }else{
|
|
|
+ $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->get()->all();
|
|
|
+ }
|
|
|
+ if(empty($choice)){
|
|
|
+ return Result::error("请选择已有的选项!",0);
|
|
|
+ }
|
|
|
+ return Result::success($choice);
|
|
|
+ $where = [
|
|
|
+ 'website_id'=>$data['website_id'],
|
|
|
+ 'sur_id'=>$data['sur_id'],
|
|
|
+ 'choice_id'=>$data['choice_id']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return Result::success("111");
|
|
|
+ // 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::success("2222");
|
|
|
+ }
|
|
|
}
|