作者 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')) {
if(is_array($string)){
$string = $string[0];
}
$last5Chars = substr($string, -5);
if($last5Chars == '.html'){
return strtolower($string);
}
$sign = str_replace(".", "", trim(strtolower(preg_replace('/[^\w.]+/', '-', trim($string))), '-'));
$length = strlen($sign);
if($length > 180){
$sign = trim(mb_substr($sign, 0, 180, 'UTF-8'),'-');
}
return $sign;
}
}
... ...
... ... @@ -38,27 +38,6 @@ class ProductRequest extends FormRequest
return [
'title' => 'required|max:200',
'route' => 'required|max:200',
// 'gallery' => ['required', 'array'],
// 'icon' => 'required|array',
// 'attrs' => ['array', function ($attribute, $value, $fail) {
// foreach ($value as $v) {
// if (empty($v['key'])) {
// $fail('产品属性名不能为空');
// }
// if (empty($v['value'])) {
// $fail('产品属性值不能为空');
// }
// }
// }],
// 'category_id' => 'required',
// 'intro' => 'required|max:500',
// 'content' => 'required',
// 'related_product_id' => [function ($attribute, $value, $fail) {
// $value = array_filter(Arr::splitFilterToArray($value), 'intval');
// if(count($value) > 16){
// $fail('关联产品不能超过16个');
// }
// }],
'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
];
}
... ... @@ -70,16 +49,6 @@ class ProductRequest extends FormRequest
'title.max' => '产品标题不能超过200个字符',
'route.required' => '请输入产品链接',
'route.max' => '产品链接不能超过200个字符',
// 'gallery.required' => '请上传产品图片',
// 'gallery.array' => '产品图片格式异常',
// 'attrs.required' => '请添加产品参数',
// 'attrs.array' => '产品参数格式异常',
// 'icon.required' => '图标不能为空',
// 'category_id.required' => '请选择分类',
// 'intro.required' => '请输入短描述',
// 'intro.max' => '短描述不能超过500个字符',
// 'content.required' => '请输入产品描述',
// 'related_product_id.required' => '请选择相关产品',
'status.required' => '请选择产品状态',
'status.in' => '产品状态值异常',
];
... ...
... ... @@ -26,7 +26,7 @@ class RouteMap extends Base
const SOURCE_PRODUCT_CATE = 'product_category';
const SOURCE_PRODUCT_KEYWORD = 'product_keyword';
const SOURCE_PAGE = 'page'; //单页面
const SOURCE_INDEX = 'index'; //单页面
const SOURCE_INDEX = 'index'; //首页
const SOURCE_BLOG = 'blog';
const SOURCE_BLOG_CATE = 'blog_category';
const SOURCE_NEWS = 'news';
... ... @@ -46,32 +46,43 @@ class RouteMap extends Base
const PATH_MODULE_CATE = 'module_category_route';//扩展模块
const SOURCE_NAV = 'nav';
/**
* 生成路由标识
* @param $title
* @param $source
* @param $source_id
* @param $project_id
* @return string
* @author zbj
* @date 2023/4/17
* @remark :(新增与编辑)处理路由route
* @name :generateRoute
* @author :lyh
* @method :post
* @time :2025/3/12 9:30
* @param :title:路由 source:模块类型 source_id:对应数据id
* @notes :route_len:路由长度; suffix:路由后缀
*/
public static function generateRoute($title, $source, $source_id, $project_id){
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){
$title = Translate::tran($title, 'en');
//发现路由是.html结尾时,不做任何处理
$last5Chars = substr($title, -5);
if($last5Chars == '.html'){
return $title;
}
if(contains_russian($title)){
//处理其他情况(俄语+中文时翻译为英文)
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title) || contains_russian($title)){
$title = Translate::tran($title, 'en');
}
$i=1;
//过滤特殊字符
$sign = generateRoute($title);
$info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
$suffix = '';
if(empty($info)){
//查看当前数据路由是否存在
$routeInfo = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
$suffix = '';//设置路由后缀
$route_len = 180;//默认设置字符为180
if(empty($routeInfo)){
if($source == self::SOURCE_PRODUCT){
$suffix = '-product';
}
$route_len = 65;
}
$length = strlen($sign);
if($length > $route_len){
$sign = trim(mb_substr($sign, 0, $route_len, 'UTF-8'),'-');
}
$i=1;//路由重复时拼接
$route = $sign.$suffix;
while(self::isExist($route, $source_id, $project_id)){
$route = $sign .'-'.$i.$suffix;
... ... @@ -81,14 +92,12 @@ class RouteMap extends Base
}
/**
* 路由是否存在
* @param $route
* @param $source
* @param $source_id
* @param $project_id
* @return bool
* @author zbj
* @date 2023/4/17
* @remark :验证路由是否重复
* @name :isExist
* @author :lyh
* @method :post
* @time :2025/3/12 9:51
* @param :route:路由 source:模块类型 source_id:对应数据id
*/
protected static function isExist($route, $source_id, $project_id){
$fixed = ['api']; //固定的路由
... ... @@ -100,23 +109,20 @@ class RouteMap extends Base
];
$route = self::where($where)->first();
if($route){
if($route->source_id == $source_id){
return false;
if($route->source_id != $source_id){
return true;
}
return true;
}
return false;
}
/**
* @param $title
* @param $source
* @param $source_id
* @param int $project_id
* @return bool
* @throws \Exception
* @author zbj
* @date 2023/4/17
* @remark :保存路由
* @name :setRoute
* @author :lyh
* @method :post
* @time :2025/3/12 9:54
* @param :title:路由 source:模块类型 source_id:对应数据id
*/
public static function setRoute($title, $source, $source_id, $project_id = 0){
$route = self::generateRoute($title, $source, $source_id, $project_id);
... ... @@ -124,13 +130,14 @@ class RouteMap extends Base
throw new \Exception('路由生成失败');
}
try {
$route_map = self::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
$route_map = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
if(!$route_map){
$route_map = new self();
$route_map->source = $source;
$route_map->source_id = $source_id;
$route_map->project_id = $project_id;
}
$route_map->route = $route;
if($source == self::SOURCE_NEWS){
$route_map->path = self::SOURCE_NEWS;
}elseif ($source == self::SOURCE_BLOG){
... ... @@ -138,7 +145,6 @@ class RouteMap extends Base
}elseif($source == self::SOURCE_MODULE){
$route_map->path = self::PATH_MODULE_CATE;
}
$route_map->route = $route;
$route_map->save();
}catch (\Exception $e){
throw new \Exception('路由映射失败');
... ... @@ -147,17 +153,6 @@ class RouteMap extends Base
}
/**
* @param $route
* @param $project_id
* @return mixed
* @author zbj
* @date 2023/4/17
*/
public function getRouteInfo($route, $project_id){
return self::where('project_id',$project_id)->where('route', $route)->get();
}
/**
* @param $source
* @param $source_id
* @param $project_id
... ... @@ -170,19 +165,6 @@ class RouteMap extends Base
}
/**
* @param $route
* @param $source
* @param int $project_id
* @return mixed
* @author zbj
* @date 2023/4/17
*/
public static function getSourceId($route, $source, $project_id){
return self::where('project_id', $project_id)->where('source', $source)->where('route', $route)->value('source_id');
}
/**
* @param $source
* @param $source_id
* @param $project_id
... ...