diff --git a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go index 6713bc9..b29a685 100644 --- a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go +++ b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go @@ -1136,9 +1136,18 @@ func CentralKitchenForSchoolReserveDetail(c *gin.Context) { } func CentralKitchenForSchoolOrdRefund(c *gin.Context) { + //TODO:: 加锁 Redis 锁,防并发 + getString, _ := cache.GetString(md.OrdRefundLockKeyForCentralKitchenSchool) + if getString != "" { + e.OutErr(c, e.ERR, "请稍等,存在其他订单退款处理中!") + return + } + cache.Set(md.OrdRefundLockKeyForCentralKitchenSchool, "running") + var req md.CentralKitchenForSchoolOrdRefundReq err := c.ShouldBindJSON(&req) if err != nil { + cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool) err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) @@ -1148,18 +1157,23 @@ func CentralKitchenForSchoolOrdRefund(c *gin.Context) { enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) if err != nil { + cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool) e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { + cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool) e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } err = svc2.CentralKitchenForSchoolOrdRefund(req) if err != nil { + cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool) e.OutErr(c, e.ERR, err.Error()) return } + + cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool) e.OutSuc(c, "success", nil) return } @@ -1190,7 +1204,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { e.OutErr(c, e.ERR, "请稍等,存在其他退款处理中!") return } - cache.Set(md.AuditLockKeyForCentralKitchenLockKey, "running") + cache.Set(md.BatchAskForLeaveLockKeyForCentralKitchen, "running") utils.FilePutContents("DealCentralKitchenForSchoolBatchAskForLeave", "批量请假处理,开始时间:::"+time.Now().Format("2006-01-02 15:04:05")) Kind := c.DefaultQuery("kind", "1") @@ -1200,7 +1214,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { var req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool err := c.ShouldBindJSON(&req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) @@ -1218,7 +1232,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { err = svc2.CentralKitchenForSchoolBatchAskForLeaveBySchool(req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) e.OutErr(c, e.ERR, err.Error()) return } @@ -1228,7 +1242,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { var req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade err := c.ShouldBindJSON(&req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) @@ -1246,7 +1260,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { err = svc2.CentralKitchenForSchoolBatchAskForLeaveByGrade(req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) e.OutErr(c, e.ERR, err.Error()) return } @@ -1256,7 +1270,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { var req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass err := c.ShouldBindJSON(&req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) @@ -1274,14 +1288,14 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { err = svc2.CentralKitchenForSchoolBatchAskForLeaveByClass(req) if err != nil { - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) e.OutErr(c, e.ERR, err.Error()) return } break } - cache.Del(md.AuditLockKeyForCentralKitchenLockKey) + cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen) e.OutSuc(c, "success", nil) return } diff --git a/app/admin/md/md_app_redis_key.go b/app/admin/md/md_app_redis_key.go index 807bb7b..b857946 100644 --- a/app/admin/md/md_app_redis_key.go +++ b/app/admin/md/md_app_redis_key.go @@ -13,4 +13,5 @@ const ( WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 AuditLockKeyForCentralKitchenLockKey = "audit_lock_key_for_central_kitchen_lock_key" BatchAskForLeaveLockKeyForCentralKitchen = "batch_ask_for_leave_lock_key_for_central_kitchen" + OrdRefundLockKeyForCentralKitchenSchool = "ord_refund_lock_key_for_central_kitchen_school" ) diff --git a/app/customer/hdl/hdl_central_kitchen_for_school_order.go b/app/customer/hdl/hdl_central_kitchen_for_school_order.go index 22ff85a..e1825e8 100644 --- a/app/customer/hdl/hdl_central_kitchen_for_school_order.go +++ b/app/customer/hdl/hdl_central_kitchen_for_school_order.go @@ -3,13 +3,16 @@ package hdl import ( "applet/app/admin/lib/validate" "applet/app/customer/md" + svc2 "applet/app/customer/svc" svc "applet/app/customer/svc/order" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/enum" "applet/app/utils" + "applet/app/utils/cache" "encoding/json" + "fmt" "github.com/gin-gonic/gin" "time" ) @@ -251,12 +254,26 @@ func CentralKitchenForSchoolOrderRefund(c *gin.Context) { e.OutErr(c, err1.Code, err1.Error()) return } + + //TODO:: 加锁 Redis 锁,防并发 + user := svc2.GetUser(c) + redisKey := fmt.Sprintf(md.CustomerOrdRefundLockKeyForCentralKitchenSchool, utils.AnyToString(user.Id)) + getString, _ := cache.GetString(redisKey) + if getString != "" { + e.OutErr(c, e.ERR, "请稍等,您当前存在其他订单退款处理中!") + return + } + cache.Set(redisKey, "running") + utils.FilePutContents("CentralKitchenForSchoolOrderRefund", utils.SerializeStr(req)) err = svc.CentralKitchenForSchoolOrderRefund(req) if err != nil { + cache.Del(redisKey) e.OutErr(c, e.ERR, err.Error()) return } + + cache.Del(redisKey) e.OutSuc(c, "success", nil) return } diff --git a/app/customer/md/md_app_redis_key.go b/app/customer/md/md_app_redis_key.go index 45efaa1..02ad730 100644 --- a/app/customer/md/md_app_redis_key.go +++ b/app/customer/md/md_app_redis_key.go @@ -2,9 +2,10 @@ package md // 缓存key统一管理 const ( - UserJwtTokenKey = "%s:smart_canteen_user_jwt_token:%s" // jwt, 占位符:ip, user:id - WxAccessToken = "smart_canteen_wx_access_token" // 微信接口凭证 - JwtTokenCacheTime = 3600 * 24 * 1 - WxAccessTokenCacheTime = 7200 - 1200 - WxSessionCacheKey = "wx_session_key" // 占位符: key的第一个字母 + UserJwtTokenKey = "%s:smart_canteen_user_jwt_token:%s" // jwt, 占位符:ip, user:id + WxAccessToken = "smart_canteen_wx_access_token" // 微信接口凭证 + JwtTokenCacheTime = 3600 * 24 * 1 + WxAccessTokenCacheTime = 7200 - 1200 + WxSessionCacheKey = "wx_session_key" // 占位符: key的第一个字母 + CustomerOrdRefundLockKeyForCentralKitchenSchool = "customer_ord_refund_lock_key_for_central_kitchen_school:%s" )