Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
524b055f
authored
Sep 03, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
商品主图也要处理
parent
d8d89b94
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
17 deletions
app/Http/Services/DealImageService.php
app/Http/routes.php
resources/views/script/SkuListScript.blade.php
app/Http/Services/DealImageService.php
View file @
524b055f
...
...
@@ -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
dealSkuDetail
AndImage
()
{
//先找出所有爱智的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
();
$d
etail
=
$skuDetail
[
'detail'
]
;
if
(
empty
(
$detail
))
{
continue
;
}
//替换图片地址并且上传
$imageUrl
s
=
self
::
getAllImage
(
$detail
);
if
(
empty
(
$imageUrl
s
))
{
//处理主图
$d
bInfo
=
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
++
;
}
}
...
...
app/Http/routes.php
View file @
524b055f
...
...
@@ -84,7 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
\App\Http\Services\DealImageService
::
deal
News
Image
();
\App\Http\Services\DealImageService
::
deal
SkuDetailAnd
Image
();
//\App\Http\Services\SupplierAddressService::initUnitedAddress();
//\App\Http\Services\DataService::checkSupplierBandAccount();
//(new CompanyService())->checkSupplierCompanyAndAddress(11042);
...
...
resources/views/script/SkuListScript.blade.php
View file @
524b055f
...
...
@@ -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>"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment