Skip to content

Commit

Permalink
获取当前商品相关优惠券(APP端)
Browse files Browse the repository at this point in the history
  • Loading branch information
koobe committed Jul 13, 2023
1 parent 7a5d792 commit 4c14598
Show file tree
Hide file tree
Showing 26 changed files with 1,624 additions and 1,183 deletions.
71 changes: 30 additions & 41 deletions front-api/doc/api/coupon.api
Expand Up @@ -36,45 +36,34 @@ type (
Message string `json:"message"`
Data []*ListCouponHistoryData `json:"data"`
}
// ListCouponReq {
// Current int64 `json:"current,default=1"`
// PageSize int64 `json:"pageSize,default=20"`
// Type int64 `json:"type,default=4"` // 优惠券类型;0->全场赠券;1->会员赠券;2->购物赠券;3->注册赠券
// Name string `json:"name,optional"`
// Platform int64 `json:"platform,default=3"` // 使用平台:0->全部;1->移动;2->PC
// StartTime string `json:"startTime,optional"`
// EndTime string `json:"endTime,optional"`
// UseType int64 `json:"useType,default=3"` // 使用类型:0->全场通用;1->指定分类;2->指定商品
// }
// ListtCouponData {
// Id int64 `json:"id"`
// Type int64 `json:"type"` // 优惠券类型;0->全场赠券;1->会员赠券;2->购物赠券;3->注册赠券
// Name string `json:"name"`
// Platform int64 `json:"platform"` // 使用平台:0->全部;1->移动;2->PC
// Count int64 `json:"count"` // 数量
// Amount float64 `json:"amount"` // 金额
// PerLimit int64 `json:"perLimit"` // 每人限领张数
// MinPoint float64 `json:"minPoint"` // 使用门槛;0表示无门槛
// StartTime string `json:"startTime"`
// EndTime string `json:"endTime"`
// UseType int64 `json:"useType"` // 使用类型:0->全场通用;1->指定分类;2->指定商品
// Note string `json:"note"` // 备注
// PublishCount int64 `json:"publishCount"` // 发行数量
// UseCount int64 `json:"useCount"` // 已使用数量
// ReceiveCount int64 `json:"receiveCount"` // 领取数量
// EnableTime string `json:"enableTime"` // 可以领取的日期
// Code string `json:"code"` // 优惠码
// MemberLevel int64 `json:"memberLevel"` // 可领取的会员类型:0->无限时
// }
// ListCouponResp {
// Code string `json:"code"`
// Message string `json:"message"`
// Current int64 `json:"current,default=1"`
// Data []*ListtCouponData `json:"data"`
// PageSize int64 `json:"pageSize,default=20"`
// Success bool `json:"success"`
// Total int64 `json:"total"`
// }
ListCouponReq {
ProductId int64 `json:"productId"` // 商品id
}
ListtCouponData {
Id int64 `json:"id"`
Type int64 `json:"type"` // 优惠券类型;0->全场赠券;1->会员赠券;2->购物赠券;3->注册赠券
Name string `json:"name"`
Platform int64 `json:"platform"` // 使用平台:0->全部;1->移动;2->PC
Count int64 `json:"count"` // 数量
Amount float64 `json:"amount"` // 金额
PerLimit int64 `json:"perLimit"` // 每人限领张数
MinPoint float64 `json:"minPoint"` // 使用门槛;0表示无门槛
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
UseType int64 `json:"useType"` // 使用类型:0->全场通用;1->指定分类;2->指定商品
Note string `json:"note"` // 备注
PublishCount int64 `json:"publishCount"` // 发行数量
UseCount int64 `json:"useCount"` // 已使用数量
ReceiveCount int64 `json:"receiveCount"` // 领取数量
EnableTime string `json:"enableTime"` // 可以领取的日期
Code string `json:"code"` // 优惠码
MemberLevel int64 `json:"memberLevel"` // 可领取的会员类型:0->无限时
}
ListCouponResp {
Code int64 `json:"code"`
Message string `json:"message"`
Data []*ListtCouponData `json:"data"`
}
// UpdateCouponReq {
// Id int64 `json:"id"`
// Type int64 `json:"type"` // 优惠券类型;0->全场赠券;1->会员赠券;2->购物赠券;3->注册赠券
Expand Down Expand Up @@ -118,8 +107,8 @@ service front-api {
@handler CouponHistoryList
post /list (ListCouponHistoryReq) returns (ListCouponHistoryResp)

// @handler CouponList
// post /list (ListCouponReq) returns (ListCouponResp)
@handler CouponListByProductId
post /listByProductId (ListCouponReq) returns (ListCouponResp)
//
// @handler CouponUpdate
// post /update (UpdateCouponReq) returns (UpdateCouponResp)
Expand Down
@@ -0,0 +1,28 @@
package coupon

import (
"net/http"

"github.com/zeromicro/go-zero/rest/httpx"
"zero-admin/front-api/internal/logic/member/coupon"
"zero-admin/front-api/internal/svc"
"zero-admin/front-api/internal/types"
)

func CouponListByProductIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListCouponReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := coupon.NewCouponListByProductIdLogic(r.Context(), svcCtx)
resp, err := l.CouponListByProductId(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
5 changes: 5 additions & 0 deletions front-api/internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions front-api/internal/logic/member/coupon/couponaddlogic.go
Expand Up @@ -26,6 +26,7 @@ func NewCouponAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CouponA
}
}

