作者 陈志颖

feat:增加系统悬赏任务统计

@@ -87,32 +87,58 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string @@ -87,32 +87,58 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
87 }, nil 87 }, nil
88 } 88 }
89 89
90 -// 计算个人素币情况 90 +// 计算个人素币情况,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
91 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { 91 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
92 var incomeSuMoney float64 92 var incomeSuMoney float64
  93 + var expendSuMoney float64
93 var incomeSuMoneyOfYesterday float64 94 var incomeSuMoneyOfYesterday float64
  95 + var expendSuMoneyOfYesterday float64
94 tx := dao.transactionContext.PgTx 96 tx := dao.transactionContext.PgTx
95 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 97 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
96 yesterday := time.Now().AddDate(0, 0, -1) 98 yesterday := time.Now().AddDate(0, 0, -1)
  99 + // 昨日收益
97 if err := tx.Model(suMoneyTransactionRecordModel). 100 if err := tx.Model(suMoneyTransactionRecordModel).
98 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 101 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
99 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 102 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
100 - Where(`su_money_transaction_record.record_type = ?`, 2). 103 + //Where(`su_money_transaction_record.record_type = ?`, 2).
  104 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
101 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). 105 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
102 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). 106 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
103 Select(&incomeSuMoneyOfYesterday); err != nil { 107 Select(&incomeSuMoneyOfYesterday); err != nil {
104 return nil, err 108 return nil, err
105 } 109 }
  110 + // 昨日支出
  111 + if err := tx.Model(suMoneyTransactionRecordModel).
  112 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  113 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  114 + //Where(`su_money_transaction_record.record_type = ?`, 2).
  115 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
  116 + Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
  117 + Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
  118 + Select(&expendSuMoneyOfYesterday); err != nil {
  119 + return nil, err
  120 + }
  121 + // 总收益
106 if err := tx.Model(suMoneyTransactionRecordModel). 122 if err := tx.Model(suMoneyTransactionRecordModel).
107 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
108 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
109 - Where(`su_money_transaction_record.record_type = ?`, 2). 125 + //Where(`su_money_transaction_record.record_type = ?`, 2).
  126 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
110 Select(&incomeSuMoney); err != nil { 127 Select(&incomeSuMoney); err != nil {
111 return nil, err 128 return nil, err
112 } 129 }
  130 + // 总支出
  131 + if err := tx.Model(suMoneyTransactionRecordModel).
  132 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  133 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  134 + //Where(`su_money_transaction_record.record_type = ?`, 2).
  135 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
  136 + Select(&expendSuMoney); err != nil {
  137 + return nil, err
  138 + }
113 return map[string]interface{}{ 139 return map[string]interface{}{
114 - "incomeSuMoney": incomeSuMoney,  
115 - "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday, 140 + "incomeSuMoney": incomeSuMoney - expendSuMoney,
  141 + "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday - expendSuMoneyOfYesterday,
116 }, nil 142 }, nil
117 } 143 }
118 144
@@ -177,12 +203,13 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf @@ -177,12 +203,13 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
177 }, nil 203 }, nil
178 } 204 }
179 205
180 -// 个人素币事务统计 206 +// 个人收入支出素币统计
181 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 207 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
182 var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加) 208 var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
183 var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金) 209 var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
184 tx := dao.transactionContext.PgTx 210 tx := dao.transactionContext.PgTx
185 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 211 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  212 + // 收入素币
186 if err := tx.Model(suMoneyTransactionRecordModel). 213 if err := tx.Model(suMoneyTransactionRecordModel).
187 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 214 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
188 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 215 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -192,10 +219,11 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -192,10 +219,11 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
192 Select(&incomeSuMoney); err != nil { 219 Select(&incomeSuMoney); err != nil {
193 return nil, err 220 return nil, err
194 } 221 }
  222 + // 支出素币
195 if err := tx.Model(suMoneyTransactionRecordModel). 223 if err := tx.Model(suMoneyTransactionRecordModel).
196 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 224 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
197 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 225 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
198 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})). 226 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
199 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 227 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
200 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 228 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
201 Select(&expendSuMoney); err != nil { 229 Select(&expendSuMoney); err != nil {
@@ -112,10 +112,12 @@ func (dao *TaskDao) CancelSuccessfulBidder(taskId int64) error { @@ -112,10 +112,12 @@ func (dao *TaskDao) CancelSuccessfulBidder(taskId int64) error {
112 return err 112 return err
113 } 113 }
114 114
  115 +// 系统任务统计
115 func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) { 116 func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) {
116 - var released int64  
117 - var underway int64  
118 - var completed int64 117 + var released int64 // 待领取的任务
  118 + var underway int64 // 进行中的任务
  119 + var completed int64 // 已完成任务
  120 + var reward int64 // 公司悬赏任务
119 tx := dao.transactionContext.PgTx 121 tx := dao.transactionContext.PgTx
120 taskModel := new(models.Task) 122 taskModel := new(models.Task)
121 if count, err := tx.Model(taskModel). 123 if count, err := tx.Model(taskModel).
@@ -142,10 +144,19 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{} @@ -142,10 +144,19 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}
142 } else { 144 } else {
143 completed = int64(count) 145 completed = int64(count)
144 } 146 }
  147 + if count, err := tx.Model(taskModel).
  148 + Where("task.company_id = ?", companyId).
  149 + Where("task.is_reward_take = ?", true).
  150 + Count(); err != nil {
  151 + return nil, err
  152 + } else {
  153 + reward = int64(count)
  154 + }
145 return map[string]interface{}{ 155 return map[string]interface{}{
146 "released": released + underway + completed, 156 "released": released + underway + completed,
147 "underway": underway, 157 "underway": underway,
148 "completed": completed, 158 "completed": completed,
  159 + "reward": reward,
149 }, nil 160 }, nil
150 } 161 }
151 162