This commit is contained in:
李子铭 2025-03-06 14:46:05 +08:00
parent 357bab2626
commit f51c470d66
6 changed files with 98 additions and 17 deletions

View File

@ -74,13 +74,13 @@ message CmbQueryProductReply {
string activityName = 9 [json_name = "activityName"]; string activityName = 9 [json_name = "activityName"];
// //
string activityId = 10 [json_name = "activityId"]; string activityId = 10 [json_name = "activityId"];
// //
string amount = 11 [json_name = "amount"]; string amount = 11 [json_name = "amount"];
// //
string minAmount = 12 [json_name = "minAmount"]; string minAmount = 12 [json_name = "minAmount"];
// 01 // 01
string availableType = 13 [json_name = "availableType"]; string availableType = 13 [json_name = "availableType"];
// - yyyy-mm-dd hh:mm:ss.sss // -
string availableDays = 14 [json_name = "availableDays"]; string availableDays = 14 [json_name = "availableDays"];
// - // -
string startTime = 15 [json_name = "startTime"]; string startTime = 15 [json_name = "startTime"];

View File

@ -4,10 +4,12 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"gorm.io/gorm" "gorm.io/gorm"
"time" "time"
v1 "voucher/api/v1" v1 "voucher/api/v1"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
"voucher/internal/biz/vo"
"voucher/internal/pkg/lock" "voucher/internal/pkg/lock"
) )
@ -63,18 +65,38 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
return err return err
} }
// todo
reps = &v1.CmbQueryProductReply{ reps = &v1.CmbQueryProductReply{
ActivityName: product.Name, ActivityName: product.Name,
ActivityId: product.ProductNo, ActivityId: product.ProductNo,
Amount: *wechatResp.GoodsName,
MinAmount: fmt.Sprintf("%d", *wechatResp.StockSendRule.MaxAmount), StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
AvailableType: *wechatResp.GoodsName, EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime),
AvailableDays: *wechatResp.GoodsName, Detail: *wechatResp.DisplayPatternInfo.Description,
StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime), Amount: "",
//AvailableStock: *wechatResp.SendCountInformation.TotalSendNum, MinAmount: "",
Detail: *wechatResp.GoodsName,
AvailableType: "",
AvailableDays: "",
AvailableStock: "",
}
availableStock := *wechatResp.StockSendRule.MaxCoupons - *wechatResp.SendCountInformation.TotalSendNum
reps.AvailableStock = fmt.Sprintf("%d", availableStock)
if wechatResp.CouponUseRule.CouponAvailableTime.AvailableDayAfterReceive != nil {
reps.AvailableType = vo.CmbAvailableTypeDynamic.GetValue()
reps.AvailableDays = fmt.Sprintf("%d", *wechatResp.CouponUseRule.CouponAvailableTime.AvailableDayAfterReceive)
} else {
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
}
if *wechatResp.StockType == merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_NORMAL {
reps.Amount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.DiscountAmount)
reps.MinAmount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.TransactionMinimum)
} else if *wechatResp.StockType == merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_DISCOUNT {
reps.Amount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.DiscountCoupon.DiscountPercent)
reps.MinAmount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.TransactionMinimum)
} }
return nil return nil

View File

@ -13,7 +13,11 @@ import (
func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo string, err error) { func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo string, err error) {
if order.Status.IsWait() { if order.Status.IsWait() {
return "", fmt.Errorf("订单状态错误,%s", order.Status.GetText()) return outRequestNo, fmt.Errorf("订单状态错误,%s", order.Status.GetText())
}
if !order.Channel.IsWeChat() {
return outRequestNo, fmt.Errorf("订单渠道错误,%s", order.Channel.GetText())
} }
if err = v.ing(ctx, order.ID); err != nil { if err = v.ing(ctx, order.ID); err != nil {
@ -25,13 +29,15 @@ func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo
return return
} }
// todo
// 注册“刚哥那边”回调中心tag,一个批次只能注册一个tag微信立减金消费时根据不同的tag消费(区分测试/正式注册tag
couponId, err := v.WechatCpnRepo.Order(ctx, orderWechat) couponId, err := v.WechatCpnRepo.Order(ctx, orderWechat)
if err != nil { if err != nil {
return "", v.fail(ctx, order, orderWechat, err.Error()) return outRequestNo, v.fail(ctx, order, orderWechat, err.Error())
} }
err = v.success(ctx, order, orderWechat, couponId) if err = v.success(ctx, order, orderWechat, couponId); err != nil {
if err != nil {
return return
} }
@ -63,20 +69,25 @@ func (v *Cmb) create(ctx context.Context, order *bo.OrderBo) (*bo.OrderWechatBo,
} }
func (v *Cmb) ing(ctx context.Context, id uint64) error { func (v *Cmb) ing(ctx context.Context, id uint64) error {
return v.OrderRepo.Ing(ctx, id) return v.OrderRepo.Ing(ctx, id)
} }
func (v *Cmb) success(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo, couponId string) error { func (v *Cmb) success(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo, couponId string) error {
if err := v.OrderWechatRepo.Success(ctx, orderWechat.ID, couponId); err != nil { if err := v.OrderWechatRepo.Success(ctx, orderWechat.ID, couponId); err != nil {
return err return err
} }
return v.OrderRepo.Success(ctx, order.ID) return v.OrderRepo.Success(ctx, order.ID)
} }
func (v *Cmb) fail(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo, remarks string) error { func (v *Cmb) fail(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo, remarks string) error {
if err := v.OrderWechatRepo.Fail(ctx, orderWechat.ID, remarks); err != nil { if err := v.OrderWechatRepo.Fail(ctx, orderWechat.ID, remarks); err != nil {
return err return err
} }
return v.OrderRepo.Fail(ctx, order.ID) return v.OrderRepo.Fail(ctx, order.ID)
} }

View File

@ -95,6 +95,7 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Sign = sing req.Sign = sing
return req, nil return req, nil
@ -128,6 +129,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
if err != nil { if err != nil {
return nil, err return nil, err
} }
reply.Sign = sign reply.Sign = sign
return reply, nil return reply, nil

View File

@ -0,0 +1,44 @@
package data
import (
"context"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"testing"
)
func TestGetClient(t *testing.T) {
server := &Server{
MchID: "",
MchCertificateSerialNumber: "",
}
stockId := ""
ctx := context.Background()
client, err := GetClient(ctx, server)
if err != nil {
t.Error(err)
return
}
svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
response, result, err := svc.QueryStock(ctx, merchantexclusivecoupon.QueryStockRequest{
StockId: core.String(stockId),
})
if err != nil {
t.Error(err)
return
}
if result.Response.StatusCode != 200 {
err = fmt.Errorf("查询活动微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
t.Error(err)
return
}
t.Log(response)
}

View File

@ -70,6 +70,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
} }
func (s *VoucherService) CmbProductQuery(ctx http.Context) error { func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
var ( var (
reply *v1.CmbReply reply *v1.CmbReply
err error err error
@ -97,6 +98,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
} }
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) { func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
var req *v1.CmbRequest var req *v1.CmbRequest
if err := ctx.BindForm(&req); err != nil { if err := ctx.BindForm(&req); err != nil {
return nil, err return nil, err