123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package dao
- import (
- "youngee_b_api/app/entity"
- )
- type SelectionTaskInfoDao struct{}
- func (s SelectionTaskInfoDao) CountBySelectionId(selectionId string) (int64, error) {
- var count int64
- err := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ?", selectionId).Count(&count).Error
- return count, err
- }
- // 根据openid获取报名的带货子任务阶段
- func (d SelectionTaskInfoDao) CountAllByOpenid(openid string) int64 {
- var total int64
- Db.Model(&entity.SelectionTaskInfo{}).Where("open_id = ?", openid).Count(&total)
- return total
- }
- // 根据openid获取指定任务阶段的带货子任务阶段
- func (d SelectionTaskInfoDao) CountByOpenid(openid string, taskStage int) int64 {
- var total int64
- Db.Model(&entity.SelectionTaskInfo{}).Where("open_id = ? AND task_stage = ?", openid, taskStage).Count(&total)
- return total
- }
- // 根据openid获取执行中的带货子任务阶段
- func (d SelectionTaskInfoDao) CountExcuteNumByOpenid(openid string) int64 {
- var total int64
- Db.Model(&entity.SelectionTaskInfo{}).
- Where("open_id = ? AND task_stage NOT IN (?)", openid, []int{1, 2, 3, 5, 10}).
- Count(&total)
- return total
- }
- // 获取带货子任务中指定悬赏阶段的数据
- func (s SelectionTaskInfoDao) GetRewardDetailByRewardStage(selectionId string, rewardStage int64, order int64, page int, pageSize int) ([]*entity.SelectionTaskInfo, int64, error) {
- selectionTaskInfos := []*entity.SelectionTaskInfo{}
- var total int64
- query := Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND reward_stage = ?", selectionId, rewardStage)
- query.Count(&total)
- query = query.Select("talent_id, sale_actual, withdraw_date, task_reward, open_id")
- offset := (page - 1) * pageSize
- var err error
- if order == 1 {
- err = query.Order("withdraw_date asc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
- } else {
- err = query.Order("withdraw_date desc").Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
- }
- if err != nil {
- return nil, 0, err
- }
- return selectionTaskInfos, total, nil
- }
- func (s SelectionTaskInfoDao) GetSecInfoByOpenId(talentid string, others string, sortField []string, sortOrder []string, page int, pageSize int, reltype int, enterpriseid string) ([]*entity.SelectionTaskInfo, int64, error) {
- selectionTaskInfos := []*entity.SelectionTaskInfo{}
- var total int64
- // 正确JOIN younggee_selection_info表
- query := Db.Model(&entity.SelectionTaskInfo{}).
- Joins("JOIN younggee_selection_info ysi ON ysi.selection_id = selection_task_info.selection_id").
- Where("selection_task_info.talent_id = ? AND selection_task_info.task_stage = ? ", talentid, 10)
- // 搜索条件(针对selection_name)
- if others != "" {
- query = query.Where("ysi.selection_name LIKE ?", "%"+others+"%")
- }
- if reltype == 2 {
- query = query.Where("ysi.enterprise_id = ?", enterpriseid)
- }
- // 排序处理
- if len(sortField) > 0 && len(sortOrder) > 0 && len(sortField) == len(sortOrder) {
- for i := 0; i < len(sortField); i++ {
- sortfield := sortField[i]
- sortorder := sortOrder[i]
- switch sortfield {
- case "sale_actual":
- if sortorder == "asc" {
- query = query.Order("selection_task_info.sale_actual asc")
- } else {
- query = query.Order("selection_task_info.sale_actual desc")
- }
- }
- }
- }
- // 获取总数
- if err := query.Count(&total).Error; err != nil {
- return nil, 0, err
- }
- // 选择字段(明确指定表名)
- query = query.Select(`
- selection_task_info.selection_id,
- selection_task_info.task_id,
- ysi.selection_name,
- selection_task_info.sale_actual
- `)
- // 分页查询
- offset := (page - 1) * pageSize
- err := query.Offset(offset).Limit(pageSize).Find(&selectionTaskInfos).Error
- if err != nil {
- return nil, 0, err
- }
- return selectionTaskInfos, total, nil
- }
|