作者 lyh

gx

@@ -120,18 +120,34 @@ class LoginController extends BaseController @@ -120,18 +120,34 @@ class LoginController extends BaseController
120 } 120 }
121 121
122 public function ceshi(){ 122 public function ceshi(){
123 - $templateModel = new Template(); 123 + $templateModel = new TemplateModule();
124 $list = $templateModel->list(); 124 $list = $templateModel->list();
125 foreach ($list as $k => $v){ 125 foreach ($list as $k => $v){
126 - $html = str_replace(  
127 - "https://develop.globalso.com/a/image/",  
128 - "https://ecdn6.globalso.com/public/template/",  
129 - $v['html']  
130 - );  
131 - $templateModel->edit(['html'=>$html],['id'=>$v['id']]);  
132 - 126 + // 使用正则表达式和 preg_match_all 函数来匹配多个 img 标签的 src 值
  127 + preg_match_all('/\"https:\/\/develop.globalso.com\/a\/image\/(.*?)\"/', $v['html'], $matches);
  128 + if (!empty($matches[1])) {
  129 + $srcValues = $matches[1];
  130 + $imageModel = new Image();
  131 + $html = $v['html'];
  132 + foreach ($srcValues as $srcValue) {
  133 + $image_info = $imageModel->read(['hash'=>$srcValue]);
  134 + if($image_info !== false){
  135 + $path = basename($image_info['path']);
  136 + $html = $this->re($html,$srcValue,$path);
  137 + }
  138 + }
  139 + $templateModel->edit(['html'=>$html],['id'=>$v['id']]);
  140 + }
133 } 141 }
134 return 1; 142 return 1;
135 } 143 }
136 144
  145 + public function re(&$html,$srcValue,$path){
  146 + $html = str_replace(
  147 + $srcValue,
  148 + $path,
  149 + $html
  150 + );
  151 + return $html;
  152 + }
137 } 153 }