From ef0ed3eac488c21a9b15e004572c37f4bde8ed89 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 6 Nov 2023 20:40:22 +0800 Subject: [PATCH] feat: create_coupon_order add set_info status check --- dao/t_coupon_info.go | 2 +- http_server/handle/coupon_code_list.go | 6 ++++-- http_server/handle/coupon_create.go | 2 +- http_server/handle/coupon_order_create.go | 4 ++++ tables/t_coupon_set_info.go | 1 + 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dao/t_coupon_info.go b/dao/t_coupon_info.go index e95dc5dd..85a9c742 100644 --- a/dao/t_coupon_info.go +++ b/dao/t_coupon_info.go @@ -79,7 +79,7 @@ func (d *DbDao) UpdateCouponSetInfo(setInfo *tables.CouponSetInfo) error { } func (d *DbDao) GetUnPaidCouponSetByAccId(accId string) (res tables.CouponSetInfo, err error) { - if err = d.db.Where("account_id = ? and order_id = ''", accId).First(&res).Error; err != nil { + if err = d.db.Where("account_id = ? and status = ?", accId, tables.CouponSetInfoStatusDefault).First(&res).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { err = nil return diff --git a/http_server/handle/coupon_code_list.go b/http_server/handle/coupon_code_list.go index b0993b87..a6d44bdb 100644 --- a/http_server/handle/coupon_code_list.go +++ b/http_server/handle/coupon_code_list.go @@ -24,8 +24,9 @@ type RespCouponCodeList struct { Account string `json:"account" ` Name string `json:"name"` Note string `json:"note"` - Price string `json:"price" ` - Num int `json:"num" ` + Price string `json:"price"` + Num int `json:"num"` + Status int `json:"status"` ExpiredAt int64 `json:"expired_at"` CreatedAt int64 `json:"created_at"` List []RespCouponCode `json:"list"` @@ -115,6 +116,7 @@ func (h *HttpHandle) doCouponCodeList(req *ReqCouponCodeList, apiResp *api_code. Note: setInfo.Note, Price: setInfo.Price.String(), Num: setInfo.Num, + Status: setInfo.Status, ExpiredAt: setInfo.ExpiredAt, CreatedAt: setInfo.CreatedAt.UnixMilli(), List: make([]RespCouponCode, 0), diff --git a/http_server/handle/coupon_create.go b/http_server/handle/coupon_create.go index d0410273..3731f8b9 100644 --- a/http_server/handle/coupon_create.go +++ b/http_server/handle/coupon_create.go @@ -254,7 +254,7 @@ func (h *HttpHandle) couponCreateParamsCheck(req *ReqCouponCreate, apiResp *api_ } address := common.FormatAddressPayload(res.AddressPayload, res.DasAlgorithmId) - if !strings.EqualFold(accInfo.Manager, address) { + if !strings.EqualFold(accInfo.Manager, address) && !strings.EqualFold(accInfo.Owner, address) { apiResp.ApiRespErr(api_code.ApiCodeNoAccountPermissions, "no account permissions") return nil } diff --git a/http_server/handle/coupon_order_create.go b/http_server/handle/coupon_order_create.go index 8f81a693..2fb677c6 100644 --- a/http_server/handle/coupon_order_create.go +++ b/http_server/handle/coupon_order_create.go @@ -100,6 +100,10 @@ func (h *HttpHandle) doCouponOrderCreate(req *ReqCouponOrderCreate, apiResp *api apiResp.ApiRespErr(api_code.ApiCodeNoAccountPermissions, "no account permissions") return nil } + if setInfo.Status != tables.CouponSetInfoStatusPending { + apiResp.ApiRespErr(api_code.ApiCodeParamsInvalid, "coupon status invalid") + return nil + } tokenPrice, err := h.DbDao.GetTokenById(req.TokenId) if err != nil { diff --git a/tables/t_coupon_set_info.go b/tables/t_coupon_set_info.go index 03ebab0d..d934217f 100644 --- a/tables/t_coupon_set_info.go +++ b/tables/t_coupon_set_info.go @@ -8,6 +8,7 @@ import ( ) const ( + CouponSetInfoStatusPending = 0 CouponSetInfoStatusSuccess = 1 CouponSetInfoStatusFailed = 2 )