Commit 1495c88d by mushishixian

数据逻辑准备

parent 658d3b6c
...@@ -20,14 +20,48 @@ use Maatwebsite\Excel\Facades\Excel; ...@@ -20,14 +20,48 @@ use Maatwebsite\Excel\Facades\Excel;
//这个服务是处理数据的,比如导出信息,或者临时修复数据,所以代码会比较多 //这个服务是处理数据的,比如导出信息,或者临时修复数据,所以代码会比较多
class DataService class DataService
{ {
public function initSystemTag()
{
$tagList = [
1 => '临时供应商',
2 => '优质供应商',
3 => '客户指定供应商',
4 => '开票不及时',
5 => '跳票',
];
$client = new Client([
'base_uri' => config('website.TagUrl'),
]);
foreach ($tagList as $tag) {
//构建请求参数
$params = [
$tag => [
'tag_use' => 14,
'tag_type' => 2,
'remark' => '',
'creator' => 1000,
'creator_name' => 'admin',
'status' => 1,
]
];
$response = $client->post('/create', [
RequestOptions::JSON => $params,
]);
}
// dd($response->getBody()->getContents());
}
//20210722 //20210722
//转移文件数据(之前是只存到一个字段,现在要存到一张表里面去) //转移文件数据(之前是只存到一个字段,现在要存到一张表里面去)
public function transferFileData() public function transferFileData()
{ {
//先找出所有上传文件非空的供应商 //先找出所有上传文件非空的供应商
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$suppliers = $model->where('qualification_photos', '!=', '') $suppliers = $model->where('qualification_photos', '!=', '')->get()->toArray();
->where('is_type', 0)->get()->toArray();
$attachmentModel = new SupplierAttachmentModel(); $attachmentModel = new SupplierAttachmentModel();
foreach ($suppliers as $key => $supplier) { foreach ($suppliers as $key => $supplier) {
$supplierId = $supplier['supplier_id']; $supplierId = $supplier['supplier_id'];
...@@ -85,72 +119,36 @@ class DataService ...@@ -85,72 +119,36 @@ class DataService
$suppliers = $model->where(function ($q) { $suppliers = $model->where(function ($q) {
$q->where('channel_uid', '!=', '')->orWhere('purchase_uid', '!=', ''); $q->where('channel_uid', '!=', '')->orWhere('purchase_uid', '!=', '');
})->where('is_type', 1)->get()->toArray(); })->where('is_type', 1)->get()->toArray();
// if (count($suppliers) > 1709) { // dd(count($suppliers));
// dd("数量有问题"); if (count($suppliers) > 1670) {
// } dd("数量有问题");
}
$redis = new RedisModel(); $redis = new RedisModel();
//非正式供应商中存在渠道员/采购员,将供应商改为正式供应商 //非正式供应商中存在渠道员/采购员,将供应商改为正式供应商
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
//先查询是否有重复的供应商 //先查询是否有重复的供应商
$count = $model->where('supplier_name', $supplier['supplier_name'])->count(); $count = $model->where('supplier_name', $supplier['supplier_name'])->count();
if ($count > 1) { if ($count > 1) {
dd($supplier['supplier_name']);
continue; continue;
} }
//同时记录被修改的supplier_id列表到redis以防万一 //同时记录被修改的supplier_id列表到redis以防万一
$redis->hset('lie_change_is_type_suppliers', $supplier['supplier_id'], json_encode($supplier)); $redis->hset('lie_change_is_type_suppliers', $supplier['supplier_id'], json_encode($supplier));
//没有的话直接修改成审核中,并且转正 //没有的话直接修改成待审核,并且转正
$model->where('supplier_id', $supplier['supplier_id']) $model->where('supplier_id', $supplier['supplier_id'])
->update([ ->update([
'update_time' => time(), // 'update_time' => time(),
'is_type' => 0, 'is_type' => 0,
'status' => 1 'status' => 0
]); ]);
} }
} }
public function initSystemTag()
{
$tagList = [
1 => '标签1',
2 => '标签2',
3 => '标签3',
4 => '标签4',
];
$tagList = [
5 => '客户指定供应商',
];
$client = new Client([
'base_uri' => config('website.TagUrl'),
]);
foreach ($tagList as $tag) {
//构建请求参数
$params = [
$tag => [
'tag_use' => 14,
'tag_type' => 2,
'remark' => '',
'creator' => 1000,
'creator_name' => 'admin',
'status' => 1,
]
];
$response = $client->post('/create', [
RequestOptions::JSON => $params,
]);
dd($response->getBody()->getContents());
}
}
//替换老的品牌选择成为新的标准品牌id //替换老的品牌选择成为新的标准品牌id
public function replaceStandardBrandId() public function replaceStandardBrandId()
{ {
$supplierModel = new SupplierChannelModel(); $supplierModel = new SupplierChannelModel();
$suppliers = $supplierModel->where('main_brands', '!=', '')->get()->toArray(); $suppliers = $supplierModel->where('main_brands', '!=', '')->limit(20)->get()->toArray();
$redis = new RedisModel(); $redis = new RedisModel();
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
$mainBrands = explode(',', $supplier['main_brands']); $mainBrands = explode(',', $supplier['main_brands']);
...@@ -158,20 +156,23 @@ class DataService ...@@ -158,20 +156,23 @@ class DataService
foreach ($mainBrands as $brandId) { foreach ($mainBrands as $brandId) {
//找标准品牌ID,没有直接跳过 //找标准品牌ID,没有直接跳过
$standardBrandId = $redis->hget('standard_brand_mapping', $brandId); $standardBrandId = $redis->hget('standard_brand_mapping', $brandId);
if (empty($standardBrandId)) { if (empty($standardBrandId) or empty($brandId)) {
continue; continue;
} }
$standardBrandIds[] = $standardBrandId; $standardBrandIds[] = $standardBrandId;
} }
print_r($mainBrands);
print_r($standardBrandIds);
echo PHP_EOL;
if (!empty($standardBrandIds)) { if (!empty($standardBrandIds)) {
$standardBrandIdsStr = implode(',', $standardBrandIds); $standardBrandIdsStr = implode(',', $standardBrandIds);
} else { } else {
$standardBrandIdsStr = ''; $standardBrandIdsStr = '';
} }
// $supplierModel->where('supplier_id', $supplier['supplier_id'])->update([ $supplierModel->where('supplier_id', $supplier['supplier_id'])->update([
// 'main_brands' => $standardBrandIdsStr 'main_brands' => $standardBrandIdsStr
// ]); ]);
print_r($standardBrandIds);
} }
} }
} }
......
...@@ -174,7 +174,7 @@ class SupplierTransformer ...@@ -174,7 +174,7 @@ class SupplierTransformer
$brandNames = ''; $brandNames = '';
foreach ($brands as $brand) { foreach ($brands as $brand) {
$brand = json_decode($brand, true); $brand = json_decode($brand, true);
$brandNames = $brandNames . $brand['brand_name']; $brandNames = $brandNames .' | '. $brand['brand_name'];
} }
return $brandNames; return $brandNames;
} }
......
...@@ -45,7 +45,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -45,7 +45,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
$service->initSystemTag(); $service->initSystemTag();
$service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid(); // $service->transferFileData();
// $service->initSystemTag(); // $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $service->transferFileData(); // $service->replaceStandardBrandId();
}); });
...@@ -13,7 +13,7 @@ class TransformableTimeIntervalPresenter ...@@ -13,7 +13,7 @@ class TransformableTimeIntervalPresenter
$unique = "unique_" . mt_rand(1, 100000); $unique = "unique_" . mt_rand(1, 100000);
$defaultKey = array_keys($map)[0]; $defaultKey = array_keys($map)[0];
$todayTimeInterval = Carbon::now()->startOfDay()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString(); $todayTimeInterval = Carbon::now()->startOfDay()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$threeDayTimeInterval = Carbon::now()->subDay(3)->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString(); $threeDayTimeInterval = Carbon::now()->subDay(2)->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$thisWeekTimeInterval = Carbon::now()->startOfWeek()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString(); $thisWeekTimeInterval = Carbon::now()->startOfWeek()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$thisMonthTimeInterval = Carbon::now()->startOfMonth()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString(); $thisMonthTimeInterval = Carbon::now()->startOfMonth()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$html = <<<EOF $html = <<<EOF
......
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