Commit 524b055f by 杨树贤

商品主图也要处理

parent d8d89b94
......@@ -4,6 +4,7 @@
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\RedisModel;
use App\Model\SupplierBlacklistModel;
use App\Model\SupplierChannelModel;
use http\Exception\InvalidArgumentException;
......@@ -22,6 +23,10 @@ class DealImageService
preg_match_all($pattern, $text, $matches);
$imageUrls = array_merge($imageUrls, $matches[1]);
$pattern = '/<img [^>]*src\s*=\s*["\']?([^"\'>]*file\.ichunt\.net[^"\'>]*)/i';
preg_match_all($pattern, $text, $matches);
$imageUrls = array_merge($imageUrls, $matches[1]);
return $imageUrls;
}
......@@ -99,7 +104,7 @@ class DealImageService
}
//处理sku详细描述
public static function dealSkuDetail()
public static function dealSkuDetailAndImage()
{
//先找出所有爱智的sku,按搜索的来
//先去搜索找出所有华云的数据
......@@ -113,34 +118,64 @@ class DealImageService
dump("需要处理的总数 : " . $total);
$count = 0;
$totalPage = (int)ceil($total / 20);
$redis = new RedisModel();
//进入修复循环
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,
// ]);
//}
//break;
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)) {
//处理主图
$dbInfo = getSpuSkuDb($skuId);
$connection = DB::connection($dbInfo["db"]);
$table = $dbInfo['table'];
$selectFields = ['goods_images', 'goods_id'];
$skuDBData = $connection->table($table)->select($selectFields)->where('goods_id', $skuId)->first();
$imageUrl = self::checkImage($skuDBData['goods_images']);
if (empty($imageUrl)) {
continue;
}
//dump($imageUrls); // 输出所有提取出的 'img.ichunt.com' 图片链接
$imageMap = self::downloadAndUploadToPicServer($imageUrls);
$imageMap = self::downloadAndUploadToPicServer([$imageUrl]);
//进行全局替换
foreach ($imageMap as $originImage => $newImage) {
$detail = str_replace($originImage, $newImage, $detail);
$skuDBData['goods_images'] = str_replace($originImage, $newImage, $skuDBData['goods_images']);
}
//回写到mongo
DB::connection('mongo')->table('sku_detail')->where('sku_id', (string)$skuId)->update([
'update_time' => time(),
'detail' => $detail,
$connection->table($table)->where('goods_id', $skuId)->update([
'goods_images' => $skuDBData['goods_images'],
]);
dump($skuId);
//redis也要修改
$skuCache = json_decode($redis->hget('sku', $skuId), true);
$skuCache['goods_images'] = $skuDBData['goods_images'];
$redis->hset('sku', $skuId, json_encode($skuCache));
$count++;
}
}
......
......@@ -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::dealSkuDetailAndImage();
//\App\Http\Services\SupplierAddressService::initUnitedAddress();
//\App\Http\Services\DataService::checkSupplierBandAccount();
//(new CompanyService())->checkSupplierCompanyAndAddress(11042);
......
......@@ -44,6 +44,7 @@
let cols = [
{type: 'checkbox'},
{field: 'goods_id', title: 'SKUID', align: 'center', width: 180},
{field: 'goods_images', title: 'goods_images', align: 'center', width: 180},
{
field: 'status_name', title: '状态', align: 'center', width: 70, templet: function (d) {
return d.goods_status == 1 ? "<a class='layui-btn layui-btn-xs'>上架</a>" :
......
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