作者 刘锟

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

... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Models\Devops\DevopsTaskLog;
use App\Models\Project\Project;
use App\Utils\EncryptUtils;
use Illuminate\Console\Command;
use App\Models\Devops\DevopsTask as DevopsTaskModel;
... ... @@ -45,16 +46,13 @@ class DevopsTask extends Command
*/
public function handle()
{
while (true){
$tasks = DevopsTaskModel::where('status', DevopsTaskModel::STATUS_PENDING)->get();
foreach ($tasks as $task){
echo "Start task " . $task->id . PHP_EOL;
if($task->type == DevopsTaskModel::TYPE_MYSQL){
$this->updateTable($task);
}
echo "End task " . $task->id . PHP_EOL;
$tasks = DevopsTaskModel::where('status', DevopsTaskModel::STATUS_PENDING)->get();
foreach ($tasks as $task){
echo "Start task " . $task->id;
if($task->type == DevopsTaskModel::TYPE_MYSQL){
$this->updateTable($task);
}
sleep(10);
echo "End task " . $task->id . PHP_EOL;
}
}
... ... @@ -64,6 +62,7 @@ class DevopsTask extends Command
echo "project " . $project->id;
$log = DevopsTaskLog::addLog($task->id, $project->id);
if($log->status == DevopsTaskModel::STATUS_ACTIVE){
echo 'continue' . PHP_EOL;
continue;
}
if(!$project->mysqlConfig){
... ... @@ -73,13 +72,22 @@ class DevopsTask extends Command
continue;
}
//DB类是单例模式,生命周期内修改配置不会生效
$conn = new \mysqli(
$project->mysqlConfig->host,
$project->mysqlConfig->user,
$project->mysqlConfig->password,
$project->databaseName(),
$project->mysqlConfig->port,
);
$encrypt = new EncryptUtils();
try {
$conn = new \mysqli(
$project->mysqlConfig->host,
$encrypt->unlock_url($project->mysqlConfig->user),
$encrypt->unlock_url($project->mysqlConfig->password),
$project->databaseName(),
$encrypt->unlock_url($project->mysqlConfig->port),
);
}catch (\Exception $e){
$log->remark = mb_substr('数据库连接失败:' . $e->getMessage(), 0, 500);
$log->status = DevopsTaskLog::STATUS_ERROR;
$log->save();
echo '-->' . $log->remark . PHP_EOL;
continue;
}
$res = $conn->query($task->sql);
$log->status = $res ? DevopsTaskLog::STATUS_ACTIVE : DevopsTaskLog::STATUS_ERROR;
... ...
... ... @@ -125,6 +125,7 @@ class ProjectController extends BaseController
'gl_project.company AS company',
'gl_project.type AS type',
'gl_project.created_at AS created_at',
'gl_project.cooperate_date AS cooperate_date',
'gl_project_online_check.id AS online_check_id',
'gl_project_online_check.question AS question',
'gl_project_online_check.optimist_status AS optimist_status',
... ...
... ... @@ -32,53 +32,97 @@ class CNoticeController extends BaseController
* @param WebSettingLogic $webSettingLogic
*/
public function sendNotify(){
$type = $this->request->input('type', UpdateNotify::TYPE_MASTER);
if (FALSE == in_array($type, [UpdateNotify::TYPE_MASTER, UpdateNotify::TYPE_MINOR])){
$this->response('非法参数!', Code::USER_ERROR);
}
$page = $this->request->input('page', UpdateNotify::PAGE_ALL);
if (FALSE == in_array($type, [UpdateNotify::PAGE_ALL, UpdateNotify::PAGE_SINGLE])){
$this->response('非法参数!', Code::USER_ERROR);
$updateProgressModel = new UpdateProgress();
$progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']])->orderBy('id','desc')->first();
if((!empty($progressInfo))){
$progressInfo = $progressInfo->toArray();
if(($progressInfo['total_num'] > $progressInfo['current_num'])){
$this->response('当前页面正在生成了,请完成后再点击',Code::USER_ERROR,$progressInfo);
}
}
$data = $this->sendNotifyMessage($type,$page);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);
if(!empty($data)){
$this->response('当前页面正在生成了,请完成后再点击',Code::USER_ERROR,$data);
//通知更新
if($this->param['type'] == UpdateNotify::TYPE_MASTER){
$this->updateMaster();
}else{
$this->updateMinorLanguages();
}
$urlStr = $this->getString($this->param['type'],$this->param['page']);
$this->curlGet($urlStr);
$this->response('success');
}
/**
* 通知c端
* @param string $type
* @return array
* @remark :主键通知
* @name :updateMaster
* @author :lyh
* @method :post
* @time :2023/9/12 14:46
*/
public function sendNotifyMessage($type,$page){
$updateProgressModel = new UpdateProgress();
$progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$type])->orderBy('id','desc')->first();
if((!empty($progressInfo))){
$progressInfo = $progressInfo->toArray();
if(($progressInfo['total_num'] > $progressInfo['current_num'])){
return $progressInfo;
public function updateMaster(){
try {
$updateNotifyModel = new UpdateNotify();
if($this->param['page'] == UpdateNotify::PAGE_ALL){
//如果是更新所有
$routeMapModel = new RouteMap();
$count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count();
$updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]);
$this->addProgress($count,$this->param['type']);
}elseif($this->param['page'] == UpdateNotify::PAGE_SINGLE){
//更新所有已修改的更新
$count = $updateNotifyModel->formatQuery(['project_id' => $this->user['project_id'], 'status' => 0])->count();
$updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]);
$this->addProgress($count,$this->param['type']);
}else{
//根据传递的参数更新
$count = count($this->param['url']);
$extent = json_encode(['url'=>$this->param['url']]);
$this->addProgress($count,$this->param['type'],$extent);
}
}catch (\Exception $e){
$this->response('error',Code::USER_ERROR);
}
return true;
}
/**
* @remark :更新小语种
* @name :updateMinorLanguages
* @author :lyh
* @method :post
* @time :2023/9/12 14:48
*/
public function updateMinorLanguages(){
$updateNotifyModel = new UpdateNotify();
$field = ($type == UpdateNotify::TYPE_MINOR) ? 'minor_languages_status' : 'status';
if($page == UpdateNotify::PAGE_ALL){
//如果是更新所有
$routeMapModel = new RouteMap();
$count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count();
}else{
$count = $updateNotifyModel->formatQuery(['project_id' => $this->user['project_id'], $field => 0])->count();
}
if($count == 0){
return [];
try {
if($this->param['page'] == UpdateNotify::PAGE_ALL){
$this->request->validate([
'language' => 'required',
], [
'language.required' => '请选择语种',
]);
//如果是更新所有
$routeMapModel = new RouteMap();
$count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count();
$updateNotifyModel->edit(['minor_languages_status' => 1], ['project_id' => $this->user['project_id'], 'minor_languages_status' => 0]);
$extent = json_encode(['language'=>$this->param['language']]);
$this->addProgress($count,$this->param['type'],$extent);
}else{
$this->request->validate([
'url'=>'required',
'language' => 'required',
], [
'url.required' => '请输入更新链接',
'language.required' => '请选择语种',
]);
//根据传递的参数更新
$count = count($this->param['url']);
$extent = json_encode(['url'=>$this->param['url'],'language'=>$this->param['language']]);
$this->addProgress($count,$this->param['type'],$extent);
}
}catch (\Exception $e){
$this->response('error',Code::USER_ERROR);
}
$this->addProgress($count,$type);
$updateNotifyModel->edit([$field => 1], ['project_id' => $this->user['project_id'], $field => 0]);
$urlStr = $this->getString($type,$page);
$this->curlGet($urlStr);
return [];
return true;
}
/**
... ... @@ -111,11 +155,12 @@ class CNoticeController extends BaseController
* @method :post
* @time :2023/9/6 17:01
*/
public function addProgress($count,$type){
public function addProgress($count,$type,$extend = ''){
$data = [
'total_num'=>$count,
'current_num'=>0,
'type'=>$type,
'extend'=>$extend,
'project_id'=>$this->user['project_id'],
'created_at'=>date('Y-m-d H;i:s')
];
... ...
... ... @@ -11,7 +11,9 @@ use App\Models\Project\Project;
use App\Models\Devops\ServerConfig;
use App\Services\ProjectServer;
use App\Utils\EncryptUtils;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Process\Process;
/**
* Class ServerConfigLogic
... ... @@ -174,6 +176,9 @@ class ServerConfigLogic extends BaseLogic
*/
public function updateAllTable($param){
DevopsTask::addTask($param['sql']);
//执行命令行
$process = new Process(['php', 'artisan', 'devops_task']);
$process->start();
return $this->success();
}
}
... ...
... ... @@ -127,7 +127,7 @@ class ProductLogic extends BaseLogic
DB::beginTransaction();
try {
foreach ($this->param['ids'] as $k => $id) {
$info = $this->model->read(['id'=>$id]);
$info = $this->model->read(['id'=>$id],['id','status']);
if($info['status'] == Product::STATUS_RECYCLE){
$this->delRoute($id);
//删除当前产品模版
... ...
... ... @@ -51,9 +51,11 @@ class Product extends Base
}
public function setGalleryAttribute($value){
foreach ($value as $k => $v){
$v['url'] = str_replace_url($v['url']);
$value[$k] = $v;
if(!empty($value)){
foreach ($value as $k => $v){
$v['url'] = str_replace_url($v['url']);
$value[$k] = $v;
}
}
$this->attributes['gallery'] = Arr::a2s($value);
}
... ... @@ -91,9 +93,11 @@ class Product extends Base
*/
public function getIconAttribute($value){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
$v = getImageUrl($v);
$value[$k] = $v;
if(!empty($value)){
foreach ($value as $k => $v){
$v = getImageUrl($v);
$value[$k] = $v;
}
}
return $value;
}
... ...