作者 陈志颖

fix:昨日收益

@@ -92,51 +92,54 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string @@ -92,51 +92,54 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
92 // 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金 92 // 计算个人素币收益,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
93 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { 93 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
94 var incomeSuMoney float64 94 var incomeSuMoney float64
95 - var expendSuMoney float64 95 + //var expendSuMoney float64
96 var incomeSuMoneyOfYesterday float64 96 var incomeSuMoneyOfYesterday float64
97 - var expendSuMoneyOfYesterday float64 97 + //var expendSuMoneyOfYesterday float64
98 tx := dao.transactionContext.PgTx 98 tx := dao.transactionContext.PgTx
99 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 99 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
100 yesterday := time.Now().Local().AddDate(0, 0, -1) 100 yesterday := time.Now().Local().AddDate(0, 0, -1)
101 - // 昨日收益 101 + // 昨日收益
102 if err := tx.Model(suMoneyTransactionRecordModel). 102 if err := tx.Model(suMoneyTransactionRecordModel).
103 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 103 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
104 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 104 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
105 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})). 105 + //Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
  106 + Where(`su_money_transaction_record.record_type = ?`, 2).
106 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). 107 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
107 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). 108 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
108 Select(&incomeSuMoneyOfYesterday); err != nil { 109 Select(&incomeSuMoneyOfYesterday); err != nil {
109 return nil, err 110 return nil, err
110 } 111 }
111 - // 昨日总支出 112 + //// 昨日支出
  113 + //if err := tx.Model(suMoneyTransactionRecordModel).
  114 + // ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  115 + // Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  116 + // //Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
  117 + // Where(`su_money_transaction_record.record_type = ?`, 2).
  118 + // Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
  119 + // Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
  120 + // Select(&expendSuMoneyOfYesterday); err != nil {
  121 + // return nil, err
  122 + //}
  123 + // 收益
112 if err := tx.Model(suMoneyTransactionRecordModel). 124 if err := tx.Model(suMoneyTransactionRecordModel).
113 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 125 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
114 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 126 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
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 - // 总收益  
122 - if err := tx.Model(suMoneyTransactionRecordModel).  
123 - ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").  
124 - Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).  
125 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})). 127 + //Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
  128 + Where(`su_money_transaction_record.record_type = ?`, 2).
126 Select(&incomeSuMoney); err != nil { 129 Select(&incomeSuMoney); err != nil {
127 return nil, err 130 return nil, err
128 } 131 }
129 - // 总支出  
130 - if err := tx.Model(suMoneyTransactionRecordModel).  
131 - ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").  
132 - Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).  
133 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).  
134 - Select(&expendSuMoney); err != nil {  
135 - return nil, err  
136 - } 132 + //// 支出
  133 + //if err := tx.Model(suMoneyTransactionRecordModel).
  134 + // ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  135 + // Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  136 + // Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
  137 + // Select(&expendSuMoney); err != nil {
  138 + // return nil, err
  139 + //}
137 return map[string]interface{}{ 140 return map[string]interface{}{
138 - "incomeSuMoney": incomeSuMoney - expendSuMoney,  
139 - "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday - expendSuMoneyOfYesterday, 141 + "incomeSuMoney": incomeSuMoney,
  142 + "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday,
140 }, nil 143 }, nil
141 } 144 }
142 145
@@ -216,9 +219,9 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf @@ -216,9 +219,9 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
216 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 219 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
217 var ( 220 var (
218 incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加 6: 兑换素币撤回) 221 incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加 6: 兑换素币撤回)
219 - expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)  
220 - expendSuMoneyExchange float64  
221 - incomeSuMoneyExchangeRestore float64 222 + expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, )
  223 + expendSuMoneyExchange float64 // 5: 兑换现金
  224 + incomeSuMoneyExchangeRestore float64 // 6: 兑换素币撤回
222 ) 225 )
223 tx := dao.transactionContext.PgTx 226 tx := dao.transactionContext.PgTx
224 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 227 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
@@ -236,7 +239,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -236,7 +239,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
236 if err := tx.Model(suMoneyTransactionRecordModel). 239 if err := tx.Model(suMoneyTransactionRecordModel).
237 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 240 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
238 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 241 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
239 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})). 242 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})).
240 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 243 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
241 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 244 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
242 Select(&expendSuMoney); err != nil { 245 Select(&expendSuMoney); err != nil {