task_info.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package talent_service
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/frame/g"
  5. "github.com/gogf/gf/net/ghttp"
  6. "reflect"
  7. "youngmini_server/app/dao"
  8. "youngmini_server/app/model/talent_model"
  9. "youngmini_server/app/utils"
  10. )
  11. type accountExamineState int
  12. const (
  13. accountExamineWait accountExamineState = iota + 1
  14. accountExamineSuc
  15. accountExamineFail
  16. )
  17. type taskStatus int
  18. const (
  19. taskStatusNotStart = iota + 1
  20. taskStatusInProgress
  21. taskStatusComplete
  22. taskStatusDelete
  23. )
  24. const taskDetailCacheNamePrefix = "task_cache_"
  25. func GetTaskInfoList(r *ghttp.Request) *TalentHttpResult {
  26. pageIndex := r.GetQueryInt("idx", -1)
  27. cntPerPage := r.GetQueryInt("cnt", -1)
  28. platform := r.Get("platform")
  29. taskMode := r.Get("mode")
  30. if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
  31. return &TalentHttpResult{Code: -1, Msg: "参数错误"}
  32. }
  33. // 如果有平台的过滤条件,则将平台列表保存于platformList
  34. var platformList []interface{}
  35. if platform != nil {
  36. if reflect.TypeOf(platform).Kind() != reflect.Slice {
  37. return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
  38. }
  39. platformList = make([]interface{}, 0)
  40. platformList = platform.([]interface{})
  41. }
  42. // 如果有任务模式的过滤条件,则将过滤条件保存于taskModeList
  43. var taskModeList []interface{}
  44. if taskMode != nil {
  45. if reflect.TypeOf(taskMode).Kind() != reflect.Slice {
  46. return &TalentHttpResult{Code: -3, Msg: "搜索条件任务模式错误"}
  47. }
  48. taskModeList = make([]interface{}, 0)
  49. taskModeList = taskMode.([]interface{})
  50. }
  51. // 构造查询的条件
  52. startId := pageIndex * cntPerPage
  53. whereStr := fmt.Sprintf("task_status = %d", taskStatusInProgress)
  54. if platformList != nil {
  55. whereStr = whereStr + " and task_platform in ("
  56. for _, v := range platformList {
  57. whereStr += v.(string) + ", "
  58. }
  59. whereStr = whereStr[0:len(whereStr) - 2]
  60. whereStr += ")"
  61. }
  62. if taskModeList != nil {
  63. whereStr += " and task_mode in ("
  64. for _, v := range taskModeList {
  65. whereStr += v.(string) + ", "
  66. }
  67. whereStr = whereStr[0:len(whereStr) - 2]
  68. whereStr += ")"
  69. }
  70. // 判断请求页面是否超过最大页面
  71. c, err := g.DB().Model(dao.TaskBaseInfo.Table).Fields("task_id").
  72. Count(whereStr)
  73. if c <= 0 {
  74. return &TalentHttpResult{Code: -4, Msg: "has no task", Data: nil}
  75. }
  76. maxPage := c / cntPerPage
  77. if c % cntPerPage > 0 {
  78. maxPage += 1
  79. }
  80. if pageIndex + 1 > maxPage {
  81. return &TalentHttpResult{Code: -5, Msg: "over max page"}
  82. }
  83. var taskSimple = talent_model.SimpleTaskResult{}
  84. err = g.DB().Model("task_base_info").WithAll().
  85. Where(whereStr).
  86. Order("deadline_time DESC, task_id").Limit(startId, cntPerPage).Scan(&taskSimple.TaskInfos)
  87. if err != nil {
  88. return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
  89. }
  90. taskSimple.MaxPage = maxPage
  91. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskSimple}
  92. }
  93. // GetTaskDetailInfo 获取任务详情
  94. func GetTaskDetailInfo(r *ghttp.Request) *TalentHttpResult {
  95. tid := r.GetQueryInt("taskid", 0)
  96. if tid == 0 {
  97. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  98. }
  99. var taskDetail *talent_model.TaskDetail
  100. err := g.DB().Model(talent_model.TaskDetail{}).WithAll().
  101. Where("task_id", tid).Scan(&taskDetail)
  102. if err != nil {
  103. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  104. }
  105. // 计算各招募等级的已报名人数
  106. for _, v := range taskDetail.NeedTalentCount {
  107. cnt, err1 := g.DB().Model(dao.OrderInfo.Table).Count("task_level_id = ? and order_status > 1", v.TrtId)
  108. if err1 == nil {
  109. v.SignupCount = int64(cnt)
  110. } else {
  111. v.SignupCount = 0
  112. }
  113. }
  114. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  115. }
  116. func GetPlatformFansCount(r *ghttp.Request) *TalentHttpResult {
  117. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  118. if err != nil {
  119. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  120. }
  121. pid := r.GetQueryInt("pid", 0)
  122. if pid == 0 {
  123. return &TalentHttpResult{Code: -2, Msg: "input pid param"}
  124. }
  125. // 如果账号为通过审核则返回空
  126. rec, err := g.DB().Model(dao.RTalentPlatformTable.Table).
  127. One("p_id = ? and tid = ?", pid, tid)
  128. if err != nil {
  129. return &TalentHttpResult{Code: -3, Msg: "query platform examine info failed"}
  130. }
  131. if rec == nil {
  132. return &TalentHttpResult{Code: -4, Msg: "have no platform account"}
  133. }
  134. if rec[dao.RTalentPlatformTable.Columns.ExamineState].Int() == int(accountExamineWait) {
  135. return &TalentHttpResult{Code: -5, Msg: "platform account waiting examine"}
  136. }
  137. if rec[dao.RTalentPlatformTable.Columns.ExamineState].Int() == int(accountExamineFail) {
  138. return &TalentHttpResult{Code: -6, Msg: "platform account examine failed"}
  139. }
  140. rec, err = g.DB().Model(dao.InfoThirdPlatform.Table).
  141. Fields(dao.InfoThirdPlatform.Columns.PlatformTableName).
  142. One("platform_id", pid)
  143. if err != nil || rec == nil {
  144. return &TalentHttpResult{Code: -7, Msg: "get platform table name failed"}
  145. }
  146. fansRec, err := g.DB().Model(rec[dao.InfoThirdPlatform.Columns.PlatformTableName].String()).
  147. Fields("fans_count").One("talent_id", tid)
  148. if err != nil {
  149. return &TalentHttpResult{Code: -8, Msg: "query fans count failed"}
  150. }
  151. taskId := r.GetQueryInt("task_id", 0)
  152. if taskId == 0 {
  153. return &TalentHttpResult{Code: -9, Msg: "input task id"}
  154. }
  155. rec, err = g.DB().Model(dao.OrderInfo.Table).One("task_id = ? and talent_id = ?", taskId, tid)
  156. if err != nil {
  157. return &TalentHttpResult{Code: -10, Msg: "query talent signup task info failed"}
  158. }
  159. fansCountAndTaskSignupInfo := talent_model.FansCountAndTaskSignupInfo{
  160. FansCountInfo: fansRec,
  161. IsSignupTask: 0,
  162. }
  163. if rec != nil {
  164. fansCountAndTaskSignupInfo.IsSignupTask = 1
  165. }
  166. return &TalentHttpResult{Code: 0, Msg: "success", Data: fansCountAndTaskSignupInfo}
  167. }
  168. func GetSignupPageTaskDetail(r *ghttp.Request) *TalentHttpResult {
  169. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  170. if err != nil {
  171. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  172. }
  173. taskId := r.GetQueryInt("task_id", 0)
  174. if taskId == 0 {
  175. return &TalentHttpResult{Code: -2, Msg: "请输入任务id"}
  176. }
  177. addrRec, err := g.DB().Model(dao.TalentDeliveryAddress.Table).One("talent_id = ? and default_tag = 1", tid)
  178. if err != nil {
  179. return &TalentHttpResult{Code: -2, Msg: "设置收货地址才可以接任务"}
  180. }
  181. var taskDetail *talent_model.SignupPageTaskDetail
  182. err = g.DB().Model(talent_model.TaskDetail{}).WithAll().Where("task_id", taskId).Scan(&taskDetail)
  183. if err != nil {
  184. return &TalentHttpResult{Code: -3, Msg: "data query failed"}
  185. }
  186. platRec, err := g.DB().Model(taskDetail.PlatformInfo.PlatformTableName).One("talent_id", tid)
  187. if err != nil {
  188. return &TalentHttpResult{Code: -4, Msg: "查询平台信息出错"}
  189. }
  190. taskDetail.PlatformDetail = &platRec
  191. taskDetail.DeliveryAddress = &addrRec
  192. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  193. }