|
...
|
...
|
@@ -129,44 +129,34 @@ class lyhDemo extends Command |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function _actions(){
|
|
|
|
public function _actions() {
|
|
|
|
echo '565' . PHP_EOL;
|
|
|
|
ProjectServer::useProject(565);
|
|
|
|
$table = 'gl_product';
|
|
|
|
$connection = DB::connection('custom_mysql');
|
|
|
|
// 要替换的品牌关键词
|
|
|
|
// 品牌关键词
|
|
|
|
$str = 'Trimos,insize,Fowler,Mahr,Starrett,Tesa,Mitutoyo,Wixey,Shars,Fisso,Spi,Grizzly,Accumaster,Accuremote,Baker,Sharpe,Compac,Earth,Etalon,Federal,Fell,Fisso,Fowler,Gem,Grizzly,Husky,iGaging,Insize,Kanetec,Magnetics,Mighty,Mitutoyo,Noga,Pittsburgh,Procheck,Saker,Scherr Tumico,Shars,Shinwa,SPI,Starrett,Tesa,Technidea,Trimos,Verdict,Wyler,Wixey';
|
|
|
|
$arr = array_map('trim', explode(',', $str)); // 去空格
|
|
|
|
// 获取所有字段名(列名)
|
|
|
|
$brands = array_unique(array_map('trim', explode(',', $str)));
|
|
|
|
// 获取所有列名
|
|
|
|
$columns = $connection->getSchemaBuilder()->getColumnListing($table);
|
|
|
|
// 获取所有数据
|
|
|
|
$rows = $connection->table($table)->select('*')->get();
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$updateData = [];
|
|
|
|
foreach ($columns as $field) {
|
|
|
|
echo '处理的字段:'.$field.PHP_EOL;
|
|
|
|
// 只处理文本字段,跳过 id 或 null 字段
|
|
|
|
if ($field === 'id' || !is_string($row->$field)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$original = $row->$field;
|
|
|
|
$replaced = $original;
|
|
|
|
foreach ($arr as $val) {
|
|
|
|
$replaced = str_ireplace($val . '-', '', $replaced); // 替换 brand-
|
|
|
|
$replaced = str_ireplace($val, '', $replaced); // 替换 brand
|
|
|
|
}
|
|
|
|
if ($replaced !== $original) {
|
|
|
|
$updateData[$field] = $replaced;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 有变更再更新
|
|
|
|
if (!empty($updateData)) {
|
|
|
|
$connection->table($table)
|
|
|
|
->where('id', $row->id)
|
|
|
|
->update($updateData);
|
|
|
|
|
|
|
|
// 遍历每个字段执行更新
|
|
|
|
foreach ($columns as $field) {
|
|
|
|
if ($field === 'id' || $field === 'image' || $field === 'og_image') continue; // 跳过主键
|
|
|
|
// 构造多重 REPLACE()
|
|
|
|
$sqlField = "`$field`";
|
|
|
|
$updateExpr = $sqlField;
|
|
|
|
foreach ($brands as $brand) {
|
|
|
|
$brand = addslashes($brand); // 避免特殊字符
|
|
|
|
$updateExpr = "REPLACE($updateExpr, '$brand-', '')";
|
|
|
|
$updateExpr = "REPLACE($updateExpr, '$brand', '')";
|
|
|
|
}
|
|
|
|
$sql = "UPDATE `$table` SET $sqlField = $updateExpr WHERE $sqlField IS NOT NULL AND $sqlField != ''";
|
|
|
|
echo "执行字段:$field" . PHP_EOL;
|
|
|
|
$connection->update($sql);
|
|
|
|
}
|
|
|
|
echo '执行结束'.PHP_EOL;
|
|
|
|
|
|
|
|
echo '执行结束' . PHP_EOL;
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|