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. fmt.Println("进入种草主页")
  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. searchValue := r.Get("searchvalue")
  35. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  36. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  37. }
  38. // 如果有稿费形式的过滤条件,则将过滤条件保存于taskModeList
  39. var feeFormList []interface{}
  40. if feeForm != nil {
  41. if reflect.TypeOf(feeForm).Kind() != reflect.Slice {
  42. return &TalentHttpResult{Code: -2, Msg: "搜索条件稿费形式错误"}
  43. }
  44. feeFormList = make([]interface{}, 0)
  45. feeFormList = feeForm.([]interface{})
  46. }
  47. // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
  48. var projectFormList []interface{}
  49. if projectForm != nil {
  50. if reflect.TypeOf(projectForm).Kind() != reflect.Slice {
  51. return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
  52. }
  53. projectFormList = make([]interface{}, 0)
  54. projectFormList = projectForm.([]interface{})
  55. }
  56. // 如果有平台的过滤条件,则将平台列表保存于platformList
  57. var platformList []interface{}
  58. if platform != nil {
  59. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  60. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  61. }
  62. platformList = make([]interface{}, 0)
  63. platformList = platform.([]interface{})
  64. }
  65. // 构造查询的条件
  66. startId := pageIndex * cntPerPage
  67. // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
  68. whereStr := fmt.Sprintf("(project_status >= %d and fail_reason <> 2 and project_type = 1)", projectStatusRecruiting)
  69. if platformList != nil {
  70. whereStr = whereStr + " and project_platform in ("
  71. for _, v := range platformList {
  72. whereStr += v.(string) + ", "
  73. }
  74. whereStr = whereStr[0 : len(whereStr)-2]
  75. whereStr += ")"
  76. }
  77. if projectFormList != nil {
  78. whereStr += " and project_form in ("
  79. for _, v := range projectFormList {
  80. whereStr += v.(string) + ", "
  81. }
  82. whereStr = whereStr[0 : len(whereStr)-2]
  83. whereStr += ")"
  84. }
  85. if searchValue != nil {
  86. whereStr += " and project_name like '%" + searchValue.(string) + "%'"
  87. }
  88. // 查询所有project
  89. var projectList = []model.ProjectInfo{}
  90. var projectIdList []string
  91. err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&projectList)
  92. if err != nil {
  93. return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
  94. }
  95. fmt.Println("searchValue:", searchValue)
  96. fmt.Println("feeFormList:", feeFormList)
  97. fmt.Println("projectList:", projectList)
  98. // 筛选出满足稿费形式条件的项目id列表
  99. for _, v := range projectList {
  100. string_slice := strings.Split(v.FeeForm, ",")
  101. // fmt.Println("str:", string_slice)
  102. tmp := 0
  103. for _, w := range feeFormList {
  104. i := arrays.ContainsString(string_slice, w.(string))
  105. if i < 0 {
  106. tmp = 0
  107. break
  108. }
  109. tmp = 1
  110. }
  111. if tmp == 1 {
  112. projectIdList = append(projectIdList, v.ProjectId)
  113. }
  114. }
  115. if projectIdList != nil {
  116. whereStr += " and project_id in ("
  117. for _, v := range projectIdList {
  118. whereStr += v + ", "
  119. }
  120. whereStr = whereStr[0 : len(whereStr)-2]
  121. whereStr += ")"
  122. } else if feeForm != nil {
  123. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  124. }
  125. fmt.Println("whereStr: ", whereStr)
  126. // 判断请求页面是否超过最大页面
  127. c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
  128. if c <= 0 {
  129. return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
  130. }
  131. maxPage := c / cntPerPage
  132. if c%cntPerPage > 0 {
  133. maxPage += 1
  134. }
  135. if pageIndex+1 > maxPage {
  136. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  137. }
  138. var projectInfoList = youngee_talent_model.ProjectInfoList{}
  139. err = g.DB().Model("project_info").WithAll().Where(whereStr).
  140. Order("project_status ASC,recruit_ddl ASC, project_id").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
  141. if err != nil {
  142. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  143. }
  144. projectInfoList.MaxPage = maxPage
  145. return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
  146. }
  147. // 获取单个项目详情service
  148. func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
  149. pid := r.GetQueryInt("projectid", 0)
  150. if pid == 0 {
  151. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  152. }
  153. var ProjectDetail *youngee_talent_model.ProjectDetail
  154. err := g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", pid).Scan(&ProjectDetail)
  155. if err != nil {
  156. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  157. }
  158. return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
  159. }