Commit ce33544a by 杨树贤

数据脚本完善

parent 94953e01
...@@ -1000,6 +1000,7 @@ class DataService ...@@ -1000,6 +1000,7 @@ class DataService
$supplierCode = trim($data[0]); $supplierCode = trim($data[0]);
$dataFollowers = trim($data[2]); $dataFollowers = trim($data[2]);
$onlinePurchaser = trim($data[3]); $onlinePurchaser = trim($data[3]);
$onlinePurchaser = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $onlinePurchaser);
// 处理多个数据跟单员的情况 // 处理多个数据跟单员的情况
$followerList = []; $followerList = [];
...@@ -1023,12 +1024,14 @@ class DataService ...@@ -1023,12 +1024,14 @@ class DataService
return; return;
} }
$adminUserService = new AdminUserService(); $adminUserService = new AdminUserService();
$intracodeModel = new IntracodeModel();
$historicalSuppliers = array_slice($historicalSuppliers, 0, 50); // 只处理前5个进行测试 $historicalSuppliers = array_slice($historicalSuppliers, 0, 50); // 只处理前5个进行测试
foreach ($historicalSuppliers as $supplierCode => $supplierInfo) { foreach ($historicalSuppliers as $supplierCode => $supplierInfo) {
\dump("----------------------------------------------------------------");
\dump("开始处理供应商: " . $supplierCode . '----' . $supplierInfo['name']);
// 查找供应商 // 查找供应商
$supplier = SupplierChannelModel::where('supplier_code', $supplierCode)->first(); $supplier = SupplierChannelModel::where('supplier_code', $supplierCode)->first();
if (!$supplier) { if (!$supplier) {
\dump("供应商不存在: " . $supplierCode);
continue; continue;
} }
...@@ -1052,12 +1055,16 @@ class DataService ...@@ -1052,12 +1055,16 @@ class DataService
$followerCodeId = $adminUserService->getCodeIdByUserName('邱沛敏'); $followerCodeId = $adminUserService->getCodeIdByUserName('邱沛敏');
if ($followerCodeId) { if ($followerCodeId) {
$dataFollowersCodeIds[] = $followerCodeId; $dataFollowersCodeIds[] = $followerCodeId;
} else {
dd('找不到邱沛敏', $supplierCode, $supplier->region, $supplier);
} }
} else { } else {
// 其他区域分配李尚文杰 // 其他区域分配李尚文杰
$followerCodeId = $adminUserService->getCodeIdByUserName('李尚文杰'); $followerCodeId = $adminUserService->getCodeIdByUserName('李尚文杰');
if ($followerCodeId) { if ($followerCodeId) {
$dataFollowersCodeIds[] = $followerCodeId; $dataFollowersCodeIds[] = $followerCodeId;
} else {
dd('找不到李尚文杰', $supplierCode, $supplier->region, $supplier);
} }
} }
} }
...@@ -1071,62 +1078,95 @@ class DataService ...@@ -1071,62 +1078,95 @@ class DataService
$allChannelUids = array_unique(array_merge($existingChannelUids, $dataFollowersCodeIds)); $allChannelUids = array_unique(array_merge($existingChannelUids, $dataFollowersCodeIds));
$allChannelUids = array_filter($allChannelUids); // 移除空值 $allChannelUids = array_filter($allChannelUids); // 移除空值
\dump('allChannelUids:', $allChannelUids); \dump('跟单采购员 : ' . implode(',', $dataFollowersCodeIds));
if ($updateData) { \dump('所有采购员 : ' . implode(',', $allChannelUids));
// 更新供应商的channel_uid $onlinePurchaserCodeId = $adminUserService->getCodeIdByUserName($onlinePurchaser);
SupplierChannelModel::where('supplier_id', $supplierId)->update([ \dump($onlinePurchaserCodeId);
'channel_uid' => implode(',', $allChannelUids), \dump('需要获取联系人的采购员 : ' . $onlinePurchaserCodeId);
'update_time' => time() if (empty($onlinePurchaserCodeId)) {
]); \dump('表格里的线上采购员不存在,跳过');
continue;
} }
//3.2 数据跟单员的联系人信息:初始化为【线上采购员】维护的联系人信息
// 为每个数据跟单员创建联系人记录 //如果数据跟单员已经存在在供应商的采购员里,也需要把他对应的联系人初始化成线上采购员对应的联系人信息
foreach ($dataFollowersCodeIds as $followerCodeId) { foreach ($dataFollowersCodeIds as $followerCodeId) {
$onlinePurchaserContact = SupplierContactModel::where('can_check_uids', $onlinePurchaserCodeId)->first();
if (!empty($onlinePurchaserContact)) {
$onlinePurchaserContact = $onlinePurchaserContact->toArray();
}
$contactData = [
'supplier_id' => $supplierId,
'supplier_consignee' => !empty($onlinePurchaserContact['supplier_consignee']) ? $onlinePurchaserContact['supplier_consignee'] : '',
'supplier_telephone' => !empty($onlinePurchaserContact['supplier_telephone']) ? $onlinePurchaserContact['supplier_telephone'] : '',
'supplier_fax' => !empty($onlinePurchaserContact['supplier_fax']) ? $onlinePurchaserContact['supplier_fax'] : '',
'supplier_qq' => !empty($onlinePurchaserContact['supplier_qq']) ? $onlinePurchaserContact['supplier_qq'] : '',
'supplier_mobile' => !empty($onlinePurchaserContact['supplier_mobile']) ? $onlinePurchaserContact['supplier_mobile'] : '',
'supplier_email' => !empty($onlinePurchaserContact['supplier_email']) ? $onlinePurchaserContact['supplier_email'] : '',
'supplier_position' => !empty($onlinePurchaserContact['supplier_position']) ? $onlinePurchaserContact['supplier_position'] : '',
];
// 检查是否已存在该数据跟单员的联系人记录 // 检查是否已存在该数据跟单员的联系人记录
$exists = SupplierContactModel::where('supplier_id', $supplierId) $exists = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $followerCodeId) ->where('can_check_uids', $followerCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists(); ->exists();
if ($exists) {
\dump('已经存在跟单联系人 : ' . $followerCodeId . ' 跳过');
continue;
}
if (!$exists) { if (!$exists) {
// 创建联系人记录 // 联系人不存在,需要创建
$contactData = [ //先去判断已经有的供应商联系人里面有没有一样的采购员
'supplier_id' => $supplierId, $existingContact = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $followerCodeId)->where('supplier_telephone', '!=', '')
->first();
if (!empty($existingContact)) {
$existingContact = $existingContact->toArray();
\dump('已存在线上采购员相同联系人 : ' . $followerCodeId . ' 进行信息覆盖');
$contactData = [
'supplier_id' => $supplierId,
'supplier_consignee' => !empty($existingContact['supplier_consignee']) ? $existingContact['supplier_consignee'] : '',
'supplier_telephone' => !empty($existingContact['supplier_telephone']) ? $existingContact['supplier_telephone'] : '',
'supplier_fax' => !empty($existingContact['supplier_fax']) ? $existingContact['supplier_fax'] : '',
'supplier_qq' => !empty($existingContact['supplier_qq']) ? $existingContact['supplier_qq'] : '',
'supplier_mobile' => !empty($existingContact['supplier_mobile']) ? $existingContact['supplier_mobile'] : '',
'supplier_email' => !empty($existingContact['supplier_email']) ? $existingContact['supplier_email'] : '',
'supplier_position' => !empty($existingContact['supplier_position']) ? $existingContact['supplier_position'] : '',
];
}
$contactData = array_merge($contactData, [
'can_check_uids' => $followerCodeId, 'can_check_uids' => $followerCodeId,
'channel_user_type' => 4, // 数据跟单员 'channel_user_type' => 4, // 数据跟单员
'add_time' => time(), 'add_time' => time(),
'admin_id' => 1000 // 系统管理员 'admin_id' => 1000 // 系统管理员
]; ]);
\dump('Creating contact for follower:', $followerCodeId, $supplierId); \dump('创建跟单联系人: ' . $followerCodeId . ' 供应商ID : ' . $supplierId . ' 供应商名称 : ' . $supplierInfo['name']);
if ($updateData) { if ($updateData) {
SupplierContactModel::insert($contactData); SupplierContactModel::insert($contactData);
} }
} }
} }
}
// 更新数据跟单员的联系人信息为线上采购员维护的联系人信息 $allChannelUids = SupplierContactModel::where('supplier_id', $supplierId)
if (!empty($dataFollowersCodeIds)) { ->pluck('can_check_uids')->toArray();
foreach ($dataFollowersCodeIds as $followerCodeId) { $allChannelUids = array_unique($allChannelUids);
// 检查数据跟单员是否已存在对应的采购员code_id且channel_user_type=1 $allChannelUids = array_filter($allChannelUids, function ($value) {
$contact = SupplierContactModel::where('supplier_id', $supplierId) return !empty($value);
->where('can_check_uids', $followerCodeId) });
->where('channel_user_type', 1)
->first(); \dump('最后更新的供应商采购员列表为 : ' . \implode(',', $allChannelUids));
\dump('Checking contact for follower:', $followerCodeId, $supplierId, $contact ? 'exists' : 'not exists', $updateData ? 'update' : 'no update');
if ($contact && $updateData) { if ($updateData) {
// 更新channel_user_type为4 if ($allChannelUids) {
SupplierContactModel::where('contact_id', $contact->contact_id)->update([ SupplierChannelModel::where('supplier_id', $supplierId)->update([
'channel_user_type' => 4 'channel_uid' => \implode(',', $allChannelUids),
]); ]);
} }
} }
} }
Log::info("供应商 {$supplierCode} 数据初始化完成");
} }
Log::info('历史供应商数据初始化完成');
} }
} }
...@@ -96,7 +96,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -96,7 +96,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
DataService::initHistoricalSupplierData(); DataService::initHistoricalSupplierData(false);
// DataService::initSupplierReceiptNationId(); // DataService::initSupplierReceiptNationId();
// SupplierAccountService::initYunxinAccountName(); // SupplierAccountService::initYunxinAccountName();
// DataService::syncSupplierToErp(); // DataService::syncSupplierToErp();
......
...@@ -4,6 +4,8 @@ namespace App\Providers; ...@@ -4,6 +4,8 @@ namespace App\Providers;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
...@@ -14,8 +16,33 @@ class AppServiceProvider extends ServiceProvider ...@@ -14,8 +16,33 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
//共享全局模板变量 // 只在本地环境生效
if ($this->app->environment('local')) {
// 自定义一个新的 Handler
\Symfony\Component\VarDumper\VarDumper::setHandler(function ($var) {
$cloner = new VarCloner();
$dumper = new HtmlDumper();
// 关键:自定义白色背景的样式(覆盖默认黑色)
$dumper->setStyles([
'default' => 'background-color:#fff; color:#222; line-height:1.5; font-weight: normal; font:12px Menlo, Monaco, Consolas, "Courier New", monospace; padding: 15px; border:1px solid #ddd; border-radius:4px; margin:10px 0;',
'num' => 'color:#a71d5d;',
'const' => 'color:#795da3;',
'str' => 'color:#df5000;',
'note' => 'color:#a71d5d;',
'ref' => 'color:#a0a0a0;',
'public' => 'color:#795da3;',
'protected' => 'color:#795da3;',
'private' => 'color:#795da3;',
'meta' => 'color:#b729d9;',
'key' => 'color:#df5000;',
'index' => 'color:#a71d5d;',
]);
// 正确传参:先 cloner 克隆,再 dumper 输出
$dumper->dump($cloner->cloneVar($var));
});
}
} }
/** /**
......
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