作者 陈志颖

fix:增加验收任务时更新现金池

... ... @@ -1358,45 +1358,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
}
//// 判断当前员工是否已经在素币兑换清单中,区分excel导入新增和页面添加新增
//if !createFlag { // 页面新增
// count, _, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
// "uid": employeeFound.EmployeeInfo.Uid,
// "exchangeCashActivityId": activityFound.ActivityId,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 { // 已存在兑换素币清单
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前员工已经在素币兑换清单中")
// }
// if count == 0 { // 未存在,新增兑换素币清单
//
// }
//} else { // 导入新增
// count, peopleFound, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
// "employeeAccount": employeeFound.EmployeeInfo.EmployeeAccount,
// "exchangeCashActivityId": activityFound.ActivityId,
// "offset": 0,
// "limit": 1,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if count > 0 { // 追加素币兑换或撤回素币兑换
// if createExchangeCashPersonCommand.ExchangedSuMoney < peopleFound[0].ExchangedSuMoney { // 当前兑换的素币小于已兑换素币,撤回兑换素币
// suMoneyDecrement := peopleFound[0].ExchangedSuMoney - createExchangeCashPersonCommand.ExchangedSuMoney // 减量
//
// } else if createExchangeCashPersonCommand.ExchangedSuMoney > peopleFound[0].ExchangedSuMoney { // 当前兑换素币大于已兑换素币,追加兑换素币
// suMoneyIncrement := createExchangeCashPersonCommand.ExchangedSuMoney - peopleFound[0].ExchangedSuMoney // 增量
//
// }
// }
// if count == 0 { // 新增
//
// }
//}
// 新增兑换清单命令
newPersonExchangedCash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", createExchangeCashPersonCommand.ExchangedSuMoney * activityFound.Rate), 64)
... ...
... ... @@ -153,39 +153,41 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
//for _, suMoneyTransactionRecord := range suMoneyTransactionRecords {
// contributions := []int{2,3,4}
// suMoney := []int{1,2,3,4,5}
// // 查询贡献值时规范描述
// if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, contributions) {
// switch suMoneyTransactionRecord.RecordType {
// case 2: // 任务奖励
// suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
// case 3: // 增加
// suMoneyTransactionRecord.RecordDescription = "增加贡献"
// case 4: // 扣除
// suMoneyTransactionRecord.RecordDescription = "扣除贡献"
// }
// }
// // 查询素币值时规范描述
// if utils.StringSliceEqualBCE(searchSuMoneyTransactionRecordCommand.RecordTypes, suMoney) {
// switch suMoneyTransactionRecord.RecordType {
// case 1: // 兑换物资
// suMoneyTransactionRecord.RecordDescription = "兑换物资"
// case 2: // 任务奖励
// suMoneyTransactionRecord.RecordDescription = suMoneyTransactionRecord.RecordDescription + "奖励"
// case 3: // 增加
// suMoneyTransactionRecord.RecordDescription = "增加素币"
// case 4: // 扣除
// suMoneyTransactionRecord.RecordDescription = "扣除素币"
// case 5: // 兑换现金
// suMoneyTransactionRecord.RecordDescription = "素币兑换现金"
// }
// }
//}
var suMoneyTransactionRecordsFormat []interface{}
//loc, _ := time.LoadLocation("Local")
for _, suMoneyTransactionRecord := range suMoneyTransactionRecords {
//dt, _ := ("2006-01-02 15:04:05", suMoneyTransactionRecord.CreateTime, loc)
suMoneyTransactionRecordFormat := map[string]interface{} {
"suMoneyTransactionRecordId": suMoneyTransactionRecord.SuMoneyTransactionRecordId,
"recordType": suMoneyTransactionRecord.RecordType,
"employee": map[string]interface{} {
"uid": suMoneyTransactionRecord.Employee.Uid,
"employeeName": suMoneyTransactionRecord.Employee.EmployeeName,
"employeeAccount": suMoneyTransactionRecord.Employee.EmployeeAccount,
"employeeAvatarUrl": suMoneyTransactionRecord.Employee.EmployeeAvatarUrl,
"isPrincipal": suMoneyTransactionRecord.Employee.IsPrincipal,
},
"suMoneyBeforeTransaction": suMoneyTransactionRecord.SuMoneyBeforeTransaction,
"currentSuMoney": suMoneyTransactionRecord.CurrentSuMoney,
"suMoney": suMoneyTransactionRecord.SuMoney,
"cashBeforeTransaction": suMoneyTransactionRecord.CashBeforeTransaction,
"currentCash": suMoneyTransactionRecord.CurrentCash,
"cash": suMoneyTransactionRecord.Cash,
"operator": map[string]interface{} {
"uid": suMoneyTransactionRecord.Operator.Uid,
"employeeName": suMoneyTransactionRecord.Operator.EmployeeName,
"employeeAccount": suMoneyTransactionRecord.Operator.EmployeeAccount,
"employeeAvatarUrl": suMoneyTransactionRecord.Operator.EmployeeAvatarUrl,
"isPrincipal": suMoneyTransactionRecord.Operator.IsPrincipal,
},
"recordDescription": suMoneyTransactionRecord.RecordDescription,
"createTime": suMoneyTransactionRecord.CreateTime.Location(),
}
suMoneyTransactionRecordsFormat = append(suMoneyTransactionRecordsFormat, suMoneyTransactionRecordFormat)
}
return map[string]interface{}{
"count": count,
"suMoneyTransactionRecords": suMoneyTransactionRecords,
"suMoneyTransactionRecords": suMoneyTransactionRecordsFormat,
}, nil
}
}
... ...
... ... @@ -2,6 +2,7 @@ package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
... ... @@ -20,6 +21,8 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
var employeeRepository domain.EmployeeRepository
var taskRepository domain.TaskRepository
var suMoneyTransactionRecordRepository domain.SuMoneyTransactionRecordRepository
var cashPoolRepository domain.CashPoolRepository
var employeeDao *dao.EmployeeDao
if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil {
return nil, err
... ... @@ -36,11 +39,17 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
} else {
suMoneyTransactionRecordRepository = repository
}
if repository, err := repository.NewCashPoolRepository(service.transactionContext); err != nil {
return nil, err
} else {
cashPoolRepository = repository
}
if dao, err := dao.NewEmployeeDao(service.transactionContext); err != nil {
return nil, err
} else {
employeeDao = dao
}
operator, err := employeeRepository.FindOne(map[string]interface{}{
"uid": operatorUid,
})
... ... @@ -53,6 +62,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
task, err := taskRepository.FindOne(map[string]interface{}{
"taskId": taskId,
})
if err != nil {
return nil, err
}
... ... @@ -124,6 +134,41 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, taskPercentageItem.SuMoney); err != nil {
return nil, err
}
// 更新现金池未兑换素币
_, cashPoolFound, err := cashPoolRepository.Find(map[string]interface{}{
"companyId": task.CompanyId,
})
if err != nil {
return nil, err
}
if len(cashPoolFound) > 0 {
// 获取平台素币兑换情况
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(task.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemSuMoneyStatistics == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
}
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
cashPool := &domain.CashPool{
CashPoolId: cashPoolFound[0].CashPoolId,
Cash: cashPoolFound[0].Cash,
CompanyId: cashPoolFound[0].CompanyId,
ExchangedCash: cashPoolFound[0].ExchangedCash,
UnExchangeCash: cashPoolFound[0].UnExchangeCash,
ExchangedSuMoney: cashPoolFound[0].ExchangedSuMoney,
UnExchangeSuMoney: systemUnExchangeSuMoney,
Rate: cashPoolFound[0].Rate,
LastRate: cashPoolFound[0].LastRate,
CreateTime: time.Now(),
}
if _, err := cashPoolRepository.Save(cashPool); err != nil {
return nil, err
}
}
}
if task, err := taskRepository.Save(task); err != nil {
return nil, err
... ...
... ... @@ -73,7 +73,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindById(queryOptions map[
//if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 {
// query = query.Where(`su_money_transaction_record.id IN (?)`, pg.In(iDs.([]int)))
//}
if iDs, ok := queryOptions["iDs"]; ok {
if iDs, ok := queryOptions["ids"]; ok {
query = query.Where(`su_money_transaction_record.id IN (?)`, pg.In(iDs.([]int)))
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
... ...
... ... @@ -693,7 +693,7 @@ func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
var data []map[string]interface{}
records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
for _, record := range records {
timString := record.CreateTime.Format("2006/01/02 15:04:05")
timString := record.CreateTime.UTC().Format("2006/01/02 15:04:05")
p := map[string]interface{} {
"name": record.Employee.EmployeeName,
... ...