Browse Source

完成搭建网站修-搜索及获取皮肤列表、选择皮肤的接口完善修改皮肤、添加皮肤的接口

15313670163 5 ngày trước cách đây
mục cha
commit
6174ddc567

+ 218 - 20
app/JsonRpc/PublicRpcService.php

@@ -15,6 +15,7 @@ use Hyperf\Di\Annotation\Inject;
 use Hyperf\RpcServer\Annotation\RpcService;
 use App\Service\MinioService;
 use Hyperf\Redis\Redis;
+use Overtrue\ChineseCalendar\Calendar;
 
 use App\Model\TemplateClass;
 use App\Model\Template;
@@ -22,7 +23,8 @@ use App\Model\WebsiteTemplate;
 use App\Model\WebsiteTemplateInfo;
 use App\Model\Sector;
 use App\Model\Component;
-
+use App\Model\Link;
+use App\Model\FooterCategory;
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
 {
@@ -803,11 +805,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->select('template.*', 'template_class.name as template_class_name')
             ->orderBy('template.id', 'desc')
             ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
-        // 使用 items 方法获取分页数据
-        // $items = collect($result->items());
-        // $items->each(function ($item) {
-        //     $item['template_content'] = json_decode($item['template_content'], true);
-        // });
+        if(empty($result)){
+            return Result::error("暂无皮肤", 0);
+        }
         return Result::success($result);
     }
     public function getTemplateInfo(array $data): array
@@ -816,6 +816,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
             ->select('template.*', 'template_class.name as template_class_name')
             ->first();
+        if(empty($result)){
+            return Result::error("暂无皮肤", 0);
+        }
         return Result::success($result);
     }
     /**
@@ -834,6 +837,8 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
         }
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
+        $page_type = json_decode($data['page_type'], true);
+        $data['page_type'] = json_encode(array_values(array_unique($page_type)));
         $result = Template::insertGetId($data);
         if(empty($result)){
             return Result::error("创建失败", 0);
@@ -879,6 +884,8 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
         }
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
+        $page_type = json_decode($data['page_type'], true);
+        $data['page_type'] = json_encode(array_values(array_unique($page_type)));
         $result = Template::where('id', $data['id'])->update($data);
         var_dump($result, '-------------------update');
         if (!$result) {
@@ -925,6 +932,80 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->get();
         return Result::success($result);
     }
+    
+    /**
+     * 获取经纬度信息
+     * @return void
+     */
+    public function getIpInfo(array $data) :array
+    {
+        $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
+        // 使用 IPinfo 服务获取 IP 信息
+        $api_url = "https://ipinfo.io/{$client_ip}/json";
+        $ch = curl_init($api_url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($ch);
+        curl_close($ch);
+        // 解析 JSON 响应
+        $ip_info = json_decode($response, true);
+        // 提取地址和经纬度
+        if ($ip_info && !isset($ip_info['bogon'])) {
+            $latitude = explode(',', $ip_info['loc'])[0];
+            $longitude = explode(',', $ip_info['loc'])[1];
+            $ip_info['latitude'] = $latitude;
+            $ip_info['longitude'] = $longitude;
+            return Result::success($ip_info);
+        } else {
+            $data['ip'] = '101.254.114.212';
+            $this->getIpinfo(["ip"=>$data['ip']]);
+        }
+    }
+
+    /**
+     * 获取天气
+     * @param array $data
+     * @return array
+     */
+    public function getWeatherInfo(array $data) :array
+    {
+        $month = $data['month'] ?? date('m');
+        $day = $data['day'] ?? date('d');
+        // 使用缓存键
+        $cacheKey = "tsbb_data_weather_{$month}_{$day}";
+
+        // 尝试从缓存获取数据
+        $container = \Hyperf\Context\ApplicationContext::getContainer();
+        $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
+        if ($cachedData = $cache->get($cacheKey)) {
+            return Result::success(unserialize($cachedData));
+        }
+        $location = $data['latitude'].":".$data['longitude'];
+        $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
+        $ch = curl_init($api_url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($ch);
+        curl_close($ch);
+        // 解析 JSON 响应
+        $WeatherInfo = json_decode($response, true);
+        // 缓存结果,设置1小时过期
+        $cache->set($cacheKey, serialize($WeatherInfo), 3600);
+        if($WeatherInfo){
+            return Result::success($WeatherInfo);
+        }else{
+            return Result::error("获取天气失败", 0);
+        }
+    }
+
+    /**
+     * 获取农历信息
+     * @return void
+     */
+    public function getCalendar(array $data) :array
+    {
+        $calendar = new Calendar();
+        $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
+        return Result::success($result);
+    }
     public function addSector(array $data): array
     {
         unset($data['user_id']);
@@ -1007,36 +1088,153 @@ class PublicRpcService implements PublicRpcServiceInterface
         $result = Component::where('id', $data['id'])->update($data);
         return Result::success($result);
     }
-    public function getWebsiteTemplateList(array $data): array
+    
+    public function getWebsiteTemplateInfo(array $data)
     {
         $where = [];
-
+        if (isset($data['id'])) {
+            $where[] = ['id', '=', $data['id']];
+        }
         $result = WebsiteTemplateInfo::where($where)
             ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
+            ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
             ->select('website_template_info.*', 'website.website_name')
-            ->orderBy('website_template_info.id', 'desc')
-            ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+            ->get();
         if ($result) {
             return Result::success($result);
         } else {
             return Result::error('暂无数据');
         }
     }
-    public function getWebsiteTemplateInfo(array $data)
+    /**
+     * 自助建站----1.获取页面类型回显
+     * @param array $data
+     * @return array
+     */
+    public function getWebPageType(array $data): array
     {
-        $where = [];
-        if (isset($data['id'])) {
-            $where[] = ['id', '=', $data['id']];
+        // 1:图片 2:文字 3:底部
+        $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
+        if(empty($friend_link->toArray())){
+            return Result::error('暂无友情链接数据!');
         }
-        $result = WebsiteTemplateInfo::where($where)
-            ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
-            ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
-            ->select('website_template_info.*', 'website.website_name')
-            ->get();
+        $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
+        if(empty($footer_category->toArray())){
+            return Result::error('暂无底部导航数据!');
+        }
+        $result = [
+            'friend_link' => $friend_link,
+            'footer_category' => $footer_category,
+        ];
+        return Result::success($result);
+    }
+    /**
+     * 自助建站----2.添加页面类型
+     * @param array $data
+     * @return array
+     */
+    public function addWebPageType(array $data): array
+    {
+        // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
+        if($data['is_search'] == 1){
+            $page_type = json_encode([1,2,3,4,5,6,7]);
+        }else{
+            $page_type = json_encode([1,2,3,4,6,7]);
+        }
+        // 0:未构建;1:已填写基础信息;2:已选择模板;    action_id
+        $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]);
         if ($result) {
             return Result::success($result);
         } else {
-            return Result::error('暂无数据');
+            return Result::error('添加失败');
+        }
+    }
+    /**
+     * 自助建站---流程---3.选择皮肤列表
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteTemplateList(array $data): array
+    {
+        $where = [];
+        if(isset($data['template_class_id']) && $data['template_class_id']){
+            $where[] = ['template_class_id', '=', $data['template_class_id']];
+        }
+        // 0:未构建 1:未应用 2:已应用   status
+        $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
+        if(empty($templste_info)){
+            return Result::error('请先填写网站基础信息!');
+        }
+        if($templste_info['status'] == 2){
+            return Result::error('网站已应用,不可再次修改!');
+        }
+        
+        if(isset($data['keyword']) && !empty($data['keyword'])){
+            if (is_array($data['keyword'])) {
+                // 拼接多个模糊查询条件
+                $query = Template::query();
+                foreach ($data['keyword'] as $kw) {
+                    $escapedKw = addcslashes($kw, '%_'); // 转义通配符
+                    $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
+                }
+            } else {
+                $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
+                $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
+            }
+        }
+        // $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
+        if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
+            $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
+        }else{
+            $template_page = [];
+        }
+        if(!empty($template_id['template_id'])){
+            $result['template_id'] = $templste_info['template_id'];
+        }
+        // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
+        $template_page_str = json_encode($template_page);
+        if (isset($query)) {
+            $result['template'] = $query->where($where)
+                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        } else {
+            $result['template'] = Template::where($where)
+                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        }
+        if (!empty($result['template']['data'])) {
+            return Result::success($result);
+        } else {
+            $result['template'] = Template::orderBy('updated_at','desc')
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+            return Result::success($result);
+        }
+    }
+    /**
+     * 自助建站---流程---4.选择皮肤
+     * @param array $data
+     * @return array
+     */
+    public function chooseWebsiteTemplate(array $data): array
+    {
+        $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
+        if(empty($website_template_info)){
+            return Result::error('请先填写网站基础信息!');
+        }
+        // 0:未构建 1:未应用 2:已应用   status
+        if($website_template_info['status'] == 2){
+            return Result::error('网站已应用,不可再次修改!');
+        }
+        $template = Template::where('id', $data['template_id'])->first();
+        if(empty($template)){
+            return Result::error('未查询到皮肤!');
+        }
+        // 0:未构建;1:已填写基础信息;2:已选择模板;    action_id
+        $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
+        if ($web_template) {
+            return Result::success($web_template);
+        } else {
+            return Result::error('选择皮肤失败!');
         }
     }
 }

