Browse Source

建立接口:获取c端网站所有头底信息

15313670163 2 days ago
parent
commit
1a67dbdeaa

+ 317 - 0
app/JsonRpc/FooterService.php

@@ -0,0 +1,317 @@
+<?php
+
+namespace App\JsonRpc;
+
+use App\Model\FooterCategory;
+use App\Model\Website;
+use App\Model\FooterContent;
+use App\Model\Web;
+use Hyperf\RpcServer\Annotation\RpcService;
+use App\Tools\Result;
+use Hyperf\DbConnection\Db;
+use PhpParser\Node\Expr\Clone_;
+use Overtrue\Pinyin\Pinyin;
+
+#[RpcService(name: "FooterService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
+class FooterService implements FooterServiceInterface
+{
+    /**
+     * 获取底部导航
+     * @param array $data
+     * @return array
+     */
+    public function getFooterCategory(array $data): array
+    {
+        $where = [];
+        if(isset($data['website_name'])){
+            array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
+        }
+        if(isset($data['name'])){
+            array_push($where, ['footer_category.name','like','%'.$data['name'].'%']);
+        }
+        $query = FooterCategory::leftJoin("website", "website.id", "footer_category.website_id")
+        ->select("footer_category.*", "website.website_name", "website.id as website_id");
+        if (!empty($where)) {
+            $query->where($where);
+        }
+        $count = $query->count();
+        $rep = $query->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->orderByDesc("updated_at")
+            ->get();
+        
+        // var_dump($where);
+        $result  = [];
+        $result = [
+            'rows'=>$rep,
+            'count'=>$count
+        ];
+        if(empty($result)){
+            return Result::error("没有查到相关数据!");
+        }
+        return Result::success($result);
+    }
+     /**
+      * 添加底部导航
+     * @param array $data
+     * @return array
+     */
+    public function addFooterCategory(array $data): array
+    {
+        if(empty($data)){
+            $result = Website::select('website_name','id')->get();
+        }else{
+            // 底部导航类型  0:内容型;1:列表型;
+            $webid = Website::select('website_name','id')->where('id',$data['website_id'])->first();
+            if(empty($webid)){
+                return Result::error("该网站不存在!");
+            }
+            Db::beginTransaction();
+            try{
+                // 同一网站下的底部导航名称不能重复
+                $name = FooterCategory::where('website_id',$data['website_id'])->where('name',$data['name'])->first();
+                if(!empty($name)){
+                    return Result::error("该底部导航名称已存在!");
+                }
+                $pinyin = new Pinyin();
+                $result = FooterCategory::insertGetId($data); 
+                $name_pinyin['name_pinyin'] = $pinyin->permalink($data['name'], '') ;
+                // return Result::success($name_pinyin);
+                $result = FooterCategory::where('id', $result)->update($name_pinyin);
+                Db::commit();
+            } catch(\Throwable $ex){
+                Db::rollBack();
+                $errorMessage = $ex->getMessage();
+                return Result::error("添加失败!",$errorMessage);
+            }
+        }
+        if(empty($result)){
+            return Result::error("添加失败!");
+        }else{
+            return Result::success($result);
+        }
+    }
+     /**
+      * 修改底部导航
+     * @param array $data
+     * @return array
+     */
+    public function upFooterCategory(array $data): array
+    {   
+        $footer_category = FooterCategory::where('id', $data['id'])->first();
+        if(empty($footer_category)) {
+            return Result::error("该底部导航不存在!");
+        }
+        if(empty($data['website_id'])){
+            $web = Website::select('website_name','id')->get();
+            $footer_category = FooterCategory::where('footer_category.id',$data['id'])
+            ->leftJoin("website","website.id","footer_category.website_id")
+            ->select("footer_category.*","website.website_name","website.id as website_id")
+            ->first();
+            if(isset($data['name'])){
+                $footer_category['name'] = $data['name'];
+            }
+            $result = [
+                'rows'=>$footer_category,
+                'web'=>$web
+            ];
+        }else{
+            $all_categories = FooterCategory::where('website_id',$data['website_id'])->where('id','!=',$data['id'])->pluck('name')->toArray();
+            // 检查修改后的数据是否与已有数据重复
+            if (in_array($data['name'], $all_categories)) {
+                return Result::error("修改后的底部导航名称已存在!");
+            }
+            $webid = Website::where('id',$data['website_id'])->first();
+            if(empty($webid)){
+                return Result::error("该网站不存在!");
+            }
+            $pinyin = new Pinyin();
+            $data['name_pinyin'] = $pinyin->permalink($data['name'], '');
+
+            $result = FooterCategory::where('id', $data['id'])->update($data);
+        }
+        if (empty($result)) {
+            return Result::error("修改失败!");
+        }else{
+            return Result::success($result);
+        }
+        
+    }
+    /**
+     * 删除底部导航
+     * @param array $data
+     * @return array
+     */
+    public function delFooterCategory(array $data): array
+    {
+        Db::beginTransaction();
+        try{
+            $footer_category = FooterCategory::where('id', $data['id'])->first();
+            if (!$footer_category) {
+                Db::rollBack();
+                return Result::error("该底部导航不存在!");
+            }else{
+                $result['footer_category'] = FooterCategory::where('id', $data['id'])->delete();
+                $result['footer_content'] = FooterContent::where('fcat_id', $data['id'])->delete();
+                Db::commit();
+                // $result = FooterCategory::where('footer_category.id',$data['id'])
+                // ->leftJoin("footer_content","footer_content.fcat_id","footer_category.id")
+                // ->delete();
+            }
+            
+        } catch(\Throwable $ex){
+            Db::rollBack();
+            var_dump($ex->getMessage());
+            return Result::error("删除失败",0);
+        }
+        return Result::success($result);
+    }
+    /**
+     * 添加底部导航(列表)内容
+     * @param array $data
+     * @return array
+     */
+    public function addFooterContent(array $data): array
+    {
+        // 底部导航类型    0:内容型;1:列表型;
+        // var_dump($data);
+       
+        $cat = FooterCategory::where('id', $data['fcat_id'])->first();
+        if (!$cat) {
+            return Result::error("该底部导航不存在!");
+        }
+        if($cat['type'] != $data['type']){
+            return Result::error("请输入正确的底部导航类型!");
+        }
+        if($cat['type'] == 0){
+            $content = FooterContent::where('fcat_id', $data['fcat_id'])->first();
+            if(!empty($content)){
+                return Result::error("该底部导航已添加内容!");
+            }
+        }else{
+            // return Result::success($data);
+            if(!isset($data['list_title']) || empty($data['list_title'])){
+                return Result::error("请输入底部导航列表标题!");
+            }
+            $content = FooterContent::where('fcat_id', $data['fcat_id'])->where('list_title',$data['list_title'])->first();
+            if(!empty($content)){
+                return Result::error("该列表标题已存在!");
+            }
+        }
+        unset($data['type']);
+        $result = FooterContent::insertGetId($data);
+        if(empty($result)){
+            return Result::error("添加失败!");
+        }else{
+            return Result::success($result);
+        }
+    }
+     /**
+     * 获取底部导航(列表)内容
+     * @param array $data
+     * @return array
+     */
+    public function getFooterContent(array $data): array
+    {
+
+        $where = [];
+        array_push($where, ['fcat_id',$data['fcat_id']]);
+        $type = FooterCategory::where('id', $data['fcat_id'])->value('type');
+        // return Result::success($type);
+        if($type == 1){
+            if(isset($data['list_title'])){
+                array_push($where, ['list_title','like','%'.$data['list_title'].'%']);
+            }
+            if(isset($data['con_title'])){
+                array_push($where, ['con_title','like','%'.$data['con_title'].'%']);
+            }
+            var_dump($where);
+        }
+        // return Result::success($where);
+        $query = FooterContent:: leftJoin('footer_category','footer_category.id','fcat_id')
+        ->select('footer_content.*','footer_category.type');
+        $count = $query->where($where)->count();
+        $rep = $query->where($where)
+        ->limit($data['pageSize'])
+        ->offset(($data['page']-1)*$data['pageSize'])
+        ->orderBy("updated_at","desc")
+        ->get();
+        
+        if(empty($rep)){
+            return Result::error("没有查到相关数据!");
+        }else{
+            $result = [
+                'rows'=>$rep,
+                'count'=>$count
+            ];
+            return Result::success($result);
+        }
+
+    }
+     /**
+     * 获取某个底部导航(列表)内容
+     * @param array $data
+     * @return array
+     */
+    public function getOneFooterContent(array $data): array
+    {      
+        $result = FooterContent::where('footer_content.id', $data['id'])
+        ->leftJoin('footer_category','footer_category.id','fcat_id')
+        ->select('footer_content.*','footer_category.type')
+        ->first();   
+        if(empty($result)){
+            return Result::error("请输入正确的底部导航内容id!");
+        }else{
+            return Result::success($result);
+        }
+    }
+    /**
+     * 编辑底部导航(列表)内容
+     * @param array $data
+     * @return array
+     */
+    public function upFooterContent(array $data): array
+    {
+        $content = FooterContent::where('footer_content.id', $data['id'])
+        ->leftJoin('footer_category','footer_category.id','fcat_id')
+        ->select('footer_content.*','footer_category.type','footer_category.id as fcat_id')
+        ->first();
+        if(!$content){
+            return Result::error("该底部导航内容不存在!");
+        }
+        if($content['type'] != $data['type']){
+            return Result::error("请输入正确的底部导航类型!");
+        }
+        if($content['type'] == 1){
+            if(!isset($data['list_title']) || empty($data['list_title'])){
+                return Result::error("请输入底部导航列表标题!");
+            }
+            $list_title = FooterContent::where('id','!=',$data['id'])->where('fcat_id', $content['fcat_id'])->where('list_title',$data['list_title'])->first();
+            if(!empty($list_title)){
+                return Result::error("该列表标题已存在!");
+            }
+        }
+        unset($data['type']);            
+        $result = FooterContent::where('id', $data['id'])->update($data);   
+        if(empty($result)){
+            return Result::error("修改失败!");
+        }else{
+            return Result::success($result);
+        }
+    }
+    /**
+     * 删除底部导航(列表)内容
+     * @param array $data
+     * @return array
+     */
+    public function delFooterContent(array $data): array
+    {
+        $result = FooterContent::where('id', $data['id'])->delete($data);  
+        if(empty($result)){
+            return Result::error("删除失败!");
+        }else{
+            return Result::success($result);
+        }
+    }
+
+}

