Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
colorway
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
golang
colorway
Commits
17fe7a73
Commit
17fe7a73
authored
Jul 04, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): 入库接口时间打印
parent
68a0b2e2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
23 deletions
+40
-23
uploadlogic.go
internal/rpc/internal/logic/product/uploadlogic.go
+8
-0
platform_store_sku.go
internal/rpc/internal/svc/convert/platform_store_sku.go
+18
-20
rate.go
internal/rpc/internal/svc/rate/rate.go
+3
-2
servicecontext.go
internal/rpc/internal/svc/servicecontext.go
+1
-0
reflect.go
pkg/reflect/reflect.go
+1
-1
time.go
pkg/time/time.go
+9
-0
No files found.
internal/rpc/internal/logic/product/uploadlogic.go
View file @
17fe7a73
...
...
@@ -8,6 +8,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"log"
"time"
)
type
UploadLogic
struct
{
...
...
@@ -25,16 +27,20 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
}
func
(
l
*
UploadLogic
)
Upload
(
in
*
colorway
.
ProductUploadRequest
)
(
*
colorway
.
ProductUploadResponse
,
error
)
{
start
:=
time
.
Now
()
productList
,
err
:=
l
.
svcCtx
.
Pc4RpcService
.
Product
.
GetListByDesignerIds
(
l
.
ctx
,
&
product
.
ProductGetListByDesignerIdsRequest
{
DesignerIds
:
in
.
GetStyleNumbers
(),
})
if
err
!=
nil
{
return
nil
,
err
}
log
.
Println
(
"GetListByDesignerIds "
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
start
=
time
.
Now
()
ps
,
err
:=
l
.
svcCtx
.
ProductConvert
.
Convert
(
productList
.
GetDesignerProducts
())
if
err
!=
nil
{
return
nil
,
err
}
log
.
Println
(
"Convert "
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
var
writeModels
[]
mongo
.
WriteModel
for
_
,
p
:=
range
ps
{
filter
:=
bson
.
M
{
...
...
@@ -45,6 +51,8 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ
}
writeModels
=
append
(
writeModels
,
mongo
.
NewUpdateOneModel
()
.
SetFilter
(
filter
)
.
SetUpdate
(
update
)
.
SetUpsert
(
true
))
}
start
=
time
.
Now
()
_
,
err
=
l
.
svcCtx
.
MongoManager
.
ProductModel
.
BulkWrite
(
l
.
ctx
,
writeModels
)
log
.
Println
(
"BulkWrite "
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
return
&
colorway
.
ProductUploadResponse
{},
err
}
internal/rpc/internal/svc/convert/platform_store_sku.go
View file @
17fe7a73
...
...
@@ -6,7 +6,6 @@ import (
"git.chillcy.com/golang/chillcy/pkg/gender"
math2
"git.chillcy.com/golang/chillcy/pkg/math"
"git.chillcy.com/golang/chillcy/pkg/platform"
"git.chillcy.com/golang/chillcy/pkg/sdk/pc3"
"git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
...
...
@@ -46,8 +45,7 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk
})
categoryIds
:=
product
.
GetCategoryIds
()
for
_
,
sitePlatformPriceConfig
:=
range
sitePlatformPriceConfigs
{
var
pc3SkuModel
pc3
.
ModelSku
platformPriceSku
,
err
:=
receiver
.
calculatePlatformPrice
(
product
,
sku
,
oldProduct
,
pc3SkuModel
,
categoryIds
,
sitePlatformPriceConfig
)
platformPriceSku
,
err
:=
receiver
.
calculatePlatformPrice
(
product
,
sku
,
oldProduct
,
categoryIds
,
sitePlatformPriceConfig
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -57,19 +55,19 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk
return
platformStoreSkus
,
nil
}
func
(
receiver
*
PlatformStoreSku
)
calculatePlatformPrice
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
oldProduct
*
productModel
.
Product
,
pc3SkuModel
pc3
.
ModelSku
,
categories
[]
string
,
priceConfig
sitePlatformPriceConfigModel
.
SitePlatformPriceConfig
)
(
productModel
.
ProductColorSkuPlatformStoreSku
,
error
)
{
func
(
receiver
*
PlatformStoreSku
)
calculatePlatformPrice
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
oldProduct
*
productModel
.
Product
,
categories
[]
string
,
priceConfig
sitePlatformPriceConfigModel
.
SitePlatformPriceConfig
)
(
productModel
.
ProductColorSkuPlatformStoreSku
,
error
)
{
var
psSku
productModel
.
ProductColorSkuPlatformStoreSku
if
!
priceConfig
.
IsValid
()
{
return
psSku
,
fmt
.
Errorf
(
"路线价格配置不合法"
)
}
psSku
,
err
:=
receiver
.
calculateRoutePrice
(
product
,
sku
,
oldProduct
,
pc3SkuModel
,
categories
,
priceConfig
.
RoutePriceConfig
,
priceConfig
.
Seller
)
psSku
,
err
:=
receiver
.
calculateRoutePrice
(
product
,
sku
,
oldProduct
,
categories
,
priceConfig
.
RoutePriceConfig
,
priceConfig
.
Seller
)
if
err
!=
nil
{
return
psSku
,
err
}
return
psSku
,
nil
}
func
(
receiver
*
PlatformStoreSku
)
calculateRoutePrice
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
oldProduct
*
productModel
.
Product
,
pc3SkuModel
pc3
.
ModelSku
,
categories
[]
string
,
routeConfig
sitePlatformPriceConfigModel
.
RoutePriceConfig
,
seller
types
.
Seller
)
(
productModel
.
ProductColorSkuPlatformStoreSku
,
error
)
{
func
(
receiver
*
PlatformStoreSku
)
calculateRoutePrice
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
oldProduct
*
productModel
.
Product
,
categories
[]
string
,
routeConfig
sitePlatformPriceConfigModel
.
RoutePriceConfig
,
seller
types
.
Seller
)
(
productModel
.
ProductColorSkuPlatformStoreSku
,
error
)
{
var
platformStoreSku
productModel
.
ProductColorSkuPlatformStoreSku
adapter
,
err
:=
priceRouteAdapter
.
SelectAdapter
(
routeConfig
.
Route
)
...
...
@@ -77,7 +75,7 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel,
return
platformStoreSku
,
err
}
currencyRate
,
err
:=
receiver
.
rate
.
GetRate
(
seller
.
Store
,
pc3SkuModel
.
PriceDetail
.
Currency
,
routeConfig
.
Currency
.
String
())
currencyRate
,
err
:=
receiver
.
rate
.
GetRate
(
seller
.
Store
,
sku
.
PriceDetail
.
Currency
,
routeConfig
.
Currency
.
String
())
if
err
!=
nil
{
return
platformStoreSku
,
err
}
...
...
@@ -106,33 +104,33 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel,
if
fixMargin
!=
0
{
margin
=
1
+
(
fixMargin
/
100
)
}
else
{
margin
,
err
=
receiver
.
calculateMargin
(
product
,
sku
,
routeConfig
,
pc3SkuModel
,
seller
)
margin
,
err
=
receiver
.
calculateMargin
(
product
,
sku
,
routeConfig
,
sku
,
seller
)
if
err
!=
nil
{
return
platformStoreSku
,
err
}
}
margin
=
math2
.
Round
(
math
.
Max
(
1.0
,
margin
),
3
)
// 保底1.0
freight
,
err
:=
receiver
.
calculateFreight
(
pc3SkuModel
,
categories
,
routeConfig
.
FreightConfig
,
seller
.
Store
)
freight
,
err
:=
receiver
.
calculateFreight
(
sku
,
categories
,
routeConfig
.
FreightConfig
,
seller
.
Store
)
if
err
!=
nil
{
return
platformStoreSku
,
err
}
priceDetail
:=
priceRouteAdapter
.
RoutePriceDetail
{
Route
:
routeConfig
.
Route
,
Currency
:
string
(
routeConfig
.
Currency
),
OriginCurrency
:
pc3SkuModel
.
PriceDetail
.
Currency
,
OriginCurrency
:
sku
.
PriceDetail
.
Currency
,
Rate
:
currencyRate
,
Margin
:
margin
,
SubjectRate
:
subjectRate
,
Subject
:
subjectId
,
DiscountRate
:
pc3SkuModel
.
PriceDetail
.
Discount
,
TotalDiscount
:
pc3SkuModel
.
PriceDetail
.
Discount
*
subjectRate
,
DiscountRate
:
sku
.
PriceDetail
.
Discount
,
TotalDiscount
:
sku
.
PriceDetail
.
Discount
*
subjectRate
,
TaxRate
:
1
+
routeConfig
.
TaxRate
,
Freight
:
freight
,
Express
:
receiver
.
calculateExpress
(
categories
,
routeConfig
.
ExpressConfig
),
}
// 计算最终价格
priceDetail
.
Price
,
err
=
adapter
.
GetPrice
(
pc3SkuModel
.
PriceDetail
.
Now
,
priceDetail
,
platform
.
Platform
(
seller
.
Platform
))
priceDetail
.
Price
,
err
=
adapter
.
GetPrice
(
sku
.
PriceDetail
.
Now
,
priceDetail
,
platform
.
Platform
(
seller
.
Platform
))
if
err
!=
nil
{
return
platformStoreSku
,
err
}
...
...
@@ -285,7 +283,7 @@ func (receiver *PlatformStoreSku) isSuitcases(categoryIds []string) bool {
return
false
}
func
(
receiver
*
PlatformStoreSku
)
calculateFreight
(
pc3Sku
pc3
.
ModelSku
,
categoryIds
[]
string
,
config
sitePlatformPriceConfigModel
.
FreightConfig
,
store
types
.
Store
)
(
float64
,
error
)
{
func
(
receiver
*
PlatformStoreSku
)
calculateFreight
(
sk
*
pc4
.
SkuModel
,
categoryIds
[]
string
,
config
sitePlatformPriceConfigModel
.
FreightConfig
,
store
types
.
Store
)
(
float64
,
error
)
{
switch
config
.
FreightStyle
{
case
sitePlatformPriceConfigModel
.
FreightStyleDefault
:
return
config
.
Freight
,
nil
...
...
@@ -301,11 +299,11 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category
// 其他分类就用250
return
100
,
nil
case
sitePlatformPriceConfigModel
.
FreightStylePrice
:
if
pc3Sku
.
PriceDetail
.
Price
<
1500
{
if
sk
.
PriceDetail
.
Price
<
1500
{
return
30
,
nil
}
else
if
pc3Sku
.
PriceDetail
.
Price
<
2500
{
}
else
if
sk
.
PriceDetail
.
Price
<
2500
{
return
50
,
nil
}
else
if
pc3Sku
.
PriceDetail
.
Price
<
3500
{
}
else
if
sk
.
PriceDetail
.
Price
<
3500
{
return
80
,
nil
}
else
{
return
100
,
nil
...
...
@@ -317,7 +315,7 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category
return
0
,
err
}
limitPrice
:=
float64
(
config
.
OverFreight
)
*
currencyRate
goodCnyPrice
:=
pc3Sku
.
PriceDetail
.
Price
*
pc3Sku
.
PriceDetail
.
SubjectRate
goodCnyPrice
:=
sk
.
PriceDetail
.
Price
*
sk
.
PriceDetail
.
SubjectRate
if
goodCnyPrice
>=
limitPrice
{
return
0
,
nil
}
...
...
@@ -334,7 +332,7 @@ func StringSliceToGenders(gs []string) gender.Genders {
return
genders
}
func
(
receiver
*
PlatformStoreSku
)
calculateMargin
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
routeConfig
sitePlatformPriceConfigModel
.
RoutePriceConfig
,
pc3Sku
pc3
.
ModelSku
,
seller
types
.
Seller
)
(
float64
,
error
)
{
func
(
receiver
*
PlatformStoreSku
)
calculateMargin
(
product
*
pc4
.
ProductModel
,
sku
*
pc4
.
SkuModel
,
routeConfig
sitePlatformPriceConfigModel
.
RoutePriceConfig
,
sk
*
pc4
.
SkuModel
,
seller
types
.
Seller
)
(
float64
,
error
)
{
floatMargin
:=
1.0
if
routeConfig
.
Route
==
types
.
RouteComplex
{
...
...
@@ -391,7 +389,7 @@ func (receiver *PlatformStoreSku) calculateMargin(product *pc4.ProductModel, sku
if
marginConfig
.
IsValidLadders
()
{
marginConfig
.
FormatLadders
()
for
_
,
ladder
:=
range
marginConfig
.
Ladders
{
if
ladder
.
IsMatch
(
pc3Sku
.
PriceDetail
.
Price
)
{
if
ladder
.
IsMatch
(
sk
.
PriceDetail
.
Price
)
{
return
(
1
+
ladder
.
Margin
)
*
floatMargin
,
nil
}
}
...
...
internal/rpc/internal/svc/rate/rate.go
View file @
17fe7a73
package
rate
import
(
"fmt"
"git.chillcy.com/golang/chillcy/pkg/sdk/rate"
"git.chillcy.com/golang/colorway/pkg/types"
)
...
...
@@ -21,5 +20,7 @@ func (receiver *Rate) GetRate(store types.Store, from, to string) (float64, erro
case
types
.
StoreTmall2bHK
,
types
.
StoreTmall2bEUR
,
types
.
StoreTmall2bUS
:
return
receiver
.
rateClient
.
Net
(
from
,
to
)
}
return
0
,
fmt
.
Errorf
(
"未配置店铺汇率 %s"
,
store
)
// todo 配置店铺汇率
return
receiver
.
rateClient
.
Net
(
from
,
to
)
//return 0, fmt.Errorf("未配置店铺汇率 %s", store)
}
internal/rpc/internal/svc/servicecontext.go
View file @
17fe7a73
...
...
@@ -32,6 +32,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
if
etcd
.
GetEnv
()
==
etcd
.
EnvDev
{
pc4RpcProductServiceTarget
=
"127.0.0.1:5100"
etcd
.
SetEtcd
(
etcd
.
KeyHttpRateApiUri
.
String
(),
"http://127.0.0.1:6060"
)
}
svc
:=
&
ServiceContext
{
Config
:
c
,
...
...
pkg/reflect/reflect.go
View file @
17fe7a73
...
...
@@ -21,7 +21,7 @@ func MemberMethodCall(obj any, methodName string, in []reflect.Value) error {
method
:=
field
.
MethodByName
(
methodName
)
if
!
method
.
IsValid
()
{
//log.Println(fmt.Errorf("字段 %s 没有 %s 方法\n", fieldType.Name, methodName))
return
nil
continue
}
// 调用 methodName 方法
...
...
pkg/time/time.go
0 → 100644
View file @
17fe7a73
package
time
import
"time"
func
ConsumeSeconds
(
f
func
())
float64
{
start
:=
time
.
Now
()
f
()
return
time
.
Now
()
.
Sub
(
start
)
.
Seconds
()
}
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