cmb
This commit is contained in:
parent
357bab2626
commit
f51c470d66
|
|
@ -74,13 +74,13 @@ message CmbQueryProductReply {
|
|||
string activityName = 9 [json_name = "activityName"];
|
||||
// 外部合作方权益批次号
|
||||
string activityId = 10 [json_name = "activityId"];
|
||||
// 批次额度 单位为分
|
||||
// 面额,单位为分
|
||||
string amount = 11 [json_name = "amount"];
|
||||
// 门槛,单位为分
|
||||
string minAmount = 12 [json_name = "minAmount"];
|
||||
// 有效期形式,0:固定有效期,1:动态有效期
|
||||
string availableType = 13 [json_name = "availableType"];
|
||||
// 动态有效期天数-非必填 格式yyyy-mm-dd hh:mm:ss.sss
|
||||
// 动态有效期天数-非必填
|
||||
string availableDays = 14 [json_name = "availableDays"];
|
||||
// 有效期开始时间-非必填
|
||||
string startTime = 15 [json_name = "startTime"];
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/vo"
|
||||
"voucher/internal/pkg/lock"
|
||||
)
|
||||
|
||||
|
|
@ -63,18 +65,38 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
|||
return err
|
||||
}
|
||||
|
||||
// todo
|
||||
reps = &v1.CmbQueryProductReply{
|
||||
ActivityName: product.Name,
|
||||
ActivityId: product.ProductNo,
|
||||
Amount: *wechatResp.GoodsName,
|
||||
MinAmount: fmt.Sprintf("%d", *wechatResp.StockSendRule.MaxAmount),
|
||||
AvailableType: *wechatResp.GoodsName,
|
||||
AvailableDays: *wechatResp.GoodsName,
|
||||
StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
|
||||
EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime),
|
||||
//AvailableStock: *wechatResp.SendCountInformation.TotalSendNum,
|
||||
Detail: *wechatResp.GoodsName,
|
||||
ActivityName: product.Name,
|
||||
ActivityId: product.ProductNo,
|
||||
|
||||
StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
|
||||
EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime),
|
||||
Detail: *wechatResp.DisplayPatternInfo.Description,
|
||||
|
||||
Amount: "",
|
||||
MinAmount: "",
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ import (
|
|||
func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo string, err error) {
|
||||
|
||||
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 {
|
||||
|
|
@ -25,13 +29,15 @@ func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo
|
|||
return
|
||||
}
|
||||
|
||||
// todo
|
||||
// 注册“刚哥那边”回调中心tag,一个批次只能注册一个tag,微信立减金消费时根据不同的tag消费(区分测试/正式注册tag
|
||||
|
||||
couponId, err := v.WechatCpnRepo.Order(ctx, orderWechat)
|
||||
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 != nil {
|
||||
if err = v.success(ctx, order, orderWechat, couponId); err != nil {
|
||||
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 {
|
||||
|
||||
return v.OrderRepo.Ing(ctx, id)
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
return v.OrderRepo.Success(ctx, order.ID)
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
return v.OrderRepo.Fail(ctx, order.ID)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Sign = sing
|
||||
|
||||
return req, nil
|
||||
|
|
@ -128,6 +129,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reply.Sign = sign
|
||||
|
||||
return reply, nil
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -70,6 +70,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
|||
}
|
||||
|
||||
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||
|
||||
var (
|
||||
reply *v1.CmbReply
|
||||
err error
|
||||
|
|
@ -97,6 +98,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|||
}
|
||||
|
||||
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err := ctx.BindForm(&req); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue