作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -53,7 +53,7 @@ class UpdateRoute extends Command @@ -53,7 +53,7 @@ class UpdateRoute extends Command
53 */ 53 */
54 public function handle(){ 54 public function handle(){
55 $projectModel = new Project(); 55 $projectModel = new Project();
56 - $list = $projectModel->list(['id'=>688]); 56 + $list = $projectModel->list(['id'=>783]);
57 $data = []; 57 $data = [];
58 foreach ($list as $v){ 58 foreach ($list as $v){
59 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 59 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
@@ -119,14 +119,80 @@ class UpdateRoute extends Command @@ -119,14 +119,80 @@ class UpdateRoute extends Command
119 // $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); 119 // $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
120 // } 120 // }
121 }else{ 121 }else{
  122 + echo date('Y-m-d H:i:s') . 'route :'.$v['id'] . PHP_EOL;
122 $route = Translate::tran($v['title'], 'en'); 123 $route = Translate::tran($v['title'], 'en');
123 - echo date('Y-m-d H:i:s') . 'route :'.$route . PHP_EOL;  
124 - $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);  
125 - $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); 124 + if(!empty($route)){
  125 + echo date('Y-m-d H:i:s') . $route . PHP_EOL;
  126 + $route = $this->setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);
  127 + $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
  128 + }
126 } 129 }
127 -// echo date('Y-m-d H:i:s') . 'end :' . PHP_EOL; 130 + echo date('Y-m-d H:i:s') . 'end :' . PHP_EOL;
  131 + }
  132 + }
  133 + }
  134 +
  135 + /**
  136 + * @param $title
  137 + * @param $source
  138 + * @param $source_id
  139 + * @param int $project_id
  140 + * @return bool
  141 + * @throws \Exception
  142 + * @author zbj
  143 + * @date 2023/4/17
  144 + */
  145 + public static function setRoute($title, $source, $source_id, $project_id = 0){
  146 + $route = self::generateRoute($title, $source, $source_id, $project_id);
  147 + if(!$route){
  148 + throw new \Exception('路由生成失败');
  149 + }
  150 + try {
  151 + $route_map = RouteMap::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
  152 + if(!$route_map){
  153 + $route_map = new RouteMap();
  154 + $route_map->source = $source;
  155 + $route_map->source_id = $source_id;
  156 + $route_map->project_id = $project_id;
128 } 157 }
  158 + $route_map->route = $route;
  159 + $route_map->save();
  160 + }catch (\Exception $e){
  161 + throw new \Exception('路由映射失败');
  162 + }
  163 + return $route;
  164 + }
  165 +
  166 + /**
  167 + * 生成路由标识
  168 + * @param $title
  169 + * @param $source
  170 + * @param $source_id
  171 + * @param $project_id
  172 + * @return string
  173 + * @author zbj
  174 + * @date 2023/4/17
  175 + */
  176 + public static function generateRoute($title, $source, $source_id, $project_id){
  177 + $i=1;
  178 + $sign = generateRoute($title);
  179 + $length = strlen($sign);
  180 + if($length > 100){
  181 + $sign = trim(mb_substr($sign, 0, 100, 'UTF-8'),'-');
  182 + }
  183 + $info = RouteMap::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
  184 + $suffix = '';
  185 + if(empty($info)){
  186 + if($source == 'product'){
  187 + $suffix = '-product';
  188 + }
  189 + }
  190 + $route = $sign.$suffix;
  191 + while(RouteMap::isExist($route, $source_id, $project_id)){
  192 + $route = $sign .'-'.$i.$suffix;
  193 + $i++;
129 } 194 }
  195 + return $route;
130 } 196 }
131 197
132 /** 198 /**
@@ -60,7 +60,7 @@ class UserLogic extends BaseLogic @@ -60,7 +60,7 @@ class UserLogic extends BaseLogic
60 } 60 }
61 $this->param = $this->editPassword($this->param); 61 $this->param = $this->editPassword($this->param);
62 $rs = $this->model->edit($this->param, ['id' => $this->param['id']]); 62 $rs = $this->model->edit($this->param, ['id' => $this->param['id']]);
63 - DB::table('gl_user_edit_log')->insert(['message'=>json_encode($this->param),'user_id'=>$this->manager['id'],'project_id'=>$this->user['project_id'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]); 63 + DB::table('gl_user_edit_log')->insert(['message'=>json_encode($this->param),'user_id'=>$this->manager['id'],'project_id'=>$info['project_id'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]);
64 } else { 64 } else {
65 $this->param['password'] = base64_encode(md5($this->param['password'])); 65 $this->param['password'] = base64_encode(md5($this->param['password']));
66 $rs = $this->model->add($this->param); 66 $rs = $this->model->add($this->param);
@@ -58,6 +58,7 @@ class RouteMap extends Base @@ -58,6 +58,7 @@ class RouteMap extends Base
58 }elseif(preg_match('/^[\x{0400}-\x{04FF}]+$/u', $title)){ 58 }elseif(preg_match('/^[\x{0400}-\x{04FF}]+$/u', $title)){
59 $title = Translate::tran($title, 'en'); 59 $title = Translate::tran($title, 'en');
60 } 60 }
  61 +
61 $i=1; 62 $i=1;
62 $sign = generateRoute($title); 63 $sign = generateRoute($title);
63 $length = strlen($sign); 64 $length = strlen($sign);