liuxiaolong
2020-08-13 83414efff580cd4168e7cbc2e1e3288895444fff
controllers/restriction.go
@@ -3,11 +3,15 @@
import (
   "car-service/extend/code"
   "car-service/extend/util"
   "car-service/models"
   "encoding/json"
   "fmt"
   "github.com/astaxie/beego"
   "net/http"
   "github.com/robfig/cron"
   "strconv"
   "strings"
   "time"
)
type RestrictionController struct {
@@ -15,7 +19,29 @@
}
func init() {
   getRestrictionInfo()
   date := time.Now().Format("2006-01-02")
   var r models.Restriction
   err := r.SelectByDate(date)
   if err == nil {
      //今日已获取过限行信息
      todayRes = &RestrictionResult{
         Date: date,
         Week: r.Week,
         CityName: r.CityName,
         IsXianXing: r.IsXianXing,
      }
      arr := strings.Split(r.WeiHao, ",")
      if len(arr) >0 {
         for _,s := range arr {
            n, e := strconv.Atoi(s)
            if e ==nil {
               todayRes.XxWeiHao = append(todayRes.XxWeiHao,n)
            }
         }
      }
   } else {
      getRestrictionInfo()
   }
}
// @Title 查询限行尾号
@@ -99,6 +125,18 @@
         IsXianXing: result.Result.IsXianXing,
         XxWeiHao: result.Result.XXWeiHao,
      }
      rc := models.Restriction{
         Date: result.Result.Date,
         Week: result.Result.Week,
         CityName: result.Result.CityName,
         IsXianXing: result.Result.IsXianXing,
      }
      var arr []string
      for _,n := range result.Result.XXWeiHao {
         arr=append(arr, strconv.Itoa(n))
      }
      rc.WeiHao = strings.Join(arr, ",")
      rc.Insert()
   }
}