作者 刘锟

翻译校对拆表

... ... @@ -14,8 +14,10 @@ use App\Models\Com\UpdateLog;
use App\Models\RouteMap\RouteMap;
use App\Models\User\UserLog;
use App\Models\WebSetting\Translate as TranslateModel;
use App\Models\WebSetting\TranslateData;
use App\Models\WebSetting\WebLanguage;
use App\Helper\Translate;
use Illuminate\Support\Facades\DB;
class TranslateLogic extends BaseLogic
{
... ... @@ -36,9 +38,9 @@ class TranslateLogic extends BaseLogic
public function getTranslateList(){
$data = [];
if($this->param['url'] == 'All' || $this->param['url'] == 'other_all_text'){
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray();
if(!empty($info) && !empty($info['translate_data'])){
$translateInfo = json_decode($info['translate_data']['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -50,12 +52,12 @@ class TranslateLogic extends BaseLogic
// 需要校对语种
$languageInfo = $this->getLanguage($this->param['language_id']);
// 原始校对内容
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
$info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray();
//获取当前URl的所有文本内容
$text_array = $this->getUrlRead($url);
// 原始校对程序
$old_key = [];//key值组成数据
$data_read = json_decode($info ? $info['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if(!empty($data_read)){
foreach ($data_read as $k => $v){
$k = urldecode($k);
... ... @@ -109,10 +111,10 @@ class TranslateLogic extends BaseLogic
*/
public function getTranslateImageList(){
if($this->param['url'] == 'All'){
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
$info = $this->model->with('translate_data')->where(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']])->first()->toArray();
$data = [];
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if(!empty($info) && !empty($info['translate_data'])){
$translateInfo = json_decode($info['translate_data']['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -120,9 +122,9 @@ class TranslateLogic extends BaseLogic
return $this->success($data);
}
$url = $this->user['domain'].(($this->param['url'] != '/') ? $this->param['url'] : '');
$info = $this->model->read(['url'=>str_replace_url($this->param['url']),'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
$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();
$data = [];
if($info === false){
if(empty($info)){
$new_list = $this->getUrlImageRead($url);
foreach ($new_list as $v){
$data[] = [
... ... @@ -133,7 +135,7 @@ class TranslateLogic extends BaseLogic
}
$new_list = $this->getUrlImageRead($url);
$old_list = [];
$data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
foreach ($data_read as $k=>$v){
$old_list[] = $k;
$data[] = [
... ... @@ -258,6 +260,7 @@ class TranslateLogic extends BaseLogic
}
//解析路由
$sendData = $this->handleRoute($this->param['url']);
DB::beginTransaction();
try {
$info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
if($info === false){
... ... @@ -273,18 +276,21 @@ class TranslateLogic extends BaseLogic
'is_list'=>$sourceInfo['is_list'],
'is_custom'=>$sourceInfo['is_custom']
];
$param['data'] = json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$rs = $this->model->add($param);
$id = $this->model->add($param);
TranslateData::insert(['trans_id'=>$id,'data'=>json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
}else{
if(!empty($data)){
$data = json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$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']]);
TranslateData::where(['trans_id'=>$info['id']])->update(['data'=>json_encode($data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
}
}
//写日志
$userLogModel = new UserLog();
$userLogModel->add(['model'=>'translate/save','remark'=>json_encode($this->param,true),'type'=>0,'operator_id'=>$this->user['id'],'project_id'=>$this->user['project_id']]);
DB::commit();
}catch (\Exception $e){
DB::rollback();
$this->fail('系统错误请联系管理员');
}
$this->sendMessage($sendData);
... ...
... ... @@ -20,4 +20,15 @@ class Translate extends Base
public static $textType = 1;
public static $imageType = 2;
/**
* 校对详情数据
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @author Akun
* @date 2024/06/14 14:54
*/
public function translate_data()
{
return self::hasOne(TranslateData::class, 'trans_id', 'id');
}
}
... ...
<?php
namespace App\Models\WebSetting;
use App\Models\Base;
class TranslateData extends Base
{
protected $table = 'gl_translate_data';
//连接数据库
protected $connection = 'custom_mysql';
public $timestamps = false;
}
... ...