Commit c4c3a2c6 by 杨树贤

cms图片替换完成

parent e7b4abcd
......@@ -41,6 +41,13 @@ DB_SELF_USERNAME=spu
DB_SELF_PASSWORD=spu
DB_SELF_PORT=3306
#MONGO配置
MONGO_HOST=192.168.1.237
MONGO_USERNAME=ichunt
MONGO_PASSWORD=huntmon6699
MONGO_PORT=27017
MONGO_DB_SELF_SIMILAR_DATABASE=ichunt
#芯链 MYSQL配置
DB_HOST_YUNXIN=192.168.1.252
DB_DATABASE_YUNXIN=liexin_yunxin
......
......@@ -20,6 +20,15 @@ class DealImageService
return $imageUrls;
}
public static function checkImage($link)
{
if (strpos($link, 'img.ichunt.com') !== false) {
return $link;
} else {
return '';
}
}
//先去处理芯媒体的图片链接
public static function dealNewsImage()
{
......@@ -62,16 +71,100 @@ class DealImageService
}
//处理cms的图片链接
public function dealCmsImage()
public static function dealCmsImage()
{
//先去找出所有带有图片的cms数据
$bcatIdList = DB::connection('mysql')->table('lie_base_cat')->where('bcat_name', 'like', "%爱智%")->pluck('bcat_id');
$baseList = DB::connection('mysql')->table('lie_base')->whereIn('bcat_id', $bcatIdList)->where('images', '!=', '')->limit(1000)->get();
foreach ($baseList as $base) {
$imageUrl = self::checkImage($base['images']);
if (empty($imageUrl)) {
continue;
}
$imageMap = self::downloadAndUploadToPicServer([$imageUrl]);
//进行全局替换
foreach ($imageMap as $originImage => $newImage) {
$base['images'] = str_replace($originImage, $newImage, $base['images']);
}
//回写到数据库
DB::connection('mysql')->table('lie_base')->where('base_id', $base['base_id'])->update([
'images' => $base['images']
]);
}
}
//处理sku详细描述
public function dealSkuDetail()
public static function dealSkuDetail()
{
//先找出所有爱智的sku,按搜索的来
//先去搜索找出所有华云的数据
$data = self::searchIedgeSku();
//获取总数
$total = !empty($data['data']['total']) ? $data['data']['total'] : 0;
if (!$total) {
dump("找不到sku数据");
return;
}
dump("需要处理的总数 : " . $total);
$count = 0;
$totalPage = (int)ceil($total / 20);
//进入修复循环
for ($i = 1; $i <= $totalPage; $i = $i + 1) {
$itemList = self::searchIedgeSku($i);
if (empty($itemList['data']['goods_id'])) {
continue;
}
foreach ($itemList['data']['goods_id'] as $skuId) {
$skuDetail = DB::connection('mongo')->table('sku_detail')->where('sku_id', (string)$skuId)->first();
$detail = $skuDetail['detail'];
if (empty($detail)) {
continue;
}
//替换图片地址并且上传
$imageUrls = self::getAllImage($detail);
if (empty($imageUrls)) {
continue;
}
//dump($imageUrls); // 输出所有提取出的 'img.ichunt.com' 图片链接
$imageMap = self::downloadAndUploadToPicServer($imageUrls);
//进行全局替换
foreach ($imageMap as $originImage => $newImage) {
$detail = str_replace($originImage, $newImage, $detail);
}
//回写到mongo
DB::connection('mongo')->table('sku_detail')->where('sku_id', (string)$skuId)->update([
'update_time' => time(),
'detail' => $detail,
]);
$count++;
}
dump('已处理sku数量 : ' . $count);
}
}
private static function searchIedgeSku($page = 1)
{
$url = config('website.search_domain_new') . '/search/es/searchSku';
$map['p'] = $page;
$map['show_status'] = 1;
$map['offset'] = 20;
$map['supplier_id/sr'] = "gt,0";
$map['admin'] = 1; // 后台搜索
$map['no_rule'] = "1122"; // 后台搜索
$map['org_id/eq'] = 3;
$res = Http::get($url, $map)->body();
$data = json_decode($res, true);
return $data;
}
//根据url下载图片并且上传到图片服务
......
......@@ -84,7 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
\App\Http\Services\DealImageService::dealNewsImage();
\App\Http\Services\DealImageService::dealCmsImage();
//\App\Http\Services\SupplierAddressService::initUnitedAddress();
//\App\Http\Services\DataService::checkSupplierBandAccount();
//(new CompanyService())->checkSupplierCompanyAndAddress(11042);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment