Skip to content

Commit

Permalink
📄新增代码注释
Browse files Browse the repository at this point in the history
  • Loading branch information
dalaohekele committed Oct 22, 2022
1 parent f340561 commit d05839f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions api/v1/mall/mall_goods_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import (
type MallGoodsInfoApi struct {
}

// 商品搜索
func (m *MallGoodsInfoApi) GoodsSearch(c *gin.Context) {

pageNumber, _ := strconv.Atoi(c.Query("pageNumber"))
goodsCategoryId, _ := strconv.Atoi(c.Query("goodsCategoryId"))
keyword := c.Query("keyword")
orderBy := c.Query("orderBy")

if err, list, total := mallGoodsInfoService.MallGoodsListBySearch(pageNumber, goodsCategoryId, keyword, orderBy); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败"+err.Error(), c)
Expand All @@ -29,7 +28,6 @@ func (m *MallGoodsInfoApi) GoodsSearch(c *gin.Context) {
PageSize: 10,
}, "获取成功", c)
}

}

func (m *MallGoodsInfoApi) GoodsDetail(c *gin.Context) {
Expand Down
3 changes: 2 additions & 1 deletion service/mall/mall_goods_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type MallGoodsInfoService struct {
}

// MallGoodsListBySearch 商品搜索分页
func (m *MallGoodsInfoService) MallGoodsListBySearch(pageNumber int, goodsCategoryId int, keyword string, orderBy string) (err error, searchGoodsList []mallRes.GoodsSearchResponse, total int64) {
// 根据搜索条件查询
var goodsList []manage.MallGoodsInfo
Expand Down Expand Up @@ -45,10 +46,10 @@ func (m *MallGoodsInfoService) MallGoodsListBySearch(pageNumber int, goodsCatego
}
searchGoodsList = append(searchGoodsList, searchGoods)
}

return
}

