作者 lyh

Merge branch 'master-server' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

@@ -30,15 +30,7 @@ if (!function_exists('generateRoute')) { @@ -30,15 +30,7 @@ if (!function_exists('generateRoute')) {
30 if(is_array($string)){ 30 if(is_array($string)){
31 $string = $string[0]; 31 $string = $string[0];
32 } 32 }
33 - $last5Chars = substr($string, -5);  
34 - if($last5Chars == '.html'){  
35 - return strtolower($string);  
36 - }  
37 $sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-')); 33 $sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-'));
38 - $length = strlen($sign);  
39 - if($length > 180){  
40 - $sign = trim(mb_substr($sign, 0, 180, 'UTF-8'),'-');  
41 - }  
42 return $sign; 34 return $sign;
43 } 35 }
44 } 36 }
@@ -38,27 +38,6 @@ class ProductRequest extends FormRequest @@ -38,27 +38,6 @@ class ProductRequest extends FormRequest
38 return [ 38 return [
39 'title' => 'required|max:200', 39 'title' => 'required|max:200',
40 'route' => 'required|max:200', 40 'route' => 'required|max:200',
41 -// 'gallery' => ['required', 'array'],  
42 -// 'icon' => 'required|array',  
43 -// 'attrs' => ['array', function ($attribute, $value, $fail) {  
44 -// foreach ($value as $v) {  
45 -// if (empty($v['key'])) {  
46 -// $fail('产品属性名不能为空');  
47 -// }  
48 -// if (empty($v['value'])) {  
49 -// $fail('产品属性值不能为空');  
50 -// }  
51 -// }  
52 -// }],  
53 -// 'category_id' => 'required',  
54 -// 'intro' => 'required|max:500',  
55 -// 'content' => 'required',  
56 -// 'related_product_id' => [function ($attribute, $value, $fail) {  
57 -// $value = array_filter(Arr::splitFilterToArray($value), 'intval');  
58 -// if(count($value) > 16){  
59 -// $fail('关联产品不能超过16个');  
60 -// }  
61 -// }],  
62 'status' => ['required', Rule::in(array_keys(Product::statusMap()))], 41 'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
63 ]; 42 ];
64 } 43 }
@@ -70,16 +49,6 @@ class ProductRequest extends FormRequest @@ -70,16 +49,6 @@ class ProductRequest extends FormRequest
70 'title.max' => '产品标题不能超过200个字符', 49 'title.max' => '产品标题不能超过200个字符',
71 'route.required' => '请输入产品链接', 50 'route.required' => '请输入产品链接',
72 'route.max' => '产品链接不能超过200个字符', 51 'route.max' => '产品链接不能超过200个字符',
73 -// 'gallery.required' => '请上传产品图片',  
74 -// 'gallery.array' => '产品图片格式异常',  
75 -// 'attrs.required' => '请添加产品参数',  
76 -// 'attrs.array' => '产品参数格式异常',  
77 -// 'icon.required' => '图标不能为空',  
78 -// 'category_id.required' => '请选择分类',  
79 -// 'intro.required' => '请输入短描述',  
80 -// 'intro.max' => '短描述不能超过500个字符',  
81 -// 'content.required' => '请输入产品描述',  
82 -// 'related_product_id.required' => '请选择相关产品',  
83 'status.required' => '请选择产品状态', 52 'status.required' => '请选择产品状态',
84 'status.in' => '产品状态值异常', 53 'status.in' => '产品状态值异常',
85 ]; 54 ];
@@ -26,7 +26,7 @@ class RouteMap extends Base @@ -26,7 +26,7 @@ class RouteMap extends Base
26 const SOURCE_PRODUCT_CATE = 'product_category'; 26 const SOURCE_PRODUCT_CATE = 'product_category';
27 const SOURCE_PRODUCT_KEYWORD = 'product_keyword'; 27 const SOURCE_PRODUCT_KEYWORD = 'product_keyword';
28 const SOURCE_PAGE = 'page'; //单页面 28 const SOURCE_PAGE = 'page'; //单页面
29 - const SOURCE_INDEX = 'index'; //单页面 29 + const SOURCE_INDEX = 'index'; //首页
30 const SOURCE_BLOG = 'blog'; 30 const SOURCE_BLOG = 'blog';
31 const SOURCE_BLOG_CATE = 'blog_category'; 31 const SOURCE_BLOG_CATE = 'blog_category';
32 const SOURCE_NEWS = 'news'; 32 const SOURCE_NEWS = 'news';
@@ -46,32 +46,43 @@ class RouteMap extends Base @@ -46,32 +46,43 @@ class RouteMap extends Base
46 const PATH_MODULE_CATE = 'module_category_route';//扩展模块 46 const PATH_MODULE_CATE = 'module_category_route';//扩展模块
47 47
48 const SOURCE_NAV = 'nav'; 48 const SOURCE_NAV = 'nav';
  49 +
