浏览代码

Merge remote-tracking branch 'origin/20250210_lj_zhanqun' into dev

AI 2 月之前
父节点
当前提交
806a8ca14d
共有 3 个文件被更改,包括 231 次插入112 次删除
  1. 189 105
      app/JsonRpc/NewsService.php
  2. 15 7
      app/JsonRpc/NewsServiceInterface.php
  3. 27 0
      app/Model/Good.php

+ 189 - 105
app/JsonRpc/NewsService.php

@@ -7,6 +7,8 @@ use App\Model\Category;
 use App\Model\Website;
 use App\Model\WebsiteCategory;
 use App\Model\ArticleSurvey;
+use App\Model\Good;
+
 use Hyperf\DbConnection\Db;
 use Hyperf\RpcServer\Annotation\RpcService;
 use App\Tools\Result;
@@ -452,7 +454,7 @@ class NewsService implements NewsServiceInterface
     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();
@@ -570,16 +572,16 @@ 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');
-                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 (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);
@@ -596,12 +598,12 @@ class NewsService implements NewsServiceInterface
                 }
             }
         })
-        ->orderBy("created_at", "desc")
-        ->limit($data['pageSize'])
-        ->offset(($data['page'] - 1) * $data['pageSize'])
-        ->get();
+            ->orderBy("created_at", "desc")
+            ->limit($data['pageSize'])
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->get();
 
-        $count =  Article::where(function ($query) use ($where) {
+        $count = Article::where(function ($query) use ($where) {
             foreach ($where as $condition) {
                 if ($condition[1] === 'in') {
                     $query->whereIn($condition[0], $condition[2]);
@@ -615,12 +617,12 @@ class NewsService implements NewsServiceInterface
             'rows' => $rep->toArray(),
             'count' => $count,
         ];
-        
-        if(empty($rep)){
+
+        if (empty($rep)) {
             return Result::error("没有信息数据");
         }
         return Result::success($data);
-        
+
     }
     /**
      * 前端-获取新闻详情
@@ -650,39 +652,39 @@ class NewsService implements NewsServiceInterface
      * @param array $data
      * @return array
      */
-     public function getWebsiteSurvey(array $data): 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['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);
+        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); 
+            // $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); 
+        $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);
     }
@@ -693,95 +695,95 @@ class NewsService implements NewsServiceInterface
      */
     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['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['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'])){
+                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'],
-    
+                        '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);
+                    if (empty($result)) {
+                        return Result::error("添加失败", 0);
                     }
                     return Result::success($result);
                 }
             }
-            return Result::error("添加失败",0);
+            return Result::error("添加失败", 0);
         }
-        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['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);
+            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');
+                $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); 
+                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);
+                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);
+                    } 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();
+                    $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']);
+                    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);
+                    $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);
 
                 }
@@ -790,7 +792,7 @@ class NewsService implements NewsServiceInterface
                 //     $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::error("参数必填!");
     }
@@ -801,19 +803,101 @@ class NewsService implements NewsServiceInterface
     public function checkCategoryName(array $data): array
     {
         $result = Category::when($data, function ($query) use ($data) {
-            if(isset($data['name']) && $data['name']) {
+            if (isset($data['name']) && $data['name']) {
                 $query->where("name", $data['name']);
             }
-            if(isset($data['id']) && $data['id']) {
-                $query->where("id","!=" ,$data['id']);
+            if (isset($data['id']) && $data['id']) {
+                $query->where("id", "!=", $data['id']);
             }
         })->first();
-        if($result){
+        if ($result) {
             return Result::error("已存在");
-        }else{
+        } else {
             return Result::success();
         }
     }
 
-    
-}
+    //20250226  产品列表
+
+    public function getGoodList(array $data): array
+    {
+        $where = [];
+        //类型
+        if (isset($data['type_id']) && $data['type_id']) {
+            $where = [
+                'type_id' => $data['type_id'],
+            ];
+        }
+        //名称
+        if (isset($data['name']) && $data['name']) {
+            $where = [
+                'name' => $data['name'],
+            ];
+        }
+        //website_id
+        if (isset($data['website_id']) && $data['website_id']) {
+            $where = [
+                'website_id' => $data['website_id'],
+            ];
+        }
+        //catid
+        if (isset($data['catid']) && $data['catid']) {
+            $where = [
+                'catid' => $data['catid'],
+            ];
+        }
+
+        // $result = Good::where($where)
+        // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
+        $result = Good::where($where)
+            ->orderBy("updated_at", "desc")
+            ->limit($data['page_size'])
+            ->offset(($data['page'] - 1) * $data['page_size'])
+            ->get();
+        $count = Good::where($where)->count();
+        $data = [
+            'rows' => $result->toArray(),
+            'count' => $count,
+        ];
+
+        if (empty($result)) {
+            return Result::error("此栏目暂无相关产品", 0);
+        }
+        return Result::success($data);
+    }
+    public function getGoodInfo(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("此产品不存在", 0);
+        }
+        return Result::success($result);
+    }
+    public function addGood(array $data): array
+    {
+
+        $result = Good::create($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function updateGood(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->update($data);
+        if (empty($result)) {
+            return Result::error("更新失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function delGood(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->delete();
+        if (empty($result)) {
+            return Result::error("删除失败", 0);
+        }
+        return Result::success($result);
+    }
+
+    //20250226  产品列表
+}

+ 15 - 7
app/JsonRpc/NewsServiceInterface.php

@@ -96,35 +96,43 @@ interface NewsServiceInterface
      * @param array $data
      * @return array
      */
-    public function checkCategoryName(array $data):array;
+    public function checkCategoryName(array $data): array;
 
-     /**
+    /**
      * @param array $data
      * @return array
      */
-    public function getWebsiteArticleList(array $data):array;
+    public function getWebsiteArticleList(array $data): array;
     /**
      * @param array $data
      * @return array
      */
-    public function selectWebsiteArticleInfo(array $data):array;
+    public function selectWebsiteArticleInfo(array $data): array;
     /**
      * @param array $data
      * @return array
      */
-    public function getWebsiteSurvey(array $data):array;
+    public function getWebsiteSurvey(array $data): array;
 
     /**
      * @param array $data
      * @return array
      */
-    public function addWebsiteSurveyOption(array $data):array;
+    public function addWebsiteSurveyOption(array $data): array;
 
     /**
      * @param array $data
      * @return array
      */
-    public function addWebsiteSurveyVote(array $data):array;
+    public function addWebsiteSurveyVote(array $data): array;
+
+    //20250226  产品列表
+    public function getGoodList(array $data): array;
+    public function getGoodInfo(array $data): array;
+    public function addGood(array $data): array;
+    public function delGood(array $data): array;
+    public function updateGood(array $data): array;
 
+    //20250226  产品列表
 
 }

+ 27 - 0
app/Model/Good.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Good extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'good';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}