jiangshuai
2023-10-20 96844c22ef3fba86a55e0af1b51bc1009d6fa950
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, "创建失败")
@@ -59,9 +71,6 @@
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查找失败")
      return
   }
   for _, location := range list {
      location.JointName = location.ParentId + "/" + location.Name
   }
   util.ResponseFormatList(c, code.Success, list, int(total))
@@ -105,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, "位置信息更新失败")