From bde9e98f62b85bbe17faf359bcea1729a3f998dd Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 14:21:06 +0800 Subject: [PATCH] fix --- model/gmodel/fs_address_logic.go | 2 +- model/gmodel/fs_cloud_pick_up_logic.go | 2 +- model/gmodel/fs_guest_logic.go | 2 +- model/gmodel/fs_order_logic.go | 2 +- model/gmodel/fs_user_logic.go | 4 ++-- server/auth/internal/logic/usergoogleloginlogic.go | 2 +- server/auth/internal/logic/userloginlogic.go | 5 +++-- server/backend/internal/logic/backenduserloginlogic.go | 2 +- .../canteen/internal/logic/savecanteentypeproductlogic.go | 5 +++-- server/home-user-auth/internal/logic/useragainorderlogic.go | 2 +- server/home-user-auth/internal/logic/useroderdeletelogic.go | 2 +- .../home-user-auth/internal/logic/userordercancellogic.go | 4 ++-- server/home-user-auth/internal/logic/userorderlistlogic.go | 2 +- server/inventory/internal/logic/supplementlogic.go | 5 +++-- server/inventory/internal/logic/takelogic.go | 6 ++++-- server/map-library/internal/logic/savemaplibrarylogic.go | 2 +- server/pay/internal/logic/orderpaymentintentlogic.go | 2 +- server/pay/internal/logic/stripewebhooklogic.go | 4 ++-- .../product-model/internal/logic/updateproductmodellogic.go | 5 +++-- server/product-template/internal/logic/addbasemaplogic.go | 2 +- server/product/internal/logic/designgatherlogic.go | 2 +- .../internal/logic/cartaddlogic.go | 2 +- .../internal/logic/createorderlogic.go | 2 +- server/upload/internal/logic/uploadlogologic.go | 2 +- utils/auth/confirmation_link_test.go | 2 +- utils/basic/request_parse_test.go | 6 ++++-- 26 files changed, 43 insertions(+), 35 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 5e2190e1..c346c507 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -22,7 +22,7 @@ func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (r func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (result *FsAddress, err error) { err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { - // now := time.Now().Unix() + // now := time.Now().UTC().Unix() result = &FsAddress{ UserId: address.UserId, Name: address.Name, diff --git a/model/gmodel/fs_cloud_pick_up_logic.go b/model/gmodel/fs_cloud_pick_up_logic.go index f8c64590..c2edebbd 100644 --- a/model/gmodel/fs_cloud_pick_up_logic.go +++ b/model/gmodel/fs_cloud_pick_up_logic.go @@ -39,7 +39,7 @@ func (p *FsCloudPickUpModel) GetCloudPickUpByIDAndUserID(ctx context.Context, us if err != nil { return err } - ctime := time.Now().Unix() + ctime := time.Now().UTC().Unix() cs.Ctime = &ctime if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT { *cs.RelationId = 0 diff --git a/model/gmodel/fs_guest_logic.go b/model/gmodel/fs_guest_logic.go index 6e49a74c..a75639a3 100755 --- a/model/gmodel/fs_guest_logic.go +++ b/model/gmodel/fs_guest_logic.go @@ -12,7 +12,7 @@ import ( func (m *FsGuestModel) GenerateGuestID(ctx context.Context, AccessSecret uint64) (authKey string, err error) { err = m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { - now := time.Now().Unix() + now := time.Now().UTC().Unix() var record = &FsGuest{} tx.Create(record) diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index c0d27763..0fcfb6a2 100755 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -42,7 +42,7 @@ func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userI if err != nil { return err } - ctime := time.Now().Unix() + ctime := time.Now().UTC().Unix() cs.Ctime = &ctime if constants.ConcactService(*cs.Type) == constants.TYPE_DEFAULT { *cs.RelationId = 0 diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 7c1da1a4..75fbb41f 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -87,7 +87,7 @@ func (u *FsUserModel) RegisterByGoogleOAuth(ctx context.Context, token *auth.Reg if err != nil { // 没有找到在数据库就创建注册 if err == gorm.ErrRecordNotFound { - createAt := time.Now().Unix() + createAt := time.Now().UTC().Unix() user.Email = &token.Email user.CreatedAt = &createAt user.GoogleId = &token.Id @@ -129,7 +129,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT if err != nil { // 没有找到在数据库就创建注册 if err == gorm.ErrRecordNotFound { - createAt := time.Now().Unix() + createAt := time.Now().UTC().Unix() user.Email = &token.Email user.CreatedAt = &createAt user.PasswordHash = &token.Password diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index 8da743ab..fee80dbe 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -112,7 +112,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us l.isRegistered = true // 如果密码匹配,则生成 JWT Token。 - jwtToken, err := auth.GenerateJwtTokenUint64(auth.StringToHash(*user.PasswordHash), l.svcCtx.Config.Auth.AccessExpire, time.Now().Unix(), user.Id, 0) + jwtToken, err := auth.GenerateJwtTokenUint64(auth.StringToHash(*user.PasswordHash), l.svcCtx.Config.Auth.AccessExpire, time.Now().UTC().Unix(), user.Id, 0) // 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。 if err != nil { diff --git a/server/auth/internal/logic/userloginlogic.go b/server/auth/internal/logic/userloginlogic.go index 2293d650..f3484374 100644 --- a/server/auth/internal/logic/userloginlogic.go +++ b/server/auth/internal/logic/userloginlogic.go @@ -3,6 +3,7 @@ package logic import ( "errors" "fmt" + "fusenapi/shared" "fusenapi/utils/auth" "fusenapi/utils/basic" "net/http" @@ -67,8 +68,8 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.U } // 如果密码匹配,则生成 JWT Token。 - nowSec := time.Now().Unix() - us, err := l.svcCtx.SharedState.GetUserState(user.Id) + nowSec := time.Now().UTC().Unix() + us, err := shared.GetUserState(user.Id, l.svcCtx.MysqlConn) if err != nil { logx.Error(err) return resp.SetStatus(basic.CodeSharedStateErr) diff --git a/server/backend/internal/logic/backenduserloginlogic.go b/server/backend/internal/logic/backenduserloginlogic.go index f67315fe..627ce09f 100644 --- a/server/backend/internal/logic/backenduserloginlogic.go +++ b/server/backend/internal/logic/backenduserloginlogic.go @@ -46,7 +46,7 @@ func (l *BackendUserLoginLogic) BackendUserLogin(req *types.RequestUserLogin) (r } // 如果密码匹配,则生成 JWT Token。 - nowSec := time.Now().Unix() + nowSec := time.Now().UTC().Unix() jwtToken, err = auth.GenerateBackendJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0) // 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。 diff --git a/server/canteen/internal/logic/savecanteentypeproductlogic.go b/server/canteen/internal/logic/savecanteentypeproductlogic.go index f1dbd00b..2f1e9315 100644 --- a/server/canteen/internal/logic/savecanteentypeproductlogic.go +++ b/server/canteen/internal/logic/savecanteentypeproductlogic.go @@ -5,9 +5,10 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" "time" + "gorm.io/gorm" + "fusenapi/server/canteen/internal/svc" "fusenapi/server/canteen/internal/types" @@ -57,7 +58,7 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant for _, v := range productSizeList { mapProductSize[v.Id] = v } - now := time.Now().Unix() + now := time.Now().UTC().Unix() //开启事务 err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error { canteenProductModel = gmodel.NewFsCanteenProductModel(tx) diff --git a/server/home-user-auth/internal/logic/useragainorderlogic.go b/server/home-user-auth/internal/logic/useragainorderlogic.go index c1edb6c4..d6e928ae 100644 --- a/server/home-user-auth/internal/logic/useragainorderlogic.go +++ b/server/home-user-auth/internal/logic/useragainorderlogic.go @@ -107,7 +107,7 @@ func (l *UserAgainOrderLogic) UserAgainOrder(req *types.UserAgainOrderReq, useri } cartInfo, err := cartModel.FindOneCartByParams(l.ctx, cartReq) if err == nil && (err != nil && errors.Is(err, gorm.ErrRecordNotFound)) { - now := time.Now().Unix() + now := time.Now().UTC().Unix() nowTime := time.Now() data := gmodel.FsCart{ UserId: &userinfo.UserId, diff --git a/server/home-user-auth/internal/logic/useroderdeletelogic.go b/server/home-user-auth/internal/logic/useroderdeletelogic.go index 105ce065..0b4eb5ce 100644 --- a/server/home-user-auth/internal/logic/useroderdeletelogic.go +++ b/server/home-user-auth/internal/logic/useroderdeletelogic.go @@ -94,7 +94,7 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo var ( IsRefund int64 = 0 - CreatedAt = time.Now().Unix() + CreatedAt = time.Now().UTC().Unix() ) refund := &gmodel.FsRefundReason{ diff --git a/server/home-user-auth/internal/logic/userordercancellogic.go b/server/home-user-auth/internal/logic/userordercancellogic.go index 6164da9c..7e7832d6 100644 --- a/server/home-user-auth/internal/logic/userordercancellogic.go +++ b/server/home-user-auth/internal/logic/userordercancellogic.go @@ -61,7 +61,7 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "the order status not cancle") } - var cancelTime int64 = time.Now().Unix() - (*orderInfo.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) + var cancelTime int64 = time.Now().UTC().Unix() - (*orderInfo.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) // 第一次支付成功后48小时后不能进行取消操作 if *orderInfo.IsPayCompleted == 1 && cancelTime > 0 { return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "The current order cannot be cancelled") @@ -73,7 +73,7 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us orderInfo.RefundReasonId = &req.RefundReasonId orderInfo.RefundReason = &req.RefundReason - var nowTime = time.Now().Unix() + var nowTime = time.Now().UTC().Unix() var payList []handlers.PayInfo // 事务处理 ctx := l.ctx diff --git a/server/home-user-auth/internal/logic/userorderlistlogic.go b/server/home-user-auth/internal/logic/userorderlistlogic.go index c3a8b066..2a68ad2a 100644 --- a/server/home-user-auth/internal/logic/userorderlistlogic.go +++ b/server/home-user-auth/internal/logic/userorderlistlogic.go @@ -158,7 +158,7 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo //如果是部分支付状态,那么取消订单倒计时2天 if *item.Status == int64(constants.STATUS_NEW_PART_PAY) { - surplusAt = (*item.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) - time.Now().Unix() + surplusAt = (*item.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) - time.Now().UTC().Unix() if surplusAt < 0 { surplusAt = 0 } diff --git a/server/inventory/internal/logic/supplementlogic.go b/server/inventory/internal/logic/supplementlogic.go index c7cb0df0..c99ac347 100644 --- a/server/inventory/internal/logic/supplementlogic.go +++ b/server/inventory/internal/logic/supplementlogic.go @@ -9,11 +9,12 @@ import ( "fusenapi/utils/format" "fusenapi/utils/id_generator" "fusenapi/utils/step_price" - "gorm.io/gorm" "math" "strings" "time" + "gorm.io/gorm" + "context" "fusenapi/server/inventory/internal/svc" @@ -106,7 +107,7 @@ func (l *SupplementLogic) Supplement(req *types.SupplementReq, userinfo *auth.Us amount := step_price.GetCentStepPrice(int(minByNum), stepNum, stepPrice) + optionalPrice totalAmount := amount * req.Num newOrderSn := id_generator.GenSnNum() - now := time.Now().Unix() + now := time.Now().UTC().Unix() deliveryMethod := int64(constants.DELIVERY_METHOD_CLOUD) isSup := int64(1) //生成雪花id diff --git a/server/inventory/internal/logic/takelogic.go b/server/inventory/internal/logic/takelogic.go index 74faeea7..7b368d40 100644 --- a/server/inventory/internal/logic/takelogic.go +++ b/server/inventory/internal/logic/takelogic.go @@ -11,10 +11,12 @@ import ( "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/id_generator" - "gorm.io/gorm" "time" + "gorm.io/gorm" + "fusenapi/server/inventory/internal/svc" + "github.com/zeromicro/go-zero/core/logx" ) @@ -60,7 +62,7 @@ func (l *TakeLogic) Take(req *types.TakeReq, userinfo *auth.UserInfo) (resp *bas addressInfoJson := string(addressInfoBytes) trackNum := id_generator.GenSnNum() status := int64(constants.STATUS_ORDERD) - now := time.Now().Unix() + now := time.Now().UTC().Unix() pickUpData := gmodel.FsCloudPickUp{ UserId: &userinfo.UserId, TrackNum: &trackNum, diff --git a/server/map-library/internal/logic/savemaplibrarylogic.go b/server/map-library/internal/logic/savemaplibrarylogic.go index 083609ce..0b23c40b 100644 --- a/server/map-library/internal/logic/savemaplibrarylogic.go +++ b/server/map-library/internal/logic/savemaplibrarylogic.go @@ -62,7 +62,7 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.Request, userinfo *auth. } sort := int64(0) status := int64(1) - now := time.Now().Unix() + now := time.Now().UTC().Unix() createList := make([]gmodel.FsMapLibrary, 0, len(postData)) updateList := make([]gmodel.FsMapLibrary, 0, len(postData)) //开启事务 diff --git a/server/pay/internal/logic/orderpaymentintentlogic.go b/server/pay/internal/logic/orderpaymentintentlogic.go index 85946f40..35b4484d 100644 --- a/server/pay/internal/logic/orderpaymentintentlogic.go +++ b/server/pay/internal/logic/orderpaymentintentlogic.go @@ -84,7 +84,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte } // 判断订单状态以及该支付金额 - var nowAt int64 = time.Now().Unix() + var nowAt int64 = time.Now().UTC().Unix() var payAmount int64 if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) { payAmount = *orderInfo.TotalAmount / 2 diff --git a/server/pay/internal/logic/stripewebhooklogic.go b/server/pay/internal/logic/stripewebhooklogic.go index a0fe1dd2..e191b64b 100644 --- a/server/pay/internal/logic/stripewebhooklogic.go +++ b/server/pay/internal/logic/stripewebhooklogic.go @@ -66,7 +66,7 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo // 新增支付回调事件日志 var payMethod = int64(constants.PAYMETHOD_STRIPE) - var nowTime = time.Now().Unix() + var nowTime = time.Now().UTC().Unix() var eventData = string(event.Data.Raw) var fsPayEvent = &gmodel.FsPayEvent{ PayMethod: &payMethod, @@ -279,7 +279,7 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe. } } - var nowTime int64 = time.Now().Unix() + var nowTime int64 = time.Now().UTC().Unix() // 支付成功 if paymentIntent.Status == "succeeded" { diff --git a/server/product-model/internal/logic/updateproductmodellogic.go b/server/product-model/internal/logic/updateproductmodellogic.go index 06c67da0..50a1d1ba 100644 --- a/server/product-model/internal/logic/updateproductmodellogic.go +++ b/server/product-model/internal/logic/updateproductmodellogic.go @@ -7,10 +7,11 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" "strings" "time" + "gorm.io/gorm" + "context" "fusenapi/server/product-model/internal/svc" @@ -56,7 +57,7 @@ func (l *UpdateProductModelLogic) UpdateProductModel(req *types.UpdateProductMod tx := l.svcCtx.MysqlConn.Begin() lightModel := gmodel.NewFsProductModel3dLightModel(tx) productModel3dModel := gmodel.NewFsProductModel3dModel(tx) - now := time.Now().Unix() + now := time.Now().UTC().Unix() if req.LightData.Id > 0 { //更新 modelLightSaveData.Id = req.LightData.Id err = lightModel.Update(l.ctx, req.LightData.Id, &modelLightSaveData) diff --git a/server/product-template/internal/logic/addbasemaplogic.go b/server/product-template/internal/logic/addbasemaplogic.go index 163ed335..a8c48804 100644 --- a/server/product-template/internal/logic/addbasemaplogic.go +++ b/server/product-template/internal/logic/addbasemaplogic.go @@ -35,7 +35,7 @@ func (l *AddBaseMapLogic) AddBaseMap(req *types.AddBaseMapReq, userInfo *auth.Ba if req.Name == "" || req.Url == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param is empty") } - now := time.Now().Unix() + now := time.Now().UTC().Unix() err := l.svcCtx.AllModels.FsProductTemplateBasemap.Create(l.ctx, &gmodel.FsProductTemplateBasemap{ Name: &req.Name, Url: &req.Url, diff --git a/server/product/internal/logic/designgatherlogic.go b/server/product/internal/logic/designgatherlogic.go index 5c7615a8..010c21da 100644 --- a/server/product/internal/logic/designgatherlogic.go +++ b/server/product/internal/logic/designgatherlogic.go @@ -134,7 +134,7 @@ func (l *DesignGatherLogic) DesignGather(req *types.DesignGatherReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to generate design sn") } - now := time.Now().Unix() + now := time.Now().UTC().Unix() err = l.svcCtx.AllModels.FsProductDesignGather.Create(l.ctx, &gmodel.FsProductDesignGather{ Sn: &designSn, UserId: &userinfo.UserId, diff --git a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go index 54d345bf..6b520e2b 100644 --- a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go @@ -101,7 +101,7 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) ( logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get cart info") } - now := time.Now().Unix() + now := time.Now().UTC().Unix() nowTime := time.Now().UTC() data := gmodel.FsCart{ UserId: &userinfo.UserId, diff --git a/server/shopping-cart-confirmation/internal/logic/createorderlogic.go b/server/shopping-cart-confirmation/internal/logic/createorderlogic.go index 55c54953..272968b5 100644 --- a/server/shopping-cart-confirmation/internal/logic/createorderlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/createorderlogic.go @@ -85,7 +85,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth mapModel3d[v.Id] = k } var ( - now = time.Now().Unix() + now = time.Now().UTC().Unix() total int64 //总价 ) orderSn := id_generator.GenSnNum() diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index ea2eefbb..0ecb6a6d 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -184,7 +184,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us resultStr = resLogoStandard.Res var module = "logo" - var nowTime = time.Now().Unix() + var nowTime = time.Now().UTC().Unix() // 新增记录 userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) _, err = userMaterialModel.CreateOrUpdate(l.ctx, &gmodel.FsUserMaterial{ diff --git a/utils/auth/confirmation_link_test.go b/utils/auth/confirmation_link_test.go index a34fc6bc..ecb708a3 100644 --- a/utils/auth/confirmation_link_test.go +++ b/utils/auth/confirmation_link_test.go @@ -141,7 +141,7 @@ func BenchmarkJWT(b *testing.B) { for i := 0; i < b.N; i++ { claims := &jwt.StandardClaims{ - ExpiresAt: time.Now().Unix() + 1020213021, + ExpiresAt: time.Now().UTC().Unix() + 1020213021, Issuer: "test", } diff --git a/utils/basic/request_parse_test.go b/utils/basic/request_parse_test.go index d5448751..e5df9ca4 100644 --- a/utils/basic/request_parse_test.go +++ b/utils/basic/request_parse_test.go @@ -2,10 +2,10 @@ package basic import ( "crypto/sha256" - "encoding/base64" "fusenapi/utils/auth" "log" "testing" + "time" ) func TestRequestParse(t *testing.T) { @@ -17,7 +17,9 @@ func TestHash(t *testing.T) { a := "fs12345678" h := sha256.New() h.Write([]byte(a)) - s := base64.RawURLEncoding.EncodeToString(h.Sum(nil)) + s := "5JlPincPavgw0X/Fmj15xLId5vOEtdarc6hR1XlBx80=" + + log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 421231233, time.Now().UTC().Unix(), 39, 0)) key := auth.StringToHash(s) log.Println(key) // log.Println(auth.GenerateJwtTokenUint64(auth.StringToHash(s), 400000000, time.Now().UTC().Unix(), 39, 0))