project_info.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "reflect"
  5. "strings"
  6. "youngmini_server/app/dao"
  7. "youngmini_server/app/model"
  8. "youngmini_server/app/model/youngee_talent_model"
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/net/ghttp"
  11. "github.com/wxnacy/wgo/arrays"
  12. )
  13. type projectStatus int
  14. const (
  15. projectStatusCreating = iota + 1
  16. projectStatusReviewing
  17. projectStatusReviewed
  18. projectStatusRecruiting
  19. projectStatusRecruited
  20. projectStatusPaying
  21. projectStatusPaid
  22. projectStatusInvalid
  23. projectStatusInProgress
  24. projectStatusClosed
  25. )
  26. // 获取项目信息列表service
  27. func GetProjectInfoList(r *ghttp.Request) *TalentHttpResult {
  28. pageIndex := r.GetQueryInt("idx", -1)
  29. cntPerPage := r.GetQueryInt("cnt", -1)
  30. platform := r.Get("platform")
  31. projectForm := r.Get("projectform")
  32. feeForm := r.Get("feeform")
  33. searchValue := r.Get("searchvalue")
  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: -2, 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: -2, 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("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
  67. whereStr := fmt.Sprintf("(project_status >= %d and fail_reason <> 2 and project_type = 1)", 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. if searchValue != nil {
  85. whereStr += " and project_name like '%" + searchValue.(string) + "%'"
  86. }
  87. // 查询所有project
  88. var projectList = []model.ProjectInfo{}
  89. var projectIdList []string
  90. err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&projectList)
  91. if err != nil {
  92. return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
  93. }
  94. fmt.Println("searchValue:", searchValue)
  95. fmt.Println("feeFormList:", feeFormList)
  96. fmt.Println("projectList:", projectList)
  97. // 筛选出满足稿费形式条件的项目id列表
  98. for _, v := range projectList {
  99. string_slice := strings.Split(v.FeeForm, ",")
  100. // fmt.Println("str:", string_slice)
  101. tmp := 0
  102. for _, w := range feeFormList {
  103. i := arrays.ContainsString(string_slice, w.(string))
  104. if i < 0 {
  105. tmp = 0
  106. break
  107. }
  108. tmp = 1
  109. }
  110. if tmp == 1 {
  111. projectIdList = append(projectIdList, v.ProjectId)
  112. }
  113. }
  114. if projectIdList != nil {
  115. whereStr += " and project_id in ("
  116. for _, v := range projectIdList {
  117. whereStr += v + ", "
  118. }
  119. whereStr = whereStr[0 : len(whereStr)-2]
  120. whereStr += ")"
  121. } else if feeForm != nil {
  122. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  123. }
  124. fmt.Println("whereStr: ", whereStr)
  125. // 判断请求页面是否超过最大页面
  126. c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
  127. if c <= 0 {
  128. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  129. }
  130. maxPage := c / cntPerPage
  131. if c%cntPerPage > 0 {
  132. maxPage += 1
  133. }
  134. if pageIndex+1 > maxPage {
  135. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  136. }
  137. var projectInfoList = youngee_talent_model.ProjectInfoList{}
  138. err = g.DB().Model("project_info").WithAll().Where(whereStr).
  139. Order("project_status ASC,recruit_ddl ASC, project_id").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
  140. if err != nil {
  141. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  142. }
  143. projectInfoList.MaxPage = maxPage
  144. return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
  145. }
  146. // 获取单个项目详情service
  147. func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
  148. pid := r.GetQueryInt("projectid", 0)
  149. if pid == 0 {
  150. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  151. }
  152. var ProjectDetail *youngee_talent_model.ProjectDetail
  153. err := g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", pid).Scan(&ProjectDetail)
  154. if err != nil {
  155. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  156. }
  157. return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
  158. }