Browse Source

fix(用户申请):新增缓存机制

Roc 4 years ago
parent
commit
3c613638b1
2 changed files with 33 additions and 0 deletions
  1. 17 0
      controllers/user.go
  2. 16 0
      utils/config.go

+ 17 - 0
controllers/user.go

@@ -806,6 +806,17 @@ func (this *UserController) ApplyTryOut() {
 		req.CompanyName = user.CompanyName
 	}
 	uid := user.UserId
+
+	//缓存校验
+	cacheKey := fmt.Sprint("xygx:apply_record:add:",uid)
+	ttlTime := utils.Rc.GetRedisTTL(cacheKey)
+	if ttlTime > 0{
+		br.Msg = "申请失败,申请过于频繁"
+		br.ErrMsg = "申请失败,申请过于频繁"
+		return
+	}
+	utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
+
 	//判断是否已经申请过
 	applyCount, err := models.GetApplyRecordCount(uid)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -886,6 +897,7 @@ func (this *UserController) ApplyTryOut() {
 			}
 		}
 	}
+
 	//获取销售信息
 	sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -925,6 +937,8 @@ func (this *UserController) ApplyTryOut() {
 		br.ErrMsg = "申请失败,Err:" + err.Error()
 		return
 	}
+	//添加成功后,设置5分钟缓存,不允许重复添加
+	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
 
 	br.Msg = "申请成功!"
 	br.Ret = 200
@@ -932,6 +946,9 @@ func (this *UserController) ApplyTryOut() {
 	br.Data = sellerMobile
 }
 
+func sentMsgToSeller(){
+
+}
 //func init() {
 //	fmt.Println("start")
 //	realName:="沈涛"

+ 16 - 0
utils/config.go

@@ -1,7 +1,9 @@
 package utils
 
 import (
+	"fmt"
 	"github.com/astaxie/beego"
+	"rdluck_tools/cache"
 )
 
 var (
@@ -9,6 +11,10 @@ var (
 	MYSQL_URL         string //数据库连接
 	MYSQL_URL_RDDP    string //数据库连接
 	MYSQL_URL_TACTICS string
+
+	REDIS_CACHE string       //缓存地址
+	Rc          *cache.Cache //redis缓存
+	Re          error        //redis错误
 )
 
 //微信配置信息
@@ -45,6 +51,16 @@ func init() {
 	MYSQL_URL_RDDP = config["mysql_url_rddp"]
 	MYSQL_URL_TACTICS = config["mysql_url_tactics"]
 
+	REDIS_CACHE = config["beego_cache"]
+	if len(REDIS_CACHE) <= 0 {
+		panic("redis链接参数没有配置")
+	}
+	Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
+	if Re != nil {
+		fmt.Println(Re)
+		panic(Re)
+	}
+
 	if RunMode == "release" {
 		WxAppId = "wxcc32b61f96720d2f"
 		WxAppSecret = "06894933fafb24dafead7eaae09c08e0"