Commit f0f57d34 by mushishixian

数据å处理脚本

parent 540471c1
......@@ -8,11 +8,13 @@ use App\Http\Transformers\SupplierTransformer;
use App\Model\IntracodeModel;
use App\Model\LogModel;
use App\Model\RedisModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;
//这个服务是处理数据的,比如导出信息,或者临时修复数据,所以代码会比较多
class DataService
{
//供应商导出给业务整理
......@@ -288,7 +290,7 @@ class DataService
'供应商编码' => $supplier['supplier_code'],
'供应商名称' => $supplier['supplier_name'],
'供应商性质' => $supplier['supplier_group'],
'主营品牌' => rtrim($mainBrands,','),
'主营品牌' => rtrim($mainBrands, ','),
'合作类型' => $supplier['stockup_type_name'],
'联系人' => '0',
'SKU上传' => $supplier['sku_num'] ? '是' : '否',
......@@ -329,4 +331,82 @@ class DataService
});
})->export('xlsx');
}
//转移文件数据(之前是只存到一个字段,现在要存到一张表里面去)
public function transferFileData()
{
//先找出所有上传文件非空的供应商
$model = new SupplierChannelModel();
$suppliers = $model->where('qualification_photos', '!=', '')
->where('is_type', 0)->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);
$attachment = [
'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'),
'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);
}
}
}
//历史数据处理
public function changeSupplierIsTypeByCheckChannelUidOrPurchaseUid()
{
$model = new SupplierChannelModel();
$suppliers = $model->where(function ($q) {
$q->where('channel_uid', '!=', '')->orWhere('purchase_uid', '!=', '');
})->where('is_type', 1)->get()->toArray();
if (count($suppliers) > 1709) {
dd("数量有问题");
}
$redis = new RedisModel();
//非正式供应商中存在渠道员/采购员,将供应商改为正式供应商
foreach ($suppliers as $supplier) {
//先查询是否有重复的供应商
$count = $model->where('supplier_name', $supplier['supplier_name'])->count();
if ($count > 1) {
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' => 1,
'status' => 1
]);
}
}
}
......@@ -41,6 +41,6 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
});
Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
$service->exportSuppliersNew();
// $service->transferFileData();
$service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
});
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class SupplierAttachmentModel extends Model
{
protected $connection='web';
protected $table='supplier_attachment';
protected $primaryKey = 'id';
public $timestamps = false;
}
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