Commit 72cd6358 by 杨树贤

先上数据处理脚本

parent f31abdef
......@@ -1392,14 +1392,14 @@ class DataService
if (empty($yunxinChannelContact)) {
//并且有跟单采购员,那么取信息补充增减回去
$contact = SupplierContactModel::where('channel_user_type', 4)
->where('supplier_id',$supplier['supplier_id'])
->where('supplier_id', $supplier['supplier_id'])
->where('supplier_telephone', '!=', '')->first();
if (empty($contact)) {
$contact = SupplierContactModel::where('channel_user_type', 4)
->where('supplier_id',$supplier['supplier_id'])->first();
if (empty($contact)) {
$contact = SupplierContactModel::where('channel_user_type', 4)
->where('supplier_id', $supplier['supplier_id'])->first();
if (empty($contact)) {
continue;
}
}
}
//存在需要补回去的数据
if ($updateData) {
......@@ -1418,21 +1418,19 @@ class DataService
'admin_id' => $contact['admin_id'],
'channel_user_type' => 1,
]);
}
}
}
}
//找出没有yunxin_sku_id但是有采购跟单员的,然后把采购跟单员给去掉
public function fixSupplierContacts()
//找出没有yunxin_channel_uid但是有采购跟单员的,然后把采购跟单员给去掉
public static function fixSupplierContacts($isUpdate = false, $num = 10)
{
// 查询没有yunxin_sku_id但有采购跟单员的供应商
$suppliers = SupplierChannelModel::whereNull('yunxin_sku_id')
->whereNotNull('channel_uid')
// 查询没有yunxin_channel_uid但有采购跟单员的供应商
$suppliers = SupplierChannelModel::where('yunxin_channel_uid','=','')
->where('channel_uid','!=','')
->limit($num)
->get();
foreach ($suppliers as $supplier) {
// 获取该供应商的所有采购跟单员
$contacts = SupplierContactModel::where('supplier_id', $supplier->supplier_id)
......@@ -1441,17 +1439,125 @@ class DataService
// 如果有采购跟单员,就删除它们
foreach ($contacts as $contact) {
//如果can_check_uids不在 10009
//如果can_check_uids不在 10009 / 10546
if ($contact->can_check_uids != 10009 && $contact->can_check_uids != 10546) {
continue;
}
//判断创建时间是不是2025年1月3日的时间戳之前创建的
//如果是的话,那么就改成普通采购员
if ($contact->add_time < strtotime('2025-01-03')) {
$contact->channel_user_type = 1;
$contact->save();
}else{
// 如果是之后创建的,就删除
$contact->delete();
if ($contact->add_time < strtotime('2025-01-02')) {
\dump('修改 : ' . $contact->contact_id . '编码 : ' . $contact->can_check_uids);
if ($isUpdate) {
$contact->channel_user_type = 1;
$contact->save();
}
} else {
\dump('删除 : ' . $contact->contact_id . '编码 : ' . $contact->can_check_uids);
if ($isUpdate) {
// 如果是之后创建的,就删除
$contact->delete();
}
}
}
}
}
// 2、附件表格里面,跟单采购员全部改为欧阳海梅,需要判断
// 1.3号之前黄瑜娜存在在联系人信息里,则更改黄瑜娜类型为猎芯采购
// 1.3号之后黄瑜娜存在在联系人信息里,则把黄瑜娜删掉,改成欧阳海梅,表格见附件
public static function replaceInventoryUser($updateData = false)
{
ini_set('memory_limit', -1);
// 从CSV文件读取历史供应商数据
$csvFilePath = public_path('data') . DIRECTORY_SEPARATOR . '线上供应商数据ALL.csv';
$historicalSuppliers = [];
if (file_exists($csvFilePath)) {
// 检测文件编码并正确读取
$content = file_get_contents($csvFilePath);
$encoding = mb_detect_encoding($content, ['UTF-8', 'GBK', 'GB2312', 'ASCII'], true);
// 如果不是UTF-8编码,转换为UTF-8
if ($encoding && $encoding !== 'UTF-8') {
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
}
// 将内容写入临时内存流
$stream = fopen('php://memory', 'r+');
fwrite($stream, $content);
rewind($stream);
// 跳过标题行
fgetcsv($stream);
while (($data = fgetcsv($stream)) !== false) {
// 假设CSV格式为: 供应商编码,供应商名称,数据跟单员,线上采购员
if (count($data) >= 4) {
// 确保数据是UTF-8编码
$data = array_map(function ($item) {
if (is_string($item)) {
// 确保字符串是UTF-8编码
$encoding = mb_detect_encoding($item, ['UTF-8', 'GBK', 'GB2312', 'ASCII'], true);
if ($encoding && $encoding !== 'UTF-8') {
return mb_convert_encoding($item, 'UTF-8', $encoding);
}
return $item;
}
return $item;
}, $data);
$supplierCode = trim($data[0]);
$dataFollower = trim($data[7]);
if (!empty($dataFollower)) {
// 分割多个跟单员(使用顿号、中文逗号、英文逗号)
$dataFollower = preg_split('/[、,,]/u', $dataFollower);
}
$historicalSuppliers[$supplierCode] = [
'supplier_code' => trim($data[0]),
'data_follower' => $dataFollower[0],
];
}
}
fclose($stream);
// 2、附件表格里面,跟单采购员全部改为欧阳海梅,需要判断
// 1.3号之前黄瑜娜存在在联系人信息里,则更改黄瑜娜类型为猎芯采购
// 1.3号之后黄瑜娜存在在联系人信息里,则把黄瑜娜删掉,改成欧阳海梅,表格见附件
$adminUserService = new AdminUserService();
foreach ($historicalSuppliers as $key => $item) {
$followerCodeId = $adminUserService->getCodeIdByUserName($item['data_follower']);
$supplierId = SupplierChannelModel::where('supplier_code', $item['supplier_code'])->value('supplier_id');
$newExist = SupplierContactModel::where('supplier_id', $supplierId)->where('can_check_uids', '10326')->where('add_time', '>', strtotime('2025-01-02'))->first();
if ($newExist) {
\dump('黄瑜娜已存在,替换成欧阳海梅');
$newExist = $newExist->toArray();
if ($updateData) {
SupplierContactModel::where('contact_id', $newExist['contact_id'])->update([
'can_check_uids' => $followerCodeId
]);
}
} else {
$existingContact = SupplierContactModel::where('can_check_uids', $followerCodeId)->first();
if ($existingContact) {
// 如果欧阳海梅已存在,修改类型
\dump('欧阳海梅已存在,修改类型');
if ($updateData) {
SupplierContactModel::where('contact_id', $existingContact['contact_id'])->update([
'channel_user_type' => 4,
]);
}
} else {
\dump('欧阳海梅不存在,需要添加');
}
}
}
} else {
Log::error('线上供应商数据ALL.csv文件未找到');
return;
}
}
}
......@@ -338,6 +338,8 @@ class SkuService extends BaseService
$queueData[] = [
'sku_id' => $skuId,
'cp_time' => $data['cp_time'],
'source' => 'supplier',
'user_id' => request()->user->userId,
];
ManualPutawaySkuLog::addManualPutawaySkuLog($skuId, $supplierCodes[$key], 1);
}
......@@ -348,9 +350,10 @@ class SkuService extends BaseService
$queueName = 'lie_footstone_batch_downsku_queue';
$queueData['down_type'] = 2;
$queueData['data'] = $skuIds;
$queueData['source'] = 'supplier';
$queueData['user_id'] = request()->user->userId;
}
$queueData['source'] = 'supplier';
$queueData['user_id'] = request()->user->userId;
QueueService::publishQueueSecond($queueName, $queueData);
} catch (\Exception $exception) {
return $exception;
......
......@@ -97,7 +97,8 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
DataService::repair();
// DataService::replaceInventoryUser();
DataService::fixSupplierContacts(false,10);
// DataService::initInventoryNotInXsl(true);
if (request()->get('delete')) {
}
......
This diff could not be displayed because it is too large.
No preview for this file type
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