UpRate.go 871 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package controllers
  2. import (
  3. "TripUpRate/g"
  4. "TripUpRate/models"
  5. "encoding/json"
  6. beego "github.com/beego/beego/v2/server/web"
  7. "time"
  8. )
  9. type GetUpRateController struct {
  10. beego.Controller
  11. }
  12. func (c *GetUpRateController) Post() {
  13. parm := g.TaskInfo{}
  14. data := c.Ctx.Input.RequestBody
  15. err := json.Unmarshal(data, &parm)
  16. if err != nil {
  17. c.Data["json"] = models.Res{
  18. Code: 1,
  19. Msg: "参数效验错误",
  20. }
  21. } else {
  22. parm.Enddate = time.Now().Add(30 * time.Minute)
  23. //判断协程是否已存在,不存在则启动协程
  24. info, _ := g.TaskList.Load(parm.Dptcity + parm.Arrcity)
  25. g.TaskList.Store(parm.Dptcity+parm.Arrcity, parm)
  26. if info == nil {
  27. go g.ForClick(parm.Dptcity + parm.Arrcity)
  28. }
  29. c.Data["json"] = models.Res{
  30. Code: 0,
  31. Msg: parm.Dptcity + "-" + parm.Arrcity + "航线验价刷单服务启动成功",
  32. }
  33. }
  34. c.ServeJSON()
  35. }