Merge branch 'feature/mhw-v1.01' of gitee.com:fusenpack/fusenapi into feature/mhw-v1.01
This commit is contained in:
commit
ca12242768
|
@ -2,6 +2,10 @@ package gmodel
|
|||
|
||||
import "context"
|
||||
|
||||
func (l *FsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3dLight, err error) {
|
||||
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` = ? and `status` = ?", id, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
|
|
|
@ -13,9 +13,11 @@ type FsShoppingCart struct {
|
|||
TemplateId *int64 `gorm:"default:0;" json:"template_id"` // 模板id
|
||||
ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型id
|
||||
SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id
|
||||
LightId *int64 `gorm:"default:0;" json:"light_id"` // 灯光id
|
||||
FittingId *int64 `gorm:"default:0;" json:"fitting_id"` // 配件id
|
||||
PurchaseQuantity *int64 `gorm:"default:0;" json:"purchase_quantity"` // 购买数量
|
||||
Snapshot *string `gorm:"default:'';" json:"snapshot"` //
|
||||
IsSelected *int64 `gorm:"default:0;" json:"is_selected"` // 是否被选中 0非 1是
|
||||
IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车)
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/logic"
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
)
|
||||
|
||||
func ModifyCartPurchaseQuantityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.ModifyCartPurchaseQuantityReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewModifyCartPurchaseQuantityLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.ModifyCartPurchaseQuantity(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/shopping-cart/delete",
|
||||
Handler: DeleteCartHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/shopping-cart/modify",
|
||||
Handler: ModifyCartPurchaseQuantityHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/shopping-cart/get_carts",
|
||||
|
|
|
@ -66,6 +66,8 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
templateTag string //模板表的模板标签
|
||||
fittingJson string //配件的json设计信息
|
||||
fittingName string //配件名
|
||||
lightJson string //灯光设计数据
|
||||
lightName string //灯光名字
|
||||
)
|
||||
//有模板
|
||||
if req.TemplateId > 0 {
|
||||
|
@ -140,6 +142,21 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
if modelInfo.ModelInfo == nil || *modelInfo.ModelInfo == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "the model`s design info is empty")
|
||||
}
|
||||
//获取灯光信息
|
||||
if *modelInfo.Light > 0 {
|
||||
lightInfo, err := l.svcCtx.AllModels.FsProductModel3dLight.FindOne(l.ctx, *modelInfo.Light)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the model`s light info is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light info")
|
||||
}
|
||||
lightName = *lightInfo.Name
|
||||
if lightInfo.Info != nil && *lightInfo.Info != "" {
|
||||
lightJson = *lightInfo.Info
|
||||
}
|
||||
}
|
||||
var sizeKeyInfo shopping_cart.SizeInfo
|
||||
if err = json.Unmarshal([]byte(*sizeInfo.Title), &sizeKeyInfo); err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -174,6 +191,10 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
Qrcode: req.DiyInfo.Qrcode,
|
||||
Slogan: req.DiyInfo.Slogan,
|
||||
},
|
||||
LightInfo: shopping_cart.LightInfo{
|
||||
LightJson: lightJson,
|
||||
LightName: lightName,
|
||||
},
|
||||
}
|
||||
snapshotJsonBytes, _ := json.Marshal(snapshot)
|
||||
snapshotJsonStr := string(snapshotJsonBytes)
|
||||
|
@ -183,6 +204,7 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
ProductId: &req.ProductId,
|
||||
TemplateId: &req.TemplateId,
|
||||
ModelId: &modelInfo.Id,
|
||||
LightId: modelInfo.Light,
|
||||
SizeId: &req.SizeId,
|
||||
FittingId: &req.FittingId,
|
||||
PurchaseQuantity: &req.PurchaseQuantity,
|
||||
|
|
|
@ -46,13 +46,13 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{CalculateResultList: []types.CalculateResultItem{}})
|
||||
}
|
||||
cartIds := make([]int64, 0, len(req.CalculateList))
|
||||
mapCalculateQuantity := make(map[int64]int64)
|
||||
mapCalculateQuantity := make(map[int64]types.CalculateItem)
|
||||
for _, v := range req.CalculateList {
|
||||
cartIds = append(cartIds, v.CartId)
|
||||
if v.PurchaseQuantity <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "purchase quantity must grater than 0")
|
||||
}
|
||||
mapCalculateQuantity[v.CartId] = v.PurchaseQuantity
|
||||
mapCalculateQuantity[v.CartId] = v
|
||||
}
|
||||
//获取购物车列表
|
||||
carts, _, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
|
@ -128,7 +128,11 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
return errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
//请求的数量
|
||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id]
|
||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
||||
isSelected := int64(0)
|
||||
if mapCalculateQuantity[cart.Id].IsSelected {
|
||||
isSelected = 1
|
||||
}
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
|
@ -148,12 +152,16 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
|
||||
})
|
||||
subTotalPrice += totalPrice
|
||||
//更新购物车购买数量
|
||||
err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, &gmodel.FsShoppingCart{
|
||||
updData := &gmodel.FsShoppingCart{
|
||||
PurchaseQuantity: &reqPurchaseQuantity,
|
||||
})
|
||||
if err != nil {
|
||||
}
|
||||
//如果是选中则累加总价
|
||||
if isSelected == 1 {
|
||||
subTotalPrice += totalPrice
|
||||
updData.IsSelected = &isSelected
|
||||
}
|
||||
//更新购物车购买数量
|
||||
if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id))
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ModifyCartPurchaseQuantityLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewModifyCartPurchaseQuantityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModifyCartPurchaseQuantityLogic {
|
||||
return &ModifyCartPurchaseQuantityLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *ModifyCartPurchaseQuantityLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *ModifyCartPurchaseQuantityLogic) ModifyCartPurchaseQuantity(req *types.ModifyCartPurchaseQuantityReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
|
||||
}
|
||||
if req.Id <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "cart id is required")
|
||||
}
|
||||
if req.PurchaseQuantity <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "purchase quantity can not less than 0 or equal to 0")
|
||||
}
|
||||
//查询购物车
|
||||
_, err := l.svcCtx.AllModels.FsShoppingCart.FineOneUserCart(l.ctx, req.Id, userinfo.UserId, "id")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the shopping cart is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get shopping cart info ")
|
||||
}
|
||||
//修改数量
|
||||
err = l.svcCtx.AllModels.FsShoppingCart.Update(l.ctx, req.Id, userinfo.UserId, &gmodel.FsShoppingCart{
|
||||
PurchaseQuantity: &req.PurchaseQuantity,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to modify cart purchase quantity")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, "success")
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *ModifyCartPurchaseQuantityLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -29,11 +29,6 @@ type DeleteCartReq struct {
|
|||
Id int64 `json:"id"` //购物车id
|
||||
}
|
||||
|
||||
type ModifyCartPurchaseQuantityReq struct {
|
||||
Id int64 `json:"id"` //购物车id
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
||||
}
|
||||
|
||||
type GetCartsReq struct {
|
||||
CurrentPage int `form:"current_page"` //当前页
|
||||
}
|
||||
|
@ -95,6 +90,7 @@ type CalculateCartPriceReq struct {
|
|||
type CalculateItem struct {
|
||||
CartId int64 `json:"cart_id"` //购物车id
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
||||
IsSelected bool `json:"is_selected"` //是否是选中的,选中的会统计到总价中
|
||||
}
|
||||
|
||||
type CalculateCartPriceRsp struct {
|
||||
|
|
|
@ -15,9 +15,6 @@ service shopping-cart {
|
|||
//删除购物车
|
||||
@handler DeleteCartHandler
|
||||
post /api/shopping-cart/delete(DeleteCartReq) returns (response);
|
||||
//修改购物车购买数量
|
||||
@handler ModifyCartPurchaseQuantityHandler
|
||||
post /api/shopping-cart/modify(ModifyCartPurchaseQuantityReq) returns (response);
|
||||
//获取购物车列表
|
||||
@handler GetCartsHandler
|
||||
get /api/shopping-cart/get_carts(GetCartsReq) returns (response);
|
||||
|
@ -49,11 +46,7 @@ type DiyInfo {
|
|||
type DeleteCartReq {
|
||||
Id int64 `json:"id"` //购物车id
|
||||
}
|
||||
//修改购物车购买数量
|
||||
type ModifyCartPurchaseQuantityReq {
|
||||
Id int64 `json:"id"` //购物车id
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
||||
}
|
||||
|
||||
//获取购物车列表
|
||||
type GetCartsReq {
|
||||
CurrentPage int `form:"current_page"` //当前页
|
||||
|
@ -109,6 +102,7 @@ type CalculateCartPriceReq {
|
|||
type CalculateItem {
|
||||
CartId int64 `json:"cart_id"` //购物车id
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
||||
IsSelected bool `json:"is_selected"` //是否是选中的,选中的会统计到总价中
|
||||
}
|
||||
type CalculateCartPriceRsp {
|
||||
SubTotalPrice string `json:"sub_total_price"`
|
||||
|
|
|
@ -11,6 +11,7 @@ type CartSnapshot struct {
|
|||
SizeInfo SizeInfo `json:"size_info"` //尺寸基本信息
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品基本信息(只记录不要使用)
|
||||
UserDiyInformation UserDiyInformation `json:"user_diy_information"` //用户diy数据
|
||||
LightInfo LightInfo `json:"light_info"` //灯光数据
|
||||
}
|
||||
type ProductInfo struct {
|
||||
ProductName string `json:"product_name"`
|
||||
|
@ -39,3 +40,7 @@ type UserDiyInformation struct {
|
|||
Qrcode string `json:"qrcode"` //二维码
|
||||
Slogan string `json:"slogan"` //slogan
|
||||
}
|
||||
type LightInfo struct {
|
||||
LightJson string `json:"light_json"` //灯光设计json数据
|
||||
LightName string `json:"light_name"` //名称
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user