作者 陈志颖

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

... ... @@ -87,32 +87,58 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
}, nil
}
// 计算个人素币情况
// 计算个人素币情况,昨日收益:做任务验收获得的素币+额外增加-扣除素币-兑换物资-兑换现金
func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
var incomeSuMoney float64
var expendSuMoney float64
var incomeSuMoneyOfYesterday float64
var expendSuMoneyOfYesterday float64
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
yesterday := time.Now().AddDate(0, 0, -1)
// 昨日收益
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type = ?`, 2).
//Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
Select(&incomeSuMoneyOfYesterday); err != nil {
return nil, err
}
// 昨日支出
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
//Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
Select(&expendSuMoneyOfYesterday); err != nil {
return nil, err
}
// 总收益
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type = ?`, 2).
//Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
Select(&incomeSuMoney); err != nil {
return nil, err
}
// 总支出
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
//Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
Select(&expendSuMoney); err != nil {
return nil, err
}
return map[string]interface{}{
"incomeSuMoney": incomeSuMoney,
"incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday,
"incomeSuMoney": incomeSuMoney - expendSuMoney,
"incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday - expendSuMoneyOfYesterday,
}, nil
}
... ... @@ -177,12 +203,13 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf
}, nil
}
// 个人素币事务统计
// 个人收入支出素币统计
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
var incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
var expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 收入素币
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ... @@ -192,10 +219,11 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
Select(&incomeSuMoney); err != nil {
return nil, err
}
// 支出素币
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})).
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
Select(&expendSuMoney); err != nil {
... ...
... ... @@ -112,10 +112,12 @@ func (dao *TaskDao) CancelSuccessfulBidder(taskId int64) error {
return err
}
// 系统任务统计
func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) {
var released int64
var underway int64
var completed int64
var released int64 // 待领取的任务
var underway int64 // 进行中的任务
var completed int64 // 已完成任务
var reward int64 // 公司悬赏任务
tx := dao.transactionContext.PgTx
taskModel := new(models.Task)
if count, err := tx.Model(taskModel).
... ... @@ -142,10 +144,19 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}
} else {
completed = int64(count)
}
if count, err := tx.Model(taskModel).
Where("task.company_id = ?", companyId).
Where("task.is_reward_take = ?", true).
Count(); err != nil {
return nil, err
} else {
reward = int64(count)
}
return map[string]interface{}{
"released": released + underway + completed,
"underway": underway,
"completed": completed,
"reward": reward,
}, nil
}
... ...