Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
52a4a5bd
authored
Jan 09, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
统计
parent
9310690b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
2 deletions
app/Http/Services/DataService.php
app/Http/Services/DepartmentService.php
app/Http/Services/StatisticsSkuUploadService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
52a4a5bd
This diff is collapsed.
Click to expand it.
app/Http/Services/DepartmentService.php
View file @
52a4a5bd
...
...
@@ -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
{
...
...
app/Http/Services/StatisticsSkuUploadService.php
0 → 100644
View file @
52a4a5bd
<?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
;
}
}
app/Http/routes.php
View file @
52a4a5bd
...
...
@@ -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
();
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment