Commit daad3722 by 杨树贤

数据导入脚本

parent 96a132f1
...@@ -35,7 +35,9 @@ class SetSupplierFollowUp extends Command ...@@ -35,7 +35,9 @@ class SetSupplierFollowUp extends Command
// $service->importSupplierLevel(); // $service->importSupplierLevel();
// $service->changeSupplierTypeByIsType(); // $service->changeSupplierTypeByIsType();
// $service->transferPayType(); // $service->transferPayType();
$service->makeTempTagForSupplier(); $service->importSupplierGroup(true);
// $service->changeSupplierType();
// $service->generateYunxinAccount(false);
// $service->makeSupplierSystemTagAbnormal(); // $service->makeSupplierSystemTagAbnormal();
} }
} }
...@@ -68,7 +68,7 @@ class SupplierAccountController extends Controller ...@@ -68,7 +68,7 @@ class SupplierAccountController extends Controller
{ {
$id = $request->get('id'); $id = $request->get('id');
$model = new SupplierAccountModel(); $model = new SupplierAccountModel();
$account =$model->where('id',$id)->first()->toArray(); $account = $model->where('id', $id)->first()->toArray();
//获取所有启用的供应商编码,而且类型是包括云芯 //获取所有启用的供应商编码,而且类型是包括云芯
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$suppliers = $model->where('is_type', 0) $suppliers = $model->where('is_type', 0)
......
...@@ -20,6 +20,13 @@ class AdminUserService ...@@ -20,6 +20,13 @@ class AdminUserService
return $userInfoModel->where('userId', $adminId)->first(); return $userInfoModel->where('userId', $adminId)->first();
} }
public function getCodeIdByUserName($userName)
{
$userId = UserInfoModel::where('name', $userName)->value('userId');
$codeId = IntracodeModel::where('admin_id', $userId)->value('code_id');
return $codeId;
}
public function getCodeIdsByUserIds($userIds) public function getCodeIdsByUserIds($userIds)
{ {
$intraCodeModel = new IntracodeModel(); $intraCodeModel = new IntracodeModel();
......
...@@ -9,6 +9,7 @@ use App\Model\IntracodeModel; ...@@ -9,6 +9,7 @@ use App\Model\IntracodeModel;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\RedisModel; use App\Model\RedisModel;
use App\Model\StandardBrandModel; use App\Model\StandardBrandModel;
use App\Model\SupplierAccountModel;
use App\Model\SupplierAttachmentModel; use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
...@@ -17,6 +18,7 @@ use App\Model\SupplierPayTypeModel; ...@@ -17,6 +18,7 @@ use App\Model\SupplierPayTypeModel;
use Carbon\Carbon; use Carbon\Carbon;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
...@@ -63,598 +65,277 @@ class DataService ...@@ -63,598 +65,277 @@ class DataService
} }
} }
//20210722
//转移文件数据(之前是只存到一个字段,现在要存到一张表里面去)
public function transferFileData()
{
//先找出所有上传文件非空的供应商
$model = new SupplierChannelModel();
$suppliers = $model->where('qualification_photos', '!=', '')->get()->toArray();
$attachmentModel = new SupplierAttachmentModel();
foreach ($suppliers as $key => $supplier) {
$supplierId = $supplier['supplier_id'];
$files = json_decode($supplier['qualification_photos'], true);
$count = $attachmentModel->where('supplier_id', $supplierId)->count();
if (!$count) {
foreach ($files as $key => &$file) {
if (empty($file['url']) && empty($file['file_name'])) {
$file = '';
}
}
unset($file);
$business_license = array_get($files, 'business_license');
$billing_information = array_get($files, 'billing_information');
$registration_certificate = array_get($files, 'registration_certificate');
$incorporation_certificate = array_get($files, 'incorporation_certificate');
$certification_notice = array_get($files, 'certification_notice');
$supplier_survey = array_get($files, 'supplier_survey');
$proxy_certificate = array_get($files, 'proxy_certificate');
$quality_assurance_agreement = array_get($files, 'quality_assurance_agreement');
$confidentiality_agreement = array_get($files, 'confidentiality_agreement');
$cooperation_agreement = array_get($files, 'cooperation_agreement');
$other_attachment = array_get($files, 'other_attachment');
$attachment = [
'business_license' => $business_license ? [$business_license] : '',
'billing_information' => $billing_information ? [$billing_information] : '',
'registration_certificate' => $registration_certificate ? [$registration_certificate] : '',
'incorporation_certificate' => $incorporation_certificate ? [$incorporation_certificate] : '',
'certification_notice' => $certification_notice ? [$certification_notice] : '',
'supplier_survey' => $supplier_survey ? [$supplier_survey] : '',
'proxy_certificate' => $proxy_certificate ? [$proxy_certificate] : '',
'quality_assurance_agreement' => $quality_assurance_agreement ? [$quality_assurance_agreement] : '',
'confidentiality_agreement' => $confidentiality_agreement ? [$confidentiality_agreement] : '',
'cooperation_agreement' => $cooperation_agreement ? [$cooperation_agreement] : '',
'other_attachment' => $other_attachment ? [$other_attachment] : '',
'create_time' => time(),
'update_time' => time(),
'supplier_id' => $supplierId,
];
$attachment = array_filter($attachment, function ($item) {
return !empty($item);
});
$attachment = array_map(function ($item) {
return json_encode($item);
}, $attachment);
$attachmentModel->insert($attachment);
}
}
}
//历史数据处理 const TYPE_YC = 4;
public function changeSupplierIsTypeByCheckChannelUidOrPurchaseUid() const TYPE_DLS = 1;
{ const TYPE_MYS = 2;
$model = new SupplierChannelModel();
$suppliers = $model->where(function ($q) {
$q->where('channel_uid', '!=', '')->orWhere('purchase_uid', '!=', '');
})->where('is_type', 1)->get()->toArray();
// dd(count($suppliers));
if (count($suppliers) > 1670) {
dd("数量有问题");
}
$redis = new RedisModel();
//非正式供应商中存在渠道员/采购员,将供应商改为正式供应商
foreach ($suppliers as $supplier) {
//先查询是否有重复的供应商
$count = $model->where('supplier_name', $supplier['supplier_name'])->count();
if ($count > 1) {
dd($supplier['supplier_name']);
continue;
}
//同时记录被修改的supplier_id列表到redis以防万一
$redis->hset('lie_change_is_type_suppliers', $supplier['supplier_id'], json_encode($supplier));
//没有的话直接修改成待审核,并且转正
$model->where('supplier_id', $supplier['supplier_id'])
->update([
// 'update_time' => time(),
'is_type' => 0,
'status' => 0
]);
}
}
//替换老的品牌选择成为新的标准品牌id //供应商类型修改
public function replaceStandardBrandId() public function changeSupplierType()
{ {
$supplierModel = new SupplierChannelModel(); ini_set('memory_limit', -1);
$suppliers = $supplierModel->where('main_brands', '!=', '')->get()->toArray(); //统一修改掉状态先
$redis = new RedisModel(); (new SupplierChannelModel)->where('supplier_id', '>', 0)->update([
foreach ($suppliers as $supplier) { 'outside_contact_type' => 0
$mainBrands = explode(',', $supplier['main_brands']); ]);
$standardBrandIds = [];
foreach ($mainBrands as $brandId) {
//找标准品牌ID,没有直接跳过
$standardBrandId = $redis->hget('standard_brand_mapping', $brandId);
if (empty($standardBrandId) or empty($brandId)) {
continue;
}
$standardBrandIds[] = $standardBrandId;
}
print_r($mainBrands);
print_r($standardBrandIds);
echo PHP_EOL;
if (!empty($standardBrandIds)) {
$standardBrandIdsStr = implode(',', $standardBrandIds);
} else {
$standardBrandIdsStr = '';
}
$supplierModel->where('supplier_id', $supplier['supplier_id'])->update([
'main_brands' => $standardBrandIdsStr
]);
}
}
//导入黑名单供应商(前提是不存在) //先将真实对接的供应商修改状态
public function importBlockSupplier() $realApiSupplierCodes = [
{ 'L0000266',
$supplierNames = [ 'L0000198',
'Electronics Depot', 'L0000273',
'Assured Electronics Corp.', 'L0000135',
'深圳市力特电子有限公司', 'L0000135',
'深圳市铭盛微电子科技有限公司', 'L0005966',
'Aegis Components Inc', 'L0000004',
'深圳市亿博创电子公司', 'L0006149',
'L0006150',
'L0006155',
'L0007637',
'L0006148',
'L0006151',
'L0006147',
'L0007639',
'L0007640',
'L0007646',
'L0007648',
'L0007650',
'L0007653',
'L0000089',
'L0007633',
'L0007663',
'L0010826',
'L0010856',
'L0010937',
'L0007595',
'L0011054',
'L0004938',
'L0011040',
'L0001175',
'L0007243',
'L0011042',
]; ];
//构建插入数据 SupplierChannelModel::whereIn('supplier_code', $realApiSupplierCodes)
$supplierModel = new SupplierChannelModel(); ->update([
foreach ($supplierNames as $supplierName) { 'outside_contact_type' => 2
$supplierName = trim($supplierName); ]);
$exist = $supplierModel->where('supplier_name', $supplierName)->count();
if (!$exist) {
$insertData = [
'supplier_name' => $supplierName,
'create_uid' => 1000,
'create_time' => time(),
'status' => $supplierModel::STATUS_BLOCK,
'is_type' => 0,
'create_name' => 'admin',
'block_reason' => '系统拉黑',
];
$supplierId = $supplierModel->insertGetId($insertData);
$supplierService = new SupplierService();
$supplierService->saveSupplierCode($supplierId);
}
}
}
//给特定类型的供应商打上标签
//找出 国内/港台 + 现货商性质的,而且没有上传品质协议的供应商,自动打上临时供应商标签
public function makeSupplierSystemTag()
{
$channelModel = new SupplierChannelModel();
$suppliers = $channelModel->leftjoin('supplier_attachment', 'supplier_channel.supplier_id', '=',
'supplier_attachment.supplier_id')
->whereIn('region', [2, 4])
->where('supplier_group', 2)
->where('quality_assurance_agreement', '')->where('system_tags', 'not like', '%临时供应商%')
->get()->toArray();
$tagService = new SupplierTagService();
//找到后打上标签
foreach ($suppliers as $supplier) {
$supplierId = $supplier['supplier_id'];
$oldTags = $supplier['system_tags'];
$newTags = $supplier['system_tags'] ? rtrim($supplier['system_tags'], ',') . ',临时供应商' : '临时供应商';
if ($tagService->saveTags($supplierId, 14, $newTags, $oldTags)) {
$channelModel->where('supplier_id', $supplierId)->update([
'system_tags' => $newTags
]);
}
}
}
//打上历史检测异常标签 $suppliers = $this->getNeedDealSuppliers();
public function makeSupplierSystemTagAbnormal($change = false) if (empty($suppliers)) {
{ return '供应商上传类型已经全部处理';
ini_set('memory_limit', '-1');
$channelModel = new SupplierChannelModel();
//读取excel
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'abnormal_supplier.xlsx';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($change) {
$reader->sheet('QC不良记录', function () use ($reader, $change) {
$supplierModel = new SupplierChannelModel();
$suppliers = [];
foreach ($reader->all()->toArray() as $key => $item) {
if ($key == 0 || $key == 1) {
continue;
}
$supplierName = trim($item[2]);
if (empty($supplierName)) {
continue;
}
$supplier = $supplierModel->where('supplier_name', $supplierName)->first();
if (!empty($supplier)) {
$suppliers[] = $supplier->toArray();
} else {
echo "供应商 : " . $supplierName . "不存在,跳过" . PHP_EOL;
}
}
$tagService = new SupplierTagService();
//找到后打上标签
foreach ($suppliers as $supplier) {
$supplierId = $supplier['supplier_id'];
$oldTags = $supplier['system_tags'];
echo "供应商 : " . $supplier['supplier_name'] . "检测异常,需要打上标签" . PHP_EOL;
if (strpos($supplier['system_tags'], '历史检测异常') !== false) {
continue;
}
$newTags = $supplier['system_tags'] ? rtrim($supplier['system_tags'],
',') . ',历史检测异常' : '历史检测异常';
if ($change) {
if ($tagService->saveTags($supplierId, 14, $newTags, $oldTags)) {
$supplierModel->where('supplier_id', $supplierId)->update([
'system_tags' => $newTags
]);
}
}
}
});
});
} catch (\Exception $exception) {
dd($exception);
} }
} //api对接类型的供应商数量(706)
$ycApiTypeCount = 172;
$dlsApiTypeCount = 207;
$mysApiTypeCount = 327;
//要先找出原厂类型的API对接类型的供应商数量,然后要从库里面随机找出原厂的供应商打上类型
$this->dealApiSupplier(self::TYPE_YC, $ycApiTypeCount);
//要先找出代理商类型的API对接类型的供应商数量,然后要从库里面随机找出代理商的供应商打上类型
$this->dealApiSupplier(self::TYPE_DLS, $dlsApiTypeCount);
//要先找出贸易类型的API对接类型的供应商数量,然后要从库里面随机找出贸易的供应商打上类型
$this->dealApiSupplier(self::TYPE_MYS, $mysApiTypeCount);
echo "-------------------------" . PHP_EOL;
//然后随机取出云芯的供应商(1139)
//先剔除api对接的供应商
$ycYunxinTypeCount = 113;
$dlsYunxinTypeCount = 302;
$mysYunxinTypeCount = 724;
$this->dealYunxinSupplier(self::TYPE_YC, $ycYunxinTypeCount);
$this->dealYunxinSupplier(self::TYPE_DLS, $dlsYunxinTypeCount);
$this->dealYunxinSupplier(self::TYPE_MYS, $mysYunxinTypeCount);
echo "-------------------------" . PHP_EOL;
//剩下的都是人工上传的,也有一定占比(2658)
$ycManualTypeCount = 20;
$dlsManualTypeCount = 146;
$mysManualTypeCount = 2492;
$this->dealManualSupplier(self::TYPE_YC, $ycManualTypeCount);
$this->dealManualSupplier(self::TYPE_DLS, $dlsManualTypeCount);
$this->dealManualSupplier(self::TYPE_MYS, $mysManualTypeCount);
//初始化供应商对应的搜索标签到redis
public function initSupplierSearchTags()
{
//初始化所有正式服务器的标签情况到redis
$supplierModel = new SupplierChannelModel();
$suppliers = $supplierModel->where('is_type', 0)->get()->toArray();
$redis = new RedisModel();
foreach ($suppliers as $supplier) {
//1精选,2原厂直供,3认证,4猎芯自营,100无标签
$tagFlags = [];
//先去判断供应商性质是否为原厂,如果是的话,写入标签2
if ($supplier['supplier_group'] == 4) {
$tagFlags[] = 2;
}
if ($supplier['has_certification'] == 1) {
$tagFlags[] = 3;
}
$redis->hset('supplier_search_tags', $supplier['supplier_code'], json_encode([
'supplier_code' => $supplier['supplier_code'],
'tags' => $tagFlags,
]));
}
} }
//推送更新供应商的队列 public function getNeedDealSuppliers($supplierGroup = 0, $otherSupplierGroup = [])
public function pushSupplierSKu()
{ {
$supplierModel = new SupplierChannelModel(); $query = SupplierChannelModel::where('outside_contact_type', 0)
$suppliers = $supplierModel->where('is_type', 0)->where('supplier_group', 4)->orderBy('supplier_id', 'desc') ->where('channel_uid', '!=', '')
->limit(130)->get()->toArray(); ->where('status', '!=', -3)
$redis = new RedisModel(); ->whereRaw('supplier_name NOT LIKE "%-1"')
foreach ($suppliers as $supplier) { ->where('is_type', 0);
$supplierTag = $redis->hget('supplier_search_tags', $supplier['supplier_code']);
if (!$supplierTag) {
continue; if (!empty($otherSupplierGroup)) {
$query->whereIn('supplier_group', $otherSupplierGroup);
} else {
if (!empty($supplierGroup)) {
$query->where('supplier_group', $supplierGroup);
} }
$message = json_encode([
'supplier_code' => $supplier['supplier_code'],
]);
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
$channel = $conn->channel();
$channel->queue_declare('supplier_zhuanmai_update', false, true, false, false);
$msg = new AMQPMessage($message,
array('content_type' => 'text/plain'));
$channel->basic_publish($msg, '', 'supplier_zhuanmai_update');
} }
$data = $query->get()->toArray();
return $data;
} }
//导入主营品牌数据 //处理API接入的不同类型的数据
public function importMainBrandData() public function dealApiSupplier($supplierGroup, $totalApiTypeCount)
{ {
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_main_brand.xlsx'; //先找出已经存在的api对接类型的供应商数量,方便下面算出补全数量
try { $existApiTypeCount = SupplierChannelModel::where('outside_contact_type', 2)
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) { ->where('supplier_group', $supplierGroup)->count();
$reader->sheet('产出', function () use ($reader) {
$supplierMainBrandData = [];
$standardBrandModel = new StandardBrandModel();
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[0]);
$brandName = $item[1];
$brandId = $standardBrandModel->where('brand_name',
trim($brandName))->value('standard_brand_id');
if (empty($brandId)) {
continue;
}
if (!isset($supplierMainBrandData[$supplierName])) {
$supplierMainBrandData[$supplierName][] = $brandId;
} else {
$supplierMainBrandData[$supplierName][] = $brandId;
}
}
$supplierModel = new SupplierChannelModel();
foreach ($supplierMainBrandData as $supplierName => $mainBrandIds) {
$result = $supplierModel->where('supplier_name', $supplierName)->update([
'main_brands' => implode(',', $mainBrandIds),
]);
if ($result) {
var_dump('更新供应商主营品牌成功,供应商 : ' . $supplierName);
}
}
});
});
} catch (\Exception $exception) {
var_dump($exception);
}
}
//从excel导入供应商 echo "API对接类型的 $supplierGroup 供应商数量一共要有数量 : " . $totalApiTypeCount . PHP_EOL;
public function importSupplier()
{
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_import.xls';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel, $supplierService) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]);
//先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName)
->exists();
if (!$exist) {
$number++;
//往库里面插入
$data = [
'supplier_name' => $supplierName,
'create_uid' => 1000,
'create_time' => time(),
'status' => 2,
'is_type' => 1,
'create_name' => 'admin',
];
$supplierId = $supplierChannelModel->insertGetId($data);
$supplierService->saveSupplierCode($supplierId);
//然后修改excel
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商不存在,已经新增');
});
} else {
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商已经存在,不做新增');
});
}
}
var_dump("一共新增了${number}个不存在的供应商");
});
})->store('xls');
} catch (\Exception $exception) {
var_dump($exception);
}
}
/* echo "已经存在的API对接类型的 $supplierGroup 供应商数量 : " . $existApiTypeCount . PHP_EOL;
* 供应商0.5版本下面需要跑的数据方法
* */
//剩下就要补全
$needAddApiTypeCount = $totalApiTypeCount - $existApiTypeCount;
//临时供应商标记以及等级切换 echo "需要补全API对接类型的 $supplierGroup 供应商数量 :" . $needAddApiTypeCount . PHP_EOL;
public function makeTempTagForSupplier($change = false)
{ if ($needAddApiTypeCount <= 0) {
/* return;
创建时间为2021-06-01开始截至现在,供应商类别为正式/临时,供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E
创建时间为空,不在上述供应商集内
*/
$time = strtotime("2021-06-01");
$suppliers = SupplierChannelModel::where('create_time', '>', $time)->where('is_type', 0)
->where('create_time', '!=', 0)->get();
foreach ($suppliers as $supplier) {
$supplierId = $supplier['supplier_id'];
//判断是否有上传品质协议
$hasQualityAssuranceAgreement = SupplierAttachmentModel::where('supplier_id',
$supplierId)->value('quality_assurance_agreement');
//供应商性质为现货商,且没有上传品质协议,系统标签需要贴【临时供应商标签】,等级标记为E
if (!$hasQualityAssuranceAgreement && $supplier['supplier_group'] == 2) {
// if ($supplier['level'] != '' && $supplier['level'] != 'E') {
// echo "供应商编码 ${supplier['supplier_code']} 已经有等级${supplier['level']},但是不为等级E,跳过" . PHP_EOL;
// continue;
// }
echo "供应商编码 ${supplier['supplier_code']} 转换为临时供应商" . PHP_EOL;
if ($change) {
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'supplier_type' => 2
]);
}
}
} }
}
//将非正式供应商(is_type=1)的类别设置为待转正 $suppliers = $this->getNeedDealSuppliers($supplierGroup);
public function changeSupplierTypeByIsType() echo "供应商性质 $supplierGroup 可操作供应商数量 :" . count($suppliers) . PHP_EOL;
{ if (!count($suppliers)) {
SupplierChannelModel::where('supplier_id', 13038)->update([ return;
'supplier_type' => 1 }
]); $rand = array_rand($suppliers, $needAddApiTypeCount);
$apiSuppliers = array_intersect_key($suppliers,
array_flip(is_array($rand) ? $rand : [$rand]));
$apiSupplierIds = array_column($apiSuppliers, 'supplier_id');
echo "供应商性质为 : $supplierGroup 的供应商修改API上传类型数量 : " . count($apiSupplierIds) . PHP_EOL . PHP_EOL;
SupplierChannelModel::whereIn('supplier_id', $apiSupplierIds)
->where('outside_contact_type', 0)->update([
'outside_contact_type' => 2
]);
} }
//转移附件数据到新的表 //处理云芯接入的不同类型的数据
public function transferAttachmentToNewTable() public function dealYunxinSupplier($supplierGroup, $totalYunxinCount)
{ {
$supplierAttachments = SupplierAttachmentModel::get()->toArray();
foreach ($supplierAttachments as $supplierAttachment) {
$supplierId = $supplierAttachment['supplier_id'];
if (SupplierAttachmentsModel::where('supplier_id', $supplierId)->exists()) {
continue;
}
$fields = [
'business_license',
'billing_information',
'registration_certificate',
'incorporation_certificate',
'certification_notice',
'supplier_survey',
'proxy_certificate',
'quality_assurance_agreement',
'confidentiality_agreement',
'cooperation_agreement',
'other_attachment',
];
$attachmentData = [];
foreach ($fields as $field) {
if (isset($supplierAttachment[$field]) && !empty($supplierAttachment[$field])) {
$supplierAttachment[$field] = json_decode($supplierAttachment[$field], true);
foreach ($supplierAttachment[$field] as $item) {
/*
* [{"name":"business_license","url":"http:\/\/img.ichunt.com\/test\/images\/ichunt\/202106\/25\/fc9c8179aa327f878932dd6b62b4d88c.png","file_name":"38.png"}]
* */
$attachmentData[] = [
'supplier_id' => $supplierId,
'type_name' => array_get(config('fixed.FileNameMapping'), $item['name']),
'field_name' => $item['name'],
'file_url' => $item['url'],
'file_name' => array_get($item, 'file_name', ''),
];
}
}
}
SupplierAttachmentsModel::insert($attachmentData); $suppliers = $this->getNeedDealSuppliers($supplierGroup);
echo "供应商性质 $supplierGroup 需要修改数量 :" . $totalYunxinCount . PHP_EOL;
echo "供应商性质 $supplierGroup 可操作供应商数量 :" . count($suppliers) . PHP_EOL;
if (!count($suppliers)) {
return;
}
if (count($suppliers) < $totalYunxinCount) {
$totalYunxinCount = count($suppliers);
} }
$rand = array_rand($suppliers, $totalYunxinCount);
$yunxinSuppliers = array_intersect_key($suppliers,
array_flip(is_array($rand) ? $rand : [$rand]));
$yunxinSupplierIds = array_column($yunxinSuppliers, 'supplier_id');
echo "供应商性质为 : $supplierGroup 的供应商修改云芯上传类型数量 : " . count(array_unique($yunxinSupplierIds)) . PHP_EOL;
// foreach ($yunxinSupplierIds as $supplierId) {
// SupplierChannelModel::where('supplier_id', $supplierId)->update([
// 'outside_contact_type' => 3
// ]);
// }
SupplierChannelModel::whereIn('supplier_id', $yunxinSupplierIds)
->where('outside_contact_type', 0)->update([
'outside_contact_type' => 3
]);
} }
//转换交易方式和付款方式数据统一到付款方式 //处理人工上传
public function transferPayType($change = false) public function dealManualSupplier($supplierGroup, $totalManualCount)
{ {
$suppliersA = SupplierChannelModel::where('trading_method', '!=', 0)->where('pay_type', '!=', 0) $otherSupplierGroup = [];
->get()->toArray(); if ($supplierGroup == 2) {
$suppliersB = SupplierChannelModel::where('trading_method', '!=', 0)->where('pay_type', 0) $otherSupplierGroup = [0, 2, 3, 5, 6];
->get()->toArray(); // $otherSupplierGroup = [2];
$suppliersC = SupplierChannelModel::where('trading_method', 0)->where('pay_type', '!=', 0)
->get()->toArray();
$handledSupplierIds = [];
//如果供应商交易方式与付款方式都有数据,则付款周期从交易方式中映射,映射规则:先款后货映射成预付款;月结映射成账期;
if ($suppliersA) {
foreach ($suppliersA as $supplier) {
if ($supplier['trading_method'] == 1) {
$payType = 3;
} else {
$payType = 1;
}
$tradeMethod = array_get(config('fixed.TradingMethod'), $supplier['trading_method']);
$payTypeName = array_get(config('fixed.SupplierPayType'), $payType);
dump("供应商编码 ${supplier['supplier_code']} 原来的交易方式为 $tradeMethod 转换成付款周期 $payTypeName");
if ($change) {
$handledSupplierIds[] = $supplier['supplier_id'];
SupplierChannelModel::where('supplier_id', $supplier['supplier_id'])->update([
'pay_type' => $payType,
]);
}
}
} }
//人工上传这个类别,供应商性质如果是贸易商,那就要加上方案商和分销平台和代工厂
dump('--------------------------------'); $suppliers = $this->getNeedDealSuppliers($supplierGroup, $otherSupplierGroup);
echo "供应商性质 $supplierGroup 需要修改数量 :" . $totalManualCount . PHP_EOL;
//如果供应商交易方式有数据,付款方式无数据,则付款周期从交易方式中映射,映射规则:先款后货映射成预付款;月结映射成账期; echo "供应商性质 $supplierGroup 可操作供应商数量 :" . count($suppliers) . PHP_EOL;
if ($suppliersB) { if (!count($suppliers)) {
return;
foreach ($suppliersB as $supplier) {
if ($supplier['trading_method'] == 1) {
$payType = 3;
} else {
$payType = 1;
}
$tradeMethod = array_get(config('fixed.TradingMethod'), $supplier['trading_method']);
$payTypeName = array_get(config('fixed.SupplierPayType'), $payType);
dump("供应商编码 ${supplier['supplier_code']} 原来的交易方式为 $tradeMethod 转换成付款周期 $payTypeName");
if ($change) {
$handledSupplierIds[] = $supplier['supplier_id'];
SupplierChannelModel::where('supplier_id', $supplier['supplier_id'])->update([
'pay_type' => $payType,
]);
}
}
} }
if (count($suppliers) <= $totalManualCount) {
dump('--------------------------------'); $totalManualCount = count($suppliers);
//如果供应商交易方式无数据,付款方式有数据,则付款周期从付款方式中映射,映射规则:账期-周期结算映射成账期,账期-定期结算映射成账期,全款映射成预付款,定金映射成预付款;
if ($suppliersC) {
foreach ($suppliersC as $supplier) {
$payType = 0;
if (!trim($supplier['pay_type'])) {
continue;
}
switch (trim($supplier['pay_type'])) {
case 1:
$payType = 1;
break;
case 2:
$payType = 1;
break;
case 3:
$payType = 3;
break;
case 4:
$payType = 3;
break;
}
$originPayTypeNameMap = [
1 => '账期-周期结算',
2 => '账期-定期结算',
3 => '全款',
4 => '定金',
];
$originPayTypeName = array_get($originPayTypeNameMap, $supplier['pay_type']);
$payTypeName = array_get(config('fixed.SupplierPayType'), $payType);
dump("供应商编码 ${supplier['supplier_code']} 原来的付款方式为 $originPayTypeName 转换成付款周期 $payTypeName");
if ($change && $payType) {
$handledSupplierIds[] = $supplier['supplier_id'];
SupplierChannelModel::where('supplier_id', $supplier['supplier_id'])->update([
'pay_type' => $payType,
]);
}
}
} }
$rand = array_rand($suppliers, $totalManualCount);
$manualSuppliers = array_intersect_key($suppliers,
array_flip(is_array($rand) ? $rand : [$rand]));
$manualSupplierIds = array_column($manualSuppliers, 'supplier_id');
echo "供应商性质为 : $supplierGroup 的供应商修改人工上传类型数量 : " . count($manualSupplierIds) . PHP_EOL;
// foreach ($manualSupplierIds as $supplierId) {
// SupplierChannelModel::where('supplier_id', $supplierId)->update([
// 'outside_contact_type' => 1
// ]);
// }
foreach (collect($manualSupplierIds)->chunk(500) as $key => $ids) {
SupplierChannelModel::whereIn('supplier_id', $ids)
->where('outside_contact_type', 0)->update([
'outside_contact_type' => 1
]);
}
} }
//导入等级修改供应商并且找出没有等级的供应商(针对正式的) //导入公司性质
public function importSupplierLevel($change = false) public function importSupplierGroup($isUpdate = false)
{ {
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_level.xlsx'; $filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_group.xlsx';
try { try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($change) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) use ($isUpdate) {
$supplierChannelModel = new SupplierChannelModel(); $reader->sheet('Sheet2', function () use ($reader, $isUpdate) {
$reader->sheet('2021年评估', function ($sheet) use ($reader, $supplierChannelModel, $change) { $num = $ycNum = 0;
$number = 0; $redis = new RedisModel();
foreach ($reader->all()->toArray() as $key => $item) { foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]); $supplierCode = trim($item[0]);
$level = trim($item[2]); $purchaseName = trim($item[3]);
//先去判断是否存在 $channelUid = (new AdminUserService())->getCodeIdByUserName($purchaseName);
$exist = $supplierChannelModel->where('supplier_name', $supplierName) //如果采购员id不为空,那么就要写进去
->exists(); $supplierId = SupplierChannelModel::where('supplier_code', $supplierCode)
$levelExist = $supplierChannelModel->where('supplier_name', $supplierName) ->value('supplier_id');
->value('level'); if (!$supplierId) {
if ($levelExist) { echo "供应商不存在 : " . $supplierCode . PHP_EOL;
echo "供应商 ${supplierName} 已有,等级为 : " . $level . PHP_EOL;
continue;
} }
if (!$exist) { if ($channelUid) {
$number++; echo "添加采购员${purchaseName}到 : " . $supplierCode . PHP_EOL;
} else { if ($isUpdate) {
echo "修改供应商 ${supplierName} 等级为 : " . $level . PHP_EOL; (new SupplierService())->allocateChannelUser($supplierId, $channelUid, false);
if ($change) {
$supplierChannelModel->where('supplier_name', $supplierName)->update([
'level' => $level,
]);
} }
} }
$isYc = trim($item[4]);
if ($isYc == '原厂') {
//判断是否是原厂,如果是原厂,就跳过
$supplierGroup = SupplierChannelModel::where('supplier_code', $supplierCode)
->value('supplier_group');
if ($supplierGroup == self::TYPE_YC) {
echo "该供应商已经是原厂,跳过 : $supplierCode" . PHP_EOL;
continue;
}
echo "修改供应商性质为原厂 : " . $supplierCode . PHP_EOL;
if ($isUpdate) {
//写入redis,方便恢复
$redis->hset('lie_supplier_group_change', $supplierGroup, self::TYPE_YC);
SupplierChannelModel::where('supplier_code', $supplierCode)
->update([
'supplier_group' => self::TYPE_YC,
]);
}
$ycNum++;
}
$num++;
} }
var_dump("一共有${number}个不存在的供应商");
echo "一共处理 $num 家供应商采购员,处理 $ycNum 家供应商性质为原厂" . PHP_EOL;
}); });
}); });
} catch (\Exception $exception) { } catch (\Exception $exception) {
...@@ -662,7 +343,31 @@ class DataService ...@@ -662,7 +343,31 @@ class DataService
} }
} }
//生成云芯账号
public function generateYunxinAccount($isUpdate = false)
{
$suppliers = SupplierChannelModel::where('outside_contact_type', 3)->get()->toArray();
// $suppliers = SupplierChannelModel::where('is_type', 0)->limit(100)->get()->toArray();
foreach ($suppliers as $supplier) {
if (SupplierAccountModel::where('supplier_id', $supplier['supplier_id'])->exists()) {
continue;
}
$mobile = generateMobile(1)[0];
$password = makePassword(mt_rand(8, 12));
$account = [
'supplier_id' => $supplier['supplier_id'],
'supplier_code' => $supplier['supplier_code'],
'mobile' => $mobile,
'password_raw' => $password,
'password' => Hash::make($password),
'create_uid' => 1000,
'create_time' => time(),
];
if ($isUpdate) {
SupplierAccountModel::insert($account);
}
}
}
} }
...@@ -418,9 +418,9 @@ class SupplierService ...@@ -418,9 +418,9 @@ class SupplierService
} }
//分配采购员 //分配采购员
public function allocateChannelUser($supplierId, $channelUid) public function allocateChannelUser($supplierId, $channelUid, $logFlag = true)
{ {
$result = DB::connection('web')->transaction(function () use ($supplierId, $channelUid) { $result = DB::connection('web')->transaction(function () use ($supplierId, $channelUid, $logFlag) {
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $model->where('supplier_id', $supplierId)->first();
$supplier = $supplier ? $supplier->toArray() : []; $supplier = $supplier ? $supplier->toArray() : [];
...@@ -429,10 +429,18 @@ class SupplierService ...@@ -429,10 +429,18 @@ class SupplierService
$preChannelUid[] = $channelUid; $preChannelUid[] = $channelUid;
$preChannelUid = array_unique($preChannelUid); $preChannelUid = array_unique($preChannelUid);
$preChannelUid = implode(',', $preChannelUid); $preChannelUid = implode(',', $preChannelUid);
$result = $model->where('supplier_id', $supplierId)->update([ $preChannelUid = trim($preChannelUid, ',');
'update_time' => time(), if ($logFlag) {
'channel_uid' => $preChannelUid, $result = $model->where('supplier_id', $supplierId)->update([
]); 'update_time' => time(),
'channel_uid' => $preChannelUid,
]);
}else{
$result = $model->where('supplier_id', $supplierId)->update([
'channel_uid' => $preChannelUid,
]);
}
$contactResult = false; $contactResult = false;
if ($result) { if ($result) {
$contactModel = new SupplierContactModel(); $contactModel = new SupplierContactModel();
...@@ -440,11 +448,11 @@ class SupplierService ...@@ -440,11 +448,11 @@ class SupplierService
'supplier_id' => $supplierId, 'supplier_id' => $supplierId,
'can_check_uids' => $channelUid, 'can_check_uids' => $channelUid,
'add_time' => time(), 'add_time' => time(),
'admin_id' => request()->user->userId, 'admin_id' => !empty(request()->user->userId) ? request()->user->userId : 1000,
]; ];
$contactResult = $contactModel->insert($contact); $contactResult = $contactModel->insert($contact);
} }
if ($contactResult) { if ($contactResult && $logFlag) {
//判断是否是非正式供应商,如果是,自动转正,并且修改为待审核状态 //判断是否是非正式供应商,如果是,自动转正,并且修改为待审核状态
$this->autoChangeIsType($supplier); $this->autoChangeIsType($supplier);
//记录日志 //记录日志
...@@ -511,7 +519,7 @@ class SupplierService ...@@ -511,7 +519,7 @@ class SupplierService
$printData['contact'] = $contact; $printData['contact'] = $contact;
$attachmentModel = new SupplierAttachmentsModel(); $attachmentModel = new SupplierAttachmentsModel();
$hasAgreement = $attachmentModel->where('supplier_id', $supplierId) $hasAgreement = $attachmentModel->where('supplier_id', $supplierId)
->where('field_name','quality_assurance_agreement')->exists() ? '已签' : '未签'; ->where('field_name', 'quality_assurance_agreement')->exists() ? '已签' : '未签';
$printData['has_agreement'] = $hasAgreement; $printData['has_agreement'] = $hasAgreement;
$adminUserService = new AdminUserService(); $adminUserService = new AdminUserService();
$user = $adminUserService->getAdminUserInfo(request()->user->userId); $user = $adminUserService->getAdminUserInfo(request()->user->userId);
...@@ -580,8 +588,8 @@ class SupplierService ...@@ -580,8 +588,8 @@ class SupplierService
'supplier_type', 'supplier_type',
'settlement_type', 'settlement_type',
]; ];
foreach ($supplier as $key=>&$value) { foreach ($supplier as $key => &$value) {
if (in_array($key,$needChangeField) && empty($value)) { if (in_array($key, $needChangeField) && empty($value)) {
$value = ''; $value = '';
} }
} }
......
...@@ -203,4 +203,44 @@ function checkArrayAllValueNull($array, $excludeField = []) ...@@ -203,4 +203,44 @@ function checkArrayAllValueNull($array, $excludeField = [])
} }
return true; return true;
}
function generateMobile($count)
{
$arr = [
130,131,132,133,134,135,136,137,138,139,
144,147,
150,151,152,153,155,156,157,158,159,
176,177,178,
180,181,182,183,184,185,186,187,188,189,
];
$phone = [];
for($i = 0; $i < $count; $i++) {
$phone[] = $arr[array_rand($arr)].''.mt_rand(1000,9999).''.mt_rand(1000,9999);
}
return array_unique($phone);
}
function makePassword($length)
{
// 密码字符集,可任意添加你需要的字符
// $str = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
// 'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's',
// 't', 'u', 'v', 'w', 'x', 'y','z', 'A', 'B', 'C', 'D',
// 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M', 'N', 'O',
// 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z',
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$str = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y','z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
// 在 $str 中随机取 $length 个数组元素键名
$keys = array_rand($str, $length);
$password = '';
for($i = 0; $i < $length; $i++)
{
// 将 $length 个数组元素连接成字符串
$password .= $str[$keys[$i]];
}
return $password;
} }
\ No newline at end of file
...@@ -53,11 +53,5 @@ Route::group(['middleware' => ['external'],'namespace' => 'Api'], function () { ...@@ -53,11 +53,5 @@ Route::group(['middleware' => ['external'],'namespace' => 'Api'], function () {
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
$data = [ // (new \App\Http\Services\DataService())->importSupplierGroup();
'sku_ids'=> '1163833791883548099,1163833787833091377',
'is_long_term' => -1,
'operate_type' => 1,
'cp_time' => '2022-05-31 0:0:0',
];
(new SkuService())->batchUpdateSkuStatus($data);
}); });
No preview for this file type
[ZoneTransfer]
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.tapd.cn/
HostUrl=https://file.tapd.cn/56056445/attachments/download/1156056445001001663/story
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