作者 linmadan

添加素币事务字段

@@ -41,6 +41,11 @@ func (employee *Employee) Update(data map[string]interface{}) error { @@ -41,6 +41,11 @@ func (employee *Employee) Update(data map[string]interface{}) error {
41 return nil 41 return nil
42 } 42 }
43 43
  44 +func (employee *Employee) TransferSuMoney(suMoney float64) error {
  45 + employee.SuMoney = employee.SuMoney + suMoney
  46 + return nil
  47 +}
  48 +
44 func (employee *Employee) TransitionSuMoney(suMoney float64) error { 49 func (employee *Employee) TransitionSuMoney(suMoney float64) error {
45 employee.SuMoney = employee.SuMoney + suMoney 50 employee.SuMoney = employee.SuMoney + suMoney
46 return nil 51 return nil
@@ -15,6 +15,8 @@ type SuMoneyTransactionRecord struct { @@ -15,6 +15,8 @@ type SuMoneyTransactionRecord struct {
15 RecordType int `json:"recordType"` 15 RecordType int `json:"recordType"`
16 // 记录关联员工 16 // 记录关联员工
17 Employee *EmployeeInfo `json:"employee"` 17 Employee *EmployeeInfo `json:"employee"`
  18 + // 事务处理前素币值
  19 + SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"`
18 // 事务素币值 20 // 事务素币值
19 SuMoney float64 `json:"suMoney"` 21 SuMoney float64 `json:"suMoney"`
20 // 操作人 22 // 操作人
@@ -56,14 +56,15 @@ func (service *ExchangeSuMoneyService) Exchange(uid int64, operatorUid int64, su @@ -56,14 +56,15 @@ func (service *ExchangeSuMoneyService) Exchange(uid int64, operatorUid int64, su
56 return nil, fmt.Errorf("当前素币不足") 56 return nil, fmt.Errorf("当前素币不足")
57 } 57 }
58 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{ 58 suMoneyTransactionRecord := &domain.SuMoneyTransactionRecord{
59 - RecordType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE,  
60 - Employee: employee.EmployeeInfo,  
61 - SuMoney: suMoney,  
62 - Operator: operator.EmployeeInfo,  
63 - RecordDescription: recordDescription,  
64 - CreateTime: time.Now(), 59 + RecordType: domain.SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE,
  60 + Employee: employee.EmployeeInfo,
  61 + SuMoneyBeforeTransaction: employee.SuMoney,
  62 + SuMoney: suMoney,
  63 + Operator: operator.EmployeeInfo,
  64 + RecordDescription: recordDescription,
  65 + CreateTime: time.Now(),
65 } 66 }
66 - if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, 0 - suMoney); err != nil { 67 + if err := employeeDao.TransferSuMoney(employee.EmployeeInfo.Uid, 0-suMoney); err != nil {
67 return nil, err 68 return nil, err
68 } 69 }
69 if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil { 70 if suMoneyTransactionRecord, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil {
@@ -13,6 +13,8 @@ type SuMoneyTransactionRecord struct { @@ -13,6 +13,8 @@ type SuMoneyTransactionRecord struct {
13 RecordType int 13 RecordType int
14 // 记录关联员工 14 // 记录关联员工
15 Employee *domain.EmployeeInfo 15 Employee *domain.EmployeeInfo
  16 + // 事务处理前素币值
  17 + SuMoneyBeforeTransaction float64
16 // 事务素币值 18 // 事务素币值
17 SuMoney float64 19 SuMoney float64
18 // 操作人 20 // 操作人
@@ -17,16 +17,16 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec @@ -17,16 +17,16 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec
17 tx := repository.transactionContext.PgTx 17 tx := repository.transactionContext.PgTx
18 if suMoneyTransactionRecord.Identify() == nil { 18 if suMoneyTransactionRecord.Identify() == nil {
19 if _, err := tx.QueryOne( 19 if _, err := tx.QueryOne(
20 - pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),  
21 - "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",  
22 - suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil { 20 + pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoneyBeforeTransaction, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
  21 + "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",
  22 + suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoneyBeforeTransaction, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime); err != nil {
23 return suMoneyTransactionRecord, err 23 return suMoneyTransactionRecord, err
24 } 24 }
25 } else { 25 } else {
26 if _, err := tx.QueryOne( 26 if _, err := tx.QueryOne(
27 - pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),  
28 - "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",  
29 - suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil { 27 + pg.Scan(&suMoneyTransactionRecord.SuMoneyTransactionRecordId, &suMoneyTransactionRecord.RecordType, &suMoneyTransactionRecord.Employee, &suMoneyTransactionRecord.SuMoneyBeforeTransaction, &suMoneyTransactionRecord.SuMoney, &suMoneyTransactionRecord.Operator, &suMoneyTransactionRecord.RecordDescription, &suMoneyTransactionRecord.CreateTime),
  28 + "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",
  29 + suMoneyTransactionRecord.RecordType, suMoneyTransactionRecord.Employee, suMoneyTransactionRecord.SuMoneyBeforeTransaction, suMoneyTransactionRecord.SuMoney, suMoneyTransactionRecord.Operator, suMoneyTransactionRecord.RecordDescription, suMoneyTransactionRecord.CreateTime, suMoneyTransactionRecord.SuMoneyTransactionRecordId); err != nil {
30 return suMoneyTransactionRecord, err 30 return suMoneyTransactionRecord, err
31 } 31 }
32 } 32 }
@@ -110,6 +110,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo @@ -110,6 +110,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo
110 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id, 110 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id,
111 RecordType: suMoneyTransactionRecordModel.RecordType, 111 RecordType: suMoneyTransactionRecordModel.RecordType,
112 Employee: suMoneyTransactionRecordModel.Employee, 112 Employee: suMoneyTransactionRecordModel.Employee,
  113 + SuMoneyBeforeTransaction: suMoneyTransactionRecordModel.SuMoneyBeforeTransaction,
113 SuMoney: suMoneyTransactionRecordModel.SuMoney, 114 SuMoney: suMoneyTransactionRecordModel.SuMoney,
114 Operator: suMoneyTransactionRecordModel.Operator, 115 Operator: suMoneyTransactionRecordModel.Operator,
115 RecordDescription: suMoneyTransactionRecordModel.RecordDescription, 116 RecordDescription: suMoneyTransactionRecordModel.RecordDescription,