...
|
...
|
@@ -31,6 +31,7 @@ func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error { |
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 修改用户权限
|
|
|
func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error {
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
if _, err := tx.Query(
|
...
|
...
|
@@ -48,6 +49,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
_, err := tx.QueryOne(
|
...
|
...
|
@@ -87,7 +89,7 @@ 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
|
...
|
...
|
@@ -142,7 +144,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 系统已兑换素币、未兑换素币
|
|
|
// 计算系统已兑换素币、未兑换素币
|
|
|
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
|
|
|
var systemUnExchangeSuMoney float64
|
|
|
var systemExchangedSuMoney float64
|
...
|
...
|
@@ -203,10 +205,12 @@ 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: 兑换现金)
|
|
|
var (
|
|
|
incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
|
|
|
expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除, 5: 兑换现金)
|
|
|
)
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
// 收入素币
|
...
|
...
|
@@ -235,31 +239,37 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 员工财富值统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
}
|
|
|
// 计算个人贡献值收支
|
|
|
func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
|
|
|
var (
|
|
|
incomeContributions float64 // 增加的贡献值(2:任务奖励,3:增加)
|
|
|
expendContributions float64 // 扣除的贡献值 (4: 扣除)
|
|
|
)
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employee_su_money DESC").
|
|
|
Select(&ret); 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 IN (?)`, pg.In([]int{2, 3})).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
|
|
|
Select(&incomeContributions); 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 =?`, 4).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
|
|
|
Select(&expendContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeesSuMoney": ret,
|
|
|
"incomeContributions": incomeContributions,
|
|
|
"expendContributions": expendContributions,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -311,7 +321,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
|
// }, nil
|
|
|
//}
|
|
|
|
|
|
// 贡献值、财富值总榜和年榜
|
|
|
// 贡献值、财富值总榜和年榜,
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
...
|
...
|
@@ -337,10 +347,8 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
|
|
|
// 财富值榜单
|
|
|
queryWealth := tx.Model(suMoneyTransactionRecordModel)
|
|
|
queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
...
|
...
|
@@ -432,24 +440,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}
|
|
|
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee")
|
|
|
|
|
|
//if offset, ok := queryOptions["offset"]; ok {
|
|
|
// offset := offset.(int)
|
|
|
// if offset > -1 {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Offset(offset)
|
|
|
// }
|
|
|
//} else {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Offset(0)
|
|
|
//}
|
|
|
//if limit, ok := queryOptions["limit"]; ok {
|
|
|
// limit := limit.(int)
|
|
|
// if limit > -1 {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Limit(limit)
|
|
|
// }
|
|
|
//} else {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Limit(20)
|
|
|
//}
|
|
|
//contributionsDecrease := queryWealth.Order("employee_contributions_decrease DESC")
|
|
|
|
|
|
queryContributions := tx.Model()
|
|
|
queryContributions = queryContributions.With("t", contributionsDecrease)
|
|
|
queryContributions = queryContributions.Table("t")
|
...
|
...
|
@@ -555,51 +545,112 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 排行榜统计,排名(弃用)
|
|
|
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
// 排行榜统计,排名
|
|
|
//func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
|
|
|
// var retWealth []struct {
|
|
|
// Uid int
|
|
|
// EmployeeName string
|
|
|
// EmployeeSuMoney float64
|
|
|
// Ranking int
|
|
|
// }
|
|
|
// var retContributions []struct { // 员工贡献值
|
|
|
// Uid int
|
|
|
// EmployeeName string
|
|
|
// EmployeesContributions float64
|
|
|
// Ranking int
|
|
|
// }
|
|
|
// var retContributionDecrease []struct { // 员工减少的贡献值
|
|
|
// Uid int
|
|
|
// EmployeeName string
|
|
|
// EmployeesContributions float64
|
|
|
// Ranking int
|
|
|
// }
|
|
|
// tx := dao.transactionContext.PgTx
|
|
|
// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
// if limit < -1 {
|
|
|
// limit = 20
|
|
|
// }
|
|
|
// if offset < -1 {
|
|
|
// offset = 0
|
|
|
// }
|
|
|
// // 员工财富值
|
|
|
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
|
|
|
// Where(`e.company_id = ?`, companyId).
|
|
|
// Where(`e.status = ?`, 1).
|
|
|
// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
|
|
|
// Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
// Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
// Group("su_money_transaction_record.employee").
|
|
|
// Order("employee_su_money DESC").
|
|
|
// Limit(limit).
|
|
|
// Offset(offset).
|
|
|
// Select(&retWealth); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// // 增加的贡献值
|
|
|
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
// Where(`e.company_id = ?`, companyId).
|
|
|
// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
|
|
|
// Where(`e.status = ?`, 1).
|
|
|
// Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
// Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
// Group("su_money_transaction_record.employee").
|
|
|
// Order("employees_contributions DESC").
|
|
|
// Limit(limit).
|
|
|
// Offset(offset).
|
|
|
// Select(&retContributions); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// // 减少的贡献值
|
|
|
// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
// ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
// Where(`e.company_id = ?`, companyId).
|
|
|
// Where(`su_money_transaction_record.record_type = ?`, 4).
|
|
|
// Where(`e.status = ?`, 1).
|
|
|
// Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
// Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
// Group("su_money_transaction_record.employee").
|
|
|
// Order("employees_contributions DESC").
|
|
|
// Limit(limit).
|
|
|
// Offset(offset).
|
|
|
// Select(&retContributionDecrease); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// for i := 0; i < len(retContributions); i++ {
|
|
|
// for j := 0; j < len(retContributionDecrease); j++ {
|
|
|
// if retContributions[i].Uid == retContributionDecrease[j].Uid {
|
|
|
// retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// return map[string]interface{}{
|
|
|
// "employeesContributions": retContributions,
|
|
|
// "employeesWealth": retWealth,
|
|
|
// }, nil
|
|
|
//}
|
|
|
|
|
|
// 公司员工贡献值分组统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributionDecrease []struct { // 员工减少的贡献值
|
|
|
var retDecrease []struct { // 员工减少的贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
if limit < -1 {
|
|
|
limit = 20
|
|
|
}
|
|
|
if offset < -1 {
|
|
|
offset = 0
|
|
|
}
|
|
|
// 员工财富值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employee_su_money DESC").
|
|
|
Limit(limit).
|
|
|
Offset(offset).
|
|
|
Select(&retWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 增加的贡献值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
...
|
...
|
@@ -612,9 +663,7 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t |
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Limit(limit).
|
|
|
Offset(offset).
|
|
|
Select(&retContributions); err != nil {
|
|
|
Select(&ret); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 减少的贡献值
|
...
|
...
|
@@ -629,77 +678,46 @@ func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime t |
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Limit(limit).
|
|
|
Offset(offset).
|
|
|
Select(&retContributionDecrease); err != nil {
|
|
|
Select(&retDecrease); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := 0; i < len(retContributions); i++ {
|
|
|
for j := 0; j < len(retContributionDecrease); j++ {
|
|
|
if retContributions[i].Uid == retContributionDecrease[j].Uid {
|
|
|
retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions
|
|
|
for i := 0; i < len(ret); i++ {
|
|
|
for j := 0; j < len(retDecrease); j++ {
|
|
|
if ret[i].Uid == retDecrease[j].Uid {
|
|
|
ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeesContributions": retContributions,
|
|
|
"employeesWealth": retWealth,
|
|
|
"employeesContributions": ret,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 员工贡献值统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
}
|
|
|
var retDecrease []struct { // 员工减少的贡献值
|
|
|
// 公司员工财富值分组统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
EmployeeSuMoney float64
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
// 增加的贡献值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Order("employee_su_money DESC").
|
|
|
Select(&ret); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 减少的贡献值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`su_money_transaction_record.record_type = ?`, 4).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Select(&retDecrease); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := 0; i < len(ret); i++ {
|
|
|
for j := 0; j < len(retDecrease); j++ {
|
|
|
if ret[i].Uid == retDecrease[j].Uid {
|
|
|
ret[i].EmployeesContributions -= retDecrease[j].EmployeesContributions
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeesContributions": ret,
|
|
|
"employeesSuMoney": ret,
|
|
|
}, nil
|
|
|
}
|
|
|
|
...
|
...
|
|