作者 陈志颖

feat:完善现金池、兑换现金活动对象

正在显示 38 个修改的文件 包含 337 行增加203 行删除
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type SystemCashStatisticsCommand struct {
  10 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  11 +}
  12 +
  13 +func (systemCashStatisticsCommand *SystemCashStatisticsCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(systemCashStatisticsCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type SystemSuMoneyStatisticsCommand struct {
  9 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
  10 +}
  11 +
  12 +func (systemSuMoneyStatisticsCommand *SystemSuMoneyStatisticsCommand) ValidateCommand() error {
  13 + valid := validation.Validation{}
  14 + b, err := valid.Valid(systemSuMoneyStatisticsCommand)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + if !b {
  19 + for _, validErr := range valid.Errors {
  20 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  21 + }
  22 + }
  23 + return nil
  24 +}
  25 +
@@ -160,6 +160,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -160,6 +160,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
160 defer func() { 160 defer func() {
161 transactionContext.RollbackTransaction() 161 transactionContext.RollbackTransaction()
162 }() 162 }()
  163 +
163 var employeeDao *dao.EmployeeDao 164 var employeeDao *dao.EmployeeDao
164 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 165 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
165 "transactionContext": transactionContext, 166 "transactionContext": transactionContext,
@@ -168,6 +169,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -168,6 +169,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
168 } else { 169 } else {
169 employeeDao = value 170 employeeDao = value
170 } 171 }
  172 +
171 var employeeRepository domain.EmployeeRepository 173 var employeeRepository domain.EmployeeRepository
172 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 174 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
173 "transactionContext": transactionContext, 175 "transactionContext": transactionContext,
@@ -185,6 +187,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -185,6 +187,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
185 if employee == nil { 187 if employee == nil {
186 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工") 188 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业员工")
187 } 189 }
  190 +
188 if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil { 191 if personSuMoneyStatistics, err := employeeDao.CalculatePersonSuMoney(personSuMoneyStatisticsCommand.Uid); err != nil {
189 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 192 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
190 } else { 193 } else {
@@ -196,6 +199,52 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -196,6 +199,52 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
196 } 199 }
197 } 200 }
198 201
  202 +/**
  203 + * 获取系统素币统计
  204 + */
  205 +func (statisticsService *StatisticsService) SystemSuMoneyStatistics(systemSuMoneyStatisticsCommand *command.SystemSuMoneyStatisticsCommand) (interface{}, error) {
  206 + if err := systemSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
  207 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  208 + }
  209 + transactionContext, err := factory.CreateTransactionContext(nil)
  210 + if err != nil {
  211 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  212 + }
  213 + if err := transactionContext.StartTransaction(); err != nil {
  214 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  215 + }
  216 + defer func() {
  217 + transactionContext.RollbackTransaction()
  218 + }()
  219 +
  220 + var employeeDao *dao.EmployeeDao
  221 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  222 + "transactionContext": transactionContext,
  223 + }); err != nil {
  224 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  225 + } else {
  226 + employeeDao = value
  227 + }
  228 +
  229 +
  230 + if systemSuMoneyStatistics, err := employeeDao.CalculateSystemExchangedCash(systemSuMoneyStatisticsCommand.CompanyId); err != nil {
  231 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  232 + } else {
  233 + if err := transactionContext.CommitTransaction(); err != nil {
  234 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  235 + }
  236 + //systemSuMoneyStatistics["currentSuMoney"] = employee.SuMoney
  237 + return systemSuMoneyStatistics, nil
  238 + }
  239 +}
  240 +
  241 +/**
  242 + * 获取系统现金统计
  243 + */
  244 +//func (statisticsService *StatisticsService) SystemCashStatistics(systemCashStatisticsCommand *command.SystemCashStatisticsCommand) (interface{}, error) {
  245 +//
  246 +//}
  247 +
