...
|
...
|
@@ -57,6 +57,18 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// ChangePhone TODO 修改用户手机号
|
|
|
func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error {
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
if _, err := tx.QueryOne(
|
|
|
pg.Scan(),
|
|
|
"UPDATE employees SET employee_account=? WHERE employee_account=?",
|
|
|
oldPhone, newPhone); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 更新用户素币
|
|
|
func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
|
|
|
tx := dao.transactionContext.PgTx
|
...
|
...
|
@@ -139,7 +151,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
}
|
|
|
|
|
|
// 计算系统已兑换现金素币、未兑换素币
|
|
|
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] interface{}, error) {
|
|
|
func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string]interface{}, error) {
|
|
|
var systemUnExchangeSuMoney float64
|
|
|
var systemExchangedSuMoney float64
|
|
|
var systemExchangedSuMoneyRestore float64
|
...
|
...
|
@@ -172,18 +184,18 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int |
|
|
Select(&systemExchangedSuMoneyRestore); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return map[string] interface{} {
|
|
|
return map[string]interface{}{
|
|
|
"systemUnExchangeSuMoney": systemUnExchangeSuMoney,
|
|
|
"systemExchangedSuMoney": systemExchangedSuMoney - systemExchangedSuMoneyRestore,
|
|
|
},nil
|
|
|
"systemExchangedSuMoney": systemExchangedSuMoney - systemExchangedSuMoneyRestore,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 计算现金池已兑换现金、未兑换现金
|
|
|
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
|
|
|
func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string]interface{}, error) {
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
var (
|
|
|
systemUnExchangeCash float64
|
|
|
systemExchangedCash float64
|
|
|
systemExchangedCash float64
|
|
|
)
|
|
|
// 系统已兑换现金
|
|
|
cashPool := new(models.CashPool)
|
...
|
...
|
@@ -192,7 +204,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf |
|
|
Where("cash_pool.company_id = ?", companyId).
|
|
|
Order("id DESC").
|
|
|
Limit(1).
|
|
|
Select(&systemExchangedCash) ; err != nil {
|
|
|
Select(&systemExchangedCash); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 系统未兑换现金
|
...
|
...
|
@@ -201,22 +213,22 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf |
|
|
Where("cash_pool.company_id = ?", companyId).
|
|
|
Order("id DESC").
|
|
|
Limit(1).
|
|
|
Select(&systemUnExchangeCash) ; err != nil {
|
|
|
Select(&systemUnExchangeCash); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return map[string] interface{} {
|
|
|
return map[string]interface{}{
|
|
|
"systemUnExchangeCash": systemUnExchangeCash,
|
|
|
"systemExchangedCash": systemExchangedCash,
|
|
|
"systemExchangedCash": systemExchangedCash,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 计算个人素币收支(素币明细收支)
|
|
|
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
|
|
|
var (
|
|
|
incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
|
|
|
expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除)
|
|
|
expendSuMoneyExchange float64 // 5: 兑换现金
|
|
|
incomeSuMoneyExchangeRestore float64 // 6: 兑换素币撤回
|
|
|
incomeSuMoney float64 // 收入的素币(2:任务奖励,3:增加)
|
|
|
expendSuMoney float64 // 消耗的素币(1:兑换物资,4:扣除)
|
|
|
expendSuMoneyExchange float64 // 5: 兑换现金
|
|
|
incomeSuMoneyExchangeRestore float64 // 6: 兑换素币撤回
|
|
|
)
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
...
|
...
|
@@ -261,7 +273,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction |
|
|
return nil, err
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"incomeSuMoney": incomeSuMoney, // 个人素币收入
|
|
|
"incomeSuMoney": incomeSuMoney, // 个人素币收入
|
|
|
"expendSuMoney": expendSuMoney + (expendSuMoneyExchange - incomeSuMoneyExchangeRestore), // 个人素币支出
|
|
|
}, nil
|
|
|
}
|
...
|
...
|
@@ -269,8 +281,8 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction |
|
|
// 计算个人贡献值收支(贡献明细收支)
|
|
|
func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
|
|
|
var (
|
|
|
incomeContributions float64 // 收入的贡献值(2:任务奖励,3:增加)
|
|
|
expendContributions float64 // 支出的贡献值 (4: 扣除)
|
|
|
incomeContributions float64 // 收入的贡献值(2:任务奖励,3:增加)
|
|
|
expendContributions float64 // 支出的贡献值 (4: 扣除)
|
|
|
)
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
...
|
...
|
@@ -301,37 +313,37 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans |
|
|
return nil, err
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"incomeContributions": incomeContributions, // 个人贡献值收入
|
|
|
"expendContributions": expendContributions, // 个人贡献支出
|
|
|
"contributions": incomeContributions - expendContributions, // 个人贡献值
|
|
|
"incomeContributions": incomeContributions, // 个人贡献值收入
|
|
|
"expendContributions": expendContributions, // 个人贡献支出
|
|
|
"contributions": incomeContributions - expendContributions, // 个人贡献值
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 贡献值、财富值总榜和年榜,
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct { // 个人财富值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
var retWealth []struct { // 个人财富值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeWealth []struct { // 个人贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
var retEmployeeWealth []struct { // 个人贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeContributions []struct { // 员工贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
var retEmployeeContributions []struct { // 员工贡献值
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
Ranking int
|
|
|
}
|
|
|
|
|
|
tx := dao.transactionContext.PgTx
|
...
|
...
|
@@ -496,23 +508,23 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"employeesWealth": retWealth,
|
|
|
"employeesContributions": retContributions,
|
|
|
"employeesWealth": retWealth,
|
|
|
"employeesContributions": retContributions,
|
|
|
"currentEmployeeContributions": retCurrentEmployeeContributions,
|
|
|
"currentEmployeeWealth": retCurrentEmployeeWealth,
|
|
|
"currentEmployeeWealth": retCurrentEmployeeWealth,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 公司员工贡献值分组统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
var ret []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
}
|
|
|
var retDecrease []struct { // 员工减少的贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
var retDecrease []struct { // 员工减少的贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
...
|
...
|
@@ -562,8 +574,8 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime |
|
|
// 公司员工财富值分组统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
...
|
...
|
@@ -574,7 +586,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
|
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.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").
|
...
|
...
|
|