Commit aebc4c1c by mushishixian

处理金蝶采购脚本

parent a5bf8035
<?php
namespace App\Console\Commands;
use App\Http\Services\DataService;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
//设置供应商是否需要跟进
class RemoveEmptyContact extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'remove_empty_contact';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$service = new DataService();
$service->removeEmptyContactChannelUser();
}
}
<?php
namespace App\Console\Commands;
use App\Http\Services\DataService;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
//设置供应商是否需要跟进
class RepairChannelUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'repair_channel_user';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$service = new DataService();
$service->repairChannelUser();
}
}
...@@ -15,6 +15,8 @@ class Kernel extends ConsoleKernel ...@@ -15,6 +15,8 @@ class Kernel extends ConsoleKernel
protected $commands = [ protected $commands = [
// Commands\Inspire::class, // Commands\Inspire::class,
Commands\SetSupplierFollowUp::class, Commands\SetSupplierFollowUp::class,
Commands\RepairChannelUser::class,
Commands\RemoveEmptyContact::class,
]; ];
/** /**
......
...@@ -13,6 +13,7 @@ use App\Model\SupplierChannelModel; ...@@ -13,6 +13,7 @@ use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
use App\Model\UserInfoModel; use App\Model\UserInfoModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
class DataService class DataService
...@@ -20,6 +21,7 @@ class DataService ...@@ -20,6 +21,7 @@ class DataService
//供应商导出给业务整理 //供应商导出给业务整理
public function exportSuppliers() public function exportSuppliers()
{ {
set_time_limit(0);
Excel::create('供应商资料导出', function ($excel) { Excel::create('供应商资料导出', function ($excel) {
$excel->sheet('基本资料', function ($sheet) { $excel->sheet('基本资料', function ($sheet) {
$sheet->setAutoSize(true); $sheet->setAutoSize(true);
...@@ -37,6 +39,7 @@ class DataService ...@@ -37,6 +39,7 @@ class DataService
]; ];
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$suppliers = $model->where('is_type', 0)->get(); $suppliers = $model->where('is_type', 0)->get();
// $suppliers = $model->get();
if (empty($suppliers)) { if (empty($suppliers)) {
return '供应商空'; return '供应商空';
} }
...@@ -120,7 +123,32 @@ class DataService ...@@ -120,7 +123,32 @@ class DataService
//删除虚构的联系人以及对应的采购 //删除虚构的联系人以及对应的采购
public function removeEmptyContactChannelUser() public function removeEmptyContactChannelUser()
{ {
set_time_limit(0);
$supplierModel = new SupplierChannelModel();
$suppliers = $supplierModel->get()->toArray();
foreach ($suppliers as $supplier) {
//删除供应商联系方式表里面,空联系方式的数据,同时也要注意将采购修改回主表
$contactModel = new SupplierContactModel();
$count = $contactModel->where('supplier_id', $supplier['supplier_id'])->count();
if (empty($count)) {
continue;
}
$contactModel->where('supplier_id', $supplier['supplier_id'])->where('supplier_consignee', '')
->where('supplier_telephone', '')->where('supplier_mobile', '')->delete();
$canCheckUids = $contactModel->where('supplier_id', $supplier['supplier_id'])->pluck('can_check_uids');
if ($canCheckUids) {
$canCheckUids = array_unique($canCheckUids->toArray());
$canCheckUids = array_filter($canCheckUids, function ($uid) {
return !empty($uid);
});
$canCheckUids = implode(',', $canCheckUids);
} else {
$canCheckUids = '';
}
$supplierModel->where('supplier_id', $supplier['supplier_id'])->update([
'channel_uid' => $canCheckUids,
]);
}
} }
//从金蝶修复采购员 //从金蝶修复采购员
...@@ -128,7 +156,7 @@ class DataService ...@@ -128,7 +156,7 @@ class DataService
{ {
set_time_limit(0); set_time_limit(0);
$startTime = time(); $startTime = time();
$path = 'data' . DIRECTORY_SEPARATOR . '金蝶采购导入.xls'; $path = 'public' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'channel_user.xls';
Excel::load($path, function ($reader) use ($startTime) { Excel::load($path, function ($reader) use ($startTime) {
$results = $reader->all()->toArray(); $results = $reader->all()->toArray();
foreach ($results as $result) { foreach ($results as $result) {
...@@ -136,11 +164,12 @@ class DataService ...@@ -136,11 +164,12 @@ class DataService
$channelUserName = $result[0]; $channelUserName = $result[0];
$channelModel = new SupplierChannelModel(); $channelModel = new SupplierChannelModel();
//只处理正式供应商 //只处理正式供应商
$supplier = $channelModel->where('supplier_name', $supplierName)->where('is_type', 0)->first(); $supplier = $channelModel->where('supplier_name', trim($supplierName))->first();
//先找出对应的供应商,没有名字一样的,跳过 //先找出对应的供应商,没有名字一样的,跳过
if (empty($supplier)) { if (empty($supplier)) {
continue; continue;
} }
Log::error($supplierName);
$supplier = $supplier->toArray(); $supplier = $supplier->toArray();
/** /**
* 如果找到对应的供应商的话,先找出目前数据库里面的所有采购和对应的联系方式 * 如果找到对应的供应商的话,先找出目前数据库里面的所有采购和对应的联系方式
...@@ -149,44 +178,71 @@ class DataService ...@@ -149,44 +178,71 @@ class DataService
**/ **/
$channelUids = $supplier['channel_uid']; $channelUids = $supplier['channel_uid'];
$supplierId = $supplier['supplier_id']; $supplierId = $supplier['supplier_id'];
if (!empty($channelUids)) { //删除为空的联系人
//删除为空的联系人 $contactModel = new SupplierContactModel();
$contactModel = new SupplierContactModel(); // $contactModel->where('supplier_id', $supplierId)
$contactModel->where('supplier_id', $supplierId) // ->where('supplier_consignee', '')->where('supplier_telephone', '')
->where('supplier_consignee', '')->where('supplier_telephone', '') // ->where('supplier_mobile', '')->where('add_time', '<', $startTime)->delete();
->where('supplier_mobile', '')->where('add_time', '<', $startTime)->delete(); // //得到剩下的采购员
//得到剩下的采购员 $remainChannelUids = $contactModel->where('supplier_id', $supplierId)
$remainChannelUids = $contactModel->where('supplier_id', $supplierId) ->pluck('can_check_uids')->toArray();
->pluck('can_check_uids')->toArray(); // $channelUidData = $remainChannelUids ? implode(',', $remainChannelUids) : '';
$channelUidData = $remainChannelUids ? implode(',', $remainChannelUids) : ''; // $channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $channelUidData]);
$channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $channelUidData]); //把excel的新采购员写进去(先判断是否存在)
//把excel的新采购员写进去(先判断是否存在) //没有联系方式的,要添加一个空的联系方式
//没有联系方式的,要添加一个空的联系方式 $codeModel = new IntracodeModel();
$codeModel = new IntracodeModel(); $excelChannelUid = $code = $codeModel->where('admin_id', '>', 0)->join('user_info',
$excelChannelUid = $code = $codeModel->where('admin_id', '>', 0)->join('user_info', 'lie_intracode.admin_id', '=', 'user_info.userId')
'lie_intracode.admin_id', '=', 'user_info.userId') ->where('user_info.status', '!=', 4)
->where('user_info.name', $channelUserName) ->where('user_info.name', $channelUserName)
->value('code_id'); ->value('code_id');
//存在就可以跳过了 Log::error('根据excel查询到的采购员uid是:' . $excelChannelUid);
if (in_array($excelChannelUid, $remainChannelUids)) { //离职的采购,直接跳过
continue; if (empty($excelChannelUid)) {
} continue;
//不存在的话,要写一个新的空白联系人进去
$contact = [
'supplier_id' => $supplierId,
'admin_id' => 1000,
'add_time' => time(),
'can_check_uids' => $excelChannelUid,
];
$contactModel->insert($contact);
//插入联系方式以后,就可以查询当前有多少采购,然后更新回主表里面
$finalChannelUids = $contactModel->where('supplier_id',
$supplierId)->pluck('can_check_uids')->toArray();
$finalChannelUids = implode(',', $finalChannelUids);
$channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $finalChannelUids]);
dd($supplierId);
} }
//存在就可以跳过了
if (in_array($excelChannelUid, $remainChannelUids)) {
Log::error($excelChannelUid . "存在,跳过");
Log::error(json_encode($remainChannelUids));
continue;
}
//不存在的话,要写一个新的空白联系人进去
$contact = [
'supplier_id' => $supplierId,
'admin_id' => 1000,
'add_time' => time(),
'can_check_uids' => $excelChannelUid,
];
$contactModel->insert($contact);
//插入联系方式以后,就可以查询当前有多少采购,然后更新回主表里面
$finalChannelUids = $contactModel->where('supplier_id',
$supplierId)->pluck('can_check_uids')->toArray();
$finalChannelUids = array_filter($finalChannelUids, function ($uid) {
return !empty($uid);
});
$finalChannelUids = implode(',', $finalChannelUids);
var_dump($supplier['channel_uid']);
$channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $finalChannelUids]);
var_dump($supplier['supplier_id']);
} }
}); });
} }
//判断数据是否对应
public function checkSupplierChannelUser()
{
set_time_limit(0);
$supplierModel = new SupplierChannelModel();
$suppliers = $supplierModel->where('is_type', 0)->get()->toArray();
foreach ($suppliers as $supplier) {
if (empty($supplier['channel_uid'])) {
$contactModel = new SupplierContactModel();
$count = $contactModel->where('supplier_id', $supplier['supplier_id'])->count();
if ($count) {
var_dump($supplier['supplier_id']);
}
}
}
}
} }
\ No newline at end of file
...@@ -44,8 +44,10 @@ Route::match(['get', 'post'], '/test', function () { ...@@ -44,8 +44,10 @@ Route::match(['get', 'post'], '/test', function () {
// sleep(30); // sleep(30);
// echo 123; // echo 123;
$service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
$service->repairChannelUser(); // $service->checkSupplierChannelUser();
// $service->exportSuppliers(); // $service->removeEmptyContactChannelUser();
// $service->repairChannelUser();
$service->exportSuppliers();
// $service->exportSupplierContact(); // $service->exportSupplierContact();
// $service->export(); // $service->export();
// $service->repairData(10); // $service->repairData(10);
......
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