作者 赵彬吉

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

@@ -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 ];