Commit e2cf5fa3 by 杨树贤

导出供应商方法

parent 4cef2975
...@@ -1244,12 +1244,12 @@ class DataService ...@@ -1244,12 +1244,12 @@ class DataService
public function statisticsSkuNumber() public function statisticsSkuNumber()
{ {
$excludeSupplierCodeList = [ $excludeSupplierCodeList = [
'L0004938', 'L0004938',
'L0007913', 'L0007913',
'L0011546', 'L0011546',
'L0001175', 'L0001175',
'L0007243', 'L0007243',
'L0015040', 'L0015040',
]; ];
$dataManagerSupplierCodeList = DataManageModel::where('is_type', 0)->where('canal', '!=', '')->pluck('canal')->toArray(); $dataManagerSupplierCodeList = DataManageModel::where('is_type', 0)->where('canal', '!=', '')->pluck('canal')->toArray();
...@@ -1406,4 +1406,100 @@ class DataService ...@@ -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
...@@ -73,7 +73,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -73,7 +73,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
Route::match(['get', 'post'], '/test', 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())->initialMainBrandsLimit();
// (new \App\Http\Services\DataService())->initialMainBrandsToSkuRuler(); // (new \App\Http\Services\DataService())->initialMainBrandsToSkuRuler();
......
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