bidsection_api.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * @description: 标段相关的接口api
  3. * @Author: CP
  4. * @Date: 2020-09-28 10:26:49
  5. * @FilePath: \construction_management\web\api\bidsection_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "strconv"
  11. "github.com/kataras/iris/v12"
  12. "go.mod/services"
  13. "go.mod/web/utils"
  14. )
  15. type BidsectionApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceBidsection services.BidsectionService
  20. }
  21. // 获得项目目录结构
  22. func (c *BidsectionApi) Get() {
  23. }
  24. // 添标段结构
  25. func (c *BidsectionApi) PostCreate() {
  26. ErrMsg := ""
  27. // 验证内容
  28. BidsectionData, err := c.ServiceBidsection.ValidRule(c.Ctx)
  29. if err != nil {
  30. ErrMsg = utils.FormValidError(err)
  31. c.Ctx.JSON(iris.Map{
  32. "code": -1,
  33. "msg": ErrMsg,
  34. })
  35. return
  36. } else {
  37. // 获得项目ID
  38. projectIdInt, err := utils.GetProjectId(c.Ctx)
  39. if err != nil {
  40. c.Ctx.JSON(iris.Map{
  41. "code": -1,
  42. "msg": fmt.Sprintf("%s", err),
  43. })
  44. return
  45. }
  46. BidsectionData.ProjectId = strconv.Itoa(projectIdInt)
  47. // 新增标段-新增树结构里的标段
  48. err = c.ServiceBidsection.Create(BidsectionData)
  49. if err != nil {
  50. c.Ctx.JSON(iris.Map{
  51. "code": -1,
  52. "msg": fmt.Sprintf("%s", err),
  53. })
  54. return
  55. }
  56. c.Ctx.JSON(iris.Map{
  57. "code": 0,
  58. "msg": "新增成功",
  59. })
  60. }
  61. }