Commit a2af5d84 by 杨树贤

供应商导出

parent c137e3cd
......@@ -38,7 +38,7 @@ class SetSupplierFollowUp extends Command
// $service->importSupplierGroup(true);
// $service->changeSupplierType();
// $service->generateYunxinAccount(true);
$service->importSupplierLevel();
$service->exportSupplierForUnionData();
// $service->makeSupplierSystemTagAbnormal();
}
}
......@@ -469,49 +469,69 @@ class DataService
//导出供应商
public function exportSupplierForUnionData()
{
$suppliers = SupplierChannelModel::select([
'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();
$suppliers = SupplierChannelModel::where('is_type', 0)->whereRaw('supplier_name NOT LIKE "%-1"')->get();
$excelData = [];
$header = [
'ID',
'原系统供应商名称',
'标准供应商名称',
'创建时间',
'采购',
'部门组别',
'所有采购',
'供应商名称',
'主营品牌',
'性质',
'等级',
'品质协议是否签署',
'是否平台供应商',
'是否云芯商家',
'是否SKU上架中',
'现有SKU采购员或者意向分配采购员',
'采购所在采购部门',
];
$intraCodeModel = new IntracodeModel();
$users = $intraCodeModel->getSampleName(true);
foreach ($suppliers as $supplier) {
$firstChannelUserName = $firstChannelUserDepartmentName = $allChannelUserName = '';
$channelUids = $supplier['channel_uid'] ? explode(',', $supplier['channel_uid']) : [];
if ($channelUids) {
$channelUsers = (new AdminUserService())->getAdminUserListByCodeIds($channelUids);
if (!empty($channelUsers)) {
$firstChannelUser = $channelUsers[0];
$firstChannelUserDepartmentName = (new DepartmentModel())->where('department_id',
$firstChannelUser['department_id'])
->value('department_name');
$firstChannelUserName = $firstChannelUser['name'];
$allChannelUserName = implode(',', array_column($channelUsers, 'name'));
$mainBrands = (new SupplierTransformer())->getMainBrandNames($supplier['main_brands']);
$attachmentsField = SupplierAttachmentsModel::where('supplier_id', $supplier['supplier_id'])->pluck('field_name')->toArray();
$hasPinzhi = $hasHezuo = '无';
if (in_array('quality_assurance_agreement', $attachmentsField)) {
$hasPinzhi = '有';
}
if (in_array('cooperation_agreement', $attachmentsField)) {
$hasHezuo = '有';
}
$isYunxin = '否';
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.'(采购系统下单最多)';
}
}
}
$itemData = [
$supplier['supplier_id'],
$supplier['supplier_name'],
'',
$supplier['create_time'] ? date('Y-m-d H:i:s', $supplier['create_time']) : '',
$firstChannelUserName,
$firstChannelUserDepartmentName,
$allChannelUserName,
$skuUserDepartment = '';
if ($skuUserNameRaw) {
$skuUserDepartment = (new DepartmentService())->getDepartmentNameByUserName($skuUserNameRaw);
}
$itemData = [
$supplier['supplier_name'],
$mainBrands,
array_get(config('fixed.SupplierGroup'), $supplier['supplier_group'], '未设置'),
$supplier['level'],
$hasPinzhi,
$hasHezuo,
$isYunxin,
$supplier['sku_num'] > 0 ? "是" : "否",
$skuUserName,
$skuUserDepartment
];
$excelData[] = $itemData;
}
......@@ -520,7 +540,7 @@ class DataService
$excel->sheet('sheet1', function ($sheet) use ($excelData) {
$sheet->fromArray($excelData);
});
})->export('csv');
})->store('csv');
}
public function exportSupplierJsonForUnited()
......
......@@ -248,7 +248,7 @@ class SupplierTransformer
return $supplier;
}
private function getMainBrandNames($mainBrandsIds)
public function getMainBrandNames($mainBrandsIds)
{
$mainBrandsIds = explode(',', $mainBrandsIds);
$redis = new RedisModel();
......
......@@ -63,7 +63,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
\App\Model\SupplierChannelModel::where('supplier_code', 'L0014845')->update([
'supplier_name' => 'HK GANGJIANXIANG TRADE CO LTD',
]);
(new \App\Http\Services\DataService())->exportSupplierForUnionData();
});
......@@ -79,6 +79,18 @@ class IntracodeModel extends Model
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()
{
......
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