作者 tangxvhui

@@ -142,6 +142,11 @@ func (c RankController) RankSeasonAdd() { @@ -142,6 +142,11 @@ func (c RankController) RankSeasonAdd() {
142 return 142 return
143 } 143 }
144 endTime = t2.Unix() + 86399 //60*60*24-1 144 endTime = t2.Unix() + 86399 //60*60*24-1
  145 + ok := serverank.RankPeriodCheckTime(param.RankTypeId, beginTime, endTime, 0)
  146 + if !ok {
  147 + msg = protocol.BadRequestParam("10101")
  148 + return
  149 + }
145 companyid := c.GetCompanyId() 150 companyid := c.GetCompanyId()
146 err = serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid) 151 err = serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid)
147 msg = protocol.NewReturnResponse(nil, err) 152 msg = protocol.NewReturnResponse(nil, err)
@@ -156,10 +161,11 @@ func (c RankController) RankSeasonEdit() { @@ -156,10 +161,11 @@ func (c RankController) RankSeasonEdit() {
156 c.ResposeJson(msg) 161 c.ResposeJson(msg)
157 }() 162 }()
158 type Parameter struct { 163 type Parameter struct {
159 - Id int64 `json:"id"`  
160 - Name string `json:"name"`  
161 - BeginTime string `json:"begin_time"`  
162 - EndTime string `json:"end_time"` 164 + Id int64 `json:"id"`
  165 + Name string `json:"name"`
  166 + RankTypeId int64 `json:"rank_type_id"`
  167 + BeginTime string `json:"begin_time"`
  168 + EndTime string `json:"end_time"`
163 } 169 }
164 var param Parameter 170 var param Parameter
165 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 171 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
@@ -189,6 +195,11 @@ func (c RankController) RankSeasonEdit() { @@ -189,6 +195,11 @@ func (c RankController) RankSeasonEdit() {
189 } 195 }
190 196
191 endTime = t2.Unix() + 86399 //60*60*24-1 197 endTime = t2.Unix() + 86399 //60*60*24-1
  198 + ok := serverank.RankPeriodCheckTime(param.RankTypeId, beginTime, endTime, param.Id)
  199 + if !ok {
  200 + msg = protocol.BadRequestParam("10101")
  201 + return
  202 + }
192 companyid := c.GetCompanyId() 203 companyid := c.GetCompanyId()
193 fmt.Println(beginTime, endTime) 204 fmt.Println(beginTime, endTime)
194 err = serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid) 205 err = serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid)
@@ -106,6 +106,8 @@ var errmessge ErrorMap = map[string]string{ @@ -106,6 +106,8 @@ var errmessge ErrorMap = map[string]string{
106 "12102": "评分规则不符合要求", 106 "12102": "评分规则不符合要求",
107 //权限配置相关 107 //权限配置相关
108 "10091": "至少选择一个特定部门", 108 "10091": "至少选择一个特定部门",
  109 + //榜单设置
  110 + "10101": "赛季周期设置与其他赛季重叠",
109 } 111 }
110 112
111 //错误码转换 ,兼容需要 113 //错误码转换 ,兼容需要
@@ -197,6 +197,31 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string @@ -197,6 +197,31 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string
197 return nil 197 return nil
198 } 198 }
199 199
  200 +//RankPeriodCheckTime 设置赛季时检查时间范围的合法性
  201 +func RankPeriodCheckTime(rankTypeId int64, beginTime int64, endTime int64, idNot int64) bool {
  202 + sql := `SELECT 1 FROM rank_period
  203 + WHERE rank_type_id = %d
  204 + AND id <> %d
  205 + AND
  206 + (
  207 + (UNIX_TIMESTAMP(begin_time) BETWEEN %d AND %d)
  208 + OR
  209 + (UNIX_TIMESTAMP(end_time) BETWEEN %d AND %d)
  210 + )
  211 + LIMIT 1 `
  212 + sql = fmt.Sprintf(sql, rankTypeId, idNot, beginTime, endTime, beginTime, endTime)
  213 + var cnt int
  214 + err := utils.ExecuteQueryOne(&cnt, sql)
  215 + if err != nil {
  216 + log.Error("SQL Execute err:%s", err)
  217 + return false
  218 + }
  219 + if cnt > 0 {
  220 + return false
  221 + }
  222 + return true
  223 +}
  224 +
200 func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, companyid int64) error { 225 func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, companyid int64) error {
201 var ( 226 var (
202 err error 227 err error
@@ -607,3 +632,21 @@ func AllowRankRange(id int64, companyid int64) error { @@ -607,3 +632,21 @@ func AllowRankRange(id int64, companyid int64) error {
607 } 632 }
608 return nil 633 return nil
609 } 634 }
  635 +
  636 +func RankRangeMove(fromId int64, toId int64, moveIds []int64, companyid int64) error {
  637 + // var (
  638 + // err error
  639 + // rankRange *models.RankRange
  640 + // )
  641 + // rankRange, err = models.GetRankRangeById(id)
  642 + // if err != nil {
  643 + // log.Error("获取rank_range数据失败:%s", err)
  644 + // return protocol.NewErrWithMessage("1")
  645 + // }
  646 + // rankRange.Status = 0
  647 + // err = models.UpdateRankRangeById(rankRange, []string{"Status"})
  648 + // if err != nil {
  649 + // log.Error("更新rank_range数据失败:%s", err)
  650 + // }
  651 + return nil
  652 +}