Commit 7dcecc38 by 杨树贤

fix

parent 376990bc
......@@ -1264,7 +1264,7 @@ class DataService
}
}
//判断是否已经存在,不存在就新增,存在就更新
$exist = SupplierContactModel::where('supplier_id',$supplier['supplier_id'])->whereIn('can_check_uids', [
$exist = SupplierContactModel::where('supplier_id', $supplier['supplier_id'])->whereIn('can_check_uids', [
'10009',
'10546'
])->value('contact_id');
......@@ -1308,4 +1308,114 @@ class DataService
}
}
}
public static function repair($updateData = false)
{
ini_set('memory_limit', -1);
// 从CSV文件读取历史供应商数据
$csvFilePath = public_path('data') . DIRECTORY_SEPARATOR . '数据跟单员.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]);
$dataFollowers = trim($data[2]);
$onlinePurchaser = trim($data[3]);
$onlinePurchaser = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $onlinePurchaser);
// 处理多个数据跟单员的情况
$followerList = [];
if (!empty($dataFollowers)) {
// 分割多个跟单员(使用顿号、中文逗号、英文逗号)
$followerList = preg_split('/[、,,]/u', $dataFollowers);
$followerList = array_map('trim', $followerList);
$followerList = array_filter($followerList);
}
$historicalSuppliers[$supplierCode] = [
'name' => trim($data[1]),
'data_followers' => $followerList,
'online_purchaser' => $onlinePurchaser
];
}
}
fclose($stream);
} else {
Log::error('数据跟单员.csv文件未找到');
return;
}
$inXslSupplierCodes = array_keys($historicalSuppliers);
//获取所有供应商
$supplierList = SupplierChannelModel::whereIn('supplier_code', $inXslSupplierCodes)->select([
'supplier_id',
'channel_uid',
'supplier_code',
'yunxin_channel_uid',
'region'
])->get();
foreach ($supplierList as $key => $supplier) {
$yunxinChannelContact = SupplierContactModel::where('supplier_id', $supplier['supplier_id'])
->where('can_check_uids', $supplier['yunxin_channel_uid'])->first();
if (empty($yunxinChannelContact)) {
//并且有跟单采购员,那么取信息补充增减回去
$contact = SupplierContactModel::where('channel_user_type', 4)
->where('supplier_telephone', '!=', '')->first();
if (empty($contact)) {
continue;
}
//存在需要补回去的数据
\dump('supplier_code : ' . $supplier['supplier_code']);
if ($updateData) {
//新增回去
SupplierContactModel::insert([
'supplier_id' => $supplier['supplier_id'],
'supplier_consignee' => $contact['supplier_consignee'],
'supplier_telephone' => $contact['supplier_telephone'],
'supplier_fax' => $contact['supplier_fax'],
'supplier_qq' => $contact['supplier_qq'],
'supplier_mobile' => $contact['supplier_mobile'],
'supplier_email' => $contact['supplier_email'],
'supplier_position' => $contact['supplier_position'],
'can_check_uids' => $contact['can_check_uids'],
'add_time' => time(),
'admin_id' => $contact['admin_id'],
'channel_user_type' => 1,
]);
}
}
}
}
}
......@@ -97,7 +97,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
DataService::initInventoryNotInXsl();
DataService::repair();
// DataService::initInventoryNotInXsl(true);
if (request()->get('delete')) {
}
......
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