This commit is contained in:
laodaming
2023-06-20 18:37:56 +08:00
parent 313e8a9457
commit f6cee27c3f
19 changed files with 351 additions and 346 deletions

View File

@@ -83,46 +83,49 @@ func (l *CartListLogic) CartList(req *types.CartListReq, userinfo *auth.UserInfo
name = *cartRelativeData.ProductList[productIndex].Title
productSn = strings.ToLower(*cartRelativeData.ProductList[productIndex].Sn)
}
capacity := ""
var sizeList types.CartSizeItem
if sizeIndex, ok := mapProductSize[*v.SizeId]; ok {
capacity = *cartRelativeData.ProductSizeList[sizeIndex].Capacity
err = json.Unmarshal([]byte(*cartRelativeData.ProductSizeList[sizeIndex].Title), &sizeList)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product size`s title")
}
}
designSn := ""
if designIndex, ok := mapProductDesign[*v.DesignId]; ok {
designSn = strings.ToLower(*cartRelativeData.ProductDesignList[designIndex].Sn)
}
option := types.CartOption{}
if model3dIndex, ok := mapProductModel3d[*v.OptionalId]; ok {
option.Id = cartRelativeData.ProductModel3dList[model3dIndex].Id
option.Title = *cartRelativeData.ProductModel3dList[model3dIndex].Title
option.Price = float64(*cartRelativeData.ProductModel3dList[model3dIndex].Price) / float64(100)
}
pcList, err := l.getPcList(cartRelativeData.ProductPriceList, *v.ProductId, *v.MaterialId, *v.SizeId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to calculate step price")
}
rspList = append(rspList, types.CartListRsp{
d := types.CartListRsp{
Id: v.Id,
Cover: *v.Cover,
Name: name,
Capacity: capacity,
Capacity: "",
ETA: time.Now().AddDate(0, 0, 60).Format("2006-01-02 15:04:05"),
Pcs: *v.BuyNum,
ProductSn: productSn,
DesignSn: designSn,
Option: option,
Option: nil,
IsCheck: *v.IsCheck,
TsTime: v.TsTime.Format("2006-01-02 15:04:05"),
PcsList: pcList,
Size: sizeList,
})
Size: nil,
}
var sizeList types.CartSizeItem
if sizeIndex, ok := mapProductSize[*v.SizeId]; ok {
d.Capacity = *cartRelativeData.ProductSizeList[sizeIndex].Capacity
err = json.Unmarshal([]byte(*cartRelativeData.ProductSizeList[sizeIndex].Title), &sizeList)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product size`s title")
}
d.Size = &sizeList
}
if model3dIndex, ok := mapProductModel3d[*v.OptionalId]; ok {
d.Option = &types.CartOption{
Id: cartRelativeData.ProductModel3dList[model3dIndex].Id,
Title: *cartRelativeData.ProductModel3dList[model3dIndex].Title,
Price: float64(*cartRelativeData.ProductModel3dList[model3dIndex].Price) / float64(100),
}
}
rspList = append(rspList, d)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", rspList)
}
@@ -138,7 +141,7 @@ type GetUserCartRelativeListRsp struct {
}
// 获取阶梯对应的价格
func (l *CartListLogic) getPcList(productPriceList []gmodel.FsProductPrice, productId int64, materialId int64, sizeId int64) (list []types.PcsItem, err error) {
func (l *CartListLogic) getPcList(productPriceList []gmodel.FsProductPrice, productId int64, materialId int64, sizeId int64) (list []*types.PcsItem, err error) {
for _, price := range productPriceList {
if *price.ProductId != productId || *price.MaterialId != materialId || *price.SizeId != sizeId {
continue
@@ -159,7 +162,7 @@ func (l *CartListLogic) getPcList(productPriceList []gmodel.FsProductPrice, prod
return nil, errors.New("step num or step price item count can`t be 0 ")
}
for int(*price.MinBuyNum) < stepNumSlice[lenStepNumSlice-1]+5 {
list = append(list, types.PcsItem{
list = append(list, &types.PcsItem{
Num: *price.MinBuyNum,
TotalNum: *price.MinBuyNum * *price.EachBoxNum,
Title: *price.Title,

View File

@@ -109,9 +109,9 @@ func (l *CartOrderDetailLogic) CartOrderDetail(req *types.CartOrderDetailReq, us
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get address")
}
//处理订单数据
addressItems := make([]types.CartAddr, 0, len(addressList))
addressItems := make([]*types.CartAddr, 0, len(addressList))
for _, v := range addressList {
addressItems = append(addressItems, types.CartAddr{
addressItems = append(addressItems, &types.CartAddr{
Id: v.Id,
Name: *v.Name,
FirstName: *v.FirstName,
@@ -125,7 +125,7 @@ func (l *CartOrderDetailLogic) CartOrderDetail(req *types.CartOrderDetailReq, us
IsDefault: *v.IsDefault,
})
}
items := make([]types.CartDetailItem, 0, len(orderDetailList))
items := make([]*types.CartDetailItem, 0, len(orderDetailList))
totalAmount := int64(0) //订单总金额
for _, v := range orderDetailList {
thisTotal := (*v.BuyNum) * (*v.Amount)
@@ -140,7 +140,7 @@ func (l *CartOrderDetailLogic) CartOrderDetail(req *types.CartOrderDetailReq, us
if productIndex, ok := mapProduct[*v.ProductId]; ok {
name = *productList[productIndex].Title
}
items = append(items, types.CartDetailItem{
items = append(items, &types.CartDetailItem{
Cover: *v.Cover,
Pcs: *v.BuyNum,
Amount: fmt.Sprintf("$ %.2f", float64(thisTotal)/100),