作者 linmadan

添加素币事务字段

... ... @@ -41,6 +41,11 @@ func (employee *Employee) Update(data map[string]interface{}) error {
return nil
}
func (employee *Employee) TransferSuMoney(suMoney float64) error {
employee.SuMoney = employee.SuMoney + suMoney
return nil
}
func (employee *Employee) TransitionSuMoney(suMoney float64) error {
employee.SuMoney = employee.SuMoney + suMoney
return nil
... ...
... ... @@ -15,6 +15,8 @@ type SuMoneyTransactionRecord struct {
RecordType int `json:"recordType"`
// 记录关联员工
Employee *EmployeeInfo `json:"employee"`
// 事务处理前素币值
SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"`
// 事务素币值
SuMoney float64 `json:"suMoney"`
// 操作人
... ...
... ... @@ -58,12 +58,13 @@ func (service *ExchangeSuMoneyService) Exchange(uid int64, operatorUid int64, su
suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
RecordType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE,
Employee: employee.EmployeeInfo,
SuMoneyBeforeTransaction: employee.SuMoney,
SuMoney: suMoney,
Operator: operator.EmployeeInfo,
RecordDescription: recordDescription,
CreateTime: time.Now(),
}
if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, 0 - suMoney); err != nil {
if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, 0-suMoney); err != nil {
return nil, err
}
if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil {
... ...
... ... @@ -13,6 +13,8 @@ type SuMoneyTransactionRecord struct {
RecordType int
// 记录关联员工
Employee *domain.EmployeeInfo
// 事务处理前素币值
SuMoneyBeforeTransaction float64
// 事务素币值
SuMoney float64
// 操作人
... ...
... ... @@ -17,16 +17,16 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec
tx := repository.transactionContext.PgTx
if suMoneyTransactionRecord.Identify() == nil {
if _, err := tx.QueryOne(
pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
"INSERT INTO su_money_transaction_records (record_type, employee, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?) RETURNING id, record_type, employee, su_money, operator, record_description, create_time",
suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil {
pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoneyBeforeTransaction, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
"INSERT INTO su_money_transaction_records (record_type, employee, su_money_before_transaction, su_money, operator, record_description, create_time) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id, record_type, employee, su_money_before_transaction, su_money, operator, record_description, create_time",
suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoneyBeforeTransaction, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil {
return suMoneyTransactionRecord, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
"UPDATE su_money_transaction_records SET record_type=?, employee=?, su_money=?, operator=?, record_description=?, create_time=? WHERE id=? RETURNING id, record_type, employee, su_money, operator, record_description, create_time",
suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil {
pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoneyBeforeTransaction, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
"UPDATE su_money_transaction_records SET record_type=?, employee=?, su_money_before_transaction=?, su_money=?, operator=?, record_description=?, create_time=? WHERE id=? RETURNING id, record_type, employee, su_money, operator, record_description, create_time",
suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoneyBeforeTransaction, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil {
return suMoneyTransactionRecord, err
}
}
... ... @@ -110,6 +110,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo
SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id,
RecordType: suMoneyTransactionRecordModel.RecordType,
Employee: suMoneyTransactionRecordModel.Employee,
SuMoneyBeforeTransaction: suMoneyTransactionRecordModel.SuMoneyBeforeTransaction,
SuMoney: suMoneyTransactionRecordModel.SuMoney,
Operator: suMoneyTransactionRecordModel.Operator,
RecordDescription: suMoneyTransactionRecordModel.RecordDescription,
... ...