sec_task_info_dao.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package dao
  2. import (
  3. "youngee_b_api/app/entity"
  4. )
  5. type SelectionTaskInfoDao struct{}
  6. func (s SelectionTaskInfoDao) CountBySelectionId(selectionId string) (int64, error) {
  7. var count int64
  8. err := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
  9. return count, err
  10. }
  11. // 根据openid获取报名的带货子任务阶段
  12. func (d SelectionTaskInfoDao) CountAllByOpenid(openid string) int64 {
  13. var total int64
  14. Db.Model(&entity.SelectionTaskInfo{}).Where("open_id = ?", openid).Count(&total)
  15. return total
  16. }
  17. // 根据openid获取指定任务阶段的带货子任务阶段
  18. func (d SelectionTaskInfoDao) CountByOpenid(openid string, taskStage int) int64 {
  19. var total int64
  20. Db.Model(&entity.SelectionTaskInfo{}).Where("open_id = ? AND task_stage = ?", openid, taskStage).Count(&total)
  21. return total
  22. }
  23. // 根据openid获取执行中的带货子任务阶段
  24. func (d SelectionTaskInfoDao) CountExcuteNumByOpenid(openid string) int64 {
  25. var total int64
  26. Db.Model(&entity.SelectionTaskInfo{}).
  27. Where("open_id = ? AND task_stage NOT IN (?)", openid, []int{1, 2, 3, 5, 10}).
  28. Count(&total)
  29. return total
  30. }
  31. // 获取带货子任务中指定悬赏阶段的数据
  32. func (s SelectionTaskInfoDao) GetRewardDetailByRewardStage(selectionId string, rewardStage int64, order int64, page int, pageSize int) ([]*entity.SelectionTaskInfo, int64, error) {
  33. selectionTaskInfos := []*entity.SelectionTaskInfo{}
  34. var total int64
  35. query := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND reward_stage = ?", selectionId, rewardStage)
  36. query.Count(&total)
  37. query = query.Select("talent_id, sale_actual, withdraw_date, task_reward, open_id")
  38. offset := (page - 1) * pageSize
  39. var err error
  40. if order == 1 {
  41. err = query.Order("withdraw_date asc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
  42. } else {
  43. err = query.Order("withdraw_date desc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
  44. }
  45. if err != nil {
  46. return nil, 0, err
  47. }
  48. return selectionTaskInfos, total, nil
  49. }
  50. func (s SelectionTaskInfoDao) GetSecInfoByOpenId(talentid string, others string, sortField []string, sortOrder []string, page int, pageSize int, reltype int, enterpriseid string) ([]*entity.SelectionTaskInfo, int64, error) {
  51. selectionTaskInfos := []*entity.SelectionTaskInfo{}
  52. var total int64
  53. // 正确JOIN younggee_selection_info表
  54. query := Db.Model(&entity.SelectionTaskInfo{}).
  55. Joins("JOIN younggee_selection_info ysi ON ysi.selection_id = younggee_sec_task_info.selection_id").
  56. Where("younggee_sec_task_info.talent_id = ? AND younggee_sec_task_info.task_stage = ? ", talentid, 10)
  57. // 搜索条件(针对selection_name)
  58. if others != "" {
  59. query = query.Where("ysi.selection_name LIKE ?", "%"+others+"%")
  60. }
  61. if reltype == 2 {
  62. query = query.Where("ysi.enterprise_id = ?", enterpriseid)
  63. }
  64. // 排序处理
  65. if len(sortField) > 0 && len(sortOrder) > 0 && len(sortField) == len(sortOrder) {
  66. for i := 0; i < len(sortField); i++ {
  67. sortfield := sortField[i]
  68. sortorder := sortOrder[i]
  69. switch sortfield {
  70. case "sale_actual":
  71. if sortorder == "asc" {
  72. query = query.Order("younggee_sec_task_info.sale_actual asc")
  73. } else {
  74. query = query.Order("younggee_sec_task_info.sale_actual desc")
  75. }
  76. }
  77. }
  78. }
  79. // 获取总数
  80. if err := query.Count(&total).Error; err != nil {
  81. return nil, 0, err
  82. }
  83. // 选择字段(明确指定表名)
  84. query = query.Select(`
  85. younggee_sec_task_info.selection_id,
  86. younggee_sec_task_info.task_id,
  87. ysi.selection_name,
  88. younggee_sec_task_info.sale_actual
  89. `)
  90. // 分页查询
  91. offset := (page - 1) * pageSize
  92. err := query.Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
  93. if err != nil {
  94. return nil, 0, err
  95. }
  96. return selectionTaskInfos, total, nil
  97. }