49 /** 50 /**
50 - * 生成路由标识  
51 - * @param $title  
52 - * @param $source  
53 - * @param $source_id  
54 - * @param $project_id  
55 - * @return string  
56 - * @author zbj  
57 - * @date 2023/4/17 51 + * @remark :(新增与编辑)处理路由route
  52 + * @name :generateRoute
  53 + * @author :lyh
  54 + * @method :post
  55 + * @time :2025/3/12 9:30
  56 + * @param :title:路由 source:模块类型 source_id:对应数据id
  57 + * @notes :route_len:路由长度; suffix:路由后缀
58 */ 58 */
59 public static function generateRoute($title, $source, $source_id, $project_id){ 59 public static function generateRoute($title, $source, $source_id, $project_id){
60 - if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){  
61 - $title = Translate::tran($title, 'en'); 60 + //发现路由是.html结尾时,不做任何处理
  61 + $last5Chars = substr($title, -5);
  62 + if($last5Chars == '.html'){
  63 + return $title;
62 } 64 }
63 - if(contains_russian($title)){ 65 + //处理其他情况(俄语+中文时翻译为英文)
  66 + if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title) || contains_russian($title)){
64 $title = Translate::tran($title, 'en'); 67 $title = Translate::tran($title, 'en');
65 } 68 }
66 - $i=1; 69 + //过滤特殊字符
67 $sign = generateRoute($title); 70 $sign = generateRoute($title);
68 - $info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();  
69 - $suffix = '';  
70 - if(empty($info)){ 71 + //查看当前数据路由是否存在
  72 + $routeInfo = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
  73 + $suffix = '';//设置路由后缀
  74 + $route_len = 180;//默认设置字符为180
  75 + if(empty($routeInfo)){
71 if($source == self::SOURCE_PRODUCT){ 76 if($source == self::SOURCE_PRODUCT){
72 $suffix = '-product'; 77 $suffix = '-product';
73 } 78 }
  79 + $route_len = 65;
  80 + }
  81 + $length = strlen($sign);
  82 + if($length > $route_len){
  83 + $sign = trim(mb_substr($sign, 0, $route_len, 'UTF-8'),'-');
74 } 84 }
  85 + $i=1;//路由重复时拼接
75 $route = $sign.$suffix; 86 $route = $sign.$suffix;
76 while(self::isExist($route, $source_id, $project_id)){ 87 while(self::isExist($route, $source_id, $project_id)){
77 $route = $sign .'-'.$i.$suffix; 88 $route = $sign .'-'.$i.$suffix;
@@ -81,14 +92,12 @@ class RouteMap extends Base @@ -81,14 +92,12 @@ class RouteMap extends Base
81 } 92 }
82 93
83 /** 94 /**
84 - * 路由是否存在  
85 - * @param $route  
86 - * @param $source  
87 - * @param $source_id  
88 - * @param $project_id  
89 - * @return bool  
90 - * @author zbj  
91 - * @date 2023/4/17 95 + * @remark :验证路由是否重复
  96 + * @name :isExist
  97 + * @author :lyh
  98 + * @method :post
  99 + * @time :2025/3/12 9:51
  100 + * @param :route:路由 source:模块类型 source_id:对应数据id
92 */ 101 */
93 protected static function isExist($route, $source_id, $project_id){ 102 protected static function isExist($route, $source_id, $project_id){
94 $fixed = ['api']; //固定的路由 103 $fixed = ['api']; //固定的路由
@@ -100,23 +109,20 @@ class RouteMap extends Base @@ -100,23 +109,20 @@ class RouteMap extends Base
100 ]; 109 ];
101 $route = self::where($where)->first(); 110 $route = self::where($where)->first();
102 if($route){ 111 if($route){
103 - if($route->source_id == $source_id){  
104 - return false;  
105 - } 112 + if($route->source_id != $source_id){
106 return true; 113 return true;
107 } 114 }
  115 + }