// GetMallGoodsInfo 获取商品信息
func (m *MallGoodsInfoService) GetMallGoodsInfo(id int) (err error, res mallRes.GoodsInfoDetailResponse) {
var mallGoodsInfo manage.MallGoodsInfo
err = global.GVA_DB.Where("goods_id = ?", id).First(&mallGoodsInfo).Error
Expand Down
3 changes: 1 addition & 2 deletions service/mall/mall_index_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type MallIndexInfoService struct {
}

// 首页返回相关IndexConfig
// GetConfigGoodsForIndex 首页返回相关IndexConfig
func (m *MallIndexInfoService) GetConfigGoodsForIndex(configType int, num int) (err error, list interface{}) {
var indexConfigs []manage.MallIndexConfig
err = global.GVA_DB.Where("config_type = ?", configType).Where("is_deleted = 0").Order("config_rank desc").Limit(num).Find(&indexConfigs).Error
Expand All @@ -25,7 +25,6 @@ func (m *MallIndexInfoService) GetConfigGoodsForIndex(configType int, num int) (
// 获取商品信息
var goodsList []manage.MallGoodsInfo
err = global.GVA_DB.Where("goods_id in ?", ids).Find(&goodsList).Error

var indexGoodsList []response.MallIndexConfigGoodsResponse
// 超出30个字符显示....
for _, indexGoods := range goodsList {
Expand Down
9 changes: 6 additions & 3 deletions service/mall/mall_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ import (
type MallOrderService struct {
}

// SaveOrder 保存订单
func (m *MallOrderService) SaveOrder(token string, userAddress mall.MallUserAddress, myShoppingCartItems []mallRes.CartItemResponse) (err error, orderNo string) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
if err != nil {
return errors.New("不存在的用户"), orderNo
}

var itemIdList []int
var goodsIds []int
for _, cartItem := range myShoppingCartItems {
itemIdList = append(itemIdList, cartItem.CartItemId)
goodsIds = append(goodsIds, cartItem.GoodsId)
}

var newBeeMallGoods []manage.MallGoodsInfo
global.GVA_DB.Where("goods_id in ? ", goodsIds).Find(&newBeeMallGoods)
//检查是否包含已下架商品
Expand All @@ -53,7 +52,6 @@ func (m *MallOrderService) SaveOrder(token string, userAddress mall.MallUserAddr
return errors.New("库存不足!"), orderNo
}
}

//删除购物项
if len(itemIdList) > 0 && len(goodsIds) > 0 {
if err = global.GVA_DB.Where("cart_item_id in ?", itemIdList).Updates(mall.MallShoppingCartItem{IsDeleted: 1}).Error; err == nil {
Expand Down Expand Up @@ -109,6 +107,7 @@ func (m *MallOrderService) SaveOrder(token string, userAddress mall.MallUserAddr
return
}

// PaySuccess 支付订单
func (m *MallOrderService) PaySuccess(orderNo string, payType int) (err error) {
var mallOrder manage.MallOrder
err = global.GVA_DB.Where("order_no = ? and is_deleted=0 ", orderNo).First(&mallOrder).Error
Expand All @@ -126,6 +125,7 @@ func (m *MallOrderService) PaySuccess(orderNo string, payType int) (err error) {
return
}

// FinishOrder 完结订单
func (m *MallOrderService) FinishOrder(token string, orderNo string) (err error) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
Expand All @@ -145,6 +145,7 @@ func (m *MallOrderService) FinishOrder(token string, orderNo string) (err error)
return
}

// CancelOrder 关闭订单
func (m *MallOrderService) CancelOrder(token string, orderNo string) (err error) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
Expand All @@ -168,6 +169,7 @@ func (m *MallOrderService) CancelOrder(token string, orderNo string) (err error)
return
}

// GetOrderDetailByOrderNo 获取订单详情
func (m *MallOrderService) GetOrderDetailByOrderNo(token string, orderNo string) (err error, orderDetail mallRes.MallOrderDetailVO) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
Expand Down Expand Up @@ -200,6 +202,7 @@ func (m *MallOrderService) GetOrderDetailByOrderNo(token string, orderNo string)
return
}

// MallOrderListBySearch 搜索订单
func (m *MallOrderService) MallOrderListBySearch(token string, pageNumber int, status string) (err error, list []mallRes.MallOrderResponse, total int64) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
Expand Down
2 changes: 1 addition & 1 deletion service/mall/mall_shop_cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type MallShopCartService struct {
}

// 不分页
// GetMyShoppingCartItems 不分页
func (m *MallShopCartService) GetMyShoppingCartItems(token string) (err error, cartItems []mallRes.CartItemResponse) {
var userToken mall.MallUserToken
var shopCartItems []mall.MallShoppingCartItem
Expand Down
1 change: 1 addition & 0 deletions service/mall/mall_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type MallUserService struct {
}

// RegisterUser 注册用户
func (m *MallUserService) RegisterUser(req mallReq.RegisterUserParam) (err error) {
if !errors.Is(global.GVA_DB.Where("login_name =?", req.LoginName).First(&mall.MallUser{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同用户名")
Expand Down
3 changes: 3 additions & 0 deletions service/mall/mall_user_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type MallUserAddressService struct {
}

// GetMyAddress 获取收货地址
func (m *MallUserAddressService) GetMyAddress(token string) (err error, userAddress []mall.MallUserAddress) {
var userToken mall.MallUserToken
err = global.GVA_DB.Where("token =?", token).First(&userToken).Error
Expand All @@ -23,6 +24,7 @@ func (m *MallUserAddressService) GetMyAddress(token string) (err error, userAddr
return
}

// SaveUserAddress 保存用户地址
func (m *MallUserAddressService) SaveUserAddress(token string, req mallReq.AddAddressParam) (err error) {
var userToken mall.MallUserToken
if err = global.GVA_DB.Where("token =?", token).First(&userToken).Error; err != nil {
Expand Down Expand Up @@ -52,6 +54,7 @@ func (m *MallUserAddressService) SaveUserAddress(token string, req mallReq.AddAd
return
}

// UpdateUserAddress 更新用户地址
func (m *MallUserAddressService) UpdateUserAddress(token string, req mallReq.UpdateAddressParam) (err error) {
var userToken mall.MallUserToken
if err = global.GVA_DB.Where("token =?", token).First(&userToken).Error; err != nil {
Expand Down

0 comments on commit d05839f

Please sign in to comment.