+ 54 - 0
app/JsonRpc/FooterServiceInterface.php

@@ -0,0 +1,54 @@
+<?php
+
+namespace App\JsonRpc;
+interface FooterServiceInterface
+{
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getFooterCategory(array $data): array;
+
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function addFooterCategory(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function upFooterCategory(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function delFooterCategory(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function getFooterContent(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function addFooterContent(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function getOneFooterContent(array $data): array;
+    /**
+     * @param int $data
+     * @return array
+     */
+    public function upFooterContent(array $data): array;
+        /**
+     * @param int $data
+     * @return array
+     */
+    public function delFooterContent(array $data): array;
+
+
+}

+ 40 - 1
app/JsonRpc/WebsiteService.php

@@ -2181,6 +2181,45 @@ class WebsiteService implements WebsiteServiceInterface
         }
         }
         return Result::success($result); 
         return Result::success($result); 
     }
     }
-
+    /**
+     * 获取网站栏目信息
+     * @param array $data
+     */
+    public function getWebsiteAllinfo(array $data): array
+    {
+        $website = Website::where('id',$data['website_id'])->where('status',1)->first();
+        if (empty($website)) {
+            return Result::error("暂无该网站",0); 
+        }
+        if(isset($data['website_id']) && !empty($data['website_id'])){
+            $website_head = Website::where('id',$data['website_id'])
+                ->where('status',1)
+                ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url','ad_key')
+                ->first();
+            if (empty($website_head)) {
+                return Result::error("找不到网站",0); 
+            }
+        }else{
+            return Result::error("参数错误",0);
+        }
+        $website_foot = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
+        if (empty($website_foot)) {
+            return Result::error("暂无底部基础信息",0);
+        }
+        $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
+        $result['website_head'] =$website_head;
+        $result['website_foot'] = $website_foot;
+        
+        // return Result::success($result);
+        // 1:图片 2:文字 3:底部
+        $result['website_foot']['foot_cate'] = FooterCategory::where('website_id',$data['website_id'])->get()->all();
+        $result['website_foot']['link_img'] = Link::where('website_id',$data['website_id'])->where('type',1)->where('status',1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all(); 
+        $result['website_foot']['link_text'] = Link::where('website_id',$data['website_id'])->where('type',2)->where('status',1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
+        $result['website_foot']['link_foot'] = Link::where('website_id',$data['website_id'])->where('type',3)->where('status',1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
+        if(empty($result)){
+            return Result::error("暂无此网站信息",0);
+        }
+        return Result::success($result);
+    }
 
 
 }
 }

+ 1 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -115,4 +115,5 @@ interface WebsiteServiceInterface
     public function getWebsiteHead(array $data): array;
     public function getWebsiteHead(array $data): array;
     
     
     public function getWebsiteRoute(array $data): array;
     public function getWebsiteRoute(array $data): array;
+    public function getWebsiteAllinfo(array $data): array;
 }
 }