Merge remote-tracking branch 'origin/develop' into akun
正在显示
6 个修改的文件
包含
102 行增加
和
39 行删除
| @@ -5,6 +5,7 @@ namespace App\Console\Commands; | @@ -5,6 +5,7 @@ namespace App\Console\Commands; | ||
| 5 | 5 | ||
| 6 | use App\Models\Devops\DevopsTaskLog; | 6 | use App\Models\Devops\DevopsTaskLog; |
| 7 | use App\Models\Project\Project; | 7 | use App\Models\Project\Project; |
| 8 | +use App\Utils\EncryptUtils; | ||
| 8 | use Illuminate\Console\Command; | 9 | use Illuminate\Console\Command; |
| 9 | use App\Models\Devops\DevopsTask as DevopsTaskModel; | 10 | use App\Models\Devops\DevopsTask as DevopsTaskModel; |
| 10 | 11 | ||
| @@ -45,17 +46,14 @@ class DevopsTask extends Command | @@ -45,17 +46,14 @@ class DevopsTask extends Command | ||
| 45 | */ | 46 | */ |
| 46 | public function handle() | 47 | public function handle() |
| 47 | { | 48 | { |
| 48 | - while (true){ | ||
| 49 | $tasks = DevopsTaskModel::where('status', DevopsTaskModel::STATUS_PENDING)->get(); | 49 | $tasks = DevopsTaskModel::where('status', DevopsTaskModel::STATUS_PENDING)->get(); |
| 50 | foreach ($tasks as $task){ | 50 | foreach ($tasks as $task){ |
| 51 | - echo "Start task " . $task->id . PHP_EOL; | 51 | + echo "Start task " . $task->id; |
| 52 | if($task->type == DevopsTaskModel::TYPE_MYSQL){ | 52 | if($task->type == DevopsTaskModel::TYPE_MYSQL){ |
| 53 | $this->updateTable($task); | 53 | $this->updateTable($task); |
| 54 | } | 54 | } |
| 55 | echo "End task " . $task->id . PHP_EOL; | 55 | echo "End task " . $task->id . PHP_EOL; |
| 56 | } | 56 | } |
| 57 | - sleep(10); | ||
| 58 | - } | ||
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | public function updateTable($task){ | 59 | public function updateTable($task){ |
| @@ -64,6 +62,7 @@ class DevopsTask extends Command | @@ -64,6 +62,7 @@ class DevopsTask extends Command | ||
| 64 | echo "project " . $project->id; | 62 | echo "project " . $project->id; |
| 65 | $log = DevopsTaskLog::addLog($task->id, $project->id); | 63 | $log = DevopsTaskLog::addLog($task->id, $project->id); |
| 66 | if($log->status == DevopsTaskModel::STATUS_ACTIVE){ | 64 | if($log->status == DevopsTaskModel::STATUS_ACTIVE){ |
| 65 | + echo 'continue' . PHP_EOL; | ||
| 67 | continue; | 66 | continue; |
| 68 | } | 67 | } |
| 69 | if(!$project->mysqlConfig){ | 68 | if(!$project->mysqlConfig){ |
| @@ -73,13 +72,22 @@ class DevopsTask extends Command | @@ -73,13 +72,22 @@ class DevopsTask extends Command | ||
| 73 | continue; | 72 | continue; |
| 74 | } | 73 | } |
| 75 | //DB类是单例模式,生命周期内修改配置不会生效 | 74 | //DB类是单例模式,生命周期内修改配置不会生效 |
| 75 | + $encrypt = new EncryptUtils(); | ||
| 76 | + try { | ||
| 76 | $conn = new \mysqli( | 77 | $conn = new \mysqli( |
| 77 | $project->mysqlConfig->host, | 78 | $project->mysqlConfig->host, |
| 78 | - $project->mysqlConfig->user, | ||
| 79 | - $project->mysqlConfig->password, | 79 | + $encrypt->unlock_url($project->mysqlConfig->user), |
| 80 | + $encrypt->unlock_url($project->mysqlConfig->password), | ||
| 80 | $project->databaseName(), | 81 | $project->databaseName(), |
| 81 | - $project->mysqlConfig->port, | 82 | + $encrypt->unlock_url($project->mysqlConfig->port), |
| 82 | ); | 83 | ); |
| 84 | + }catch (\Exception $e){ | ||
| 85 | + $log->remark = mb_substr('数据库连接失败:' . $e->getMessage(), 0, 500); | ||
| 86 | + $log->status = DevopsTaskLog::STATUS_ERROR; | ||
| 87 | + $log->save(); | ||
| 88 | + echo '-->' . $log->remark . PHP_EOL; | ||
| 89 | + continue; | ||
| 90 | + } | ||
| 83 | $res = $conn->query($task->sql); | 91 | $res = $conn->query($task->sql); |
| 84 | 92 | ||
| 85 | $log->status = $res ? DevopsTaskLog::STATUS_ACTIVE : DevopsTaskLog::STATUS_ERROR; | 93 | $log->status = $res ? DevopsTaskLog::STATUS_ACTIVE : DevopsTaskLog::STATUS_ERROR; |
| @@ -125,6 +125,7 @@ class ProjectController extends BaseController | @@ -125,6 +125,7 @@ class ProjectController extends BaseController | ||
| 125 | 'gl_project.company AS company', | 125 | 'gl_project.company AS company', |
| 126 | 'gl_project.type AS type', | 126 | 'gl_project.type AS type', |
| 127 | 'gl_project.created_at AS created_at', | 127 | 'gl_project.created_at AS created_at', |
| 128 | + 'gl_project.cooperate_date AS cooperate_date', | ||
| 128 | 'gl_project_online_check.id AS online_check_id', | 129 | 'gl_project_online_check.id AS online_check_id', |
| 129 | 'gl_project_online_check.question AS question', | 130 | 'gl_project_online_check.question AS question', |
| 130 | 'gl_project_online_check.optimist_status AS optimist_status', | 131 | 'gl_project_online_check.optimist_status AS optimist_status', |
| @@ -32,53 +32,97 @@ class CNoticeController extends BaseController | @@ -32,53 +32,97 @@ class CNoticeController extends BaseController | ||
| 32 | * @param WebSettingLogic $webSettingLogic | 32 | * @param WebSettingLogic $webSettingLogic |
| 33 | */ | 33 | */ |
| 34 | public function sendNotify(){ | 34 | public function sendNotify(){ |
| 35 | - $type = $this->request->input('type', UpdateNotify::TYPE_MASTER); | ||
| 36 | - if (FALSE == in_array($type, [UpdateNotify::TYPE_MASTER, UpdateNotify::TYPE_MINOR])){ | ||
| 37 | - $this->response('非法参数!', Code::USER_ERROR); | 35 | + $updateProgressModel = new UpdateProgress(); |
| 36 | + $progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']])->orderBy('id','desc')->first(); | ||
| 37 | + if((!empty($progressInfo))){ | ||
| 38 | + $progressInfo = $progressInfo->toArray(); | ||
| 39 | + if(($progressInfo['total_num'] > $progressInfo['current_num'])){ | ||
| 40 | + $this->response('当前页面正在生成了,请完成后再点击',Code::USER_ERROR,$progressInfo); | ||
| 38 | } | 41 | } |
| 39 | - $page = $this->request->input('page', UpdateNotify::PAGE_ALL); | ||
| 40 | - if (FALSE == in_array($type, [UpdateNotify::PAGE_ALL, UpdateNotify::PAGE_SINGLE])){ | ||
| 41 | - $this->response('非法参数!', Code::USER_ERROR); | ||
| 42 | } | 42 | } |
| 43 | - $data = $this->sendNotifyMessage($type,$page); | ||
| 44 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND); | ||
| 45 | - if(!empty($data)){ | ||
| 46 | - $this->response('当前页面正在生成了,请完成后再点击',Code::USER_ERROR,$data); | 43 | + //通知更新 |
| 44 | + if($this->param['type'] == UpdateNotify::TYPE_MASTER){ | ||
| 45 | + $this->updateMaster(); | ||
| 46 | + }else{ | ||
| 47 | + $this->updateMinorLanguages(); | ||
| 47 | } | 48 | } |
| 49 | + $urlStr = $this->getString($this->param['type'],$this->param['page']); | ||
| 50 | + $this->curlGet($urlStr); | ||
| 48 | $this->response('success'); | 51 | $this->response('success'); |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | /** | 54 | /** |
| 52 | - * 通知c端 | ||
| 53 | - * @param string $type | ||
| 54 | - * @return array | 55 | + * @remark :主键通知 |
| 56 | + * @name :updateMaster | ||
| 57 | + * @author :lyh | ||
| 58 | + * @method :post | ||
| 59 | + * @time :2023/9/12 14:46 | ||
| 55 | */ | 60 | */ |
| 56 | - public function sendNotifyMessage($type,$page){ | ||
| 57 | - $updateProgressModel = new UpdateProgress(); | ||
| 58 | - $progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$type])->orderBy('id','desc')->first(); | ||
| 59 | - if((!empty($progressInfo))){ | ||
| 60 | - $progressInfo = $progressInfo->toArray(); | ||
| 61 | - if(($progressInfo['total_num'] > $progressInfo['current_num'])){ | ||
| 62 | - return $progressInfo; | 61 | + public function updateMaster(){ |
| 62 | + try { | ||
| 63 | + $updateNotifyModel = new UpdateNotify(); | ||
| 64 | + if($this->param['page'] == UpdateNotify::PAGE_ALL){ | ||
| 65 | + //如果是更新所有 | ||
| 66 | + $routeMapModel = new RouteMap(); | ||
| 67 | + $count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count(); | ||
| 68 | + $updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]); | ||
| 69 | + $this->addProgress($count,$this->param['type']); | ||
| 70 | + }elseif($this->param['page'] == UpdateNotify::PAGE_SINGLE){ | ||
| 71 | + //更新所有已修改的更新 | ||
| 72 | + $count = $updateNotifyModel->formatQuery(['project_id' => $this->user['project_id'], 'status' => 0])->count(); | ||
| 73 | + $updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]); | ||
| 74 | + $this->addProgress($count,$this->param['type']); | ||
| 75 | + }else{ | ||
| 76 | + //根据传递的参数更新 | ||
| 77 | + $count = count($this->param['url']); | ||
| 78 | + $extent = json_encode(['url'=>$this->param['url']]); | ||
| 79 | + $this->addProgress($count,$this->param['type'],$extent); | ||
| 80 | + } | ||
| 81 | + }catch (\Exception $e){ | ||
| 82 | + $this->response('error',Code::USER_ERROR); | ||
| 63 | } | 83 | } |
| 84 | + return true; | ||
| 64 | } | 85 | } |
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @remark :更新小语种 | ||
| 89 | + * @name :updateMinorLanguages | ||
| 90 | + * @author :lyh | ||
| 91 | + * @method :post | ||
| 92 | + * @time :2023/9/12 14:48 | ||
| 93 | + */ | ||
| 94 | + public function updateMinorLanguages(){ | ||
| 65 | $updateNotifyModel = new UpdateNotify(); | 95 | $updateNotifyModel = new UpdateNotify(); |
| 66 | - $field = ($type == UpdateNotify::TYPE_MINOR) ? 'minor_languages_status' : 'status'; | ||
| 67 | - if($page == UpdateNotify::PAGE_ALL){ | 96 | + try { |
| 97 | + if($this->param['page'] == UpdateNotify::PAGE_ALL){ | ||
| 98 | + $this->request->validate([ | ||
| 99 | + 'language' => 'required', | ||
| 100 | + ], [ | ||
| 101 | + 'language.required' => '请选择语种', | ||
| 102 | + ]); | ||
| 68 | //如果是更新所有 | 103 | //如果是更新所有 |
| 69 | $routeMapModel = new RouteMap(); | 104 | $routeMapModel = new RouteMap(); |
| 70 | $count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count(); | 105 | $count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count(); |
| 106 | + $updateNotifyModel->edit(['minor_languages_status' => 1], ['project_id' => $this->user['project_id'], 'minor_languages_status' => 0]); | ||
| 107 | + $extent = json_encode(['language'=>$this->param['language']]); | ||
| 108 | + $this->addProgress($count,$this->param['type'],$extent); | ||
| 71 | }else{ | 109 | }else{ |
| 72 | - $count = $updateNotifyModel->formatQuery(['project_id' => $this->user['project_id'], $field => 0])->count(); | 110 | + $this->request->validate([ |
| 111 | + 'url'=>'required', | ||
| 112 | + 'language' => 'required', | ||
| 113 | + ], [ | ||
| 114 | + 'url.required' => '请输入更新链接', | ||
| 115 | + 'language.required' => '请选择语种', | ||
| 116 | + ]); | ||
| 117 | + //根据传递的参数更新 | ||
| 118 | + $count = count($this->param['url']); | ||
| 119 | + $extent = json_encode(['url'=>$this->param['url'],'language'=>$this->param['language']]); | ||
| 120 | + $this->addProgress($count,$this->param['type'],$extent); | ||
| 73 | } | 121 | } |
| 74 | - if($count == 0){ | ||
| 75 | - return []; | 122 | + }catch (\Exception $e){ |
| 123 | + $this->response('error',Code::USER_ERROR); | ||
| 76 | } | 124 | } |
| 77 | - $this->addProgress($count,$type); | ||
| 78 | - $updateNotifyModel->edit([$field => 1], ['project_id' => $this->user['project_id'], $field => 0]); | ||
| 79 | - $urlStr = $this->getString($type,$page); | ||
| 80 | - $this->curlGet($urlStr); | ||
| 81 | - return []; | 125 | + return true; |
| 82 | } | 126 | } |
| 83 | 127 | ||
| 84 | /** | 128 | /** |
| @@ -111,11 +155,12 @@ class CNoticeController extends BaseController | @@ -111,11 +155,12 @@ class CNoticeController extends BaseController | ||
| 111 | * @method :post | 155 | * @method :post |
| 112 | * @time :2023/9/6 17:01 | 156 | * @time :2023/9/6 17:01 |
| 113 | */ | 157 | */ |
| 114 | - public function addProgress($count,$type){ | 158 | + public function addProgress($count,$type,$extend = ''){ |
| 115 | $data = [ | 159 | $data = [ |
| 116 | 'total_num'=>$count, | 160 | 'total_num'=>$count, |
| 117 | 'current_num'=>0, | 161 | 'current_num'=>0, |
| 118 | 'type'=>$type, | 162 | 'type'=>$type, |
| 163 | + 'extend'=>$extend, | ||
| 119 | 'project_id'=>$this->user['project_id'], | 164 | 'project_id'=>$this->user['project_id'], |
| 120 | 'created_at'=>date('Y-m-d H;i:s') | 165 | 'created_at'=>date('Y-m-d H;i:s') |
| 121 | ]; | 166 | ]; |
| @@ -11,7 +11,9 @@ use App\Models\Project\Project; | @@ -11,7 +11,9 @@ use App\Models\Project\Project; | ||
| 11 | use App\Models\Devops\ServerConfig; | 11 | use App\Models\Devops\ServerConfig; |
| 12 | use App\Services\ProjectServer; | 12 | use App\Services\ProjectServer; |
| 13 | use App\Utils\EncryptUtils; | 13 | use App\Utils\EncryptUtils; |
| 14 | +use Illuminate\Support\Facades\Artisan; | ||
| 14 | use Illuminate\Support\Facades\DB; | 15 | use Illuminate\Support\Facades\DB; |
| 16 | +use Symfony\Component\Process\Process; | ||
| 15 | 17 | ||
| 16 | /** | 18 | /** |
| 17 | * Class ServerConfigLogic | 19 | * Class ServerConfigLogic |
| @@ -174,6 +176,9 @@ class ServerConfigLogic extends BaseLogic | @@ -174,6 +176,9 @@ class ServerConfigLogic extends BaseLogic | ||
| 174 | */ | 176 | */ |
| 175 | public function updateAllTable($param){ | 177 | public function updateAllTable($param){ |
| 176 | DevopsTask::addTask($param['sql']); | 178 | DevopsTask::addTask($param['sql']); |
| 179 | + //执行命令行 | ||
| 180 | + $process = new Process(['php', 'artisan', 'devops_task']); | ||
| 181 | + $process->start(); | ||
| 177 | return $this->success(); | 182 | return $this->success(); |
| 178 | } | 183 | } |
| 179 | } | 184 | } |
| @@ -127,7 +127,7 @@ class ProductLogic extends BaseLogic | @@ -127,7 +127,7 @@ class ProductLogic extends BaseLogic | ||
| 127 | DB::beginTransaction(); | 127 | DB::beginTransaction(); |
| 128 | try { | 128 | try { |
| 129 | foreach ($this->param['ids'] as $k => $id) { | 129 | foreach ($this->param['ids'] as $k => $id) { |
| 130 | - $info = $this->model->read(['id'=>$id]); | 130 | + $info = $this->model->read(['id'=>$id],['id','status']); |
| 131 | if($info['status'] == Product::STATUS_RECYCLE){ | 131 | if($info['status'] == Product::STATUS_RECYCLE){ |
| 132 | $this->delRoute($id); | 132 | $this->delRoute($id); |
| 133 | //删除当前产品模版 | 133 | //删除当前产品模版 |
| @@ -51,10 +51,12 @@ class Product extends Base | @@ -51,10 +51,12 @@ class Product extends Base | ||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | public function setGalleryAttribute($value){ | 53 | public function setGalleryAttribute($value){ |
| 54 | + if(!empty($value)){ | ||
| 54 | foreach ($value as $k => $v){ | 55 | foreach ($value as $k => $v){ |
| 55 | $v['url'] = str_replace_url($v['url']); | 56 | $v['url'] = str_replace_url($v['url']); |
| 56 | $value[$k] = $v; | 57 | $value[$k] = $v; |
| 57 | } | 58 | } |
| 59 | + } | ||
| 58 | $this->attributes['gallery'] = Arr::a2s($value); | 60 | $this->attributes['gallery'] = Arr::a2s($value); |
| 59 | } | 61 | } |
| 60 | 62 | ||
| @@ -91,10 +93,12 @@ class Product extends Base | @@ -91,10 +93,12 @@ class Product extends Base | ||
| 91 | */ | 93 | */ |
| 92 | public function getIconAttribute($value){ | 94 | public function getIconAttribute($value){ |
| 93 | $value = Arr::s2a($value); | 95 | $value = Arr::s2a($value); |
| 96 | + if(!empty($value)){ | ||
| 94 | foreach ($value as $k => $v){ | 97 | foreach ($value as $k => $v){ |
| 95 | $v = getImageUrl($v); | 98 | $v = getImageUrl($v); |
| 96 | $value[$k] = $v; | 99 | $value[$k] = $v; |
| 97 | } | 100 | } |
| 101 | + } | ||
| 98 | return $value; | 102 | return $value; |
| 99 | } | 103 | } |
| 100 | 104 |
-
请 注册 或 登录 后发表评论