拓展参数字段
This commit is contained in:
parent
4fadebfea0
commit
d5ffbbd7d6
|
|
@ -3,6 +3,7 @@ package biz
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"time"
|
"time"
|
||||||
err2 "voucher/api/err"
|
err2 "voucher/api/err"
|
||||||
v1 "voucher/api/v1"
|
v1 "voucher/api/v1"
|
||||||
|
|
@ -112,6 +113,24 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
||||||
return fmt.Errorf("批次号:%s,微信错误返回:%v", product.BatchNo, err)
|
return fmt.Errorf("批次号:%s,微信错误返回:%v", product.BatchNo, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Warnf("微信查询券详情返回:%v", wechatResp)
|
||||||
|
|
||||||
|
inputFormat := time.RFC3339
|
||||||
|
|
||||||
|
beginTime := ""
|
||||||
|
if wechatResp.AvailableBeginTime != nil {
|
||||||
|
// 解析开始时间
|
||||||
|
availableBeginTime, _ := time.Parse(inputFormat, *wechatResp.AvailableBeginTime)
|
||||||
|
beginTime = availableBeginTime.Format(time.DateTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
endTime := ""
|
||||||
|
if wechatResp.AvailableEndTime != nil {
|
||||||
|
// 解析结束时间
|
||||||
|
availableEndTime, _ := time.Parse(inputFormat, *wechatResp.AvailableEndTime)
|
||||||
|
endTime = availableEndTime.Format(time.DateTime)
|
||||||
|
}
|
||||||
|
|
||||||
reps = &v1.CmbQueryProductReply{
|
reps = &v1.CmbQueryProductReply{
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
RespMsg: "成功",
|
RespMsg: "成功",
|
||||||
|
|
@ -121,8 +140,8 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
||||||
MinAmount: "",
|
MinAmount: "",
|
||||||
AvailableType: "",
|
AvailableType: "",
|
||||||
AvailableDays: "", // 动态有效期天数
|
AvailableDays: "", // 动态有效期天数
|
||||||
StartTime: *wechatResp.AvailableBeginTime,
|
StartTime: beginTime,
|
||||||
EndTime: *wechatResp.AvailableEndTime,
|
EndTime: endTime,
|
||||||
AvailableStock: "",
|
AvailableStock: "",
|
||||||
Detail: *wechatResp.Description,
|
Detail: *wechatResp.Description,
|
||||||
}
|
}
|
||||||
|
|
@ -134,10 +153,12 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
||||||
reps.AvailableStock = fmt.Sprintf("%d", availableStock)
|
reps.AvailableStock = fmt.Sprintf("%d", availableStock)
|
||||||
|
|
||||||
if wechatResp.StartTime != nil {
|
if wechatResp.StartTime != nil {
|
||||||
reps.SaleStartTime = *wechatResp.StartTime
|
s, _ := time.Parse(inputFormat, *wechatResp.StartTime)
|
||||||
|
reps.SaleStartTime = s.Format(time.DateTime)
|
||||||
}
|
}
|
||||||
if wechatResp.StopTime != nil {
|
if wechatResp.StopTime != nil {
|
||||||
reps.SaleEndTime = *wechatResp.StopTime
|
e, _ := time.Parse(inputFormat, *wechatResp.StopTime)
|
||||||
|
reps.SaleEndTime = e.Format(time.DateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
|
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func Parse(inputTime string) (time.Time, error) {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
// 解析时间字符串并指定时区
|
// 解析时间字符串并指定时区
|
||||||
parsedTime, err := time.ParseInLocation("2006-01-02 15:04:05", inputTime, loc)
|
parsedTime, err := time.ParseInLocation(DefaultFormatLayout, inputTime, loc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
|
|
@ -64,3 +66,38 @@ func TestIsInSameNaturalMonth(t *testing.T) {
|
||||||
b := IsInSameNaturalMonth(startTime, endTime)
|
b := IsInSameNaturalMonth(startTime, endTime)
|
||||||
t.Log(b) // false
|
t.Log(b) // false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRFC3339(t *testing.T) {
|
||||||
|
// 输入的时间字符串
|
||||||
|
availableBeginTimeStr := "2025-03-07T00:00:00+08:00"
|
||||||
|
availableEndTimeStr := "2025-06-05T23:59:59+08:00"
|
||||||
|
|
||||||
|
// 定义输入时间字符串的格式
|
||||||
|
inputFormat := time.RFC3339
|
||||||
|
|
||||||
|
// 解析开始时间
|
||||||
|
availableBeginTime, err := time.Parse(inputFormat, availableBeginTimeStr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("解析开始时间出错: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析结束时间
|
||||||
|
availableEndTime, err := time.Parse(inputFormat, availableEndTimeStr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("解析结束时间出错: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义输出时间的格式
|
||||||
|
outputFormat := "2006-01-02 15:04:05"
|
||||||
|
|
||||||
|
// 格式化开始时间
|
||||||
|
formattedBeginTime := availableBeginTime.Format(outputFormat)
|
||||||
|
// 格式化结束时间
|
||||||
|
formattedEndTime := availableEndTime.Format(outputFormat)
|
||||||
|
|
||||||
|
// 输出格式化后的时间
|
||||||
|
fmt.Printf("格式化后的开始时间: %s\n", formattedBeginTime)
|
||||||
|
fmt.Printf("格式化后的结束时间: %s\n", formattedEndTime)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue