|
...
|
...
|
@@ -14,7 +14,9 @@ use App\Http\Controllers\Bside\BaseController; |
|
|
|
use App\Http\Logic\Bside\Setting\WebSettingLogic;
|
|
|
|
use App\Models\Com\UpdateNotify;
|
|
|
|
use App\Models\Com\UpdateProgress;
|
|
|
|
use App\Models\Project\Country as CountryModel;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\WebSetting\WebSettingCountry;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -32,53 +34,98 @@ 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']);
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($urlStr, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
$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'],$this->param['page']);
|
|
|
|
}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'],$this->param['page']);
|
|
|
|
}else{
|
|
|
|
//根据传递的参数更新
|
|
|
|
$count = count($this->param['url']);
|
|
|
|
$extent = json_encode(['url'=>$this->param['url']]);
|
|
|
|
$this->addProgress($count,$this->param['type'],$this->param['page'],$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'],$this->param['page'],$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'],$this->param['page'],$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -89,19 +136,22 @@ class CNoticeController extends BaseController |
|
|
|
* @time :2023/9/12 10:10
|
|
|
|
*/
|
|
|
|
public function curlGet($url){
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt_array($curl, array(
|
|
|
|
CURLOPT_URL => $url,
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
|
CURLOPT_ENCODING => '',
|
|
|
|
CURLOPT_MAXREDIRS => 10,
|
|
|
|
CURLOPT_TIMEOUT => 0,
|
|
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET',
|
|
|
|
));
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
$ch1 = curl_init();
|
|
|
|
$timeout = 0;
|
|
|
|
curl_setopt($ch1, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch1, CURLOPT_ENCODING, '');
|
|
|
|
curl_setopt($ch1, CURLOPT_MAXREDIRS, 10);
|
|
|
|
curl_setopt($ch1, CURLOPT_HTTPHEADER, array());
|
|
|
|
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
|
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
|
|
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
|
|
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'GET');
|
|
|
|
curl_setopt($ch1, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
|
|
|
$access_txt = curl_exec($ch1);
|
|
|
|
curl_close($ch1);
|
|
|
|
return json_decode($access_txt, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -111,11 +161,13 @@ class CNoticeController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/6 17:01
|
|
|
|
*/
|
|
|
|
public function addProgress($count,$type){
|
|
|
|
public function addProgress($count,$type,$page,$extend = ''){
|
|
|
|
$data = [
|
|
|
|
'total_num'=>$count,
|
|
|
|
'current_num'=>0,
|
|
|
|
'type'=>$type,
|
|
|
|
'page'=>$page,
|
|
|
|
'extends'=>$extend,
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'created_at'=>date('Y-m-d H;i:s')
|
|
|
|
];
|
|
...
|
...
|
@@ -139,4 +191,28 @@ class CNoticeController extends BaseController |
|
|
|
$string = http_build_query($param);
|
|
|
|
return $this->user['domain'].'api/updateHtmlNotify/?' . $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前项目选中的语种
|
|
|
|
* @name :getCountry
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/12 15:20
|
|
|
|
*/
|
|
|
|
public function getCountry(){
|
|
|
|
$countryModel = new CountryModel();
|
|
|
|
$info = $countryModel->read(['project_id'=>$this->user['project_id']],['id','country_lists']);
|
|
|
|
$ids = [];
|
|
|
|
if($info !== false){
|
|
|
|
$ids = explode(',',$info['country_lists']);
|
|
|
|
}
|
|
|
|
$webSettingCountryModel = new WebSettingCountry();
|
|
|
|
$lists = $webSettingCountryModel->list(['id'=>['in',$ids]],'id',['id','name','country_img']);
|
|
|
|
if (!empty($lists)){
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
$lists[$k]['image_link'] = url('upload/country/' . $v['country_img']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|