Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
55a4526536
|
@ -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
|
||||||
|
|
|
@ -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 CaculateProductPriceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.CaculateProductPriceReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewCaculateProductPriceLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.CaculateProductPrice(&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/caculate_product_price",
|
||||||
|
Handler: CaculateProductPriceHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/product/get_size_by_pid",
|
Path: "/api/product/get_size_by_pid",
|
||||||
|
|
57
server/product/internal/logic/caculateproductpricelogic.go
Normal file
57
server/product/internal/logic/caculateproductpricelogic.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CaculateProductPriceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCaculateProductPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CaculateProductPriceLogic {
|
||||||
|
return &CaculateProductPriceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *CaculateProductPriceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *CaculateProductPriceLogic) CaculateProductPrice(req *types.CaculateProductPriceReq, 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")
|
||||||
|
}
|
||||||
|
//获取产品信息(只是获取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")
|
||||||
|
}
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *CaculateProductPriceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -335,6 +335,13 @@ type GetProductStepPriceReq struct {
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CaculateProductPriceReq struct {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
FittingId int64 `json:"fitting_id,optional"`
|
||||||
|
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"`
|
||||||
|
|
|
@ -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 CaculateProductPriceHandler
|
||||||
|
post /api/product/caculate_product_price(CaculateProductPriceReq) 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,13 @@ type PriceItem {
|
||||||
type GetProductStepPriceReq {
|
type GetProductStepPriceReq {
|
||||||
ProductId int64 `form:"product_id"`
|
ProductId int64 `form:"product_id"`
|
||||||
}
|
}
|
||||||
|
//根据产品+配件搭配计算价格
|
||||||
|
type CaculateProductPriceReq {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
SizeId int64 `json:"size_id"`
|
||||||
|
FittingId int64 `json:"fitting_id,optional"`
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"`
|
||||||
|
}
|
||||||
//获取产品尺寸列表
|
//获取产品尺寸列表
|
||||||
type GetSizeByPidReq {
|
type GetSizeByPidReq {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user