Commit 35973847 by 杨树贤

重名供应商导出

parent 839e74cd
...@@ -635,21 +635,33 @@ class DataService ...@@ -635,21 +635,33 @@ class DataService
public static function exportNameInvalid() public static function exportNameInvalid()
{ {
$suppliers = DB::connection('web')->select('SELECT *, count(*) FROM lie_supplier_channel WHERE is_type=0 and group_code != "" GROUP BY supplier_name having count(*) > 1'); $suppliers = DB::connection('web')->select('SELECT *, count(*) FROM lie_supplier_channel WHERE is_type=0 and group_code != "" GROUP BY supplier_name having count(*) > 1');
foreach ($suppliers as $supplier) {
}
$supplierNameList = array_column($suppliers, 'supplier_name');
$suppliers = SupplierChannelModel::whereIn('supplier_name', $supplierNameList)->orderBy('supplier_name', 'desc')->get()->toArray();
$transformer = new SupplierTransformer();
$suppliers = $transformer->transformList($suppliers);
Excel::create('重名供应商导出', function ($excel) use ($suppliers) { Excel::create('重名供应商导出', function ($excel) use ($suppliers) {
$header = [ $header = [
'供应商名字',
'供应商编码', '供应商编码',
'集团编码', '供应商名字',
'状态',
'供应商性质',
'采购员',
'线上采购员',
'最新上传SKU时间',
]; ];
$excelData = []; $excelData = [];
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
$excelData[] = [ $excelData[] = [
$supplier['supplier_name'], $supplier['supplier_name'],
$supplier['supplier_code'], $supplier['supplier_code'],
$supplier['group_code'], $supplier['status_name'],
$supplier['supplier_group'],
$supplier['channel_username'],
$supplier['yunxin_channel_username'],
$supplier['last_upload_sku_time'],
]; ];
} }
array_unshift($excelData, $header); array_unshift($excelData, $header);
...@@ -657,7 +669,7 @@ class DataService ...@@ -657,7 +669,7 @@ class DataService
$sheet->fromArray($excelData); $sheet->fromArray($excelData);
}); });
})->export('csv'); })->export('xlsx');
} }
public static function getSpuAttrs() public static function getSpuAttrs()
...@@ -672,33 +684,32 @@ class DataService ...@@ -672,33 +684,32 @@ class DataService
ini_set('memory_limit', '2048M'); ini_set('memory_limit', '2048M');
$filePath = public_path('data') . DIRECTORY_SEPARATOR . '爱智平台SKU汇总表-2024.09.19.xlsx'; $filePath = public_path('data') . DIRECTORY_SEPARATOR . '爱智平台SKU汇总表-2024.09.19.xlsx';
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($isUpdate) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($isUpdate) {
$reader->sheet('细分商品分类', function () use ($reader, $isUpdate) { $reader->sheet('细分商品分类', function () use ($reader, $isUpdate) {
foreach ($reader->all()->toArray() as $key => $item) { foreach ($reader->all()->toArray() as $key => $item) {
if ($key == 0 || $key > 100) { if ($key == 0 || $key > 100) {
continue; continue;
}
$skuId = trim(trim($item[1]),"\t");
$oldSkuName = trim(trim($item[2],"\t"));
$newSkuName = trim(trim($item[3],"\t"));
dump($skuId,$oldSkuName,$newSkuName);
//直接去修改sku的sku_name
$dbInfo = getSpuSkuDb($skuId);
$connection = DB::connection($dbInfo["db"]);
$table = $dbInfo['table'];
$skuName = $connection->table($table)->where('goods_id', $skuId)->value('goods_name');
if (empty($skuName)) {
dump('sku_id找不到');
}
dump($skuName);
} }
});
$skuId = trim(trim($item[1]), "\t");
$oldSkuName = trim(trim($item[2], "\t"));
$newSkuName = trim(trim($item[3], "\t"));
dump($skuId, $oldSkuName, $newSkuName);
//直接去修改sku的sku_name
$dbInfo = getSpuSkuDb($skuId);
$connection = DB::connection($dbInfo["db"]);
$table = $dbInfo['table'];
$skuName = $connection->table($table)->where('goods_id', $skuId)->value('goods_name');
if (empty($skuName)) {
dump('sku_id找不到');
}
dump($skuName);
}
}); });
});
} }
} }
...@@ -84,6 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -84,6 +84,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
\App\Http\Services\DataService::exportNameInvalid();
//$goodsId = request()->input('goods_id'); //$goodsId = request()->input('goods_id');
//if (empty($goodsId)) { //if (empty($goodsId)) {
// return 'goods id null'; // return 'goods id null';
......
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