Commit 52a4a5bd by 杨树贤

统计

parent 9310690b
......@@ -95,7 +95,7 @@ class DepartmentService
return $departmentModel->where('department_id', $departmentId)->first()->toArray();
} else {
$department = $departmentModel->where('department_id', $departmentId)->first();
//如果当前的部门id已经是联营采购部门Id(二级,目前有联营一部和联营二部)
//如果当前的部门id已经是联营采购部门Id(二级,目前有联营一部和联营二P部)
if (in_array($departmentId, config('field.LiangYingDepartmentIds'))) {
return $department->toArray();
} else {
......
<?php
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\RedisModel;
use App\Model\SkuUploadItem;
use App\Model\SkuUploadLogModel;
use App\Model\SupplierBlacklistModel;
use App\Model\SupplierChannelModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class StatisticsSkuUploadService
{
//统计近半年上传过sku的品牌sku数量情况
public function statisticBrandSkuNum()
{
$redis = new RedisModel();
$startTime = Carbon::create(2023, 5, 1, 0, 0, 0)->timestamp;
$endTime = Carbon::create(2024, 1, 1, 0, 0, 0)->timestamp;
//先找出主表半年内所有供应商并且按照供应商编码来分组
$logIdsGroupBySupplierCode = SkuUploadLogModel::whereBetween('create_time', [$startTime, $endTime])
->where('status', 3)
->select([
'id',
'supplier_code'
])->get()->groupBy('supplier_code')->toArray();
foreach ($logIdsGroupBySupplierCode as $supplierCode => $items) {
$logIds = array_column($items, 'id');
$exists = $redis->hget('half_year_brand_sku_upload_statistics', $supplierCode);
if (!empty($exists)) {
continue;
}
$brandCountMap = [];
//开始根据logIds去找到所有上传详情去统计
foreach ($logIds as $logId) {
$countByBrandName = SkuUploadItem::selectRaw('brand_name,count(sku_id) as sku_count')
->where('log_id', $logId)
->where('status', 3)
->groupBy('brand_name')->get();
if (empty($countByBrandName)) {
continue;
}
$countByBrandName = collect($countByBrandName)->pluck('sku_count', 'brand_name')->toArray();
foreach ($countByBrandName as $brandName => $skuCount) {
if (isset($brandCountMap[$brandName])) {
$brandCountMap[$brandName] += $skuCount;
} else {
$brandCountMap[$brandName] = $skuCount;
}
}
}
if (empty($brandCountMap)) {
continue;
}
$redis->hset('half_year_brand_sku_upload_statistics', $supplierCode, json_encode($brandCountMap));
}
}
public function getUploadItems($firstId, $lastId)
{
$items = SkuUploadItem::select([
'brand_name',
'sku_id',
'spu_id',
])->where('id', '>=', $firstId)->where('id', '<', $lastId)->get()->toArray();
return $items;
}
}
......@@ -82,5 +82,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route::match(['get', 'post'], '/test', function () {
(new \App\Http\Services\DataService())->exportUpdatedSkuSupplier();
(new \App\Http\Services\StatisticsSkuUploadService())->statisticBrandSkuNum();
});
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