199 func NewStatisticsService(options map[string]interface{}) *StatisticsService { 248 func NewStatisticsService(options map[string]interface{}) *StatisticsService {
200 newStatisticsService := &StatisticsService{} 249 newStatisticsService := &StatisticsService{}
201 return newStatisticsService 250 return newStatisticsService
@@ -6,15 +6,16 @@ import ( @@ -6,15 +6,16 @@ import (
6 "github.com/astaxie/beego/validation" 6 "github.com/astaxie/beego/validation"
7 ) 7 )
8 8
9 -type InputCashPooCommand struct {  
10 - Cash float64 `json:"cash" valid:"Required"` // 投入的现金值  
11 - Operator int64 `json:"operator,omitempty"` // 操作人UID  
12 - InputDescription string `json:"inputDescription" valid:"Required"` // 投入描述 9 +type CreateCashPoolCommand struct {
  10 + CashPoolId int64 `json:"cashPoolId" valid:"Required"` // 现金池ID
  11 + CompanyId int64 `json:"companyId" valid:"Requires"` // 公司ID
  12 + Cash float64 `json:"cash" valid:"Required"` // 投入的现金值
  13 + Operator int64 `json:"operator,omitempty"` // 操作人UID
13 } 14 }
14 15
15 -func (inputCashPooCommand *InputCashPooCommand) ValidateCommand() error { 16 +func (createCashPoolCommand *CreateCashPoolCommand) ValidateCommand() error {
16 valid := validation.Validation{} 17 valid := validation.Validation{}
17 - rt, err := valid.Valid(inputCashPooCommand) 18 + rt, err := valid.Valid(createCashPoolCommand)
18 if err != nil { 19 if err != nil {
19 return err 20 return err
20 } 21 }
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  7 + "time"
  8 +)
  9 +
  10 +type CreateExchangeActivityCommand struct {
  11 + CompanyId int64 `json:"companyId" valid:"Required"` // 公司id
  12 + ExchangeActivityName string `json:"exchangeActivityName"` // 活动名称
  13 + Deadline time.Time `json:"deadline"` // 活动截止时间
  14 + CountDown int64 `json:"countDown"` // 活动倒计时
  15 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换素币
  16 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金
  17 + ExchangeRate float64 `json:"exchangeRate"` // 兑换汇率
  18 + ExchangeCashPeople []*domain.ExchangeCashPerson `json:"exchangeList"` // 兑换活动清单
  19 +}
  20 +
  21 +func (createExchangeActivityCommand *CreateExchangeActivityCommand) ValidateCommand() error {
  22 + valid := validation.Validation{}
  23 + b, err := valid.Valid(createExchangeActivityCommand)
  24 + if err != nil {
  25 + return err
  26 + }
  27 + if !b {
  28 + for _, validErr := range valid.Errors {
  29 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  30 + }
  31 + }
  32 + return nil
  33 +}
@@ -7,16 +7,11 @@ import ( @@ -7,16 +7,11 @@ import (
7 ) 7 )
8 8
9 type OperationSuMoneyCommand struct { 9 type OperationSuMoneyCommand struct {
10 - // 素币拥有者UID  
11 - Uid int64 `json:"uid" valid:"Required"`  
12 - // 操作类型(1增加,2扣除)  
13 - OperationType int `json:"operationType" valid:"Required"`  
14 - // 素币值  
15 - SuMoney float64 `json:"suMoney" valid:"Required"`  
16 - // 操作人UID  
17 - Operator int64 `json:"operator,omitempty"`  
18 - // 理由描述  
19 - OperationDescription string `json:"operationDescription" valid:"Required"` 10 + Uid int64 `json:"uid" valid:"Required"` // 素币拥有者UID
  11 + OperationType int `json:"operationType" valid:"Required"` // 操作类型(1增加,2扣除)
  12 + SuMoney float64 `json:"suMoney" valid:"Required"` // 素币值
  13 + Operator int64 `json:"operator,omitempty"` // 操作人UID
  14 + OperationDescription string `json:"operationDescription" valid:"Required"` // 理由描述
20 } 15 }
21 16
22 func (operationSuMoneyCommand *OperationSuMoneyCommand) ValidateCommand() error { 17 func (operationSuMoneyCommand *OperationSuMoneyCommand) ValidateCommand() error {
@@ -114,6 +114,9 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co @@ -114,6 +114,9 @@ func (suMoneyService *SuMoneyService) ExchangeSuMoney(exchangeSuMoneyCommand *co
114 } 114 }
115 } 115 }
116 116
  117 +// 素币兑换现金
  118 +//func (suMoneyService *SuMoneyService) ExchangeCash(exchangeCashComman *)
  119 +
117 // 搜索素币事务记录 120 // 搜索素币事务记录
118 func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand *command.SearchSuMoneyTransactionRecordCommand) (interface{}, error) { 121 func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMoneyTransactionRecordCommand *command.SearchSuMoneyTransactionRecordCommand) (interface{}, error) {
119 if err := searchSuMoneyTransactionRecordCommand.ValidateCommand(); err != nil { 122 if err := searchSuMoneyTransactionRecordCommand.ValidateCommand(); err != nil {
1 package domain 1 package domain
2 2
3 -// 现金池信息 3 +// 现金池
4 type CashPool struct { 4 type CashPool struct {
5 - Cash float64 `json:"cash"` // 投入现金池的现金  
6 - ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金  
7 - UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金  
8 - ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币  
9 - UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币  
10 - Rate float64 `json:"rate"` // 平均兑换汇率  
11 -}  
  5 + CashPoolId int64 `json:"cashPoolId"` // 现金池id
  6 + CompanyId int64 `json:"companyId"` // 公司id
  7 + Cash float64 `json:"cashPool"` // 投入现金池的现金
  8 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  9 + UnExchangeCash float64 `json:"unExchangeCash"` // 未兑换的现金
  10 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  11 + UnExchangeSuMoney float64 `json:"unExchangeSuMoney"` // 未兑换的素币
  12 + Rate float64 `json:"rate"` // 平均兑换汇率
  13 +}
  14 +
  15 +type CashPoolRepository interface {
  16 + Save(cashPool *CashPool) (*CashPool, error)
  17 +}
  18 +
  19 +func (cashPool *CashPool) Identity() interface{} {
  20 + if cashPool.CompanyId == 0 {
  21 + return nil
  22 + }
  23 + return cashPool.CompanyId
  24 +}
  25 +
1 -package domain  
2 -  
3 -import "time"  
4 -  
5 -// 现金池事务记录  
6 -type CashPoolTransactionRecord struct {  
7 - CashPoolTransactionRecordId int64 `json:"cashPoolTransactionRecordId"` // 现金池事务记录ID  
8 - RecordType int `json:"recordType"` // 记录类型  
9 - CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池  
10 - CurrentCashPool *CashPool `json:"CurrentCashPool"` // 当前现金池  
11 - Cash float64 `json:"CashPool"` // 事务现金值  
12 - Operator *EmployeeInfo `json:"operator"` // 操作人  
13 - RecordDescription string `json:"recordDescription"` // 现金池事务记录描述  
14 - CreateTime time.Time `json:"createTime"` // 创建时间  
15 -}  
16 -  
17 -type CashPoolTransactionRecordRepository interface {  
18 - Save(cashPoolTransactionRecord *CashPoolTransactionRecord) (*CashPoolTransactionRecord, error)  
19 -}  
20 -  
21 -func (cashPoolTransactionRecord *CashPoolTransactionRecord) Identity() interface{} {  
22 - if cashPoolTransactionRecord.CashPoolTransactionRecordId == 0 {  
23 - return nil  
24 - }  
25 - return cashPoolTransactionRecord.CashPoolTransactionRecordId  
26 -}  
27 -  
28 -// 计算当前现金池中的未兑换现金  
29 -func (cashPoolTransactionRecord *CashPoolTransactionRecord) TransferUnExchangeCash(cash float64) error {  
30 - cashPoolTransactionRecord.CurrentCashPool.UnExchangeCash += cash  
31 - return nil  
32 -}  
1 -package domain  
2 -  
3 -import "time"  
4 -  
5 -// 兑换活动  
6 -type ExchangeActivity struct {  
7 - ExchangeActivityId int64 `json:"exchangeActivityId"` // 兑换素币活动编号  
8 - ExchangeActivityName string `json:"exchangeActivityName"` // 兑换素币活动名称  
9 - CompanyId int64 `json:"companyId"` // 公司ID  
10 - ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金  
11 - ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币  
12 - CreateTime time.Time `json:"createTime"` // 创建兑换素币活动时间  
13 - Deadline time.Time `json:"deadline"` // 兑换素币活动截止时间  
14 - CountDown string `json:"countDown"` // 兑换素币活动结束倒计时  
15 - Rate float64 `json:"rate"` // 兑换汇率  
16 - LastRate float64 `json:"lastRate"` // 上期兑换汇率  
17 - ExchangeSuMoneyList []*ExchangePerson `json:"exchangeSuMoneyList"` // 素币兑换清单  
18 -}  
19 -  
20 -type ExchangeActivityRepository interface {  
21 - Save(activity *ExchangeActivity) (*ExchangeActivity, error)  
22 - Remove(activity *ExchangeActivity) (*ExchangeActivity, error)  
23 - FindOne(queryOptions map[string]interface{}) (*ExchangeActivity, error)  
24 - Find(queryOptions map[string]interface{}) (int64, []*ExchangeActivity, error)  
25 -}  
26 -  
27 -func (activity *ExchangeActivity) Identity() interface{} {  
28 - if activity.ExchangeActivityId == 0 {  
29 - return nil  
30 - }  
31 - return activity.ExchangeActivityId  
32 -}  
33 -  
34 -func (activity *ExchangeActivity) TransferSuMoney(rate float64) error {  
35 - activity.ExchangedSuMoney = activity.ExchangedCash * rate  
36 - return nil  
37 -}  
38 -  
39 -func (activity *ExchangeActivity) TransferLastRate(lastRate float64) error {  
40 - activity.LastRate = lastRate  
41 - return nil  
42 -}  
43 -  
44 -func (activity *ExchangeActivity) TransferCountDown() error {  
45 - activity.CountDown = string(time.Until(activity.Deadline))  
46 - return nil  
47 -}  
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 兑换现金活动
  6 +type ExchangeCashActivity struct {
  7 + ExchangeCashActivityId int64 `json:"exchangeActivityId"` // 兑换现金活动id
  8 + ExchangeActivityName string `json:"exchangeActivityName"` // 兑换现金活动名称
  9 + CompanyId int64 `json:"companyId"` // 公司ID
  10 + ExchangedCash float64 `json:"exchangedCash"` // 已兑换的现金
  11 + ExchangedSuMoney float64 `json:"exchangedSuMoney"` // 已兑换的素币
  12 + CreateTime time.Time `json:"createTime"` // 创建兑换现金活动时间
  13 + Deadline time.Time `json:"deadline"` // 兑换现金活动截止时间
  14 + CountDown string `json:"countDown"` // 兑换现金活动结束倒计时
  15 + Rate float64 `json:"rate"` // 兑换汇率
  16 + LastRate float64 `json:"lastRate"` // 上期兑换汇率
  17 + ExchangeCashPeople []*ExchangeCashPerson `json:"exchangeCashPeople"` // 兑换现金人员清单
  18 +}
  19 +
  20 +type ExchangeActivityRepository interface {
  21 + Save(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
  22 + Remove(exchangeCashActivity *ExchangeCashActivity) (*ExchangeCashActivity, error)
  23 + FindOne(queryOptions map[string]interface{}) (*ExchangeCashActivity, error)
  24 + Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashActivity, error)
  25 +}
  26 +
  27 +func (exchangeCashActivity *ExchangeCashActivity) Identity() interface{} {
  28 + if exchangeCashActivity.ExchangeCashActivityId == 0 {
  29 + return nil
  30 + }
  31 + return exchangeCashActivity.ExchangeCashActivityId
  32 +}
  33 +
  34 +func (exchangeCashActivity *ExchangeCashActivity) TransferSuMoney(rate float64) error {
  35 + exchangeCashActivity.ExchangedSuMoney = exchangeCashActivity.ExchangedCash * rate
  36 + return nil
  37 +}
  38 +
  39 +func (exchangeCashActivity *ExchangeCashActivity) TransferLastRate(lastRate float64) error {
  40 + exchangeCashActivity.LastRate = lastRate
  41 + return nil
  42 +}
  43 +
  44 +func (exchangeCashActivity *ExchangeCashActivity) TransferCountDown() error {
  45 + exchangeCashActivity.CountDown = string(time.Until(exchangeCashActivity.Deadline))
  46 + return nil
  47 +}
  1 +package domain
  2 +
  3 +// 参与兑换现金人员
  4 +type ExchangeCashPerson struct {
  5 + PersonId int64 `json:"employeeId"` // 兑换人员ID
  6 + CompanyId int64 `json:"companyId"` // 公司id
  7 + PersonInfo *EmployeeInfo `json:"employeeInfo"` // 兑换人员信息
  8 + ExchangedSuMoney float64 `json:"suMoney"` // 已兑换的素币
  9 + ExchangedCash float64 `json:"cash"` // 已兑换的现金
  10 +}
  11 +
  12 +type ExchangeCashPersonRepository interface {
  13 + Save(exchangeCashPerson *ExchangeCashPerson) (*ExchangeCashPerson, error)
  14 + Remove(exchangeCashPerson *ExchangeCashPerson) (*ExchangeCashPerson, error)
  15 + FindOne(queryOptions map[string]interface{}) (*ExchangeCashPerson, error)
  16 + Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPerson, error)
  17 +}
  18 +
  19 +func (exchangeCashPerson *ExchangeCashPerson) Identity() interface{} {
  20 + if exchangeCashPerson.PersonId == 0 {
  21 + return nil
  22 + }
  23 + return exchangeCashPerson.PersonId
  24 +}
1 -package domain  
2 -  
3 -// 兑换人  
4 -type ExchangePerson struct {  
5 - Uid int64 `json:"uid"` // 统一用户ID  
6 - Name string `json:"name"` // 已兑换人员名称  
7 - Account string `json:"account"` // 已兑换人员账号  
8 - ExchangedSuMoney float64 `json:"exchangeSuMoney"` // 已兑换素币  
9 - ExchangedCash float64 `json:"exchangedCash"` // 已兑换现金  
10 -}  
11 -  
12 -type ExchangePersonRepository interface {  
13 - Save(exchangePerson *ExchangePerson) (*ExchangePerson, error)  
14 - Remove(exchangePerson *ExchangePerson) (*ExchangePerson, error)  
15 - FindOne(queryOptions map[string]interface{}) (*ExchangePerson, error)  
16 - Find(queryOptions map[string]interface{}) (int64, []*ExchangePerson, error)  
17 -}  
18 -  
19 -func (exchangePerson *ExchangePerson) TransferSuMoney(rate float64) error {  
20 - exchangePerson.ExchangedCash = exchangePerson.ExchangedSuMoney / rate  
21 - return nil  
22 -}  
@@ -3,7 +3,7 @@ package domain @@ -3,7 +3,7 @@ package domain
3 import "time" 3 import "time"
4 4
5 const ( 5 const (
6 - SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换 6 + SU_MONEY_TRANSACTION_RECORD_TYPE_EXCHANGE = iota + 1 //兑换(物资、现金)
7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励 7 SU_MONEY_TRANSACTION_RECORD_TYPE_AWARD //任务奖励
8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加 8 SU_MONEY_TRANSACTION_RECORD_TYPE_INCREASE //增加
9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除 9 SU_MONEY_TRANSACTION_RECORD_TYPE_DEDUCT //扣除
@@ -11,24 +11,18 @@ const ( @@ -11,24 +11,18 @@ const (
11 11
12 // 素币事务记录 12 // 素币事务记录
13 type SuMoneyTransactionRecord struct { 13 type SuMoneyTransactionRecord struct {
14 - // 素币事务记录ID  
15 - SuMoneyTransactionRecordId int64 `json:"suMoneyTransactionRecordId"`  
16 - // 记录类型  
17 - RecordType int `json:"recordType"`  
18 - // 记录关联员工  
19 - Employee *EmployeeInfo `json:"employee"`  
20 - // 事务处理前素币值  
21 - SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"`  
22 - // 当前素币值  
23 - CurrentSuMoney float64 `json:"currentSuMoney"`  
24 - // 事务素币值  
25 - SuMoney float64 `json:"suMoney"`  
26 - // 操作人  
27 - Operator *EmployeeInfo `json:"operator"`  
28 - // 素币事务记录描述  
29 - RecordDescription string `json:"recordDescription"`  
30 - // 创建时间  
31 - CreateTime time.Time `json:"createTime"` 14 + SuMoneyTransactionRecordId int64 `json:"suMoneyTransactionRecordId"` // 素币事务记录ID
  15 + RecordType int `json:"recordType"` // 记录类型
  16 + Employee *EmployeeInfo `json:"employee"` // 记录关联员工
  17 + SuMoneyBeforeTransaction float64 `json:"suMoneyBeforeTransaction"` // 事务处理前素币值
  18 + CurrentSuMoney float64 `json:"currentSuMoney"` // 当前素币值
  19 + CashPoolBeforeTransaction *CashPool `json:"cashPoolBeforeTransaction"` // 事务处理前现金池,用于兑换现金操作
  20 + CurrentCashPool *CashPool `json:"currentCashPool"` // 当前现金池,用于兑换现金操作
  21 + SuMoney float64 `json:"suMoney"` // 事务素币值
  22 + Cash float64 `json:"cash"` // 事务现金值,用于兑换现金
  23 + Operator *EmployeeInfo `json:"operator"` // 操作人
  24 + RecordDescription string `json:"recordDescription"` // 素币事务记录描述
  25 + CreateTime time.Time `json:"createTime"` // 创建时间
32 } 26 }
33 27
34 type SuMoneyTransactionRecordRepository interface { 28 type SuMoneyTransactionRecordRepository interface {
@@ -143,6 +143,42 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -143,6 +143,42 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
143 }, nil 143 }, nil
144 } 144 }
145 145
  146 +func (dao *EmployeeDao) CalculateSystemUnChangeSuMoney(companyId int64) (map[string]interface{}, error) {
  147 + var unExchangeSuMoney float64
  148 +
  149 + tx := dao.transactionContext.PgTx
  150 + employeeModel := new(models.Employee)
  151 +
  152 + if err := tx.Model(employeeModel).
  153 + ColumnExpr("sum(employee.su_money) AS unExchangeSuMoney").
  154 + Where("employee.company_id = ?", companyId).
  155 + Select(&employeeModel); err != nil {
  156 + return nil, err
  157 + }
  158 +
  159 + return map[string]interface{}{
  160 + "unExchangeSuMoney": unExchangeSuMoney,
  161 + }, nil
  162 +}
  163 +
  164 +func (dao *EmployeeDao) CalculateSystemExchangedCash(companyId int64) (map[string]interface{}, error) {
  165 + var exchangedCash float64
  166 +
  167 + tx := dao.transactionContext.PgTx
  168 + suMoneyExchangeTransactionRecordModel := new(models.SuMoneyExchangeTransactionRecord)
  169 +
  170 + if err := tx.Model(suMoneyExchangeTransactionRecordModel).
  171 + ColumnExpr("sum(su_money_exchange_transaction_record.cash) AS exchangedCash").
  172 + Where("su_money_exchange_transaction_record.company_id = ?", companyId).
  173 + Select(&suMoneyExchangeTransactionRecordModel) ; err != nil {
  174 + return nil, err
  175 + }
  176 +
  177 + return map[string]interface{}{
  178 + "exchangedCash": exchangedCash,
  179 + }, nil
  180 +}
  181 +
146 func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) { 182 func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
147 if transactionContext == nil { 183 if transactionContext == nil {
148 return nil, fmt.Errorf("transactionContext参数不能为nil") 184 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -37,8 +37,6 @@ func init() { @@ -37,8 +37,6 @@ func init() {
37 (*models.Notification)(nil), 37 (*models.Notification)(nil),
38 (*models.SentNotification)(nil), 38 (*models.SentNotification)(nil),
39 (*models.ExchangeActivities)(nil), 39 (*models.ExchangeActivities)(nil),
40 - (*models.CashPoolTransactionRecord)(nil),  
41 - (*models.ExchangePerson)(nil),  
42 } { 40 } {
43 err := DB.CreateTable(model, &orm.CreateTableOptions{ 41 err := DB.CreateTable(model, &orm.CreateTableOptions{
44 Temp: false, 42 Temp: false,
@@ -16,7 +16,7 @@ type ExchangeActivities struct { @@ -16,7 +16,7 @@ type ExchangeActivities struct {
16 ExchangedCash float64 // 已兑换现金 16 ExchangedCash float64 // 已兑换现金
17 ExchangedSuMoney float64 // 已兑换素币 17 ExchangedSuMoney float64 // 已兑换素币
18 ExchangeRate float64 // 兑换汇率 18 ExchangeRate float64 // 兑换汇率
19 - ExchangeSuMoneyList []*domain.ExchangePerson // 素币兑换人员清单 19 + ExchangeSuMoneyList []*domain.ExchangeCashPerson // 素币兑换人员清单
20 Sponsor *domain.EmployeeInfo // 活动发布人 20 Sponsor *domain.EmployeeInfo // 活动发布人
21 CreateTime time.Time // 创建时间 21 CreateTime time.Time // 创建时间
22 } 22 }
@@ -5,12 +5,14 @@ import ( @@ -5,12 +5,14 @@ import (
5 "time" 5 "time"
6 ) 6 )
7 7
8 -type CashPoolTransactionRecord struct {  
9 - TableName string `pg:"cash_pool_transaction_records,alias:cash_pool_transaction_record"`  
10 - Id int64 `pg:",pk"` // 现金池事务记录ID 8 +type SuMoneyExchangeTransactionRecord struct {
  9 + TableName string `pg:"su_money_exchange_transaction_records,alias:su_money_exchange_transaction_record"`
  10 + Id int64 `pg:",pk"` // 现金兑换务记录ID
11 RecordType int // 记录类型 11 RecordType int // 记录类型
12 - CashPoolBeforeTransaction *domain.CashPoolInfo // 事务处理前现金池  
13 - CurrentCashPool *domain.CashPoolInfo // 当前现金池 12 + Employee *domain.EmployeeInfo // 记录关联员工
  13 + CashPoolBeforeTransaction *domain.CashPool // 事务处理前现金池
  14 + CurrentCashPool *domain.CashPool // 当前现金池
  15 + SuMoney float64 // 事务素币值
14 Cash float64 // 事务现金值 16 Cash float64 // 事务现金值
15 Operator *domain.EmployeeInfo // 操作人 17 Operator *domain.EmployeeInfo // 操作人
16 RecordDescription string // 现金投入事务记录描述 18 RecordDescription string // 现金投入事务记录描述
1 -package repository  
2 -  
3 -import (  
4 - "github.com/go-pg/pg"  
5 - pgTransaction "github.com/linmadan/egglib-go/transaction/pg"  
6 - "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"  
7 -)  
8 -  
9 -type CashPoolTransactionRecordRepository struct {  
10 - transactionContext *pgTransaction.TransactionContext  
11 -}  
12 -  
13 -func (repository *CashPoolTransactionRecordRepository) Save(cashPoolTransactionRecord *domain.CashPoolTransactionRecord) (*domain.CashPoolTransactionRecord, error) {  
14 - tx := repository.transactionContext.PgTx  
15 - if cashPoolTransactionRecord.Identity() == nil {  
16 - if _, err := tx.QueryOne(  
17 - pg.Scan(&cashPoolTransactionRecord.CashPoolTransactionRecordId, &cashPoolTransactionRecord.RecordType, &cashPoolTransactionRecord.Cash, &cashPoolTransactionRecord.CashPoolBeforeTransaction, &cashPoolTransactionRecord.CurrentCashPool, &cashPoolTransactionRecord.Operator, &cashPoolTransactionRecord.CreateTime, &cashPoolTransactionRecord.RecordDescription),  
18 - "INSERT INTO cash_pool_transaction_records ()"); err != nil {  
19 - return cashPoolTransactionRecord, err  
20 - }  
21 - } else {  
22 - if _, err := tx.QueryOne(  
23 - pg.Scan(&cashPoolTransactionRecord.CashPoolTransactionRecordId, &cashPoolTransactionRecord.RecordType, &cashPoolTransactionRecord.Cash, &cashPoolTransactionRecord.CashPoolBeforeTransaction, &cashPoolTransactionRecord.CurrentCashPool, &cashPoolTransactionRecord.Operator, &cashPoolTransactionRecord.CreateTime, &cashPoolTransactionRecord.RecordDescription),  
24 - "UPDATE cash_pool_transaction_records SET "); err != nil {  
25 - return cashPoolTransactionRecord, err  
26 - }  
27 - }  
28 - return cashPoolTransactionRecord, nil  
29 -}  
@@ -33,6 +33,7 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec @@ -33,6 +33,7 @@ func (repository *SuMoneyTransactionRecordRepository) Save(suMoneyTransactionRec
33 } 33 }
34 return suMoneyTransactionRecord, nil 34 return suMoneyTransactionRecord, nil
35 } 35 }
  36 +
36 func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { 37 func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionRecord *domain.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) {
37 tx := repository.transactionContext.PgTx 38 tx := repository.transactionContext.PgTx
38 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 39 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
@@ -42,6 +43,7 @@ func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionR @@ -42,6 +43,7 @@ func (repository *SuMoneyTransactionRecordRepository) Remove(suMoneyTransactionR
42 } 43 }
43 return suMoneyTransactionRecord, nil 44 return suMoneyTransactionRecord, nil
44 } 45 }
  46 +
45 func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.SuMoneyTransactionRecord, error) { 47 func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[string]interface{}) (*domain.SuMoneyTransactionRecord, error) {
46 tx := repository.transactionContext.PgTx 48 tx := repository.transactionContext.PgTx
47 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 49 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
@@ -62,6 +64,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s @@ -62,6 +64,7 @@ func (repository *SuMoneyTransactionRecordRepository) FindOne(queryOptions map[s
62 return repository.transformPgModelToDomainModel(suMoneyTransactionRecordModel) 64 return repository.transformPgModelToDomainModel(suMoneyTransactionRecordModel)
63 } 65 }
64 } 66 }
  67 +
65 func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SuMoneyTransactionRecord, error) { 68 func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SuMoneyTransactionRecord, error) {
66 tx := repository.transactionContext.PgTx 69 tx := repository.transactionContext.PgTx
67 var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord 70 var suMoneyTransactionRecordModels []*models.SuMoneyTransactionRecord
@@ -114,6 +117,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri @@ -114,6 +117,7 @@ func (repository *SuMoneyTransactionRecordRepository) Find(queryOptions map[stri
114 return int64(count), suMoneyTransactionRecords, nil 117 return int64(count), suMoneyTransactionRecords, nil
115 } 118 }
116 } 119 }
  120 +
117 func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainModel(suMoneyTransactionRecordModel *models.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) { 121 func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainModel(suMoneyTransactionRecordModel *models.SuMoneyTransactionRecord) (*domain.SuMoneyTransactionRecord, error) {
118 return &domain.SuMoneyTransactionRecord{ 122 return &domain.SuMoneyTransactionRecord{
119 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id, 123 SuMoneyTransactionRecordId: suMoneyTransactionRecordModel.Id,
@@ -127,6 +131,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo @@ -127,6 +131,7 @@ func (repository *SuMoneyTransactionRecordRepository) transformPgModelToDomainMo
127 CreateTime: suMoneyTransactionRecordModel.CreateTime, 131 CreateTime: suMoneyTransactionRecordModel.CreateTime,
128 }, nil 132 }, nil
129 } 133 }
  134 +
130 func NewSuMoneyTransactionRecordRepository(transactionContext *pgTransaction.TransactionContext) (*SuMoneyTransactionRecordRepository, error) { 135 func NewSuMoneyTransactionRecordRepository(transactionContext *pgTransaction.TransactionContext) (*SuMoneyTransactionRecordRepository, error) {
131 if transactionContext == nil { 136 if transactionContext == nil {
132 return nil, fmt.Errorf("transactionContext参数不能为nil") 137 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -72,3 +72,17 @@ func (controller *StatisticsController) PersonNotificationStatistics() { @@ -72,3 +72,17 @@ func (controller *StatisticsController) PersonNotificationStatistics() {
72 controller.Data["json"] = response 72 controller.Data["json"] = response
73 controller.ServeJSON() 73 controller.ServeJSON()
74 } 74 }
  75 +
  76 +// TODO 系统素币统计
  77 +func (controller *StatisticsController) SystemSuMoneyStatistics() {
  78 + //statisticsService := service.NewStatisticsService(nil)
  79 + //systemSuMoneyStatisticsCommand := &command.SystemSuMoneyStatisticsCommand{}
  80 + //json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), systemSuMoneyStatisticsCommand)
  81 + ////data, err := statisticsService
  82 +}
  83 +
  84 +// TODO 系统现金统计
  85 +func (controller *StatisticsController) SystemCashStatistics() {
  86 + //statisticsService := service.NewStatisticsService(nil)
  87 +
  88 +}
1 package routers 1 package routers
2 2
3 // TODO 3 // TODO
4 -//func init() {  
5 -// /*****************************************现金池**********************************/  
6 -// beego.Router("/cash_pool/input", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入  
7 -//  
8 -// /*****************************************兑换活动*********************************/  
9 -// beego.Router("/cash_pool/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表  
10 -// beego.Router("/cash_pool/:aid", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动信息  
11 -// beego.Router("/cash_pool/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动  
12 -// beego.Router("/cash_pool/:aid", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动  
13 -//  
14 -// /*****************************************兑换素币清单****************************/  
15 -// beego.Router("/cash_pool/exchange", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单  
16 -// beego.Router("/cash_pool/exchange", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单列表  
17 -// beego.Router("/cash_pool/exchange/:eid", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单  
18 -// beego.Router("/cash_pool/exchange/:eid", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单  
19 -// beego.Router("/cash_pool/export", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单  
20 -// beego.Router("/cash_pool/import", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单  
21 -//}  
  4 +func init() {
  5 + ///*****************************************现金池**********************************/
  6 + //beego.Router("/cash_pool/input", &controllers.ConfigController{}, "POST:CashInput") // 现金池投入
  7 + //
  8 + ///*****************************************兑换活动*********************************/
  9 + //beego.Router("/cashPool-pool/", &controllers.ConfigController{}, "GET:ListExchangeActivities") // 返回兑换活动列表
  10 + //beego.Router("/cashPool-pool/:aid", &controllers.ConfigController{}, "PUT:UpdateExchangeActivities") // 编辑兑换活动
  11 + //beego.Router("/cashPool-pool/", &controllers.ConfigController{}, "POST:CreateExchangeActivities") // 新增兑换活动
  12 + //beego.Router("/cashPool-pool/:aid", &controllers.ConfigController{}, "DELETE:DeleteExchangeActivities") // 删除兑换活动
  13 + //
  14 + ///*****************************************兑换素币清单****************************/
  15 + //beego.Router("/cashPool-pool/exchange", &controllers.ConfigController{}, "GET:ListExchangeList") // 返回素币兑换清单
  16 + //beego.Router("/cashPool-pool/exchange", &controllers.ConfigController{}, "POST:CreateExchangeList") // 新增素币兑换清单
  17 + //beego.Router("/cashPool-pool/exchange/:eid", &controllers.ConfigController{}, "PUT:UpdateExchangeList") // 编辑素币兑换清单
  18 + //beego.Router("/cashPool-pool/exchange/:eid", &controllers.ConfigController{}, "DELETE:RemoveExchangeList") // 删除素币兑换清单
  19 + //beego.Router("/cashPool-pool/export", &controllers.ConfigController{}, "POST:ExportExchangeList") // 导出素币兑换清单
  20 + //beego.Router("/cashPool-pool/import", &controllers.ConfigController{}, "POST:ImportExchangeList") // 导入素币兑换清单
  21 +}
@@ -10,4 +10,6 @@ func init() { @@ -10,4 +10,6 @@ func init() {
10 beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics") 10 beego.Router("/statistics/person-task", &controllers.StatisticsController{}, "Post:PersonTaskStatistics")
11 beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics") 11 beego.Router("/statistics/person-su-money", &controllers.StatisticsController{}, "Post:PersonSuMoneyStatistics")
12 beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics") 12 beego.Router("/statistics/person-notification", &controllers.StatisticsController{}, "Post:PersonNotificationStatistics")
  13 + beego.Router("/statistics/system-su-money", &controllers.StatisticsController{}, "Post:SystemSuMoneyStatistics") // 系统素币统计
  14 + beego.Router("/statistics/system-cashPool", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计
13 } 15 }