From 7cf4bacbe85aec141d6dde8245ef68a3c85286eb Mon Sep 17 00:00:00 2001 From: sunjiayu <767978963@qq.com> Date: Thu, 19 Sep 2024 14:54:11 +0800 Subject: [PATCH] add new free_user judgement --- service/wx_payment/wx_payment.go | 37 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/service/wx_payment/wx_payment.go b/service/wx_payment/wx_payment.go index 346ed6d..0bb0841 100644 --- a/service/wx_payment/wx_payment.go +++ b/service/wx_payment/wx_payment.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "time" "github.com/pkusunjy/grpc-gateway/service/platform" "github.com/pkusunjy/openai-server-proto/wx_payment" @@ -138,20 +139,30 @@ func (server WxPaymentServiceImpl) Jsapi(ctx context.Context, req *wx_payment.Js grpclog.Errorf("whitelist query openid: %v fail err:%v", dbQueryData.OpenID, err) return &resp, nil } - if len(dbQueryRes) > 0 { - grpclog.Infof("openid:%v is in whitelist, order_type=3", openid) - // Edit order db - editOrderReqBody, _ := json.Marshal(OrderParam{ - OrderCode: *outTradeNo, - }) - editOrderUrl := fmt.Sprintf("http://%s/utility-project/ysOrder/editOrderStatus", server.DataPlatformEndpoint) - editOrderRespBody, err := platform.DoHttpPost(editOrderUrl, editOrderReqBody) - if err != nil { - grpclog.Errorf("Error HttpPost, url:%v, reqBody:%v, error:%v", editOrderUrl, string(editOrderReqBody), err) + if len(dbQueryRes) > 0 && dbQueryRes[0].Status != nil && *dbQueryRes[0].Status == 1 { + now_unix := time.Now().Unix() + is_free_user := false + if dbQueryRes[0].Status != nil { + is_free_user = is_free_user && *dbQueryRes[0].Status == 1 + } + if dbQueryRes[0].AddedTime != nil && dbQueryRes[0].ExpirationTime != nil { + is_free_user = is_free_user && (*dbQueryRes[0].AddedTime < uint64(now_unix) && uint64(now_unix) < *dbQueryRes[0].ExpirationTime) + } + if is_free_user { + grpclog.Infof("openid:%v is in whitelist, order_type=3", openid) + // Edit order db + editOrderReqBody, _ := json.Marshal(OrderParam{ + OrderCode: *outTradeNo, + }) + editOrderUrl := fmt.Sprintf("http://%s/utility-project/ysOrder/editOrderStatus", server.DataPlatformEndpoint) + editOrderRespBody, err := platform.DoHttpPost(editOrderUrl, editOrderReqBody) + if err != nil { + grpclog.Errorf("Error HttpPost, url:%v, reqBody:%v, error:%v", editOrderUrl, string(editOrderReqBody), err) + } + grpclog.Infof("edit order received response:%v", string(editOrderRespBody)) + // Whitelist users don't need to create payment, so return an empty JsApiResponse + return &resp, nil } - grpclog.Infof("edit order received response:%v", string(editOrderRespBody)) - // Whitelist users don't need to create payment, so return an empty JsApiResponse - return &resp, nil } }