作者 陈志颖

feat:增加兑换清单总榜

@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 7
8 // 获取兑换活动兑换清单 8 // 获取兑换活动兑换清单
9 type ListExchangeCashPersonQuery struct { 9 type ListExchangeCashPersonQuery struct {
  10 + CompanyId int64 `json:"companyId"` // 公司id
10 ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id 11 ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
11 ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配 12 ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配
12 Offset int `json:"offset,omitempty"` // 查询偏离量 13 Offset int `json:"offset,omitempty"` // 查询偏离量
@@ -998,6 +998,11 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer @@ -998,6 +998,11 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
998 } 998 }
999 } 999 }
1000 1000
  1001 +// 返回素币兑换现金活动总清单
  1002 +//func (cashPoolService *CashPoolService) ListSystemExchangeCashPerson(listSystemExchangeCashPersonQuery *query.ListSystemExchangeCashPersonQuery) (interface{}, error) {
  1003 +//
  1004 +//}
  1005 +
1001 // 返回兑换素币清单列表 1006 // 返回兑换素币清单列表
1002 func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { 1007 func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) {
1003 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { 1008 if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil {
@@ -1023,7 +1028,48 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP @@ -1023,7 +1028,48 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
1023 exchangeCashPersonListRepository = value 1028 exchangeCashPersonListRepository = value
1024 } 1029 }
1025 1030
1026 - // TODO 增加总榜单查询 1031 + fmt.Print(listExchangeCashPersonQuery, "\n")
  1032 +
  1033 + // TODO 返回兑换现金活动总榜
  1034 + if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 {
  1035 + // 找到该公司下的所有活动id
  1036 + var exchangeActivityRepository domain.ExchangeActivityRepository
  1037 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  1038 + "transactionContext": transactionContext,
  1039 + }); err != nil {
  1040 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1041 + } else {
  1042 + exchangeActivityRepository = value
  1043 + }
  1044 +
  1045 + if _, activities, err := exchangeActivityRepository.Find(map[string]interface{}{
  1046 + "companyId": listExchangeCashPersonQuery.CompanyId,
  1047 + }); err != nil {
  1048 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1049 + } else {
  1050 + var activityIds []int64
  1051 + for _, activity := range activities {
  1052 + activityIds = append(activityIds, activity.ActivityId)
  1053 + }
  1054 +
  1055 + if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{
  1056 + "exchangeCashActivityIds": activityIds,
  1057 + "offset": listExchangeCashPersonQuery.Offset,
  1058 + "limit": listExchangeCashPersonQuery.Limit,
  1059 + }); err != nil {
  1060 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1061 + } else {
  1062 + if err := transactionContext.CommitTransaction(); err != nil {
  1063 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1064 + }
  1065 + return map[string]interface{}{
  1066 + "count": count,
  1067 + "people": people,
  1068 + }, nil
  1069 + }
  1070 + }
  1071 + }
  1072 +
1027 if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil { 1073 if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
1028 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1074 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1029 } else { 1075 } else {
@@ -14,6 +14,7 @@ type ExchangeCashPersonListRepository interface { @@ -14,6 +14,7 @@ type ExchangeCashPersonListRepository interface {
14 Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error) 14 Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
15 FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error) 15 FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error)
16 Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) 16 Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
  17 + FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
17 } 18 }
18 19
19 func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { 20 func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
@@ -54,6 +54,45 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str @@ -54,6 +54,45 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str
54 } 54 }
55 } 55 }
56 56
  57 +// 获取平台所有兑换活动清单(兑换现金活动总清单)
  58 +func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
  59 + tx := repository.transactionContext.PgTx
  60 + var exchangeCashListModels []*models.ExchangeCashPersonList
  61 + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
  62 + query := tx.Model(&exchangeCashListModels)
  63 + if exchangeCashActivityIds, ok := queryOptions["exchangeCashActivityIds"]; ok && len(exchangeCashActivityIds.([]int64)) != 0 {
  64 + query = query.Where("exchange_cash_person_list.activity_id IN (?)", pg.In(exchangeCashActivityIds.([]int64)) )
  65 + }
  66 + if offset, ok := queryOptions["offset"]; ok {
  67 + offset := offset.(int)
  68 + if offset > -1 {
  69 + query = query.Offset(offset)
  70 + }
  71 + } else {
  72 + query = query.Offset(0)
  73 + }
  74 + if limit, ok := queryOptions["limit"]; ok {
  75 + limit := limit.(int)
  76 + if limit > -1 {
  77 + query = query.Limit(limit)
  78 + }
  79 + } else {
  80 + query = query.Limit(20)
  81 + }
  82 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  83 + return 0, exchangeCashPeople, err
  84 + } else {
  85 + for _, exchangeCashListModel := range exchangeCashListModels {
  86 + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
  87 + return 0, exchangeCashPeople, err
  88 + } else {
  89 + exchangeCashPeople = append(exchangeCashPeople, taskNature)
  90 + }
  91 + }
  92 + return int64(count), exchangeCashPeople, nil
  93 + }
  94 +}
  95 +
57 func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { 96 func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
58 tx := repository.transactionContext.PgTx 97 tx := repository.transactionContext.PgTx
59 var exchangeCashListModels []*models.ExchangeCashPersonList 98 var exchangeCashListModels []*models.ExchangeCashPersonList
@@ -231,6 +231,8 @@ func (controller *SuMoneyController) ListExchangeList () { @@ -231,6 +231,8 @@ func (controller *SuMoneyController) ListExchangeList () {
231 listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{} 231 listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{}
232 activityId, _ := controller.GetInt64("activityId") 232 activityId, _ := controller.GetInt64("activityId")
233 listExchangeCashListQuery.ExchangeCashActivityId = activityId 233 listExchangeCashListQuery.ExchangeCashActivityId = activityId
  234 + companyId, _ := controller.GetInt64("companyId")
  235 + listExchangeCashListQuery.CompanyId = companyId
234 exchangeCashPersonNameMatch := controller.GetString("personNameMatch") 236 exchangeCashPersonNameMatch := controller.GetString("personNameMatch")
235 listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch 237 listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch
236 offset, _ := controller.GetInt("offset") 238 offset, _ := controller.GetInt("offset")