Commit 357e8527 by mushishixian

Merge branch 'ysx-处理金蝶采购-20210607'

parents 58b6f19c aebc4c1c
<?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 '供应商空';
} }
...@@ -52,8 +55,8 @@ class DataService ...@@ -52,8 +55,8 @@ class DataService
$supplier['legal_representative'], $supplier['legal_representative'],
$supplier['tax_number'], $supplier['tax_number'],
$supplier['supplier_group'], $supplier['supplier_group'],
str_replace(" | ",',',$supplier['stockup_type']), str_replace(" | ", ',', $supplier['stockup_type']),
trim($supplier['channel_username'],','), trim($supplier['channel_username'], ','),
$supplier['purchase_username'] ?: '', $supplier['purchase_username'] ?: '',
$supplier['supplier_address'], $supplier['supplier_address'],
]; ];
...@@ -116,4 +119,130 @@ class DataService ...@@ -116,4 +119,130 @@ class DataService
}); });
})->export('xlsx'); })->export('xlsx');
} }
//删除虚构的联系人以及对应的采购
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,
]);
}
}
//从金蝶修复采购员
public function repairChannelUser()
{
set_time_limit(0);
$startTime = time();
$path = 'public' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'channel_user.xls';
Excel::load($path, function ($reader) use ($startTime) {
$results = $reader->all()->toArray();
foreach ($results as $result) {
$supplierName = $result[1];
$channelUserName = $result[0];
$channelModel = new SupplierChannelModel();
//只处理正式供应商
$supplier = $channelModel->where('supplier_name', trim($supplierName))->first();
//先找出对应的供应商,没有名字一样的,跳过
if (empty($supplier)) {
continue;
}
Log::error($supplierName);
$supplier = $supplier->toArray();
/**
* 如果找到对应的供应商的话,先找出目前数据库里面的所有采购和对应的联系方式
* 如果联系方式是空的(之前有脚本设置的默认的空联系方式),就删除,并且要修改excel的采购员进去
* 但是要排除联系方式不为空的采购(即已经有完整联系人的采购)
**/
$channelUids = $supplier['channel_uid'];
$supplierId = $supplier['supplier_id'];
//删除为空的联系人
$contactModel = new SupplierContactModel();
// $contactModel->where('supplier_id', $supplierId)
// ->where('supplier_consignee', '')->where('supplier_telephone', '')
// ->where('supplier_mobile', '')->where('add_time', '<', $startTime)->delete();
// //得到剩下的采购员
$remainChannelUids = $contactModel->where('supplier_id', $supplierId)
->pluck('can_check_uids')->toArray();
// $channelUidData = $remainChannelUids ? implode(',', $remainChannelUids) : '';
// $channelModel->where('supplier_id', $supplierId)->update(['channel_uid' => $channelUidData]);
//把excel的新采购员写进去(先判断是否存在)
//没有联系方式的,要添加一个空的联系方式
$codeModel = new IntracodeModel();
$excelChannelUid = $code = $codeModel->where('admin_id', '>', 0)->join('user_info',
'lie_intracode.admin_id', '=', 'user_info.userId')
->where('user_info.status', '!=', 4)
->where('user_info.name', $channelUserName)
->value('code_id');
Log::error('根据excel查询到的采购员uid是:' . $excelChannelUid);
//离职的采购,直接跳过
if (empty($excelChannelUid)) {
continue;
}
//存在就可以跳过了
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
...@@ -40,11 +40,14 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -40,11 +40,14 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/api/supplier_account/{key}', 'SupplierAccountApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_account/{key}', 'SupplierAccountApiController@Entrance');
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
set_time_limit(0); // set_time_limit(0);
sleep(30); // sleep(30);
echo 123; // echo 123;
// $service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
// $service->exportSuppliers(); // $service->checkSupplierChannelUser();
// $service->removeEmptyContactChannelUser();
// $service->repairChannelUser();
$service->exportSuppliers();
// $service->exportSupplierContact(); // $service->exportSupplierContact();
// $service->export(); // $service->export();
// $service->repairData(10); // $service->repairData(10);
......
<?php
return array(
'cache' => array(
/*
|--------------------------------------------------------------------------
| Enable/Disable cell caching
|--------------------------------------------------------------------------
*/
'enable' => true,
/*
|--------------------------------------------------------------------------
| Caching driver
|--------------------------------------------------------------------------
|
| Set the caching driver
|
| Available methods:
| memory|gzip|serialized|igbinary|discISAM|apc|memcache|temp|wincache|sqlite|sqlite3
|
*/
'driver' => 'memory',
/*
|--------------------------------------------------------------------------
| Cache settings
|--------------------------------------------------------------------------
*/
'settings' => array(
'memoryCacheSize' => '32MB',
'cacheTime' => 600
),
/*
|--------------------------------------------------------------------------
| Memcache settings
|--------------------------------------------------------------------------
*/
'memcache' => array(
'host' => 'localhost',
'port' => 11211,
),
/*
|--------------------------------------------------------------------------
| Cache dir (for discISAM)
|--------------------------------------------------------------------------
*/
'dir' => storage_path('cache')
),
'properties' => array(
'creator' => 'Maatwebsite',
'lastModifiedBy' => 'Maatwebsite',
'title' => 'Spreadsheet',
'description' => 'Default spreadsheet export',
'subject' => 'Spreadsheet export',
'keywords' => 'maatwebsite, excel, export',
'category' => 'Excel',
'manager' => 'Maatwebsite',
'company' => 'Maatwebsite',
),
/*
|--------------------------------------------------------------------------
| Sheets settings
|--------------------------------------------------------------------------
*/
'sheets' => array(
/*
|--------------------------------------------------------------------------
| Default page setup
|--------------------------------------------------------------------------
*/
'pageSetup' => array(
'orientation' => 'portrait',
'paperSize' => '9',
'scale' => '100',
'fitToPage' => false,
'fitToHeight' => true,
'fitToWidth' => true,
'columnsToRepeatAtLeft' => array('', ''),
'rowsToRepeatAtTop' => array(0, 0),
'horizontalCentered' => false,
'verticalCentered' => false,
'printArea' => null,
'firstPageNumber' => null,
),
),
/*
|--------------------------------------------------------------------------
| Creator
|--------------------------------------------------------------------------
|
| The default creator of a new Excel file
|
*/
'creator' => 'Maatwebsite',
'csv' => array(
/*
|--------------------------------------------------------------------------
| Delimiter
|--------------------------------------------------------------------------
|
| The default delimiter which will be used to read out a CSV file
|
*/
'delimiter' => ',',
/*
|--------------------------------------------------------------------------
| Enclosure
|--------------------------------------------------------------------------
*/
'enclosure' => '"',
/*
|--------------------------------------------------------------------------
| Line endings
|--------------------------------------------------------------------------
*/
'line_ending' => "\r\n"
),
'export' => array(
/*
|--------------------------------------------------------------------------
| Autosize columns
|--------------------------------------------------------------------------
|
| Disable/enable column autosize or set the autosizing for
| an array of columns ( array('A', 'B') )
|
*/
'autosize' => true,
/*
|--------------------------------------------------------------------------
| Autosize method
|--------------------------------------------------------------------------
|
| --> PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX
| The default is based on an estimate, which does its calculation based
| on the number of characters in the cell value (applying any calculation
| and format mask, and allowing for wordwrap and rotation) and with an
| "arbitrary" adjustment based on the font (Arial, Calibri or Verdana,
| defaulting to Calibri if any other font is used) and a proportional
| adjustment for the font size.
|
| --> PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT
| The second method is more accurate, based on actual style formatting as
| well (bold, italic, etc), and is calculated by generating a gd2 imagettf
| bounding box and using its dimensions to determine the size; but this
| method is significantly slower, and its accuracy is still dependent on
| having the appropriate fonts installed.
|
*/
'autosize-method' => PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX,
/*
|--------------------------------------------------------------------------
| Auto generate table heading
|--------------------------------------------------------------------------
|
| If set to true, the array indices (or model attribute names)
| will automatically be used as first row (table heading)
|
*/
'generate_heading_by_indices' => true,
/*
|--------------------------------------------------------------------------
| Auto set alignment on merged cells
|--------------------------------------------------------------------------
*/
'merged_cell_alignment' => 'left',
/*
|--------------------------------------------------------------------------
| Pre-calculate formulas during export
|--------------------------------------------------------------------------
*/
'calculate' => false,
/*
|--------------------------------------------------------------------------
| Include Charts during export
|--------------------------------------------------------------------------
*/
'includeCharts' => false,
/*
|--------------------------------------------------------------------------
| Default sheet settings
|--------------------------------------------------------------------------
*/
'sheets' => array(
/*
|--------------------------------------------------------------------------
| Default page margin
|--------------------------------------------------------------------------
|
| 1) When set to false, default margins will be used
| 2) It's possible to enter a single margin which will
| be used for all margins.
| 3) Alternatively you can pass an array with 4 margins
| Default order: array(top, right, bottom, left)
|
*/
'page_margin' => false,
/*
|--------------------------------------------------------------------------
| Value in source array that stands for blank cell
|--------------------------------------------------------------------------
*/
'nullValue' => null,
/*
|--------------------------------------------------------------------------
| Insert array starting from this cell address as the top left coordinate
|--------------------------------------------------------------------------
*/
'startCell' => 'A1',
/*
|--------------------------------------------------------------------------
| Apply strict comparison when testing for null values in the array
|--------------------------------------------------------------------------
*/
'strictNullComparison' => false
),
/*
|--------------------------------------------------------------------------
| Store settings
|--------------------------------------------------------------------------
*/
'store' => array(
/*
|--------------------------------------------------------------------------
| Path
|--------------------------------------------------------------------------
|
| The path we want to save excel file to
|
*/
'path' => storage_path('exports'),
/*
|--------------------------------------------------------------------------
| Return info
|--------------------------------------------------------------------------
|
| Whether we want to return information about the stored file or not
|
*/
'returnInfo' => false
),
/*
|--------------------------------------------------------------------------
| PDF Settings
|--------------------------------------------------------------------------
*/
'pdf' => array(
/*
|--------------------------------------------------------------------------
| PDF Drivers
|--------------------------------------------------------------------------
| Supported: DomPDF, tcPDF, mPDF
*/
'driver' => 'DomPDF',
/*
|--------------------------------------------------------------------------
| PDF Driver settings
|--------------------------------------------------------------------------
*/
'drivers' => array(
/*
|--------------------------------------------------------------------------
| DomPDF settings
|--------------------------------------------------------------------------
*/
'DomPDF' => array(
'path' => base_path('vendor/dompdf/dompdf/')
),
/*
|--------------------------------------------------------------------------
| tcPDF settings
|--------------------------------------------------------------------------
*/
'tcPDF' => array(
'path' => base_path('vendor/tecnick.com/tcpdf/')
),
/*
|--------------------------------------------------------------------------
| mPDF settings
|--------------------------------------------------------------------------
*/
'mPDF' => array(
'path' => base_path('vendor/mpdf/mpdf/')
),
)
)
),
'filters' => array(
/*
|--------------------------------------------------------------------------
| Register read filters
|--------------------------------------------------------------------------
*/
'registered' => array(
'chunk' => 'Maatwebsite\Excel\Filters\ChunkReadFilter'
),
/*
|--------------------------------------------------------------------------
| Enable certain filters for every file read
|--------------------------------------------------------------------------
*/
'enabled' => array()
),
'import' => array(
/*
|--------------------------------------------------------------------------
| Has heading
|--------------------------------------------------------------------------
|
| The sheet has a heading (first) row which we can use as attribute names
|
| Options: true|false|slugged|slugged_with_count|ascii|numeric|hashed|trans|original
|
*/
'heading' => 'false',
/*
|--------------------------------------------------------------------------
| First Row with data or heading of data
|--------------------------------------------------------------------------
|
| If the heading row is not the first row, or the data doesn't start
| on the first row, here you can change the start row.
|
*/
'startRow' => 1,
/*
|--------------------------------------------------------------------------
| Cell name word separator
|--------------------------------------------------------------------------
|
| The default separator which is used for the cell names
| Note: only applies to 'heading' settings 'true' && 'slugged'
|
*/
'separator' => '_',
/*
|--------------------------------------------------------------------------
| Include Charts during import
|--------------------------------------------------------------------------
*/
'includeCharts' => false,
/*
|--------------------------------------------------------------------------
| Sheet heading conversion
|--------------------------------------------------------------------------
|
| Convert headings to ASCII
| Note: only applies to 'heading' settings 'true' && 'slugged'
|
*/
'to_ascii' => false,
/*
|--------------------------------------------------------------------------
| Import encoding
|--------------------------------------------------------------------------
*/
'encoding' => array(
'input' => 'UTF-8',
'output' => 'UTF-8'
),
/*
|--------------------------------------------------------------------------
| Calculate
|--------------------------------------------------------------------------
|
| By default cells with formulas will be calculated.
|
*/
'calculate' => true,
/*
|--------------------------------------------------------------------------
| Ignore empty cells
|--------------------------------------------------------------------------
|
| By default empty cells are not ignored
|
*/
'ignoreEmpty' => false,
/*
|--------------------------------------------------------------------------
| Force sheet collection
|--------------------------------------------------------------------------
|
| For a sheet collection even when there is only 1 sheets.
| When set to false and only 1 sheet found, the parsed file will return
| a row collection instead of a sheet collection.
| When set to true, it will return a sheet collection instead.
|
*/
'force_sheets_collection' => false,
/*
|--------------------------------------------------------------------------
| Date format
|--------------------------------------------------------------------------
|
| The format dates will be parsed to
|
*/
'dates' => array(
/*
|--------------------------------------------------------------------------
| Enable/disable date formatting
|--------------------------------------------------------------------------
*/
'enabled' => true,
/*
|--------------------------------------------------------------------------
| Default date format
|--------------------------------------------------------------------------
|
| If set to false, a carbon object will return
|
*/
'format' => false,
/*
|--------------------------------------------------------------------------
| Date columns
|--------------------------------------------------------------------------
*/
'columns' => array()
),
/*
|--------------------------------------------------------------------------
| Import sheets by config
|--------------------------------------------------------------------------
*/
'sheets' => array(
/*
|--------------------------------------------------------------------------
| Example sheet
|--------------------------------------------------------------------------
|
| Example sheet "test" will grab the firstname at cell A2
|
*/
'test' => array(
'firstname' => 'A2'
)
)
),
'views' => array(
/*
|--------------------------------------------------------------------------
| Styles
|--------------------------------------------------------------------------
|
| The default styles which will be used when parsing a view
|
*/
'styles' => array(
/*
|--------------------------------------------------------------------------
| Table headings
|--------------------------------------------------------------------------
*/
'th' => array(
'font' => array(
'bold' => true,
'size' => 12,
)
),
/*
|--------------------------------------------------------------------------
| Strong tags
|--------------------------------------------------------------------------
*/
'strong' => array(
'font' => array(
'bold' => true,
'size' => 12,
)
),
/*
|--------------------------------------------------------------------------
| Bold tags
|--------------------------------------------------------------------------
*/
'b' => array(
'font' => array(
'bold' => true,
'size' => 12,
)
),
/*
|--------------------------------------------------------------------------
| Italic tags
|--------------------------------------------------------------------------
*/
'i' => array(
'font' => array(
'italic' => true,
'size' => 12,
)
),
/*
|--------------------------------------------------------------------------
| Heading 1
|--------------------------------------------------------------------------
*/
'h1' => array(
'font' => array(
'bold' => true,
'size' => 24,
)
),
/*
|--------------------------------------------------------------------------
| Heading 2
|--------------------------------------------------------------------------
*/
'h2' => array(
'font' => array(
'bold' => true,
'size' => 18,
)
),
/*
|--------------------------------------------------------------------------
| Heading 2
|--------------------------------------------------------------------------
*/
'h3' => array(
'font' => array(
'bold' => true,
'size' => 13.5,
)
),
/*
|--------------------------------------------------------------------------
| Heading 4
|--------------------------------------------------------------------------
*/
'h4' => array(
'font' => array(
'bold' => true,
'size' => 12,
)
),
/*
|--------------------------------------------------------------------------
| Heading 5
|--------------------------------------------------------------------------
*/
'h5' => array(
'font' => array(
'bold' => true,
'size' => 10,
)
),
/*
|--------------------------------------------------------------------------
| Heading 6
|--------------------------------------------------------------------------
*/
'h6' => array(
'font' => array(
'bold' => true,
'size' => 7.5,
)
),
/*
|--------------------------------------------------------------------------
| Hyperlinks
|--------------------------------------------------------------------------
*/
'a' => array(
'font' => array(
'underline' => true,
'color' => array('argb' => 'FF0000FF'),
)
),
/*
|--------------------------------------------------------------------------
| Horizontal rules
|--------------------------------------------------------------------------
*/
'hr' => array(
'borders' => array(
'bottom' => array(
'style' => 'thin',
'color' => array('FF000000')
),
)
)
)
)
);
No preview for this file type
No preview for this file type
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