Commit 17941ce6 by 杨树贤

供应商导出脚本

parent 3ac6ba49
...@@ -3,16 +3,12 @@ ...@@ -3,16 +3,12 @@
namespace App\Http\Services; namespace App\Http\Services;
//后台用户相关信息服务 //后台用户相关信息服务
use App\Http\Transformers\SupplierContactTransformer;
use App\Http\Transformers\SupplierTransformer; use App\Http\Transformers\SupplierTransformer;
use App\Model\BigData\DataManageModel; use App\Model\BigData\DataManageModel;
use App\Model\BrandModel;
use App\Model\DepartmentModel; use App\Model\DepartmentModel;
use App\Model\IntracodeModel; use App\Model\IntracodeModel;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\Purchase\PurchaseOrderModel; use App\Model\Purchase\PurchaseOrderModel;
use App\Model\Purchase\StockInItemModel;
use App\Model\Purchase\StockInModel;
use App\Model\RedisModel; use App\Model\RedisModel;
use App\Model\SkuUploadItem; use App\Model\SkuUploadItem;
use App\Model\SkuUploadLogModel; use App\Model\SkuUploadLogModel;
...@@ -20,22 +16,14 @@ use App\Model\SpuBrandModel; ...@@ -20,22 +16,14 @@ use App\Model\SpuBrandModel;
use App\Model\StandardBrandMappingModel; use App\Model\StandardBrandMappingModel;
use App\Model\StandardBrandModel; use App\Model\StandardBrandModel;
use App\Model\SupplierAccountModel; use App\Model\SupplierAccountModel;
use App\Model\SupplierAttachmentModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierPayTypeModel;
use App\Model\UserInfoModel; use App\Model\UserInfoModel;
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\Redis; use Illuminate\Support\Facades\Redis;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpParser\Node\Stmt\DeclareDeclare;
//这个服务是处理数据的,比如导出信息,或者临时修复数据,所以代码会比较多 //这个服务是处理数据的,比如导出信息,或者临时修复数据,所以代码会比较多
class DataService class DataService
...@@ -1294,8 +1282,9 @@ class DataService ...@@ -1294,8 +1282,9 @@ class DataService
{ {
ini_set('memory_limit', -1); ini_set('memory_limit', -1);
$redis = new RedisModel(); $redis = new RedisModel();
$halfYearTime = Carbon::now()->startOfYear()->subMonths(7)->timestamp; $date = Carbon::create(2023, 5, 1, 0, 0, 0);
$halfYearTime = $date->timestamp;
$endTime = Carbon::create(2024, 1, 1, 0, 0, 0)->timestamp;
//$suppliers = SupplierChannelModel::where('is_type', 0)->where('uploaded_sku', 1)->get()->toArray(); //$suppliers = SupplierChannelModel::where('is_type', 0)->where('uploaded_sku', 1)->get()->toArray();
$suppliers = SupplierChannelModel::select([ $suppliers = SupplierChannelModel::select([
'supplier_id', 'supplier_id',
...@@ -1362,6 +1351,7 @@ class DataService ...@@ -1362,6 +1351,7 @@ class DataService
//要去上传记录表 //要去上传记录表
$logIds = SkuUploadLogModel::where('supplier_code', $supplier['supplier_code']) $logIds = SkuUploadLogModel::where('supplier_code', $supplier['supplier_code'])
->where('create_time', '>=', $halfYearTime) ->where('create_time', '>=', $halfYearTime)
->where('create_time', '<=', $endTime)
->where('status', 3)->pluck('id')->toArray(); ->where('status', 3)->pluck('id')->toArray();
$skuCountByStandardBrandName = []; $skuCountByStandardBrandName = [];
if (!empty($logIds)) { if (!empty($logIds)) {
...@@ -1408,7 +1398,7 @@ class DataService ...@@ -1408,7 +1398,7 @@ class DataService
$supplier['supplier_name'], $supplier['supplier_name'],
array_get(config('fixed.SupplierGroup'), $supplier['supplier_group'], '未设置'), array_get(config('fixed.SupplierGroup'), $supplier['supplier_group'], '未设置'),
$skuUserDepartment, $skuUserDepartment,
date('Y-m-d H:i:s', $supplier['sku_update_time']), $supplier['sku_update_time'] ? date('Y-m-d H:i:s', $supplier['sku_update_time']) : '',
!empty($supplierAccountMap[$supplierId]) ? '是' : '否', !empty($supplierAccountMap[$supplierId]) ? '是' : '否',
array_get($frqData, 'quote_num', 0), array_get($frqData, 'quote_num', 0),
array_get($frqData, 'pur_num', 0), array_get($frqData, 'pur_num', 0),
...@@ -1426,6 +1416,7 @@ class DataService ...@@ -1426,6 +1416,7 @@ class DataService
//近半年内,查出更新过的品牌对应SKU数量最多排名(前100名);需要字段“品牌名称,SKU数量,型号数量” //近半年内,查出更新过的品牌对应SKU数量最多排名(前100名);需要字段“品牌名称,SKU数量,型号数量”
$excelData2 = []; $excelData2 = [];
$countByBrandName = SkuUploadItem::where('status', 3)->where('create_time', '>=', $halfYearTime) $countByBrandName = SkuUploadItem::where('status', 3)->where('create_time', '>=', $halfYearTime)
->where('create_time', '<=', $endTime)
->selectRaw('brand_name,count(distinct(sku_id)) as sku_count,count(distinct(spu_id)) as spu_id_count') ->selectRaw('brand_name,count(distinct(sku_id)) as sku_count,count(distinct(spu_id)) as spu_id_count')
->groupBy('brand_name')->orderBy('sku_count', 'desc')->get()->toArray(); ->groupBy('brand_name')->orderBy('sku_count', 'desc')->get()->toArray();
foreach ($countByBrandName as &$value) { foreach ($countByBrandName as &$value) {
...@@ -1493,4 +1484,57 @@ class DataService ...@@ -1493,4 +1484,57 @@ class DataService
})->export('xlsx'); })->export('xlsx');
} }
//导出2023年有更新过sku得供应商
public function exportUpdatedSkuSupplier()
{
$startTime = Carbon::now()->subYear()->startOfYear()->timestamp;
$endTime = Carbon::now()->subYear()->endOfYear()->timestamp;
$suppliers = SupplierChannelModel::whereBetween('sku_update_time', [$startTime, $endTime])
->select([
'supplier_name',
'supplier_group',
'yunxin_channel_uid',
])->get()->toArray();
//区分采购一部,采购二部,采购三部的人员
$suppliersOne = $suppliersTwo = $suppliersThird = [];
foreach ($suppliers as &$supplier) {
$yunxinChannelUid = $supplier['yunxin_channel_uid'];
$user = (new AdminUserService())->getAdminUserInfoByCodeId($yunxinChannelUid);
$userId = $user['userId'];
//获取当前部门
$departmentName = (new DepartmentService())->getParentDepartmentNameByUserName($user['name']);
$supplier['department_name'] = $departmentName;
$supplier['yunxin_user_name'] = $user['name'];
}
unset($supplier);
$suppliers = collect($suppliers)->groupBy('department_name')->toArray();
Excel::create('供应商导出', function ($excel) use ($suppliers) {
$header = [
'供应商名称',
'供应商性质',
'线上采购员'
];
foreach ($suppliers as $departmentName => $supplierList) {
$excelData = [];
if (empty($departmentName)) {
continue;
}
foreach ($supplierList as $item) {
$excelData[] = [
$item['supplier_name'],
array_get(config('fixed.SupplierGroup'), $item['supplier_group']),
$item['yunxin_user_name'],
];
}
array_unshift($excelData, $header);
$excel->sheet($departmentName, function ($sheet) use ($excelData) {
$sheet->fromArray($excelData);
});
}
})->export('xlsx');
}
} }
...@@ -122,6 +122,18 @@ class DepartmentService ...@@ -122,6 +122,18 @@ class DepartmentService
return $departmentName; return $departmentName;
} }
//根据用户名获取父级部门名称
public function getParentDepartmentNameByUserName($userName)
{
$departmentId = UserInfoModel::where('name', $userName)->value('department_id');
$parentDepartmentId = DepartmentModel::where('department_id', $departmentId)->value('parent_id');
$parentDepartmentName = DepartmentModel::where('department_id',$parentDepartmentId)->value('department_name');
if (empty($parentDepartmentName)) {
$parentDepartmentName = DepartmentModel::where('department_id', $departmentId)->value('department_name');
}
return $parentDepartmentName;
}
public function getDepartmentNameMapByUserIds($userIds) public function getDepartmentNameMapByUserIds($userIds)
{ {
$userIds = array_unique($userIds); $userIds = array_unique($userIds);
......
...@@ -82,5 +82,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -82,5 +82,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
(new DepartmentService())->getCreateUserDepartmentList(); (new \App\Http\Services\DataService())->exportUpdatedSkuSupplier();
}); });
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