liujiandao
2023-10-23 b9a62531fb93aba42d13e62fd1b03d8dba112fa6
controllers/location.go
@@ -30,6 +30,18 @@
      util.ResponseFormat(c, code.RequestParamError, err)
      return
   }
   if params.ParentId != 0 {
      //查询上级名称
      first, err := models.NewLocationSearch().SetID(params.ParentId).First()
      if err != nil {
         util.ResponseFormat(c, code.RequestParamError, "查询上级名称失败")
         return
      }
      params.JointName = first.JointName + "/" + params.Name
   } else {
      params.JointName = params.Name
   }
   err := models.NewLocationSearch().Create(&params)
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "创建失败")
@@ -55,7 +67,7 @@
   if params.PageInfo.Check() {
      search.SetPage(params.Page, params.PageSize)
   }
   list, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
   list, total, err := search.SetKeyword(params.KeyWord).SetJointName(params.JointName).SetOrder("created_at desc").Find()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查找失败")
      return
@@ -102,6 +114,25 @@
      util.ResponseFormat(c, code.RequestParamError, err)
      return
   }
   //index := strings.LastIndex(params.JointName, "/")
   //if index > 0 {
   //   jn := params.JointName[:index]
   //   oldName := params.JointName[index+1:]
   //   if oldName != params.Name {
   //      params.JointName = jn + "/" + params.Name
   //   }
   //}
   if params.ParentId != 0 {
      //查询上级名称
      first, err := models.NewLocationSearch().SetID(params.ParentId).First()
      if err != nil {
         util.ResponseFormat(c, code.RequestParamError, "查询上级名称失败")
         return
      }
      params.JointName = first.JointName + "/" + params.Name
   } else {
      params.JointName = params.Name
   }
   err := models.NewLocationSearch().Update(&params)
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "位置信息更新失败")