local_life_task_info_dao.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package dao
  2. import (
  3. "youngee_b_api/app/entity"
  4. "youngee_b_api/app/vo"
  5. )
  6. type LocalLifeTaskInfoDao struct{}
  7. // 获取指定违约类型的本地生活子任务数量
  8. func (d LocalLifeTaskInfoDao) CountByDefaultType(localId string, defaultType int64) int64 {
  9. var total int64
  10. Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND cur_default_type = ?", localId, defaultType).Count(&total)
  11. return total
  12. }
  13. // 获取指定任务阶段的本地生活子任务数量
  14. func (d LocalLifeTaskInfoDao) CountByTaskStage(localId string, taskStage int64) int64 {
  15. var total int64
  16. Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND task_stage = ?", localId, taskStage).Count(&total)
  17. return total
  18. }
  19. // 根据openid获取报名的本地生活子任务阶段
  20. func (d LocalLifeTaskInfoDao) CountAllByOpenid(openid string) int64 {
  21. var total int64
  22. Db.Model(&entity.LocalLifeTaskInfo{}).Where("open_id = ?", openid).Count(&total)
  23. return total
  24. }
  25. // 根据openid获取指定任务阶段的本地生活子任务阶段
  26. func (d LocalLifeTaskInfoDao) CountByOpenid(openid string, taskStage int) int64 {
  27. var total int64
  28. Db.Model(&entity.LocalLifeTaskInfo{}).Where("open_id = ? AND task_stage = ?", openid, taskStage).Count(&total)
  29. return total
  30. }
  31. // 根据openid获取执行中的本地生活子任务阶段
  32. func (d LocalLifeTaskInfoDao) CountExcuteNumByOpenid(openid string) int64 {
  33. var total int64
  34. Db.Model(&entity.LocalLifeTaskInfo{}).
  35. Where("open_id = ? AND task_stage NOT IN (?)", openid, []int{1, 3, 15, 16, 17}).
  36. Count(&total)
  37. return total
  38. }
  39. // 获取指定任务阶段的本地生活子任务
  40. func (d LocalLifeTaskInfoDao) GetListByTaskStage(localId string, taskStage int64, time string, page int, pageSize int) ([]*entity.LocalLifeTaskInfo, int64, error) {
  41. var taskInfos []*entity.LocalLifeTaskInfo
  42. var total int64
  43. query := Db.Debug().Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND task_stage = ?", localId, taskStage)
  44. // 计算偏移量
  45. offset := (page - 1) * pageSize
  46. var err error
  47. if taskStage == 4 { // 待预约探店
  48. query.Count(&total)
  49. err = query.Order("select_date asc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  50. } else if taskStage == 5 { // 待确认探店
  51. if time != "" {
  52. query = query.Where("DATE(reserve_time) = ?", time)
  53. }
  54. query.Count(&total)
  55. err = query.Order("reserve_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 LocalLifeTaskInfoDao) GetListByBookStatus(localId string, bookStatus int64, time string, page int, pageSize int) ([]*entity.LocalLifeTaskInfo, int64, error) {
  64. var taskInfos []*entity.LocalLifeTaskInfo
  65. var total int64
  66. query := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND book_status = ?", localId, bookStatus)
  67. // 计算偏移量
  68. offset := (page - 1) * pageSize
  69. var err error
  70. if bookStatus == 5 { // 待探店
  71. if time != "" {
  72. query = query.Where("DATE(explore_time) = ?", time)
  73. }
  74. query.Count(&total)
  75. err = query.Order("explore_time desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  76. } else if bookStatus == 6 { // 已探店
  77. if time != "" {
  78. query = query.Where("DATE(finish_explore_time) = ?", time)
  79. }
  80. query.Count(&total)
  81. err = query.Order("finish_explore_time desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  82. }
  83. if err != nil {
  84. return nil, 0, err
  85. }
  86. return taskInfos, total, nil
  87. }
  88. // 获取未传初稿的本地生活子任务数据
  89. func (d LocalLifeTaskInfoDao) GetListBySketchDefault(param *vo.DefaultSearchParam) ([]entity.LocalLifeTaskInfo, int64, error) {
  90. localTaskInfos := []entity.LocalLifeTaskInfo{}
  91. var total int64
  92. query := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND cur_default_type = ?", param.TaskId, 4)
  93. query.Count(&total)
  94. query = query.Select("task_id, talent_id, settle_amount, draft_fee, sketch_missing_time, open_id")
  95. offset := (param.Page - 1) * param.PageSize
  96. if err := query.Order("sketch_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&localTaskInfos).Error; err != nil {
  97. return nil, 0, err
  98. }
  99. return localTaskInfos, total, nil
  100. }
  101. // 获取未发作品的本地生活子任务数据
  102. func (d LocalLifeTaskInfoDao) GetListByLinkDefault(param *vo.DefaultSearchParam) ([]entity.LocalLifeTaskInfo, int64, error) {
  103. localTaskInfos := []entity.LocalLifeTaskInfo{}
  104. var total int64
  105. query := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND cur_default_type = ?", param.TaskId, 6)
  106. query.Count(&total)
  107. query = query.Select("task_id, talent_id, settle_amount, draft_fee, link_missing_time, open_id")
  108. offset := (param.Page - 1) * param.PageSize
  109. if err := query.Order("link_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&localTaskInfos).Error; err != nil {
  110. return nil, 0, err
  111. }
  112. return localTaskInfos, total, nil
  113. }
  114. // 获取未传数据的本地生活子任务数据
  115. func (d LocalLifeTaskInfoDao) GetListByDataDefault(param *vo.DefaultSearchParam) ([]entity.LocalLifeTaskInfo, int64, error) {
  116. localTaskInfos := []entity.LocalLifeTaskInfo{}
  117. var total int64
  118. query := Db.Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND cur_default_type = ?", param.TaskId, 8)
  119. query.Count(&total)
  120. query = query.Select("task_id, talent_id, settle_amount, draft_fee, data_missing_time, open_id")
  121. offset := (param.Page - 1) * param.PageSize
  122. if err := query.Order("data_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&localTaskInfos).Error; err != nil {
  123. return nil, 0, err
  124. }
  125. return localTaskInfos, total, nil
  126. }
  127. // 获取终止合作的本地生活子任务数据
  128. func (d LocalLifeTaskInfoDao) GetListByTerminateDefault(param *vo.DefaultSearchParam) ([]entity.LocalLifeTaskInfo, int64, error) {
  129. localTaskInfos := []entity.LocalLifeTaskInfo{}
  130. var total int64
  131. query := Db.Debug().Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND task_stage = ?", param.TaskId, 17)
  132. query.Count(&total)
  133. query = query.Select("task_id, talent_id, settle_amount, draft_fee, terminate_time, terminate_reason, terminate_operator_type, terminate_operator, open_id")
  134. offset := (param.Page - 1) * param.PageSize
  135. if err := query.Order("terminate_time desc").Offset(offset).Limit(param.PageSize).Find(&localTaskInfos).Error; err != nil {
  136. return nil, 0, err
  137. }
  138. return localTaskInfos, total, nil
  139. }
  140. // 获取已解约的本地生活子任务数据
  141. func (d LocalLifeTaskInfoDao) GetListByCancelDefault(param *vo.DefaultSearchParam) ([]entity.LocalLifeTaskInfo, int64, error) {
  142. localTaskInfos := []entity.LocalLifeTaskInfo{}
  143. var total int64
  144. query := Db.Debug().Model(&entity.LocalLifeTaskInfo{}).Where("local_id = ? AND task_stage = ?", param.TaskId, 16)
  145. query.Count(&total)
  146. query = query.Select("task_id, talent_id, settle_amount, draft_fee, cancel_time, cancel_reason, cancel_operator_type, cancel_operator, open_id")
  147. offset := (param.Page - 1) * param.PageSize
  148. if err := query.Order("cancel_time desc").Offset(offset).Limit(param.PageSize).Find(&localTaskInfos).Error; err != nil {
  149. return nil, 0, err
  150. }
  151. return localTaskInfos, total, nil
  152. }
  153. // 更新字段
  154. func (d LocalLifeTaskInfoDao) UpdateField(taskId string, updateData map[string]interface{}) error {
  155. err := Db.Model(&entity.LocalLifeTaskInfo{}).Where("task_id = ?", taskId).Updates(updateData).Error
  156. if err != nil {
  157. return err
  158. }
  159. return nil
  160. }
  161. // 批量更新字段
  162. func (d LocalLifeTaskInfoDao) UpdateFieldBatch(taskIds []string, updateData map[string]interface{}) error {
  163. err := Db.Model(&entity.LocalLifeTaskInfo{}).Where("task_id IN ?", taskIds).Updates(updateData).Error
  164. if err != nil {
  165. return err
  166. }
  167. return nil
  168. }
  169. // 批量更新字段
  170. func (d LocalLifeTaskInfoDao) UpdateLocalStatus(taskIds []string, localLifeTaskInfo entity.LocalLifeTaskInfo) error {
  171. err := Db.Debug().Model(&entity.LocalLifeTaskInfo{}).Where("task_id IN ?", taskIds).Updates(localLifeTaskInfo).Error
  172. if err != nil {
  173. return err
  174. }
  175. return nil
  176. }
  177. func (d LocalLifeTaskInfoDao) GetLocalLifeInfoByTalentId(talentid string, others string, sortField []string, sortOrder []string, page int, pageSize int, reltype int, enterpriseid string, platform int) ([]*entity.LocalLifeTaskInfo, int64, error) {
  178. projectTaskInfos := []*entity.LocalLifeTaskInfo{}
  179. var total int64
  180. query := Db.Model(&entity.LocalLifeTaskInfo{}).
  181. Joins("JOIN younggee_local_life_info ylli ON ylli.local_id = youngee_local_task_info.local_id").
  182. Where("youngee_local_task_info.talent_id = ? AND youngee_local_task_info.task_stage = ? AND youngee_local_task_info.platform_id = ?", talentid, 15, platform)
  183. // 搜索条件(local_name)
  184. if others != "" {
  185. query = query.Where("ylli.local_name LIKE ?", "%"+others+"%")
  186. }
  187. if reltype == 2 {
  188. query = query.Where("ylli.enterprise_id = ?", enterpriseid)
  189. }
  190. // 排序处理
  191. if len(sortField) > 0 && len(sortOrder) > 0 && len(sortField) == len(sortOrder) {
  192. for i := 0; i < len(sortField); i++ {
  193. sortfield := sortField[i]
  194. sortorder := sortOrder[i]
  195. switch sortfield {
  196. case "commit_avg":
  197. if sortorder == "asc" {
  198. query = query.Order("youngee_local_task_info.commit_avg asc")
  199. } else {
  200. query = query.Order("youngee_local_task_info.commit_avg desc")
  201. }
  202. case "collect_num":
  203. if sortorder == "asc" {
  204. query = query.Order("youngee_local_task_info.collect_num asc")
  205. } else {
  206. query = query.Order("youngee_local_task_info.collect_num desc")
  207. }
  208. case "vote_avg":
  209. if sortorder == "asc" {
  210. query = query.Order("youngee_local_task_info.vote_avg asc")
  211. } else {
  212. query = query.Order("youngee_local_task_info.vote_avg desc")
  213. }
  214. }
  215. }
  216. }
  217. // 获取总数
  218. if err := query.Count(&total).Error; err != nil {
  219. return nil, 0, err
  220. }
  221. // 选择字段(明确指定表名)
  222. query = query.Select(`
  223. youngee_local_task_info.local_id,
  224. youngee_local_task_info.task_id,
  225. ylli.local_name,
  226. youngee_local_task_info.commit_avg,
  227. youngee_local_task_info.collect_num,
  228. youngee_local_task_info.vote_avg,`)
  229. // 分页查询
  230. offset := (page - 1) * pageSize
  231. err := query.Offset(offset).Limit(pageSize).Find(&projectTaskInfos).Error
  232. if err != nil {
  233. return nil, 0, err
  234. }
  235. return projectTaskInfos, total, nil
  236. }