正在显示
3 个修改的文件
包含
47 行增加
和
15 行删除
| @@ -14,8 +14,10 @@ use App\Models\Com\UpdateLog; | @@ -14,8 +14,10 @@ use App\Models\Com\UpdateLog; | ||
| 14 | use App\Models\RouteMap\RouteMap; | 14 | use App\Models\RouteMap\RouteMap; |
| 15 | use App\Models\User\UserLog; | 15 | use App\Models\User\UserLog; |
| 16 | use App\Models\WebSetting\Translate as TranslateModel; | 16 | use App\Models\WebSetting\Translate as TranslateModel; |
| 17 | +use App\Models\WebSetting\TranslateData; | ||
| 17 | use App\Models\WebSetting\WebLanguage; | 18 | use App\Models\WebSetting\WebLanguage; |
| 18 | use App\Helper\Translate; | 19 | use App\Helper\Translate; |
| 20 | +use Illuminate\Support\Facades\DB; | ||
| 19 | 21 | ||
| 20 | class TranslateLogic extends BaseLogic | 22 | class TranslateLogic extends BaseLogic |
| 21 | { | 23 | { |
| @@ -36,9 +38,9 @@ class TranslateLogic extends BaseLogic | @@ -36,9 +38,9 @@ class TranslateLogic extends BaseLogic | ||
| 36 | public function getTranslateList(){ | 38 | public function getTranslateList(){ |
| 37 | $data = []; | 39 | $data = []; |
| 38 | if($this->param['url'] == 'All' || $this->param['url'] == 'other_all_text'){ | 40 | if($this->param['url'] == 'All' || $this->param['url'] == 'other_all_text'){ |
| 39 | - $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | ||
| 40 | - if(!empty($info) && !empty($info['data'])){ | ||
| 41 | - $translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | 41 | + $info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray(); |
| 42 | + if(!empty($info) && !empty($info['translate_data'])){ | ||
| 43 | + $translateInfo = json_decode($info['translate_data']['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | ||
| 42 | foreach ($translateInfo as $k => $v){ | 44 | foreach ($translateInfo as $k => $v){ |
| 43 | $data[] = [$k=>$v]; | 45 | $data[] = [$k=>$v]; |
| 44 | } | 46 | } |
| @@ -50,12 +52,12 @@ class TranslateLogic extends BaseLogic | @@ -50,12 +52,12 @@ class TranslateLogic extends BaseLogic | ||
| 50 | // 需要校对语种 | 52 | // 需要校对语种 |
| 51 | $languageInfo = $this->getLanguage($this->param['language_id']); | 53 | $languageInfo = $this->getLanguage($this->param['language_id']); |
| 52 | // 原始校对内容 | 54 | // 原始校对内容 |
| 53 | - $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | 55 | + $info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray(); |
| 54 | //获取当前URl的所有文本内容 | 56 | //获取当前URl的所有文本内容 |
| 55 | $text_array = $this->getUrlRead($url); | 57 | $text_array = $this->getUrlRead($url); |
| 56 | // 原始校对程序 | 58 | // 原始校对程序 |
| 57 | $old_key = [];//key值组成数据 | 59 | $old_key = [];//key值组成数据 |
| 58 | - $data_read = json_decode($info ? $info['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | 60 | + $data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
| 59 | if(!empty($data_read)){ | 61 | if(!empty($data_read)){ |
| 60 | foreach ($data_read as $k => $v){ | 62 | foreach ($data_read as $k => $v){ |
| 61 | $k = urldecode($k); | 63 | $k = urldecode($k); |
| @@ -109,10 +111,10 @@ class TranslateLogic extends BaseLogic | @@ -109,10 +111,10 @@ class TranslateLogic extends BaseLogic | ||
| 109 | */ | 111 | */ |
| 110 | public function getTranslateImageList(){ | 112 | public function getTranslateImageList(){ |
| 111 | if($this->param['url'] == 'All'){ | 113 | if($this->param['url'] == 'All'){ |
| 112 | - $info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | 114 | + $info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray(); |
| 113 | $data = []; | 115 | $data = []; |
| 114 | - if(!empty($info) && !empty($info['data'])){ | ||
| 115 | - $translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | 116 | + if(!empty($info) && !empty($info['translate_data'])){ |
| 117 | + $translateInfo = json_decode($info['translate_data']['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | ||
| 116 | foreach ($translateInfo as $k => $v){ | 118 | foreach ($translateInfo as $k => $v){ |
| 117 | $data[] = [$k=>$v]; | 119 | $data[] = [$k=>$v]; |
| 118 | } | 120 | } |
| @@ -120,9 +122,9 @@ class TranslateLogic extends BaseLogic | @@ -120,9 +122,9 @@ class TranslateLogic extends BaseLogic | ||
| 120 | return $this->success($data); | 122 | return $this->success($data); |
| 121 | } | 123 | } |
| 122 | $url = $this->user['domain'].(($this->param['url'] != '/') ? $this->param['url'] : ''); | 124 | $url = $this->user['domain'].(($this->param['url'] != '/') ? $this->param['url'] : ''); |
| 123 | - $info = $this->model->read(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]); | 125 | + $info = $this->model->with('translate_data')->where(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray(); |
| 124 | $data = []; | 126 | $data = []; |
| 125 | - if($info === false){ | 127 | + if(empty($info)){ |
| 126 | $new_list = $this->getUrlImageRead($url); | 128 | $new_list = $this->getUrlImageRead($url); |
| 127 | foreach ($new_list as $v){ | 129 | foreach ($new_list as $v){ |
| 128 | $data[] = [ | 130 | $data[] = [ |
| @@ -133,7 +135,7 @@ class TranslateLogic extends BaseLogic | @@ -133,7 +135,7 @@ class TranslateLogic extends BaseLogic | ||
| 133 | } | 135 | } |
| 134 | $new_list = $this->getUrlImageRead($url); | 136 | $new_list = $this->getUrlImageRead($url); |
| 135 | $old_list = []; | 137 | $old_list = []; |
| 136 | - $data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | 138 | + $data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
| 137 | foreach ($data_read as $k=>$v){ | 139 | foreach ($data_read as $k=>$v){ |
| 138 | $old_list[] = $k; | 140 | $old_list[] = $k; |
| 139 | $data[] = [ | 141 | $data[] = [ |
| @@ -258,6 +260,7 @@ class TranslateLogic extends BaseLogic | @@ -258,6 +260,7 @@ class TranslateLogic extends BaseLogic | ||
| 258 | } | 260 | } |
| 259 | //解析路由 | 261 | //解析路由 |
| 260 | $sendData = $this->handleRoute($this->param['url']); | 262 | $sendData = $this->handleRoute($this->param['url']); |
| 263 | + DB::beginTransaction(); | ||
| 261 | try { | 264 | try { |
| 262 | $info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]); | 265 | $info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]); |
| 263 | if($info === false){ | 266 | if($info === false){ |
| @@ -273,18 +276,21 @@ class TranslateLogic extends BaseLogic | @@ -273,18 +276,21 @@ class TranslateLogic extends BaseLogic | ||
| 273 | 'is_list'=>$sourceInfo['is_list'], | 276 | 'is_list'=>$sourceInfo['is_list'], |
| 274 | 'is_custom'=>$sourceInfo['is_custom'] | 277 | 'is_custom'=>$sourceInfo['is_custom'] |
| 275 | ]; | 278 | ]; |
| 276 | - $param['data'] = json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | ||
| 277 | - $rs = $this->model->add($param); | 279 | + $id = $this->model->add($param); |
| 280 | + | ||
| 281 | + TranslateData::insert(['trans_id'=>$id,'data'=>json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]); | ||
| 278 | }else{ | 282 | }else{ |
| 279 | if(!empty($data)){ | 283 | if(!empty($data)){ |
| 280 | - $data = json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | ||
| 281 | - $rs = $this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'project_id'=>$this->user['project_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]); | 284 | + TranslateData::where(['trans_id'=>$info['id']])->update(['data'=>json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]); |
| 282 | } | 285 | } |
| 283 | } | 286 | } |
| 284 | //写日志 | 287 | //写日志 |
| 285 | $userLogModel = new UserLog(); | 288 | $userLogModel = new UserLog(); |
| 286 | $userLogModel->add(['model'=>'translate/save','remark'=>json_encode($this->param,true),'type'=>0,'operator_id'=>$this->user['id'],'project_id'=>$this->user['project_id']]); | 289 | $userLogModel->add(['model'=>'translate/save','remark'=>json_encode($this->param,true),'type'=>0,'operator_id'=>$this->user['id'],'project_id'=>$this->user['project_id']]); |
| 290 | + | ||
| 291 | + DB::commit(); | ||
| 287 | }catch (\Exception $e){ | 292 | }catch (\Exception $e){ |
| 293 | + DB::rollback(); | ||
| 288 | $this->fail('系统错误请联系管理员'); | 294 | $this->fail('系统错误请联系管理员'); |
| 289 | } | 295 | } |
| 290 | $this->sendMessage($sendData); | 296 | $this->sendMessage($sendData); |
| @@ -20,4 +20,15 @@ class Translate extends Base | @@ -20,4 +20,15 @@ class Translate extends Base | ||
| 20 | public static $textType = 1; | 20 | public static $textType = 1; |
| 21 | public static $imageType = 2; | 21 | public static $imageType = 2; |
| 22 | 22 | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 校对详情数据 | ||
| 26 | + * @return \Illuminate\Database\Eloquent\Relations\HasOne | ||
| 27 | + * @author Akun | ||
| 28 | + * @date 2024/06/14 14:54 | ||
| 29 | + */ | ||
| 30 | + public function translate_data() | ||
| 31 | + { | ||
| 32 | + return self::hasOne(TranslateData::class, 'trans_id', 'id'); | ||
| 33 | + } | ||
| 23 | } | 34 | } |
app/Models/WebSetting/TranslateData.php
0 → 100644
-
请 注册 或 登录 后发表评论