+ 6 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -172,4 +172,10 @@ interface PublicRpcServiceInterface
     public function addBlackWord(array $data): array;
     public function delBlackWord(array $data): array;
     public function upBlackWord(array $data): array;
+    // --------------自助建站-----------
+    public function getWebPageType(array $data): array;
+    public function addWebPageType(array $data): array;
+
+    public function chooseWebsiteTemplate(array $data): array;
+    
 }

+ 3 - 3
app/JsonRpc/WebsiteService.php

@@ -1692,6 +1692,7 @@ class WebsiteService implements WebsiteServiceInterface
             // 删除重复元素并重新索引数组
             $data['page_type'] = array_unique($data['page_type']);
             $data['page_type'] = array_values($data['page_type']);
+            // 1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
             if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
                 // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
                 $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
@@ -1700,7 +1701,6 @@ class WebsiteService implements WebsiteServiceInterface
                     $data['page_type'] = json_encode($data['page_type']) ?? '';
                     // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
                     $data['action_id'] = 1;
-
                     try {
                         $result = WebsiteTemplateInfo::insertGetId($data);
                     } catch (\Exception $e) {
@@ -1728,8 +1728,8 @@ class WebsiteService implements WebsiteServiceInterface
     }
     /**
      * 获取网站基础信息
-     *
      * @return array
+     * 
      */
     public function getWebsiteTemplateintel(array $data): array
     {
@@ -1954,7 +1954,7 @@ class WebsiteService implements WebsiteServiceInterface
         // 获取指定网站下的基础信息和模板及风格信息
         $result = WebsiteTemplateInfo::where([
             ['website_template_info.website_id', $data['website_id']],
-            ['template_id', '!=', null],
+            ['website_template_info.template_id', '!=', null],
         ])
             ->leftJoin('template', 'template.id', 'website_template_info.template_id')
             ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')