Browse Source

update

tmp
DengBiao 8 months ago
parent
commit
f5a1ed13c6
4 changed files with 46 additions and 13 deletions
  1. +22
    -8
      app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go
  2. +1
    -0
      app/admin/md/md_app_redis_key.go
  3. +17
    -0
      app/customer/hdl/hdl_central_kitchen_for_school_order.go
  4. +6
    -5
      app/customer/md/md_app_redis_key.go

+ 22
- 8
app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go View File

@@ -1136,9 +1136,18 @@ func CentralKitchenForSchoolReserveDetail(c *gin.Context) {
} }


func CentralKitchenForSchoolOrdRefund(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 var req md.CentralKitchenForSchoolOrdRefundReq
err := c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err != nil { if err != nil {
cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool)
err = validate.HandleValidateErr(err) err = validate.HandleValidateErr(err)
err1 := err.(e.E) err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error()) e.OutErr(c, err1.Code, err1.Error())
@@ -1148,18 +1157,23 @@ func CentralKitchenForSchoolOrdRefund(c *gin.Context) {
enterpriseDb.Set() enterpriseDb.Set()
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId)
if err != nil { if err != nil {
cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool)
e.OutErr(c, e.ERR_DB_ORM, err.Error()) e.OutErr(c, e.ERR_DB_ORM, err.Error())
return return
} }
if enterprise == nil { if enterprise == nil {
cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool)
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
return return
} }
err = svc2.CentralKitchenForSchoolOrdRefund(req) err = svc2.CentralKitchenForSchoolOrdRefund(req)
if err != nil { if err != nil {
cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool)
e.OutErr(c, e.ERR, err.Error()) e.OutErr(c, e.ERR, err.Error())
return return
} }

cache.Del(md.OrdRefundLockKeyForCentralKitchenSchool)
e.OutSuc(c, "success", nil) e.OutSuc(c, "success", nil)
return return
} }
@@ -1190,7 +1204,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {
e.OutErr(c, e.ERR, "请稍等,存在其他退款处理中!") e.OutErr(c, e.ERR, "请稍等,存在其他退款处理中!")
return return
} }
cache.Set(md.AuditLockKeyForCentralKitchenLockKey, "running")
cache.Set(md.BatchAskForLeaveLockKeyForCentralKitchen, "running")
utils.FilePutContents("DealCentralKitchenForSchoolBatchAskForLeave", "批量请假处理,开始时间:::"+time.Now().Format("2006-01-02 15:04:05")) utils.FilePutContents("DealCentralKitchenForSchoolBatchAskForLeave", "批量请假处理,开始时间:::"+time.Now().Format("2006-01-02 15:04:05"))


Kind := c.DefaultQuery("kind", "1") Kind := c.DefaultQuery("kind", "1")
@@ -1200,7 +1214,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {
var req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool var req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool
err := c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
err = validate.HandleValidateErr(err) err = validate.HandleValidateErr(err)
err1 := err.(e.E) err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error()) e.OutErr(c, err1.Code, err1.Error())
@@ -1218,7 +1232,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {


err = svc2.CentralKitchenForSchoolBatchAskForLeaveBySchool(req) err = svc2.CentralKitchenForSchoolBatchAskForLeaveBySchool(req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
e.OutErr(c, e.ERR, err.Error()) e.OutErr(c, e.ERR, err.Error())
return return
} }
@@ -1228,7 +1242,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {
var req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade var req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade
err := c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
err = validate.HandleValidateErr(err) err = validate.HandleValidateErr(err)
err1 := err.(e.E) err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error()) e.OutErr(c, err1.Code, err1.Error())
@@ -1246,7 +1260,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {


err = svc2.CentralKitchenForSchoolBatchAskForLeaveByGrade(req) err = svc2.CentralKitchenForSchoolBatchAskForLeaveByGrade(req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
e.OutErr(c, e.ERR, err.Error()) e.OutErr(c, e.ERR, err.Error())
return return
} }
@@ -1256,7 +1270,7 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {
var req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass var req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass
err := c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
err = validate.HandleValidateErr(err) err = validate.HandleValidateErr(err)
err1 := err.(e.E) err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error()) e.OutErr(c, err1.Code, err1.Error())
@@ -1274,14 +1288,14 @@ func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) {


err = svc2.CentralKitchenForSchoolBatchAskForLeaveByClass(req) err = svc2.CentralKitchenForSchoolBatchAskForLeaveByClass(req)
if err != nil { if err != nil {
cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
e.OutErr(c, e.ERR, err.Error()) e.OutErr(c, e.ERR, err.Error())
return return
} }
break break
} }


cache.Del(md.AuditLockKeyForCentralKitchenLockKey)
cache.Del(md.BatchAskForLeaveLockKeyForCentralKitchen)
e.OutSuc(c, "success", nil) e.OutSuc(c, "success", nil)
return return
} }


+ 1
- 0
app/admin/md/md_app_redis_key.go View File

@@ -13,4 +13,5 @@ const (
WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母
AuditLockKeyForCentralKitchenLockKey = "audit_lock_key_for_central_kitchen_lock_key" AuditLockKeyForCentralKitchenLockKey = "audit_lock_key_for_central_kitchen_lock_key"
BatchAskForLeaveLockKeyForCentralKitchen = "batch_ask_for_leave_lock_key_for_central_kitchen" BatchAskForLeaveLockKeyForCentralKitchen = "batch_ask_for_leave_lock_key_for_central_kitchen"
OrdRefundLockKeyForCentralKitchenSchool = "ord_refund_lock_key_for_central_kitchen_school"
) )

+ 17
- 0
app/customer/hdl/hdl_central_kitchen_for_school_order.go View File

@@ -3,13 +3,16 @@ package hdl
import ( import (
"applet/app/admin/lib/validate" "applet/app/admin/lib/validate"
"applet/app/customer/md" "applet/app/customer/md"
svc2 "applet/app/customer/svc"
svc "applet/app/customer/svc/order" svc "applet/app/customer/svc/order"
"applet/app/db" "applet/app/db"
"applet/app/db/model" "applet/app/db/model"
"applet/app/e" "applet/app/e"
"applet/app/enum" "applet/app/enum"
"applet/app/utils" "applet/app/utils"
"applet/app/utils/cache"
"encoding/json" "encoding/json"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"time" "time"
) )
@@ -251,12 +254,26 @@ func CentralKitchenForSchoolOrderRefund(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error()) e.OutErr(c, err1.Code, err1.Error())
return 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)) utils.FilePutContents("CentralKitchenForSchoolOrderRefund", utils.SerializeStr(req))
err = svc.CentralKitchenForSchoolOrderRefund(req) err = svc.CentralKitchenForSchoolOrderRefund(req)
if err != nil { if err != nil {
cache.Del(redisKey)
e.OutErr(c, e.ERR, err.Error()) e.OutErr(c, e.ERR, err.Error())
return return
} }

cache.Del(redisKey)
e.OutSuc(c, "success", nil) e.OutSuc(c, "success", nil)
return return
} }


+ 6
- 5
app/customer/md/md_app_redis_key.go View File

@@ -2,9 +2,10 @@ package md


// 缓存key统一管理 // 缓存key统一管理
const ( 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"
) )

Loading…
Cancel
Save