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
e2cf5fa3
authored
Jun 25, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
导出供应商方法
parent
4cef2975
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
1 deletions
app/Http/Services/DataService.php
app/Http/routes.php
public/data/没有SKU采购员供应商清单.xlsx
app/Http/Services/DataService.php
View file @
e2cf5fa3
...
...
@@ -1406,4 +1406,100 @@ class DataService
}
}
public
function
exportSupplierByPurchaseAmount
()
{
ini_set
(
'memory_limit'
,
-
1
);
$isUpdate
=
false
;
$filePath
=
public_path
(
'data'
)
.
DIRECTORY_SEPARATOR
.
'没有SKU采购员供应商清单.xlsx'
;
$supplierCodeList
=
[];
Excel
::
selectSheetsByIndex
(
0
)
->
load
(
$filePath
,
function
(
$reader
)
use
(
$isUpdate
,
&
$supplierCodeList
)
{
$reader
->
sheet
(
'Sheet1'
,
function
()
use
(
$reader
,
$isUpdate
,
&
$supplierCodeList
)
{
$allSuppliers
=
$reader
->
all
()
->
toArray
();
foreach
(
$allSuppliers
as
$supplier
)
{
$supplierCodeList
[]
=
$supplier
[
0
];
}
});
});
$suppliers
=
SupplierChannelModel
::
select
([
'supplier_name'
,
'supplier_code'
,
'supplier_id'
,
'channel_uid'
,
'yunxin_channel_uid'
])
->
where
(
'is_type'
,
0
)
->
whereIn
(
'supplier_code'
,
$supplierCodeList
)
->
whereRaw
(
'supplier_name NOT LIKE "%-1"'
)
->
get
()
->
toArray
();
$excelData
=
[];
$header
=
[
'供应商名称'
,
'最大金额采购员'
,
'sku采购员'
,
];
$intraCodeModel
=
new
IntracodeModel
();
$users
=
$intraCodeModel
->
getSampleName
(
true
);
foreach
(
$suppliers
as
$supplier
)
{
$skuUserName
=
$skuUserNameRaw
=
$purchasePurchaseName
=
''
;
if
(
$supplier
[
'yunxin_channel_uid'
])
{
$skuUserNameRaw
=
array_get
(
$users
,
$supplier
[
'yunxin_channel_uid'
]);
$skuUserName
=
$skuUserNameRaw
;
}
if
(
$supplier
[
'channel_uid'
])
{
$purchaseCodeIdList
=
explode
(
','
,
$supplier
[
'channel_uid'
]);
$channelUids
=
IntracodeModel
::
whereIn
(
'code_id'
,
$purchaseCodeIdList
)
->
pluck
(
'admin_id'
)
->
toArray
();
//去采购系统找最多金额的用户id
$purchaseAmountMap
=
[];
foreach
(
$channelUids
as
$channelUid
)
{
//去采购系统取采购单金额
$purchaseOrders
=
PurchaseOrderModel
::
where
(
'purchase_uid'
,
$channelUid
)
->
where
(
'supplier_sn'
,
$supplier
[
'supplier_code'
])
->
select
([
'purchase_amount'
,
'exchange_rate'
,
'currency'
])
->
where
(
'status'
,
'!='
,
-
3
)
->
get
()
->
toArray
();
//计算出采购金额
$totalAmount
=
0
;
foreach
(
$purchaseOrders
as
$purchaseOrder
)
{
if
(
$purchaseOrder
[
'currency'
]
==
1
)
{
$totalAmount
+=
$purchaseOrder
[
'purchase_amount'
]
*
$purchaseOrder
[
'exchange_rate'
]
*
1.13
;
}
else
{
$totalAmount
+=
$purchaseOrder
[
'purchase_amount'
]
*
$purchaseOrder
[
'exchange_rate'
];
}
}
$purchaseAmountMap
[
$channelUid
]
=
$totalAmount
;
}
if
(
!
empty
(
$purchaseAmountMap
))
{
arsort
(
$purchaseAmountMap
);
if
(
array_values
(
$purchaseAmountMap
)[
0
]
==
0
)
{
$purchasePurchaseName
=
''
;
}
else
{
$maxAmountPurchaseAdminId
=
array_keys
(
$purchaseAmountMap
)[
0
];
$codeId
=
IntracodeModel
::
where
(
'admin_id'
,
$maxAmountPurchaseAdminId
)
->
value
(
'code_id'
);
if
(
$codeId
)
{
$purchasePurchaseName
=
array_get
(
$users
,
$codeId
);
}
else
{
$purchasePurchaseName
=
''
;
}
}
}
}
else
{
$purchasePurchaseName
=
''
;
}
$itemData
=
[
$supplier
[
'supplier_name'
],
$purchasePurchaseName
,
$skuUserName
,
];
$excelData
[]
=
$itemData
;
}
array_unshift
(
$excelData
,
$header
);
dd
(
$excelData
);
Excel
::
create
(
'供应商导出'
,
function
(
$excel
)
use
(
$excelData
)
{
$excel
->
sheet
(
'sheet1'
,
function
(
$sheet
)
use
(
$excelData
)
{
$sheet
->
fromArray
(
$excelData
);
});
})
->
export
(
'csv'
);
}
}
\ No newline at end of file
app/Http/routes.php
View file @
e2cf5fa3
...
...
@@ -73,7 +73,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
(
new
\App\Http\Services\DataService
())
->
statisticsSkuNumber
();
(
new
\App\Http\Services\DataService
())
->
exportSupplierByPurchaseAmount
();
// (new \App\Http\Services\DataService())->initialMainBrandsLimit();
// (new \App\Http\Services\DataService())->initialMainBrandsToSkuRuler();
...
...
public/data/没有SKU采购员供应商清单.xlsx
0 → 100644
View file @
e2cf5fa3
No preview for this file type
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