/* 定期执行计划任务 */ func PlanTask() { timer := time.NewTicker(3 * time.Hour) for { select { case <-timer.C: //每3小时定时任务 go func() { return //暂不执行 //实例化对象 game := &models.Game{} member := &models.Member{} topic := &models.Topic{} reply := &models.Reply{} order := &models.Order{} /* 清空缓存目录 */ os.RemoveAll("cache") /* 清除成立一个月以上但活跃度不超过10的游戏 */ bads := game.FindBads() GlobalLog.Notice("删除的游戏:", fmt.Sprintln(bads)) for k, _ := range bads { if ok := member.FindOne(bads[k].Manager.Hex()); ok { //删除该游戏所有图片 game/{gamePath}/ 下所有图片 qiniu := &QiniuController{} go qiniu.DeleteAll("woku", "game/"+bads[k].Id+"/") //删除所有相关帖子 topic.DeleteGameTopic(bads[k].Id) //删除所有相关评论、回复 reply.DeleteGameReply(bads[k].Id) //生成参数 _, urlParams := member.CreateSign(time.Now().Unix()+3600, "redirect", "/article/53edfa461fc9010589000004.html") url := "http://" + beego.AppConfig.String("httpWebSite") + "/login.html" + urlParams //邮件通知管理员 SendEmail([]string{member.Email}, "抱歉,您的板块 "+bads[k].Name+" 使用率过低,已被清除 "+time.Now().String(), "非常抱歉,根据 <a href='"+url+"'>"+url+"</a> 板块清理规范,您的板块 <b>"+bads[k].Name+"</b> 已被移除,您可以重新申请板块并尝试增加使用率!") //推送消息 //AddMessage(member.Id.Hex(), "system", "", "您的板块 "+bads[k].Name+" 使用率过低,已被清除", "非常抱歉,根据 <a href='http://www.wokugame.com/article/53edfa461fc9010589000004.html'>http://www.wokugame.com/article/53edfa461fc9010589000004.html</a> 板块清理规范,您的板块 <b>"+bads[k].Name+"</b> 已被移除,您可以重新申请板块并尝试增加使用率!", "") //删除游戏 bads[k].Delete() } } /* 删除查询游戏列表缓存 */ models.DeleteCaches("game-find-") models.DeleteCaches("game-findcount-") /* 删除已失效订单 */ order.DeleteBad() /* 刷新sitemap */ refreshSitemap() }() } } }
/* 申请创建游戏 */ func (this *GameController) CreateGame() { ok, data := func() (bool, interface{}) { member := &models.Member{} var session interface{} if session = this.GetSession("WOKUID"); session == nil { return false, "未登录" } if ok := member.FindOne(session.(string)); !ok { return false, "用户不存在" } if time.Now().Sub(member.LastTime).Seconds() < 2.9 { //3秒内不能连续操作 return false, "请继续等待" } if len([]rune(this.GetString("name"))) < 2 || len([]rune(this.GetString("name"))) > 20 { //名称不能超过10个字符 return false, "名称长度2-20" } if this.GetString("name") == "" { return false, "名称不能为空" } if len([]rune(this.GetString("path"))) < 3 || len([]rune(this.GetString("path"))) > 20 { //路径不能超过10个字符 return false, "域名长度3-20" } if this.GetString("path") == "" { return false, "域名不能为空" } if this.GetString("path") == "post" || this.GetString("path") == "api" { return false, "该域名不能使用" } //正则验证 re := regexp.MustCompile("[`~!!@#$%^&*()_+<>?:\"”{},.,。/;;‘'[\\]]") result := re.FindString(this.GetString("name")) if result != "" { return false, "名称不能有特殊字符" } re = regexp.MustCompile("[a-z]+") result = re.FindString(this.GetString("path")) if this.GetString("path") != result { return false, "域名只能输入字母" } game := &models.Game{} //查询名称是否重复 if game.FindRepeatName(this.GetString("name")) { return false, "名称已存在" } //查询域名是否重复 if game.FindRepeat(this.GetString("path")) { return false, "域名已存在" } //检测type只能是0~4 _type, _ := this.GetInt("type") if _type != 0 && _type != 1 && _type != 2 && _type != 3 && _type != 4 { return false, "分类不在范围内" } //一个用户最多建立20个游戏 if member.GameNumber >= 20 { return false, "抱歉,您最多创建20个游戏" } member.GameNumber++ member.Save() //注册新游戏 game.Name = this.GetString("name") game.Id = this.GetString("path") game.Type = uint8(_type) game.Manager = member.Id game.Categorys = 3 game.Insert() //给游戏注册默认分类 defaultCategory := map[string]string{ "topic": "公告", "plan": "攻略", "bbs": "论坛", } // 存储层级 layer := 0 for k, _ := range defaultCategory { gameCategory := &models.GameCategory{} gameCategory.Game = game.Id gameCategory.Category = k gameCategory.CategoryName = defaultCategory[k] gameCategory.RecommendPri = layer gameCategory.Recommend = 5 gameCategory.Add = 1 gameCategory.Reply = 1 gameCategory.Insert() layer++ } // 删除此游戏查询缓存 models.DeleteCache("game-findpath-" + this.GetString("path")) // 删除查询游戏列表缓存 models.DeleteCaches("game-find-" + this.GetString("type")) models.DeleteCaches("game-findcount-" + this.GetString("type")) return true, nil }() this.Data["json"] = map[string]interface{}{ "ok": ok, "data": data, } this.ServeJson() }