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
34255c38
authored
Jan 08, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
统计完成
parent
392e10de
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
194 additions
and
404 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
34255c38
...
@@ -14,6 +14,7 @@ use App\Model\Purchase\PurchaseOrderModel;
...
@@ -14,6 +14,7 @@ use App\Model\Purchase\PurchaseOrderModel;
use
App\Model\Purchase\StockInItemModel
;
use
App\Model\Purchase\StockInItemModel
;
use
App\Model\Purchase\StockInModel
;
use
App\Model\Purchase\StockInModel
;
use
App\Model\RedisModel
;
use
App\Model\RedisModel
;
use
App\Model\SkuUploadItem
;
use
App\Model\SkuUploadLogModel
;
use
App\Model\SkuUploadLogModel
;
use
App\Model\SpuBrandModel
;
use
App\Model\SpuBrandModel
;
use
App\Model\StandardBrandMappingModel
;
use
App\Model\StandardBrandMappingModel
;
...
@@ -81,372 +82,6 @@ class DataService
...
@@ -81,372 +82,6 @@ class DataService
const
TYPE_DLS
=
1
;
const
TYPE_DLS
=
1
;
const
TYPE_MYS
=
2
;
const
TYPE_MYS
=
2
;
//供应商类型修改
public
function
changeSupplierType
()
{
ini_set
(
'memory_limit'
,
-
1
);
//统一修改掉状态先
(
new
SupplierChannelModel
)
->
where
(
'supplier_id'
,
'>'
,
0
)
->
update
([
'outside_contact_type'
=>
0
]);
//先将真实对接的供应商修改状态
$realApiSupplierCodes
=
[
'L0000266'
,
'L0000198'
,
'L0000273'
,
'L0000135'
,
'L0000135'
,
'L0005966'
,
'L0000004'
,
'L0006149'
,
'L0006150'
,
'L0006155'
,
'L0007637'
,
'L0006148'
,
'L0006151'
,
'L0006147'
,
'L0007639'
,
'L0007640'
,
'L0007646'
,
'L0007648'
,
'L0007650'
,
'L0007653'
,
'L0000089'
,
'L0007633'
,
'L0007663'
,
'L0010826'
,
'L0010856'
,
'L0010937'
,
'L0007595'
,
'L0011054'
,
'L0004938'
,
'L0011040'
,
'L0001175'
,
'L0007243'
,
'L0011042'
,
];
SupplierChannelModel
::
whereIn
(
'supplier_code'
,
$realApiSupplierCodes
)
->
update
([
'outside_contact_type'
=>
2
]);
$suppliers
=
$this
->
getNeedDealSuppliers
();
if
(
empty
(
$suppliers
))
{
return
'供应商上传类型已经全部处理'
;
}
//api对接类型的供应商数量(706)
$ycApiTypeCount
=
172
;
$dlsApiTypeCount
=
207
;
$mysApiTypeCount
=
327
;
//要先找出原厂类型的API对接类型的供应商数量,然后要从库里面随机找出原厂的供应商打上类型
$this
->
dealApiSupplier
(
self
::
TYPE_YC
,
$ycApiTypeCount
);
//要先找出代理商类型的API对接类型的供应商数量,然后要从库里面随机找出代理商的供应商打上类型
$this
->
dealApiSupplier
(
self
::
TYPE_DLS
,
$dlsApiTypeCount
);
//要先找出贸易类型的API对接类型的供应商数量,然后要从库里面随机找出贸易的供应商打上类型
$this
->
dealApiSupplier
(
self
::
TYPE_MYS
,
$mysApiTypeCount
);
echo
"-------------------------"
.
PHP_EOL
;
//然后随机取出芯链的供应商(1139)
//先剔除api对接的供应商
$ycYunxinTypeCount
=
113
;
$dlsYunxinTypeCount
=
302
;
$mysYunxinTypeCount
=
724
;
$this
->
dealYunxinSupplier
(
self
::
TYPE_YC
,
$ycYunxinTypeCount
);
$this
->
dealYunxinSupplier
(
self
::
TYPE_DLS
,
$dlsYunxinTypeCount
);
$this
->
dealYunxinSupplier
(
self
::
TYPE_MYS
,
$mysYunxinTypeCount
);
echo
"-------------------------"
.
PHP_EOL
;
//剩下的都是人工上传的,也有一定占比(2658)
$ycManualTypeCount
=
20
;
$dlsManualTypeCount
=
146
;
$mysManualTypeCount
=
2492
;
$this
->
dealManualSupplier
(
self
::
TYPE_YC
,
$ycManualTypeCount
);
$this
->
dealManualSupplier
(
self
::
TYPE_DLS
,
$dlsManualTypeCount
);
$this
->
dealManualSupplier
(
self
::
TYPE_MYS
,
$mysManualTypeCount
);
}
public
function
getNeedDealSuppliers
(
$supplierGroup
=
0
,
$otherSupplierGroup
=
[])
{
$query
=
SupplierChannelModel
::
where
(
'outside_contact_type'
,
0
)
->
where
(
'channel_uid'
,
'!='
,
''
)
->
where
(
'status'
,
'!='
,
-
3
)
->
whereRaw
(
'supplier_name NOT LIKE "%-1"'
)
->
where
(
'is_type'
,
0
);
if
(
!
empty
(
$otherSupplierGroup
))
{
$query
->
whereIn
(
'supplier_group'
,
$otherSupplierGroup
);
}
else
{
if
(
!
empty
(
$supplierGroup
))
{
$query
->
where
(
'supplier_group'
,
$supplierGroup
);
}
}
$data
=
$query
->
get
()
->
toArray
();
return
$data
;
}
//处理API接入的不同类型的数据
public
function
dealApiSupplier
(
$supplierGroup
,
$totalApiTypeCount
)
{
//先找出已经存在的api对接类型的供应商数量,方便下面算出补全数量
$existApiTypeCount
=
SupplierChannelModel
::
where
(
'outside_contact_type'
,
2
)
->
where
(
'supplier_group'
,
$supplierGroup
)
->
count
();
echo
"API对接类型的
$supplierGroup
供应商数量一共要有数量 : "
.
$totalApiTypeCount
.
PHP_EOL
;
echo
"已经存在的API对接类型的
$supplierGroup
供应商数量 : "
.
$existApiTypeCount
.
PHP_EOL
;
//剩下就要补全
$needAddApiTypeCount
=
$totalApiTypeCount
-
$existApiTypeCount
;
echo
"需要补全API对接类型的
$supplierGroup
供应商数量 :"
.
$needAddApiTypeCount
.
PHP_EOL
;
if
(
$needAddApiTypeCount
<=
0
)
{
return
;
}
$suppliers
=
$this
->
getNeedDealSuppliers
(
$supplierGroup
);
echo
"供应商性质
$supplierGroup
可操作供应商数量 :"
.
count
(
$suppliers
)
.
PHP_EOL
;
if
(
!
count
(
$suppliers
))
{
return
;
}
$rand
=
array_rand
(
$suppliers
,
$needAddApiTypeCount
);
$apiSuppliers
=
array_intersect_key
(
$suppliers
,
array_flip
(
is_array
(
$rand
)
?
$rand
:
[
$rand
]));
$apiSupplierIds
=
array_column
(
$apiSuppliers
,
'supplier_id'
);
echo
"供应商性质为 :
$supplierGroup
的供应商修改API上传类型数量 : "
.
count
(
$apiSupplierIds
)
.
PHP_EOL
.
PHP_EOL
;
SupplierChannelModel
::
whereIn
(
'supplier_id'
,
$apiSupplierIds
)
->
where
(
'outside_contact_type'
,
0
)
->
update
([
'outside_contact_type'
=>
2
]);
}
//处理芯链接入的不同类型的数据
public
function
dealYunxinSupplier
(
$supplierGroup
,
$totalYunxinCount
)
{
$suppliers
=
$this
->
getNeedDealSuppliers
(
$supplierGroup
);
echo
"供应商性质
$supplierGroup
需要修改数量 :"
.
$totalYunxinCount
.
PHP_EOL
;
echo
"供应商性质
$supplierGroup
可操作供应商数量 :"
.
count
(
$suppliers
)
.
PHP_EOL
;
if
(
!
count
(
$suppliers
))
{
return
;
}
if
(
count
(
$suppliers
)
<
$totalYunxinCount
)
{
$totalYunxinCount
=
count
(
$suppliers
);
}
$rand
=
array_rand
(
$suppliers
,
$totalYunxinCount
);
$yunxinSuppliers
=
array_intersect_key
(
$suppliers
,
array_flip
(
is_array
(
$rand
)
?
$rand
:
[
$rand
]));
$yunxinSupplierIds
=
array_column
(
$yunxinSuppliers
,
'supplier_id'
);
echo
"供应商性质为 :
$supplierGroup
的供应商修改芯链上传类型数量 : "
.
count
(
array_unique
(
$yunxinSupplierIds
))
.
PHP_EOL
;
// foreach ($yunxinSupplierIds as $supplierId) {
// SupplierChannelModel::where('supplier_id', $supplierId)->update([
// 'outside_contact_type' => 3
// ]);
// }
SupplierChannelModel
::
whereIn
(
'supplier_id'
,
$yunxinSupplierIds
)
->
where
(
'outside_contact_type'
,
0
)
->
update
([
'outside_contact_type'
=>
3
]);
}
//处理人工上传
public
function
dealManualSupplier
(
$supplierGroup
,
$totalManualCount
)
{
$otherSupplierGroup
=
[];
if
(
$supplierGroup
==
2
)
{
$otherSupplierGroup
=
[
0
,
2
,
3
,
5
,
6
];
// $otherSupplierGroup = [2];
}
//人工上传这个类别,供应商性质如果是贸易商,那就要加上方案商和分销平台和代工厂
$suppliers
=
$this
->
getNeedDealSuppliers
(
$supplierGroup
,
$otherSupplierGroup
);
echo
"供应商性质
$supplierGroup
需要修改数量 :"
.
$totalManualCount
.
PHP_EOL
;
echo
"供应商性质
$supplierGroup
可操作供应商数量 :"
.
count
(
$suppliers
)
.
PHP_EOL
;
if
(
!
count
(
$suppliers
))
{
return
;
}
if
(
count
(
$suppliers
)
<=
$totalManualCount
)
{
$totalManualCount
=
count
(
$suppliers
);
}
$rand
=
array_rand
(
$suppliers
,
$totalManualCount
);
$manualSuppliers
=
array_intersect_key
(
$suppliers
,
array_flip
(
is_array
(
$rand
)
?
$rand
:
[
$rand
]));
$manualSupplierIds
=
array_column
(
$manualSuppliers
,
'supplier_id'
);
echo
"供应商性质为 :
$supplierGroup
的供应商修改人工上传类型数量 : "
.
count
(
$manualSupplierIds
)
.
PHP_EOL
;
// foreach ($manualSupplierIds as $supplierId) {
// SupplierChannelModel::where('supplier_id', $supplierId)->update([
// 'outside_contact_type' => 1
// ]);
// }
foreach
(
collect
(
$manualSupplierIds
)
->
chunk
(
500
)
as
$key
=>
$ids
)
{
SupplierChannelModel
::
whereIn
(
'supplier_id'
,
$ids
)
->
where
(
'outside_contact_type'
,
0
)
->
update
([
'outside_contact_type'
=>
1
]);
}
}
//导入公司性质
public
function
importSupplierGroup
(
$isUpdate
=
false
)
{
ini_set
(
'memory_limit'
,
-
1
);
$filePath
=
public_path
(
'data'
)
.
DIRECTORY_SEPARATOR
.
'supplier_group.xlsx'
;
try
{
Excel
::
selectSheetsByIndex
(
0
)
->
load
(
$filePath
,
function
(
$reader
)
use
(
$isUpdate
)
{
$reader
->
sheet
(
'Sheet2'
,
function
()
use
(
$reader
,
$isUpdate
)
{
$num
=
$ycNum
=
0
;
$redis
=
new
RedisModel
();
foreach
(
$reader
->
all
()
->
toArray
()
as
$key
=>
$item
)
{
$supplierCode
=
trim
(
$item
[
0
]);
$purchaseName
=
trim
(
$item
[
3
]);
$channelUid
=
(
new
AdminUserService
())
->
getCodeIdByUserName
(
$purchaseName
);
//如果采购员id不为空,那么就要写进去
$supplierId
=
SupplierChannelModel
::
where
(
'supplier_code'
,
$supplierCode
)
->
value
(
'supplier_id'
);
if
(
!
$supplierId
)
{
echo
"供应商不存在 : "
.
$supplierCode
.
PHP_EOL
;
}
if
(
$channelUid
)
{
echo
"添加采购员${purchaseName}到 : "
.
$supplierCode
.
PHP_EOL
;
if
(
$isUpdate
)
{
(
new
SupplierService
())
->
allocateChannelUser
(
$supplierId
,
$channelUid
,
false
);
}
}
$isYc
=
trim
(
$item
[
4
]);
if
(
$isYc
==
'原厂'
)
{
//判断是否是原厂,如果是原厂,就跳过
$supplierGroup
=
SupplierChannelModel
::
where
(
'supplier_code'
,
$supplierCode
)
->
value
(
'supplier_group'
);
if
(
$supplierGroup
==
self
::
TYPE_YC
)
{
echo
"该供应商已经是原厂,跳过 :
$supplierCode
"
.
PHP_EOL
;
continue
;
}
echo
"修改供应商性质为原厂 : "
.
$supplierCode
.
PHP_EOL
;
if
(
$isUpdate
)
{
//写入redis,方便恢复
$redis
->
hset
(
'lie_supplier_group_change'
,
$supplierGroup
,
self
::
TYPE_YC
);
SupplierChannelModel
::
where
(
'supplier_code'
,
$supplierCode
)
->
update
([
'supplier_group'
=>
self
::
TYPE_YC
,
]);
}
$ycNum
++
;
}
$num
++
;
}
echo
"一共处理
$num
家供应商采购员,处理
$ycNum
家供应商性质为原厂"
.
PHP_EOL
;
});
});
}
catch
(
\Exception
$exception
)
{
dd
(
$exception
);
}
}
//生成芯链账号
public
function
generateYunxinAccount
(
$isUpdate
=
false
)
{
ini_set
(
'memory_limit'
,
-
1
);
$suppliers
=
SupplierChannelModel
::
where
(
'outside_contact_type'
,
3
)
->
get
()
->
toArray
();
// $suppliers = SupplierChannelModel::where('is_type', 0)->limit(100)->get()->toArray();
foreach
(
$suppliers
as
$supplier
)
{
if
(
SupplierAccountModel
::
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
exists
())
{
continue
;
}
$mobile
=
generateMobile
(
1
)[
0
];
$password
=
makePassword
(
mt_rand
(
8
,
12
));
$account
=
[
'supplier_id'
=>
$supplier
[
'supplier_id'
],
'supplier_code'
=>
$supplier
[
'supplier_code'
],
'mobile'
=>
$mobile
,
'password_raw'
=>
$password
,
'password'
=>
Hash
::
make
(
$password
),
'create_uid'
=>
1000
,
'create_time'
=>
time
(),
];
if
(
$isUpdate
)
{
SupplierAccountModel
::
insert
(
$account
);
}
}
}
//处理芯链账号的创建时间
public
function
dealYunxinAccountCreateTime
()
{
$preYearTimestamp
=
time
()
-
24
*
3600
*
252
*
1
;
$accounts
=
SupplierAccountModel
::
where
(
'id'
,
'>'
,
4
)
->
get
();
$randNum
=
0
;
$lastTimestamp
=
0
;
foreach
(
$accounts
as
$account
)
{
$randNum
+=
3600
*
5.2
;
$startTime
=
Carbon
::
createFromTimestamp
(
$preYearTimestamp
+
$randNum
)
->
startOfDay
()
->
addHour
(
9
)
->
timestamp
;
$endTime
=
Carbon
::
createFromTimestamp
(
$preYearTimestamp
+
$randNum
)
->
endOfDay
()
->
addHour
(
19
)
->
timestamp
;
$createTimestamp
=
rand
(
$startTime
,
$endTime
);
if
(
Carbon
::
createFromTimestamp
(
$createTimestamp
)
->
isWeekend
())
{
$createTimestamp
=
$createTimestamp
+
(
2
*
24
*
3600
);
}
if
(
Carbon
::
createFromTimestamp
(
$createTimestamp
)
->
hour
<
9
)
{
$createTimestamp
=
$createTimestamp
+
(
9
*
3600
);
}
if
(
$createTimestamp
<
$lastTimestamp
)
{
$createTimestamp
=
$lastTimestamp
+
rand
(
60
,
3600
);
}
$lastTimestamp
=
$createTimestamp
;
dump
(
date
(
'Y-m-d H:i:s'
,
$createTimestamp
));
SupplierAccountModel
::
where
(
'id'
,
$account
[
'id'
])
->
update
([
'create_time'
=>
$createTimestamp
]);
}
}
//修复采购员有问题的数据
public
function
fixHasProblemChannelUid
(
$isUpdate
=
false
)
{
//1743
//1753
//1527
$channelUidsMap
=
[
1743
=>
10201
,
1753
=>
10207
,
1527
=>
10177
,
];
$supplierModel
=
\DB
::
connection
(
'web'
);
foreach
(
$channelUidsMap
as
$channelUid
=>
$codeId
)
{
$suppliers
=
$supplierModel
->
table
(
'supplier_channel'
)
->
where
(
'channel_uid'
,
'like'
,
"
$channelUid
%"
)
->
where
(
'is_type'
,
0
)
->
get
();
foreach
(
$suppliers
as
$supplier
)
{
$channelUidNew
=
str_replace
(
$channelUid
,
$codeId
,
$supplier
[
'channel_uid'
]);
dump
(
"旧的采购员是 : "
.
$supplier
[
'channel_uid'
]);
dump
(
"新的采购员是 : "
.
$channelUidNew
);
if
(
$isUpdate
)
{
$supplierModel
->
table
(
'supplier_channel'
)
->
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
update
([
'channel_uid'
=>
$channelUidNew
,
]);
SupplierContactModel
::
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
where
(
'can_check_uids'
,
$channelUid
)
->
update
([
'can_check_uids'
=>
$codeId
]);
}
}
}
}
//处理供应商类型的数据
//处理供应商类型的数据
public
function
dealSupplierTypeData
(
$isUpdate
=
false
)
public
function
dealSupplierTypeData
(
$isUpdate
=
false
)
...
@@ -1654,53 +1289,208 @@ class DataService
...
@@ -1654,53 +1289,208 @@ class DataService
}
}
}
}
public
function
initCouponTime
()
//导出供应商评级数据
public
function
exportSupplierDataForLevel
()
{
{
\DB
::
connection
(
'liexin'
)
->
table
(
'coupon'
)
->
whereIn
(
'coupon_sn'
,
[
ini_set
(
'memory_limit'
,
-
1
);
'SN2023082898101485'
,
$redis
=
new
RedisModel
();
'SN2023082856541005'
,
$halfYearTime
=
Carbon
::
now
()
->
startOfYear
()
->
subMonths
(
7
)
->
timestamp
;
'SN2023082898101515'
,
'SN2023082849501019'
,
'SN2023082848531005'
,
])
->
update
([
'effect_end_time'
=>
1704038400
]);
}
public
function
repairInvalidSpaceSupplierName
()
//$suppliers = SupplierChannelModel::where('is_type', 0)->where('uploaded_sku', 1)->get()->toArray();
{
$suppliers
=
SupplierChannelModel
::
select
([
$suppliers
=
SupplierChannelModel
::
where
(
'is_type'
,
0
)
->
select
([
'supplier_name'
,
'supplier_id'
,
'supplier_id'
,
'tax_number'
,
'supplier_code'
,
'region'
'supplier_group'
,
])
->
get
()
->
toArray
();
'supplier_name'
,
'yunxin_channel_uid'
,
'uploaded_sku'
,
'sku_num'
,
'sku_update_time'
,
])
->
where
(
'is_type'
,
0
)
//->where('sku_num', '>', 0)->get()->toArray();
->
where
(
'uploaded_sku'
,
1
)
->
get
()
->
toArray
();
$excelData
=
[];
$header
=
[
'供应商名称'
,
'供应商类型'
,
'SKU采购部门'
,
'最近更新SKU时间'
,
'是否开通芯链'
,
'芯链报价次数'
,
'芯链报价单成单数量'
,
'采购成单总额(含税)'
,
'当前上架SKU数'
,
'SKU数最多的品牌1'
,
'SKU数最多的品牌2'
,
'SKU数最多的品牌3'
,
'SKU数最多的品牌4'
,
'SKU数最多的品牌5'
,
];
$supplierCodes
=
array_column
(
$suppliers
,
'supplier_code'
);
$supplierAccountMap
=
SupplierAccountModel
::
whereIn
(
'supplier_code'
,
$supplierCodes
)
->
pluck
(
'mobile'
,
'supplier_id'
)
->
toArray
();
$intraCodeModel
=
new
IntracodeModel
();
$users
=
$intraCodeModel
->
getSampleName
(
true
);
foreach
(
$suppliers
as
$supplier
)
{
foreach
(
$suppliers
as
$supplier
)
{
$oldSupplierName
=
$supplier
[
'supplier_name'
];
$supplierId
=
$supplier
[
'supplier_id'
];
$supplier
[
'supplier_name'
]
=
replaceSpace
(
$supplier
[
'supplier_name'
]);
$frqData
=
$redis
->
hget
(
'frq_supplier_data_20230501_20231231'
,
$supplier
[
'supplier_name'
]);
$frqData
=
!
empty
(
$frqData
)
?
json_decode
(
$frqData
,
true
)
:
[];
$skuUserNameRaw
=
''
;
if
(
$supplier
[
'yunxin_channel_uid'
])
{
$skuUserNameRaw
=
array_get
(
$users
,
$supplier
[
'yunxin_channel_uid'
]);
}
$skuUserDepartment
=
''
;
if
(
$skuUserNameRaw
)
{
$skuUserDepartment
=
(
new
DepartmentService
())
->
getDepartmentNameByUserName
(
$skuUserNameRaw
);
}
////获取采购系统的成单总额(含税)
//$purchaseOrders = PurchaseOrderModel::where('supplier_id', $supplierId)
// ->where('create_time', '>=', $halfYearTime)
// ->where('status', 4)->select([
// 'currency',
// 'purchase_amount',
// 'exchange_rate'
// ])->get()->toArray();
//$purchasePrice = 0;
//foreach ($purchaseOrders as $order) {
// if ($order['currency'] != 1) {
// $purchasePrice += $order['purchase_amount'] * $order['exchange_rate'] * 1.13;
// }
// $purchasePrice += $order['purchase_amount'];
//}
//获取sku数量最多的前五个品牌
//要去上传记录表
$logIds
=
SkuUploadLogModel
::
where
(
'supplier_code'
,
$supplier
[
'supplier_code'
])
->
where
(
'create_time'
,
'>='
,
$halfYearTime
)
->
where
(
'status'
,
3
)
->
pluck
(
'id'
)
->
toArray
();
$skuCountByStandardBrandName
=
[];
if
(
!
empty
(
$logIds
))
{
$uploadLogItemGroupByBrandName
=
SkuUploadItem
::
selectRaw
(
'brand_name,COUNT(DISTINCT sku_id) as sku_count'
)
->
where
(
'brand_name'
,
'!='
,
''
)
->
whereIn
(
'log_id'
,
$logIds
)
->
groupBy
(
'brand_name'
)
->
get
()
->
toArray
();
foreach
(
$uploadLogItemGroupByBrandName
as
&
$value
)
{
//然后获取每个品牌的标准品牌
//$redis->hset('brand_name_all', md5(strtolower($find['brand_name'])), $brandId);
$brandName
=
$value
[
'brand_name'
];
$brandNameAllKey
=
md5
(
strtolower
(
$brandName
));
$brandId
=
$redis
->
hget
(
'brand_name_all'
,
$brandNameAllKey
);
if
(
empty
(
$brandId
))
{
$value
[
'standard_brand_id'
]
=
0
;
continue
;
}
//然后找到标准品牌id
$standardBrandId
=
$redis
->
hget
(
'standard_brand_mapping'
,
$brandId
);
$value
[
'standard_brand_id'
]
=
$standardBrandId
;
$standardBrand
=
$redis
->
hget
(
'standard_brand'
,
$standardBrandId
);
$standardBrand
=
json_decode
(
$standardBrand
,
true
);
$value
[
'standard_brand_name'
]
=
$standardBrand
[
'brand_name'
];
}
if
(
$oldSupplierName
===
$supplier
[
'supplier_name'
])
{
//统计标品的sku数量
$uploadLogItemGroupByStandardBrandName
=
collect
(
$uploadLogItemGroupByBrandName
)
->
groupBy
(
'standard_brand_name'
)
->
toArray
();
$skuCountByStandardBrandName
=
[];
foreach
(
$uploadLogItemGroupByStandardBrandName
as
$brandName
=>
$standardBrandItem
)
{
if
(
empty
(
$brandName
))
{
continue
;
}
$skuCount
=
0
;
foreach
(
$standardBrandItem
as
$value
)
{
$skuCount
=
$value
[
'sku_count'
];
}
$skuCountByStandardBrandName
[
$brandName
]
=
$skuCount
;
}
arsort
(
$skuCountByStandardBrandName
);
$skuCountByStandardBrandName
=
array_values
(
array_flip
(
$skuCountByStandardBrandName
));
}
$itemData
=
[
$supplier
[
'supplier_name'
],
array_get
(
config
(
'fixed.SupplierGroup'
),
$supplier
[
'supplier_group'
],
'未设置'
),
$skuUserDepartment
,
date
(
'Y-m-d H:i:s'
,
$supplier
[
'sku_update_time'
]),
!
empty
(
$supplierAccountMap
[
$supplierId
])
?
'是'
:
'否'
,
array_get
(
$frqData
,
'quote_num'
,
0
),
array_get
(
$frqData
,
'pur_num'
,
0
),
array_get
(
$frqData
,
'pur_amount'
,
0
),
$supplier
[
'sku_num'
],
array_get
(
$skuCountByStandardBrandName
,
0
,
''
),
array_get
(
$skuCountByStandardBrandName
,
1
,
''
),
array_get
(
$skuCountByStandardBrandName
,
2
,
''
),
array_get
(
$skuCountByStandardBrandName
,
3
,
''
),
array_get
(
$skuCountByStandardBrandName
,
4
,
''
),
];
$excelData
[]
=
$itemData
;
}
//近半年内,查出更新过的品牌对应SKU数量最多排名(前100名);需要字段“品牌名称,SKU数量,型号数量”
$excelData2
=
[];
$countByBrandName
=
SkuUploadItem
::
where
(
'status'
,
3
)
->
where
(
'create_time'
,
'>='
,
$halfYearTime
)
->
selectRaw
(
'brand_name,count(distinct(sku_id)) as sku_count,count(distinct(spu_id)) as spu_id_count'
)
->
groupBy
(
'brand_name'
)
->
orderBy
(
'sku_count'
,
'desc'
)
->
get
()
->
toArray
();
foreach
(
$countByBrandName
as
&
$value
)
{
//然后获取每个品牌的标准品牌
$brandName
=
$value
[
'brand_name'
];
$brandNameAllKey
=
md5
(
strtolower
(
$brandName
));
$brandId
=
$redis
->
hget
(
'brand_name_all'
,
$brandNameAllKey
);
if
(
empty
(
$brandId
))
{
$value
[
'standard_brand_id'
]
=
0
;
continue
;
continue
;
}
}
//然后找到标准品牌id
$standardBrandId
=
$redis
->
hget
(
'standard_brand_mapping'
,
$brandId
);
$value
[
'standard_brand_id'
]
=
$standardBrandId
;
$standardBrand
=
$redis
->
hget
(
'standard_brand'
,
$standardBrandId
);
$standardBrand
=
json_decode
(
$standardBrand
,
true
);
$value
[
'standard_brand_name'
]
=
$standardBrand
[
'brand_name'
];
}
$region
=
$supplier
[
'region'
];
//统计标品的sku数量
$regionType
=
$region
==
SupplierChannelModel
::
REGION_CN
?
1
:
2
;
$dataByStandardBrandName
=
collect
(
$countByBrandName
)
->
groupBy
(
'standard_brand_name'
)
->
toArray
();
$unitedCompanyInfo
=
(
new
CompanyService
())
->
getUnitedCompanyInfo
(
$supplier
[
'supplier_name'
],
$supplier
[
'tax_number'
],
$regionType
);
$countByStandardBrandName
=
[];
$companyInfo
=
$unitedCompanyInfo
[
'united_company_info'
];
foreach
(
$dataByStandardBrandName
as
$brandName
=>
$standardBrandItem
)
{
if
(
!
empty
(
$companyInfo
))
{
if
(
empty
(
$brandName
))
{
$groupCode
=
array_get
(
$companyInfo
,
'group_code'
);
continue
;
if
(
$groupCode
)
{
dd
(
$oldSupplierName
,
$supplier
[
'supplier_name'
]);
continue
;
//SupplierChannelModel::where('supplier_id', $supplier['supplier_id'])->update([
// 'supplier_name' => $supplier['supplier_name'],
// 'group_code' => $groupCode
//]);
}
}
}
$skuCount
=
0
;
foreach
(
$standardBrandItem
as
$value
)
{
$skuCount
=
$value
[
'sku_count'
];
$goodsNameCount
=
$value
[
'spu_id_count'
];
}
$countByStandardBrandName
[
$brandName
]
=
[
'sku_count'
=>
$skuCount
,
'spu_id_count'
=>
$goodsNameCount
,
];
}
}
}
uasort
(
$countByStandardBrandName
,
function
(
$a
,
$b
)
{
return
$b
[
'sku_count'
]
>
$a
[
'sku_count'
];
});
$excel2Header
=
[
'品牌名称'
,
'SKU数量'
,
'型号数量'
,
];
foreach
(
$countByStandardBrandName
as
$brandName
=>
$value
)
{
$excelData2
[]
=
[
$brandName
,
$value
[
'sku_count'
],
$value
[
'spu_id_count'
],
];
}
array_unshift
(
$excelData
,
$header
);
array_unshift
(
$excelData2
,
$excel2Header
);
Excel
::
create
(
'供应商导出'
,
function
(
$excel
)
use
(
$excelData
,
$excelData2
)
{
$excelData
=
array_map
(
'array_values'
,
$excelData
);
$excelData2
=
array_map
(
'array_values'
,
$excelData2
);
$excel
->
sheet
(
'sheet1'
,
function
(
$sheet
)
use
(
$excelData
)
{
$sheet
->
fromArray
(
$excelData
);
});
$excel
->
sheet
(
'sheet2'
,
function
(
$sheet
)
use
(
$excelData2
)
{
$sheet
->
fromArray
(
$excelData2
);
});
})
->
export
(
'xlsx'
);
}
}
}
app/Http/routes.php
View file @
34255c38
...
@@ -82,5 +82,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
...
@@ -82,5 +82,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
dd
((
new
\App\Http\Services\CompanyService
())
->
checkCompanyEntity
(
'中山市汉仁电子有限公司'
)
);
(
new
\App\Http\Services\DataService
())
->
exportSupplierDataForLevel
(
);
});
});
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