DengBiao 8 meses atrás
pai
commit
f5a1ed13c6
4 arquivos alterados com 46 adições e 13 exclusões
  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 Ver arquivo

@@ -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
}


+ 1
- 0
app/admin/md/md_app_redis_key.go Ver arquivo

@@ -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"
)

+ 17
- 0
app/customer/hdl/hdl_central_kitchen_for_school_order.go Ver arquivo

@@ -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
}


+ 6
- 5
app/customer/md/md_app_redis_key.go Ver arquivo

@@ -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"
)

Carregando…
Cancelar
Salvar