project_info.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package youngee_talent_service
  2. import (
  3. "fmt"
  4. "reflect"
  5. "strconv"
  6. "strings"
  7. "youngmini_server/app/dao"
  8. "youngmini_server/app/model"
  9. "youngmini_server/app/model/youngee_talent_model"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/net/ghttp"
  12. "github.com/wxnacy/wgo/arrays"
  13. )
  14. type projectStatus int
  15. const (
  16. projectStatusCreating = iota + 1
  17. projectStatusReviewing
  18. projectStatusReviewed
  19. projectStatusRecruiting
  20. projectStatusRecruited
  21. projectStatusPaying
  22. projectStatusPaid
  23. projectStatusInvalid
  24. projectStatusInProgress
  25. projectStatusClosed
  26. )
  27. // 获取项目信息列表service
  28. func GetProjectInfoList(r *ghttp.Request) *TalentHttpResult {
  29. pageIndex := r.GetQueryInt("idx", -1)
  30. cntPerPage := r.GetQueryInt("cnt", -1)
  31. platform := r.Get("platform")
  32. projectForm := r.Get("projectform")
  33. feeForm := r.Get("feeform")
  34. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  35. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  36. }
  37. // 如果有稿费形式的过滤条件,则将过滤条件保存于taskModeList
  38. var feeFormList []interface{}
  39. if feeForm != nil {
  40. if reflect.TypeOf(feeForm).Kind() != reflect.Slice {
  41. return &TalentHttpResult{Code: -3, Msg: "搜索条件稿费形式错误"}
  42. }
  43. feeFormList = make([]interface{}, 0)
  44. feeFormList = feeForm.([]interface{})
  45. }
  46. // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
  47. var projectFormList []interface{}
  48. if projectForm != nil {
  49. if reflect.TypeOf(projectForm).Kind() != reflect.Slice {
  50. return &TalentHttpResult{Code: -3, Msg: "搜索条件任务形式错误"}
  51. }
  52. projectFormList = make([]interface{}, 0)
  53. projectFormList = projectForm.([]interface{})
  54. }
  55. // 如果有平台的过滤条件,则将平台列表保存于platformList
  56. var platformList []interface{}
  57. if platform != nil {
  58. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  59. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  60. }
  61. platformList = make([]interface{}, 0)
  62. platformList = platform.([]interface{})
  63. }
  64. // 构造查询的条件
  65. startId := pageIndex * cntPerPage
  66. // whereStr := fmt.Sprintf("")
  67. whereStr := fmt.Sprintf("(project_status >= %d)", projectStatusRecruiting)
  68. if platformList != nil {
  69. whereStr = whereStr + " and project_platform in ("
  70. for _, v := range platformList {
  71. whereStr += v.(string) + ", "
  72. }
  73. whereStr = whereStr[0 : len(whereStr)-2]
  74. whereStr += ")"
  75. }
  76. if projectFormList != nil {
  77. whereStr += " and project_form in ("
  78. for _, v := range projectFormList {
  79. whereStr += v.(string) + ", "
  80. }
  81. whereStr = whereStr[0 : len(whereStr)-2]
  82. whereStr += ")"
  83. }
  84. // 查询所有project
  85. var projectList = []model.ProjectInfo{}
  86. var projectIdList []int
  87. err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&projectList)
  88. if err != nil {
  89. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  90. }
  91. fmt.Println("feeFormList:", feeFormList)
  92. fmt.Println("projectList:", projectList)
  93. // 筛选出满足稿费形式条件的项目id列表
  94. for _, v := range projectList {
  95. string_slice := strings.Split(v.FeeForm, ",")
  96. // fmt.Println("str:", string_slice)
  97. tmp := 0
  98. for _, w := range feeFormList {
  99. i := arrays.ContainsString(string_slice, w.(string))
  100. if i < 0 {
  101. tmp = 0
  102. break
  103. }
  104. tmp = 1
  105. }
  106. if tmp == 1 {
  107. projectIdList = append(projectIdList, v.ProjectId)
  108. }
  109. }
  110. if projectIdList != nil {
  111. whereStr += " and project_id in ("
  112. for _, v := range projectIdList {
  113. whereStr += strconv.Itoa(v) + ", "
  114. }
  115. whereStr = whereStr[0 : len(whereStr)-2]
  116. whereStr += ")"
  117. } else if feeForm != nil {
  118. return &TalentHttpResult{Code: -4, Msg: "has no project", Data: nil}
  119. }
  120. fmt.Println("whereStr: ", whereStr)
  121. // 判断请求页面是否超过最大页面
  122. c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
  123. if c <= 0 {
  124. return &TalentHttpResult{Code: -4, Msg: "has no project", Data: nil}
  125. }
  126. maxPage := c / cntPerPage
  127. if c%cntPerPage > 0 {
  128. maxPage += 1
  129. }
  130. if pageIndex+1 > maxPage {
  131. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  132. }
  133. var projectInfoList = youngee_talent_model.ProjectInfoList{}
  134. err = g.DB().Model("project_info").WithAll().Where(whereStr).
  135. Order("recruit_ddl DESC, project_id").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
  136. if err != nil {
  137. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  138. }
  139. projectInfoList.MaxPage = maxPage
  140. return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
  141. }
  142. // 获取单个项目详情service
  143. func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
  144. pid := r.GetQueryInt("projectid", 0)
  145. if pid == 0 {
  146. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  147. }
  148. var ProjectDetail *youngee_talent_model.ProjectDetail
  149. err := g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", pid).Scan(&ProjectDetail)
  150. if err != nil {
  151. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  152. }
  153. return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
  154. }