Skip to content

Commit

Permalink
Merge branch 'main' into main-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
ixre committed Mar 17, 2023
2 parents 67e42e5 + 86c44dc commit f8b8336
Show file tree
Hide file tree
Showing 58 changed files with 2,329 additions and 2,103 deletions.
10 changes: 3 additions & 7 deletions core/domain/ad/hyper_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ type HyperLinkAdImpl struct {
func (h *HyperLinkAdImpl) getData() *ad.HyperLink {
if h.extValue == nil {
h.extValue = h._rep.GetTextAdData(h.GetDomainId())

//如果不存在,则创建一个新的对象
if h.extValue == nil {
h.extValue = &ad.HyperLink{
AdId: h.GetDomainId(),
}
}
}
return h.extValue
}
Expand All @@ -47,6 +40,9 @@ func (h *HyperLinkAdImpl) Save() (int64, error) {
id, err := h.adImpl.Save()
if err == nil {
v := h.getData()
if v == nil {
v = &ad.HyperLink{}
}
v.AdId = id
_, err = h._rep.SaveTextAdData(v)
}
Expand Down
14 changes: 5 additions & 9 deletions core/domain/ad/image_ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ func (i *ImageAdImpl) getData() *ad.Image {
if gallery.Len() > 0 {
i.extValue = gallery[0]
}

//如果不存在,则创建一个新的对象
if i.extValue == nil {
i.extValue = &ad.Image{
AdId: i.GetDomainId(),
ImageUrl: format.GetNoPicPath(),
Enabled: 1,
}
}
}
return i.extValue
}
Expand All @@ -54,6 +45,11 @@ func (i *ImageAdImpl) Save() (int64, error) {
id, err := i.adImpl.Save()
if err == nil {
v := i.getData()
if v == nil {
v = &ad.Image{
ImageUrl: format.GetNoPicPath(),
}
}
v.AdId = id
_, err = i._rep.SaveImageAdData(v)
}
Expand Down
49 changes: 30 additions & 19 deletions core/domain/cart/normal_cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cart

import (
"errors"
"fmt"
"time"

"github.com/ixre/go2o/core/domain/interface/cart"
"github.com/ixre/go2o/core/domain/interface/item"
"github.com/ixre/go2o/core/domain/interface/member"
"github.com/ixre/go2o/core/domain/interface/merchant/shop"
"github.com/ixre/go2o/core/infrastructure/domain"
"github.com/ixre/go2o/core/infrastructure/log"
)
Expand All @@ -20,10 +20,10 @@ type cartImpl struct {
rep cart.ICartRepo
goodsRepo item.IItemRepo
memberRepo member.IMemberRepo
summary string
shop shop.IShop
deliver member.IDeliverAddress
snapMap map[int64]*item.Snapshot
//summary string
//shop shop.IShop
//deliver member.IDeliverAddress
snapMap map[int64]*item.Snapshot
}

func NewNormalCart(val *cart.NormalCart, rep cart.ICartRepo,
Expand Down Expand Up @@ -70,6 +70,13 @@ func (c *cartImpl) init() cart.ICart {
// 初始化购物车的信息
if c.value != nil && c.value.Items != nil {
c.setAttachGoodsInfo(c.value.Items)
arr := c.value.Items
c.value.Items = make([]*cart.NormalCartItem, 0)
for _, v := range arr {
if v.Sku != nil {
c.value.Items = append(c.value.Items, v)
}
}
}
return c
}
Expand Down Expand Up @@ -120,7 +127,7 @@ func (c *cartImpl) check() error {
}
}
if stock == 0 {
return item.ErrFullOfStock // 已经卖完了
return fmt.Errorf(item.ErrFullOfStock.Error(), it.GetValue().Title) // 已经卖完了
}
if stock < v.Quantity {
return item.ErrOutOfStock // 超出库存
Expand Down Expand Up @@ -176,6 +183,10 @@ func (c *cartImpl) setAttachGoodsInfo(items []*cart.NormalCartItem) {
}
var sku *item.Sku
for _, v := range items {
in := list[v.ItemId]
if in == nil {
continue
}
it := c.goodsRepo.GetItem(v.ItemId)
if it == nil {
continue
Expand All @@ -185,18 +196,18 @@ func (c *cartImpl) setAttachGoodsInfo(items []*cart.NormalCartItem) {
} else {
iv := it.GetValue()
sku = &item.Sku{
ProductId: iv.ProductId,
ItemId: iv.Id,
Title: iv.Title,
Image: iv.Image,
ProductId: in.ProductId,
ItemId: v.ItemId,
Title: in.Title,
Image: in.Image,
SpecData: "",
SpecWord: "",
Code: iv.Code,
OriginPrice: iv.OriginPrice,
Price: iv.Price,
Cost: iv.Cost,
Weight: iv.Weight,
Bulk: iv.Bulk,
Code: in.Code,
OriginPrice: in.OriginPrice,
Price: in.Price,
Cost: in.Cost,
Weight: in.Weight,
Bulk: in.Bulk,
Stock: iv.StockNum,
SaleNum: iv.SaleNum,
}
Expand Down Expand Up @@ -247,7 +258,7 @@ func (c *cartImpl) put(itemId, skuId int64, num int32, reset bool, checkOnly boo
// 判断是否上架

if iv.ShelveState != item.ShelvesOn {
return nil, item.ErrNotOnShelves //未上架
return nil, fmt.Errorf(item.ErrNotOnShelves.Error(), iv.Title) //未上架
}
// 判断商品SkuId
if skuId > 0 {
Expand All @@ -261,7 +272,7 @@ func (c *cartImpl) put(itemId, skuId int64, num int32, reset bool, checkOnly boo
}
// 检查是否已经卖完了
if stock == 0 {
return nil, item.ErrFullOfStock
return nil, fmt.Errorf(item.ErrFullOfStock.Error(), it.GetValue().Title) // 已经卖完了
}

// 添加数量
Expand Down Expand Up @@ -420,7 +431,7 @@ func (c *cartImpl) CheckedItems(checked map[int64][]int64) []*cart.ItemPair {
if checked != nil {
for _, v := range c.value.Items {
arr, ok := checked[int64(v.ItemId)]
if !ok {
if ok {
continue
}
for _, skuId := range arr {
Expand Down
7 changes: 4 additions & 3 deletions core/domain/cart/wholesale_cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cart
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"time"

Expand Down Expand Up @@ -129,7 +130,7 @@ func (c *wholesaleCartImpl) check() error {
}
}
if stock == 0 {
return item.ErrFullOfStock // 已经卖完了
return fmt.Errorf(item.ErrFullOfStock.Error(), it.GetValue().Title) // 已经卖完了
}
if stock < v.Quantity {
return item.ErrOutOfStock // 超出库存
Expand Down Expand Up @@ -268,7 +269,7 @@ func (c *wholesaleCartImpl) put(itemId, skuId int64, quantity int32, reset bool,
stock := iv.StockNum
// 判断是否上架
if iv.ShelveState != item.ShelvesOn {
return nil, item.ErrNotOnShelves //未上架
return nil, fmt.Errorf(item.ErrNotOnShelves.Error(), iv.Title) //未上架
}
// 验证批发权限
wsIt := it.Wholesale()
Expand All @@ -290,7 +291,7 @@ func (c *wholesaleCartImpl) put(itemId, skuId int64, quantity int32, reset bool,
}
// 检查是否已经卖完了
if stock == 0 {
return nil, item.ErrFullOfStock
return nil, fmt.Errorf(item.ErrFullOfStock.Error(), it.GetValue().Title) // 已经卖完了
}
// 添加数量
for _, v := range c.value.Items {
Expand Down
Loading

0 comments on commit f8b8336

Please sign in to comment.