Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
cdeec5a4e1
model/gmodel
server
info/internal
product/internal
server_api
utils/step_price
|
@ -87,14 +87,14 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
err = tx.Model(&FsAddress{}).Where(" `user_id` = ? and `status` = ? and `address_id = ?` ", userId, 1, addressId).
|
err = tx.Model(&FsAddress{}).Where(" `user_id` = ? and `status` = ? and `address_id` = ? ", userId, 1, addressId).
|
||||||
UpdateColumn("ltime", now.Add(time.Hour*24*365*100)).
|
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
|
||||||
UpdateColumn("utime", now).Error
|
UpdateColumn("utime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id != ? and `ltime` > ?` ", userId, 1, addressId, now.Add(time.Hour*24*365)).
|
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id` != ? and `ltime` > ? ", userId, 1, addressId, now.AddDate(10, 0, 0)).
|
||||||
UpdateColumn("ltime", now).Error
|
UpdateColumn("ltime", now).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -107,10 +107,8 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
||||||
address := &FsAddress{
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).
|
||||||
AddressId: addressId,
|
Where("`address_id` = ? and `user_id` = ? and `status` = ? ", addressId, userId, 1).
|
||||||
UserId: &userId,
|
UpdateColumn("status", 0).Error
|
||||||
}
|
|
||||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = ? ", addressId, userId, 1).Delete(address).Error
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ type StepPriceJsonStruct struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) {
|
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) {
|
||||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id)
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? and `status` =? ", id, 1)
|
||||||
if len(fields) > 0 {
|
if len(fields) > 0 {
|
||||||
db = db.Select(fields[0])
|
db = db.Select(fields[0])
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (d *FsProductModel3dModel) GetAllByIdsWithoutStatus(ctx context.Context, id
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?)", ids)
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
||||||
if len(fields) > 0 {
|
if len(fields) > 0 {
|
||||||
db = db.Select(fields[0])
|
db = db.Select(fields[0])
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
func (d *FsProductModel3dModel) Update(ctx context.Context, id int64, data *FsProductModel3d) error {
|
func (d *FsProductModel3dModel) Update(ctx context.Context, id int64, data *FsProductModel3d) error {
|
||||||
return d.db.WithContext(ctx).Where("`id` = ? ", id).Updates(&data).Error
|
return d.db.WithContext(ctx).Where("`id` = ? and `status` =? ", id, 1).Updates(&data).Error
|
||||||
}
|
}
|
||||||
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64, fields ...string) (resp []FsProductModel3d, err error) {
|
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64, fields ...string) (resp []FsProductModel3d, err error) {
|
||||||
if len(sizeIds) == 0 {
|
if len(sizeIds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, tag)
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ? and `status` = ?", sizeIds, tag, 1)
|
||||||
if len(fields) != 0 {
|
if len(fields) != 0 {
|
||||||
db = db.Select(fields[0])
|
db = db.Select(fields[0])
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductModel3d, err error) {
|
func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductModel3d, err error) {
|
||||||
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Find(&resp).Error
|
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`status` = ?", 1).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func (d *FsProductModel3dModel) GetGroupPartListByProductIds(ctx context.Context
|
||||||
if len(productIds) == 0 {
|
if len(productIds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).
|
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`product_id` in(?) and `status` =? ", productIds, 1).
|
||||||
Select("product_id,group_concat(part_list) as part_list").
|
Select("product_id,group_concat(part_list) as part_list").
|
||||||
Group("product_id").Find(&resp).Error
|
Group("product_id").Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
|
@ -142,3 +142,13 @@ func (d *FsProductModel3dModel) GetAllByProductIdTag(ctx context.Context, produc
|
||||||
err = db.Find(&resp).Error
|
err = db.Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context, productId, sizeId, tag int64, fields ...string) (resp *FsProductModel3d, err error) {
|
||||||
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).
|
||||||
|
Where("`product_id` = ? and `size_id` = ? and `tag` = ? and `status` = ?", productId, sizeId, tag, 1).
|
||||||
|
Order("sort DESC")
|
||||||
|
if len(fields) != 0 {
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
|
err = db.Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/server/info/internal/svc"
|
"fusenapi/server/info/internal/svc"
|
||||||
|
@ -11,7 +10,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,6 +175,10 @@ func TestCaseJSON_EXTRACT(t *testing.T) {
|
||||||
|
|
||||||
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
|
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
|
||||||
// err = conn.Exec(updatesql, 6).Error
|
// err = conn.Exec(updatesql, 6).Error
|
||||||
|
|
||||||
|
var result []gmodel.FsAddress
|
||||||
|
conn.Model(&gmodel.FsAddress{}).Find(&result)
|
||||||
|
|
||||||
log.Println(conn.Model(&gmodel.FsChangeCode{}).Select("id").Where("id = 5").Take(nil).Error)
|
log.Println(conn.Model(&gmodel.FsChangeCode{}).Select("id").Where("id = 5").Take(nil).Error)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ type AddressNameRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressRequest struct {
|
type AddressRequest struct {
|
||||||
AddressId int64 `json:"address_id,omitempty"`
|
AddressId int64 `json:"address_id,optional"`
|
||||||
IsDefault int64 `json:"is_default"` //是否默认
|
IsDefault int64 `json:"is_default"` //是否默认
|
||||||
AddressName string `json:"address_name"` //收货人
|
AddressName string `json:"address_name"` //收货人
|
||||||
FirstName string `json:"first_name"` //first_name
|
FirstName string `json:"first_name"` //first_name
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/logic"
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CalculateProductPriceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.CalculateProductPriceReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewCalculateProductPriceLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.CalculateProductPrice(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,6 +77,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/product/get_product_step_price",
|
Path: "/api/product/get_product_step_price",
|
||||||
Handler: GetProductStepPriceHandler(serverCtx),
|
Handler: GetProductStepPriceHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/product/calculate_product_price",
|
||||||
|
Handler: CalculateProductPriceHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/product/get_size_by_pid",
|
Path: "/api/product/get_size_by_pid",
|
||||||
|
|
97
server/product/internal/logic/calculateproductpricelogic.go
Normal file
97
server/product/internal/logic/calculateproductpricelogic.go
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/format"
|
||||||
|
"fusenapi/utils/step_price"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CalculateProductPriceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCalculateProductPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CalculateProductPriceLogic {
|
||||||
|
return &CalculateProductPriceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *CalculateProductPriceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateProductPriceReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if req.ProductId <= 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product id")
|
||||||
|
}
|
||||||
|
if req.SizeId <= 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:size id")
|
||||||
|
}
|
||||||
|
if req.PurchaseQuantity <= 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:purchase quantity")
|
||||||
|
}
|
||||||
|
//获取产品信息(只是获取id)
|
||||||
|
_, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId, "id")
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||||
|
}
|
||||||
|
//根据产品跟尺寸获取模型价格信息
|
||||||
|
modelInfo, err := l.svcCtx.AllModels.FsProductModel3d.FindOneByProductIdSizeIdTag(l.ctx, req.ProductId, req.SizeId, constants.TAG_MODEL, "id,step_price")
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "model info is not exists")
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model info")
|
||||||
|
}
|
||||||
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price")
|
||||||
|
}
|
||||||
|
//配件
|
||||||
|
fittingPrice := int64(0)
|
||||||
|
if req.FittingId > 0 {
|
||||||
|
fittingInfo, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, req.FittingId, "id,price")
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "fitting info is not exists")
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting info")
|
||||||
|
fittingPrice = *fittingInfo.Price
|
||||||
|
}
|
||||||
|
totalPrice, itemPrice, err := step_price.GetNewCentStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to calculate product price ")
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateProductPriceRsp{
|
||||||
|
ItemPrice: format.CentitoDollar(itemPrice, 3),
|
||||||
|
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
|
||||||
|
PurchaseQuantity: req.PurchaseQuantity,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *CalculateProductPriceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -59,7 +59,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
||||||
} else {
|
} else {
|
||||||
//根据模板找到模型sizeId
|
//根据模板找到模型sizeId
|
||||||
defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id")
|
defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id")
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "the template`s model is not exists ")
|
||||||
|
}
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ")
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,6 +335,19 @@ type GetProductStepPriceReq struct {
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CalculateProductPriceReq struct {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
FittingId int64 `json:"fitting_id,optional"`
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CalculateProductPriceRsp struct {
|
||||||
|
ItemPrice string `json:"item_price"`
|
||||||
|
TotalPrice string `json:"total_price"`
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetSizeByPidReq struct {
|
type GetSizeByPidReq struct {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ service info {
|
||||||
post /api/info/address/default(AddressIdRequest) returns (response);
|
post /api/info/address/default(AddressIdRequest) returns (response);
|
||||||
|
|
||||||
@handler AddressAddHandler
|
@handler AddressAddHandler
|
||||||
post /api/info/address/add(AddressNameRequest) returns (response);
|
post /api/info/address/add(AddressRequest) returns (response);
|
||||||
|
|
||||||
@handler AddressUpdateHandler
|
@handler AddressUpdateHandler
|
||||||
post /api/info/address/update(AddressObjectRequest) returns (response);
|
post /api/info/address/update(AddressObjectRequest) returns (response);
|
||||||
|
@ -48,7 +48,7 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressRequest {
|
AddressRequest {
|
||||||
AddressId int64 `json:"address_id,omitempty"`
|
AddressId int64 `json:"address_id,optional"`
|
||||||
IsDefault int64 `json:"is_default"` //是否默认
|
IsDefault int64 `json:"is_default"` //是否默认
|
||||||
AddressName string `json:"address_name"` //收货人
|
AddressName string `json:"address_name"` //收货人
|
||||||
FirstName string `json:"first_name"` //first_name
|
FirstName string `json:"first_name"` //first_name
|
||||||
|
|
|
@ -50,6 +50,9 @@ service product {
|
||||||
//获取产品阶梯价格信息
|
//获取产品阶梯价格信息
|
||||||
@handler GetProductStepPriceHandler
|
@handler GetProductStepPriceHandler
|
||||||
get /api/product/get_product_step_price(GetProductStepPriceReq) returns (response);
|
get /api/product/get_product_step_price(GetProductStepPriceReq) returns (response);
|
||||||
|
//根据产品+配件搭配计算价格
|
||||||
|
@handler CalculateProductPriceHandler
|
||||||
|
post /api/product/calculate_product_price(CalculateProductPriceReq) returns (response);
|
||||||
//获取产品尺寸列表
|
//获取产品尺寸列表
|
||||||
@handler GetSizeByPidHandler
|
@handler GetSizeByPidHandler
|
||||||
get /api/product/get_size_by_pid(GetSizeByPidReq) returns (response);
|
get /api/product/get_size_by_pid(GetSizeByPidReq) returns (response);
|
||||||
|
@ -383,6 +386,18 @@ type PriceItem {
|
||||||
type GetProductStepPriceReq {
|
type GetProductStepPriceReq {
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
//根据产品+配件搭配计算价格
|
||||||
|
type CalculateProductPriceReq {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
FittingId int64 `json:"fitting_id,optional"`
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||||
|
}
|
||||||
|
type CalculateProductPriceRsp {
|
||||||
|
ItemPrice string `json:"item_price"`
|
||||||
|
TotalPrice string `json:"total_price"`
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||||
|
}
|
||||||
//获取产品尺寸列表
|
//获取产品尺寸列表
|
||||||
type GetSizeByPidReq {
|
type GetSizeByPidReq {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 返回厘
|
// 旧的返回厘(即将废弃)
|
||||||
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||||
return int64(stepPrice[len(stepPrice)-1])
|
return int64(stepPrice[len(stepPrice)-1])
|
||||||
|
@ -22,10 +22,10 @@ func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新的阶梯价格(返回美元)
|
// 新的阶梯价格(返回美元)
|
||||||
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price float64, err error) {
|
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice float64, err error) {
|
||||||
l := len(stepPrice.PriceRange)
|
l := len(stepPrice.PriceRange)
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
return 0, errors.New("price range is not set")
|
return 0, 0, errors.New("price range is not set")
|
||||||
}
|
}
|
||||||
//遍历查询合适的价格
|
//遍历查询合适的价格
|
||||||
for k, v := range stepPrice.PriceRange {
|
for k, v := range stepPrice.PriceRange {
|
||||||
|
@ -33,34 +33,34 @@ func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruc
|
||||||
if purchaseQuantity > v.StartQuantity {
|
if purchaseQuantity > v.StartQuantity {
|
||||||
//最后一个 || 小于等于终点
|
//最后一个 || 小于等于终点
|
||||||
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
||||||
return float64(v.Price+fittingPrice) / 1000, nil
|
itemPrice = float64(v.Price+fittingPrice) / 1000
|
||||||
|
return itemPrice * float64(purchaseQuantity), itemPrice / 1000, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//遍历里面没有则返回第一个
|
//遍历里面没有则返回第一个
|
||||||
return float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000, nil
|
itemPrice = float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000
|
||||||
|
return itemPrice * float64(purchaseQuantity), itemPrice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新的阶梯价格(返回厘)
|
// 新的阶梯价格(返回厘)
|
||||||
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price int64, err error) {
|
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice int64, err error) {
|
||||||
l := len(stepPrice.PriceRange)
|
l := len(stepPrice.PriceRange)
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
return 0, errors.New("price range is not set")
|
return 0, 0, errors.New("price range is not set")
|
||||||
}
|
}
|
||||||
//遍历查询合适的价格
|
//遍历查询合适的价格
|
||||||
for k, v := range stepPrice.PriceRange {
|
for k, v := range stepPrice.PriceRange {
|
||||||
//购买数量>起点
|
//购买数量>起点
|
||||||
if purchaseQuantity > v.StartQuantity {
|
if purchaseQuantity > v.StartQuantity {
|
||||||
//最后一个
|
//最后一个 || 小于等于终点
|
||||||
if k == l-1 {
|
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
||||||
return v.Price + fittingPrice, nil
|
itemPrice = v.Price + fittingPrice
|
||||||
}
|
return itemPrice * purchaseQuantity, itemPrice, nil
|
||||||
//小于等于终点
|
|
||||||
if purchaseQuantity <= v.EndQuantity {
|
|
||||||
return v.Price + fittingPrice, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//遍历里面没有则返回第一个
|
//遍历里面没有则返回第一个
|
||||||
return stepPrice.PriceRange[0].Price + fittingPrice, nil
|
itemPrice = stepPrice.PriceRange[0].Price + fittingPrice
|
||||||
|
return itemPrice * purchaseQuantity, itemPrice, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user