project_task_info_dao.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package dao
  2. import (
  3. "youngee_b_api/app/entity"
  4. "youngee_b_api/app/vo"
  5. )
  6. type ProjectTaskInfoDao struct{}
  7. // 获取指定违约类型的种草子任务数量
  8. func (d ProjectTaskInfoDao) CountByDefaultType(projectId string, defaultType int64) int64 {
  9. var total int64
  10. Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", projectId, defaultType).Count(&total)
  11. return total
  12. }
  13. // 获取指定任务阶段的种草子任务数量
  14. func (d ProjectTaskInfoDao) CountByTaskStage(projectId string, taskStage int64) int64 {
  15. var total int64
  16. Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", projectId, taskStage).Count(&total)
  17. return total
  18. }
  19. // 获取指定任务阶段的种草子任务
  20. func (d ProjectTaskInfoDao) GetListByTaskStage(projectId string, taskStage int64, time string, page int, pageSize int, talentNickname string) ([]*entity.ProjectTaskInfo, int64, error) {
  21. var taskInfos []*entity.ProjectTaskInfo
  22. var total int64
  23. query := Db.Model(&entity.ProjectTaskInfo{})
  24. if taskStage == 6 {
  25. query = query.Where("project_id = ? AND task_stage >= ?", projectId, taskStage)
  26. } else {
  27. query = query.Where("project_id = ? AND task_stage = ?", projectId, taskStage)
  28. }
  29. if talentNickname != "" {
  30. var talentInfos []entity.PlatformKuaishouUserInfo
  31. err1 := Db.Model(&entity.PlatformKuaishouUserInfo{}).Where("nick_name = ?", talentNickname).Find(&talentInfos).Error
  32. if err1 != nil {
  33. return nil, 0, err1
  34. }
  35. var openIds []string
  36. for _, talentInfo := range talentInfos {
  37. openIds = append(openIds, talentInfo.OpenID)
  38. }
  39. query = query.Where("open_id in ?", openIds)
  40. }
  41. // 计算偏移量
  42. offset := (page - 1) * pageSize
  43. var err error
  44. if taskStage == 4 {
  45. query.Count(&total)
  46. err = query.Order("create_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  47. } else if taskStage == 5 {
  48. if time != "" {
  49. query = query.Where("DATE(delivery_date) = ?", time)
  50. }
  51. query.Count(&total)
  52. err = query.Order("delivery_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  53. } else if taskStage == 6 {
  54. query.Count(&total)
  55. err = query.Order("signed_time desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  56. }
  57. if err != nil {
  58. return nil, 0, err
  59. }
  60. return taskInfos, total, nil
  61. }
  62. // 获取未传初稿的种草子任务数据
  63. func (d ProjectTaskInfoDao) GetListBySketchDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  64. projectTaskInfos := []entity.ProjectTaskInfo{}
  65. var total int64
  66. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 4)
  67. query.Count(&total)
  68. query = query.Select("task_id, talent_id, settle_amount, draft_fee, sketch_missing_time, open_id")
  69. offset := (param.Page - 1) * param.PageSize
  70. if err := query.Order("sketch_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  71. return nil, 0, err
  72. }
  73. return projectTaskInfos, total, nil
  74. }
  75. // 获取未发作品的种草子任务数据
  76. func (d ProjectTaskInfoDao) GetListByLinkDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  77. projectTaskInfos := []entity.ProjectTaskInfo{}
  78. var total int64
  79. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 6)
  80. query.Count(&total)
  81. query = query.Select("task_id, talent_id, settle_amount, draft_fee, link_missing_time, open_id")
  82. offset := (param.Page - 1) * param.PageSize
  83. if err := query.Order("link_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  84. return nil, 0, err
  85. }
  86. return projectTaskInfos, total, nil
  87. }
  88. // 获取未传数据的种草子任务数据
  89. func (d ProjectTaskInfoDao) GetListByDataDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  90. projectTaskInfos := []entity.ProjectTaskInfo{}
  91. var total int64
  92. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 8)
  93. query.Count(&total)
  94. query = query.Select("task_id, talent_id, settle_amount, draft_fee, data_missing_time, open_id")
  95. offset := (param.Page - 1) * param.PageSize
  96. if err := query.Order("data_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  97. return nil, 0, err
  98. }
  99. return projectTaskInfos, total, nil
  100. }
  101. // 获取终止合作的种草子任务数据
  102. func (d ProjectTaskInfoDao) GetListByTerminateDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  103. projectTaskInfos := []entity.ProjectTaskInfo{}
  104. var total int64
  105. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 17)
  106. query.Count(&total)
  107. query = query.Select("task_id, talent_id, settle_amount, draft_fee, terminate_time, terminate_reason, terminate_operator_type, terminate_operator, open_id")
  108. offset := (param.Page - 1) * param.PageSize
  109. if err := query.Order("terminate_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  110. return nil, 0, err
  111. }
  112. return projectTaskInfos, total, nil
  113. }
  114. // 获取已解约的种草子任务数据
  115. func (d ProjectTaskInfoDao) GetListByCancelDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  116. projectTaskInfos := []entity.ProjectTaskInfo{}
  117. var total int64
  118. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 16)
  119. query.Count(&total)
  120. query = query.Select("task_id, talent_id, settle_amount, draft_fee, cancel_time, cancel_reason, cancel_operator_type, cancel_operator, open_id")
  121. offset := (param.Page - 1) * param.PageSize
  122. if err := query.Order("cancel_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  123. return nil, 0, err
  124. }
  125. return projectTaskInfos, total, nil
  126. }
  127. // 更新字段
  128. func (d ProjectTaskInfoDao) UpdateField(taskId string, updateData map[string]interface{}) error {
  129. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id = ?", taskId).Updates(updateData).Error
  130. if err != nil {
  131. return err
  132. }
  133. return nil
  134. }
  135. // 批量更新字段
  136. func (d ProjectTaskInfoDao) UpdateFieldBatch(taskIds []string, updateData map[string]interface{}) error {
  137. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id IN ?", taskIds).Updates(updateData).Error
  138. if err != nil {
  139. return err
  140. }
  141. return nil
  142. }