108 return false; 116 return false;
109 } 117 }
110 118
111 /** 119 /**
112 - * @param $title  
113 - * @param $source  
114 - * @param $source_id  
115 - * @param int $project_id  
116 - * @return bool  
117 - * @throws \Exception  
118 - * @author zbj  
119 - * @date 2023/4/17 120 + * @remark :保存路由
  121 + * @name :setRoute
  122 + * @author :lyh
  123 + * @method :post
  124 + * @time :2025/3/12 9:54
  125 + * @param :title:路由 source:模块类型 source_id:对应数据id
120 */ 126 */
121 public static function setRoute($title, $source, $source_id, $project_id = 0){ 127 public static function setRoute($title, $source, $source_id, $project_id = 0){
122 $route = self::generateRoute($title, $source, $source_id, $project_id); 128 $route = self::generateRoute($title, $source, $source_id, $project_id);
@@ -124,13 +130,14 @@ class RouteMap extends Base @@ -124,13 +130,14 @@ class RouteMap extends Base
124 throw new \Exception('路由生成失败'); 130 throw new \Exception('路由生成失败');
125 } 131 }
126 try { 132 try {
127 - $route_map = self::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first(); 133 + $route_map = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
128 if(!$route_map){ 134 if(!$route_map){
129 $route_map = new self(); 135 $route_map = new self();
130 $route_map->source = $source; 136 $route_map->source = $source;
131 $route_map->source_id = $source_id; 137 $route_map->source_id = $source_id;
132 $route_map->project_id = $project_id; 138 $route_map->project_id = $project_id;
133 } 139 }
  140 + $route_map->route = $route;
134 if($source == self::SOURCE_NEWS){ 141 if($source == self::SOURCE_NEWS){
135 $route_map->path = self::SOURCE_NEWS; 142 $route_map->path = self::SOURCE_NEWS;
136 }elseif ($source == self::SOURCE_BLOG){ 143 }elseif ($source == self::SOURCE_BLOG){
@@ -138,7 +145,6 @@ class RouteMap extends Base @@ -138,7 +145,6 @@ class RouteMap extends Base
138 }elseif($source == self::SOURCE_MODULE){ 145 }elseif($source == self::SOURCE_MODULE){
139 $route_map->path = self::PATH_MODULE_CATE; 146 $route_map->path = self::PATH_MODULE_CATE;
140 } 147 }
141 - $route_map->route = $route;  
142 $route_map->save(); 148 $route_map->save();
143 }catch (\Exception $e){ 149 }catch (\Exception $e){
144 throw new \Exception('路由映射失败'); 150 throw new \Exception('路由映射失败');
@@ -147,17 +153,6 @@ class RouteMap extends Base @@ -147,17 +153,6 @@ class RouteMap extends Base
147 } 153 }
148 154
149 /** 155 /**
150 - * @param $route  
151 - * @param $project_id  
152 - * @return mixed  
153 - * @author zbj  
154 - * @date 2023/4/17  
155 - */  
156 - public function getRouteInfo($route, $project_id){  
157 - return self::where('project_id',$project_id)->where('route', $route)->get();  
158 - }  
159 -  
160 - /**  
161 * @param $source 156 * @param $source
162 * @param $source_id 157 * @param $source_id
163 * @param $project_id 158 * @param $project_id
@@ -170,19 +165,6 @@ class RouteMap extends Base @@ -170,19 +165,6 @@ class RouteMap extends Base
170 } 165 }
171 166
172 /** 167 /**
173 - * @param $route  
174 - * @param $source  
175 - * @param int $project_id  
176 - * @return mixed  
177 - * @author zbj  
178 - * @date 2023/4/17  
179 - */  
180 - public static function getSourceId($route, $source, $project_id){  
181 - return self::where('project_id', $project_id)->where('source', $source)->where('route', $route)->value('source_id');  
182 - }  
183 -  
184 -  
185 - /**  
186 * @param $source 168 * @param $source
187 * @param $source_id 169 * @param $source_id
188 * @param $project_id 170 * @param $project_id