Commit a2af5d84 by 杨树贤

供应商导出

parent c137e3cd
...@@ -38,7 +38,7 @@ class SetSupplierFollowUp extends Command ...@@ -38,7 +38,7 @@ class SetSupplierFollowUp extends Command
// $service->importSupplierGroup(true); // $service->importSupplierGroup(true);
// $service->changeSupplierType(); // $service->changeSupplierType();
// $service->generateYunxinAccount(true); // $service->generateYunxinAccount(true);
$service->importSupplierLevel(); $service->exportSupplierForUnionData();
// $service->makeSupplierSystemTagAbnormal(); // $service->makeSupplierSystemTagAbnormal();
} }
} }
...@@ -469,49 +469,69 @@ class DataService ...@@ -469,49 +469,69 @@ class DataService
//导出供应商 //导出供应商
public function exportSupplierForUnionData() public function exportSupplierForUnionData()
{ {
$suppliers = SupplierChannelModel::select([ $suppliers = SupplierChannelModel::where('is_type', 0)->whereRaw('supplier_name NOT LIKE "%-1"')->get();
'supplier_id',
'supplier_code',
'supplier_name',
'channel_uid',
'create_time',
])->where('is_type', 0)->where('create_time', '>', 1655778780)
->where('update_time', '>', 1655778780)->where('group_code', '!=', '')
->whereRaw('supplier_name NOT LIKE "%-1"')->get();
$excelData = []; $excelData = [];
$header = [ $header = [
'ID', '供应商名称',
'原系统供应商名称', '主营品牌',
'标准供应商名称', '性质',
'创建时间', '等级',
'采购', '品质协议是否签署',
'部门组别', '是否平台供应商',
'所有采购', '是否云芯商家',
'是否SKU上架中',
'现有SKU采购员或者意向分配采购员',
'采购所在采购部门',
]; ];
$intraCodeModel = new IntracodeModel();
$users = $intraCodeModel->getSampleName(true);
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
$firstChannelUserName = $firstChannelUserDepartmentName = $allChannelUserName = ''; $mainBrands = (new SupplierTransformer())->getMainBrandNames($supplier['main_brands']);
$channelUids = $supplier['channel_uid'] ? explode(',', $supplier['channel_uid']) : []; $attachmentsField = SupplierAttachmentsModel::where('supplier_id', $supplier['supplier_id'])->pluck('field_name')->toArray();
if ($channelUids) { $hasPinzhi = $hasHezuo = '无';
$channelUsers = (new AdminUserService())->getAdminUserListByCodeIds($channelUids); if (in_array('quality_assurance_agreement', $attachmentsField)) {
if (!empty($channelUsers)) { $hasPinzhi = '有';
$firstChannelUser = $channelUsers[0]; }
$firstChannelUserDepartmentName = (new DepartmentModel())->where('department_id', if (in_array('cooperation_agreement', $attachmentsField)) {
$firstChannelUser['department_id']) $hasHezuo = '有';
->value('department_name'); }
$firstChannelUserName = $firstChannelUser['name']; $isYunxin = '否';
$allChannelUserName = implode(',', array_column($channelUsers, 'name')); if (str_contains("5", $supplier['stockup_type'])) {
} $isYunxin = '是';
}
$skuUserName = $skuUserNameRaw = '';
if ($supplier['yunxin_channel_uid']) {
$skuUserNameRaw = array_get($users, $supplier['yunxin_channel_uid']);
$skuUserName = $skuUserNameRaw.'(供应商系统设置)';
}else{
//去采购系统找最多单的用户id
$mostPurchaseOrderUser = PurchaseOrderModel::selectRaw('purchase_uid,supplier_id,COUNT(*) AS purchase_order_num')
->where('supplier_id',$supplier['supplier_id'])
->groupBy('purchase_uid')->orderBy('purchase_order_num','DESC')->first();
if (!empty($mostPurchaseOrderUser)) {
$mostPurchaseOrderUser = $mostPurchaseOrderUser->toArray();
$codeId = IntracodeModel::where('admin_id',$mostPurchaseOrderUser['purchase_uid'])->value('code_id');
if ($codeId) {
$skuUserNameRaw = array_get($users, $codeId);
$skuUserName = $skuUserNameRaw.'(采购系统下单最多)';
}
}
}
$skuUserDepartment = '';
if ($skuUserNameRaw) {
$skuUserDepartment = (new DepartmentService())->getDepartmentNameByUserName($skuUserNameRaw);
} }
$itemData = [ $itemData = [
$supplier['supplier_id'],
$supplier['supplier_name'], $supplier['supplier_name'],
'', $mainBrands,
$supplier['create_time'] ? date('Y-m-d H:i:s', $supplier['create_time']) : '', array_get(config('fixed.SupplierGroup'), $supplier['supplier_group'], '未设置'),
$firstChannelUserName, $supplier['level'],
$firstChannelUserDepartmentName, $hasPinzhi,
$allChannelUserName, $hasHezuo,
$isYunxin,
$supplier['sku_num'] > 0 ? "是" : "否",
$skuUserName,
$skuUserDepartment
]; ];
$excelData[] = $itemData; $excelData[] = $itemData;
} }
...@@ -520,7 +540,7 @@ class DataService ...@@ -520,7 +540,7 @@ class DataService
$excel->sheet('sheet1', function ($sheet) use ($excelData) { $excel->sheet('sheet1', function ($sheet) use ($excelData) {
$sheet->fromArray($excelData); $sheet->fromArray($excelData);
}); });
})->export('csv'); })->store('csv');
} }
public function exportSupplierJsonForUnited() public function exportSupplierJsonForUnited()
......
...@@ -248,7 +248,7 @@ class SupplierTransformer ...@@ -248,7 +248,7 @@ class SupplierTransformer
return $supplier; return $supplier;
} }
private function getMainBrandNames($mainBrandsIds) public function getMainBrandNames($mainBrandsIds)
{ {
$mainBrandsIds = explode(',', $mainBrandsIds); $mainBrandsIds = explode(',', $mainBrandsIds);
$redis = new RedisModel(); $redis = new RedisModel();
......
...@@ -63,7 +63,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -63,7 +63,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
\App\Model\SupplierChannelModel::where('supplier_code', 'L0014845')->update([ (new \App\Http\Services\DataService())->exportSupplierForUnionData();
'supplier_name' => 'HK GANGJIANXIANG TRADE CO LTD',
]);
}); });
...@@ -79,6 +79,18 @@ class IntracodeModel extends Model ...@@ -79,6 +79,18 @@ class IntracodeModel extends Model
return $result; return $result;
} }
//获取简单的内部用户数据
//默认不包含离职的
public function getSampleName($includeResigned = false)
{
$codeList = $this->getEncode($includeResigned);
$result = [];
foreach ($codeList as $code) {
$result[$code['code_id']] = $code['name'];
}
return $result;
}
//获取简单的内部用户数据(包含离职) //获取简单的内部用户数据(包含离职)
public function getAllSampleEncode() public function getAllSampleEncode()
{ {
......
This diff could not be displayed because it is too large.
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