Commit 2c7af681 by 杨树贤

跑品牌脚本

parent c432aea0
...@@ -1284,8 +1284,110 @@ class DataService ...@@ -1284,8 +1284,110 @@ class DataService
dd(count((array_column($stockInItems, 'stock_in_item_id')))); dd(count((array_column($stockInItems, 'stock_in_item_id'))));
} }
public function deleteSupplierAccount() //统计有上传sku的供应商
public function exportHasSkuSupplierList()
{ {
SupplierAccountModel::where('id', 54)->delete(); $header = [
'采购部门',
'sku采购员',
'供应商性质',
'供应商编码',
'供应商名称',
'是否开通云芯',
'接入方式',
'sku上架数量',
'末次更新时间'
];
$intraCodeModel = new IntracodeModel();
$users = $intraCodeModel->getSampleName(true);
$excelData = [];
$suppliers = SupplierChannelModel::where('sku_num', '>', 0)->where('is_type', 0)->get()->toArray();
foreach ($suppliers as $supplier) {
$skuUserNameRaw = array_get($users, $supplier['yunxin_channel_uid']);
$departmentName = (new DepartmentService())->getDepartmentNameByUserName($skuUserNameRaw);
//判断是否是api对接那边的供应商
$isApiSupplier = DataManageModel::where('canal', $supplier['supplier_code'])->where('is_type', 0)->exists();
//末次人工更新时间
$lastUpload = SkuUploadLogModel::where('supplier_code', $supplier['supplier_code'])->orderBy('create_time', 'desc')
->first();
$lastUploadTime = '';
if ($lastUpload) {
$lastUpload = $lastUpload->toArray();
$lastUploadTime = date('Y-md-m H:i:s', $lastUpload['create_time']);
}
$excelData[] = [
$departmentName,
$skuUserNameRaw,
array_get(config('fixed.SupplierGroup'), $supplier['supplier_group'], '未设置'),
$supplier['supplier_code'],
$supplier['supplier_name'],
strpos($supplier['stockup_type'], "5") !== false ? '是' : '否',
$isApiSupplier ? 'API和采集对接' : '人工上传',
$supplier['sku_num'],
$lastUploadTime
];
}
array_unshift($excelData, $header);
Excel::create('供应商统计报表', function ($excel) use ($excelData) {
$excel->sheet('sheet1', function ($sheet) use ($excelData) {
$sheet->fromArray($excelData);
});
})->export('csv');
} }
//导入主营品牌
public function importMainBrands()
{
$isUpdate = request()->input('is_update', 0);
ini_set('memory_limit', -1);
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_brands.xlsx';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($isUpdate) {
$reader->sheet('Sheet1', function () use ($reader, $isUpdate) {
$allBrands = $reader->all()->toArray();
$allBrandsGroupBySupplierCode = [];
foreach ($allBrands as $brand) {
$supplierCode = trim($brand[0]);
$brandName = trim($brand[2]);
$supplierCodeList = array_keys($allBrandsGroupBySupplierCode);
if (in_array($supplierCode, $supplierCodeList)) {
$allBrandsGroupBySupplierCode[$supplierCode][] = trim($brandName);
} else {
$allBrandsGroupBySupplierCode[$supplierCode][] = trim($brandName);
}
}
foreach ($allBrandsGroupBySupplierCode as $supplierCode => $brands) {
$supplier = SupplierChannelModel::select(['main_brands','supplier_id','supplier_code'])->where('supplier_code', $supplierCode)->first();
if (empty($supplier)) {
continue;
}
$supplier = $supplier->toArray();
$supplier['main_brands'] = trim($supplier['main_brands'], ',');
dump('供应商编码 : '.$supplierCode);
//找出所有标品的id
$standardBrandIds = StandardBrandModel::whereIn('brand_name', $brands)->pluck('standard_brand_id')->toArray();
dump('excel得出的标品ids : '.implode(',', $standardBrandIds));
if ($supplier['main_brands']) {
dump('原来有标品id :'. $supplier['main_brands']);
$supplier['main_brands'] = explode(',', $supplier['main_brands']);
$mainBrands = array_merge($supplier['main_brands'],$standardBrandIds);
} else {
$mainBrands = $standardBrandIds;
}
$mainBrands = implode(',', $mainBrands);
if ($isUpdate) {
SupplierChannelModel::where('supplier_code',$supplierCode)->update([
'main_brands' => $mainBrands,
]);
}
dump($mainBrands);
}
});
});
} catch (\Exception $exception) {
dd($exception);
}
}
} }
\ No newline at end of file
...@@ -67,12 +67,14 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -67,12 +67,14 @@ 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())->statisticsSkuNumber();
(new \App\Http\Services\DataService())->importMainBrands();
// (new \App\Http\Services\DataService())->exportHasSkuSupplierList();
// (new \App\Http\Services\DataService())->initialMainBrandsLimit(); // (new \App\Http\Services\DataService())->initialMainBrandsLimit();
// (new \App\Http\Services\DataService())->initialMainBrandsToSkuRuler(); // (new \App\Http\Services\DataService())->initialMainBrandsToSkuRuler();
\App\Model\LogModel::where('action','批量配置供应商sku上架有效期')->update([ //\App\Model\LogModel::where('action','批量配置供应商sku上架有效期')->update([
'ignore_audit_check' => 1 // 'ignore_audit_check' => 1
]); //]);
// \App\Model\SupplierChannelModel::where('supplier_name', '厦门市三安集成电路有限公司')->update([ // \App\Model\SupplierChannelModel::where('supplier_name', '厦门市三安集成电路有限公司')->update([
// 'status' => 2, // 'status' => 2,
// 'update_time' => time(), // 'update_time' => time(),
......
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