// CouponAdd 领取指定优惠券
func (l *CouponAddLogic) CouponAdd(req *types.AddCouponReq) (resp *types.AddCouponResp, err error) {
coupon, err := l.svcCtx.CouponService.CouponFindById(l.ctx, &smsclient.CouponFindByIdReq{CouponId: req.CouponId})

Expand Down
Expand Up @@ -24,6 +24,7 @@ func NewCouponHistoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}

// CouponHistoryList 获取用户优惠券列表
func (l *CouponHistoryListLogic) CouponHistoryList(req *types.ListCouponHistoryReq) (resp *types.ListCouponHistoryResp, err error) {
historyList, err := l.svcCtx.CouponHistoryService.CouponHistoryList(l.ctx, &smsclient.CouponHistoryListReq{
Current: req.Current,
Expand Down
@@ -0,0 +1,87 @@
package coupon

import (
"context"
"zero-admin/rpc/pms/pmsclient"
"zero-admin/rpc/sms/smsclient"

"zero-admin/front-api/internal/svc"
"zero-admin/front-api/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type CouponListByProductIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewCouponListByProductIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CouponListByProductIdLogic {
return &CouponListByProductIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

// CouponListByProductId 获取当前商品相关优惠券
func (l *CouponListByProductIdLogic) CouponListByProductId(req *types.ListCouponReq) (resp *types.ListCouponResp, err error) {
var couponIds []int64
//获取指定商品优惠券
productRelationList, _ := l.svcCtx.CouponProductRelationService.CouponProductRelationList(l.ctx, &smsclient.CouponProductRelationListReq{
ProductId: req.ProductId,
})

for _, i := range productRelationList.List {
couponIds = append(couponIds, i.CouponId)
}

//获取指定分类优惠券
var ids []int64
ids = append(ids, req.ProductId)
productListByIds, _ := l.svcCtx.ProductService.ProductListByIds(l.ctx, &pmsclient.ProductByIdsReq{Ids: ids})
productCategoryId := productListByIds.List[0].ProductCategoryId

productCategoryRelationList, _ := l.svcCtx.CouponProductCategoryRelationService.CouponProductCategoryRelationList(l.ctx, &smsclient.CouponProductCategoryRelationListReq{
ProductCategoryId: productCategoryId,
})

for _, i := range productCategoryRelationList.List {
couponIds = append(couponIds, i.CouponId)
}

//所有优惠券
couponFindByIds, _ := l.svcCtx.CouponService.CouponFindByIds(l.ctx, &smsclient.CouponFindByIdsReq{CouponIds: couponIds})

var list []*types.ListtCouponData

for _, item := range couponFindByIds.List {
list = append(list, &types.ListtCouponData{
Id: item.Id,
Type: item.Type,
Name: item.Name,
Platform: item.Platform,
Count: item.Count,
Amount: item.Amount,
PerLimit: item.PerLimit,
MinPoint: item.MinPoint,
StartTime: item.StartTime,
EndTime: item.EndTime,
UseType: item.UseType,
Note: item.Note,
PublishCount: item.PublishCount,
UseCount: item.UseCount,
ReceiveCount: item.ReceiveCount,
EnableTime: item.EnableTime,
Code: item.Code,
MemberLevel: item.MemberLevel,
})
}

return &types.ListCouponResp{
Data: list,
Code: 0,
Message: "查询优惠券成功",
}, nil
}
33 changes: 32 additions & 1 deletion front-api/internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions rpc/model/smsmodel/smscouponmodel.go
Expand Up @@ -19,6 +19,7 @@ type (
Count(ctx context.Context) (int64, error)
FindAll(ctx context.Context, Current int64, PageSize int64, in *smsclient.CouponListReq) (*[]SmsCoupon, error)
DeleteByIds(ctx context.Context, ids []int64) error
FindAllByIds(ctx context.Context, ids []int64) (*[]SmsCoupon, error)
}

customSmsCouponModel struct {
Expand Down Expand Up @@ -106,3 +107,17 @@ func (m *customSmsCouponModel) DeleteByIds(ctx context.Context, ids []int64) err
_, err := m.conn.ExecCtx(ctx, query, args...)
return err
}

func (m *customSmsCouponModel) FindAllByIds(ctx context.Context, ids []int64) (*[]SmsCoupon, error) {
query := fmt.Sprintf("select %s from %s where `id` in (?)", smsCouponRows, m.table)
var resp []SmsCoupon
err := m.conn.QueryRows(&resp, query, strings.Replace(strings.Trim(fmt.Sprint(ids), "[]"), " ", ",", -1))
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
2 changes: 2 additions & 0 deletions rpc/sms/client/couponhistoryservice/couponhistoryservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions rpc/sms/client/couponservice/couponservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rpc/sms/client/flashpromotionservice/flashpromotionservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rpc/sms/client/homeadvertiseservice/homeadvertiseservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c14598

Please sign in to comment.