|
@@ -2,7 +2,6 @@ package service |
|
@@ -2,7 +2,6 @@ package service |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"fmt"
|
4
|
"fmt"
|
5
|
- "github.com/astaxie/beego"
|
|
|
6
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
5
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
7
|
"strconv"
|
6
|
"strconv"
|
8
|
"time"
|
7
|
"time"
|
|
@@ -59,22 +58,34 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -59,22 +58,34 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
59
|
systemUnChangeSuMoney = value2
|
58
|
systemUnChangeSuMoney = value2
|
60
|
}
|
59
|
}
|
61
|
|
60
|
|
62
|
- // TODO 获取上一个现金池现金值
|
61
|
+ var cashPoolRepository domain.CashPoolRepository
|
|
|
62
|
+ if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
|
|
63
|
+ "transactionContext": transactionContext,
|
|
|
64
|
+ }); err != nil {
|
|
|
65
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
66
|
+ } else {
|
|
|
67
|
+ cashPoolRepository = value
|
|
|
68
|
+ }
|
63
|
|
69
|
|
64
|
- rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64)
|
70
|
+ _, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
|
|
71
|
+ "companyId": createCashPoolCommand.CompanyId,
|
|
|
72
|
+ })
|
|
|
73
|
+ if err != nil {
|
|
|
74
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
75
|
+ }
|
65
|
|
76
|
|
|
|
77
|
+ rate, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemChangedSuMoney), 64) // 平均兑换汇率
|
66
|
newCashPool := &domain.CashPool{
|
78
|
newCashPool := &domain.CashPool{
|
67
|
CompanyId: createCashPoolCommand.CompanyId,
|
79
|
CompanyId: createCashPoolCommand.CompanyId,
|
68
|
Cash: createCashPoolCommand.Cash,
|
80
|
Cash: createCashPoolCommand.Cash,
|
69
|
ExchangedCash: systemExchangedCash,
|
81
|
ExchangedCash: systemExchangedCash,
|
70
|
- UnExchangeCash: createCashPoolCommand.Cash, // TODO 投入的现金 + 系统未兑换的现金
|
82
|
+ UnExchangeCash: createCashPoolCommand.Cash + cashPools[0].UnExchangeCash,
|
71
|
ExchangedSuMoney: systemChangedSuMoney,
|
83
|
ExchangedSuMoney: systemChangedSuMoney,
|
72
|
UnExchangeSuMoney: systemUnChangeSuMoney,
|
84
|
UnExchangeSuMoney: systemUnChangeSuMoney,
|
73
|
Rate: rate,
|
85
|
Rate: rate,
|
74
|
CreateTime: time.Now(),
|
86
|
CreateTime: time.Now(),
|
75
|
}
|
87
|
}
|
76
|
|
88
|
|
77
|
- var cashPoolRepository domain.CashPoolRepository
|
|
|
78
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
89
|
if value, err := factory.CreateCashPoolRepository(map[string]interface{}{
|
79
|
"transactionContext": transactionContext,
|
90
|
"transactionContext": transactionContext,
|
80
|
}); err != nil {
|
91
|
}); err != nil {
|
|
@@ -131,12 +142,9 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
@@ -131,12 +142,9 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
131
|
|
142
|
|
132
|
// 新增兑换现金活动
|
143
|
// 新增兑换现金活动
|
133
|
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
|
144
|
func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchangeCashActivityCommand *command.CreateExchangeCashActivityCommand) (interface{}, error) {
|
134
|
- // 校验新增任务命令
|
|
|
135
|
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
|
145
|
if err := createExchangeCashActivityCommand.ValidateCommand(); err != nil {
|
136
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
146
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
137
|
}
|
147
|
}
|
138
|
-
|
|
|
139
|
- // 新建校验任务事务
|
|
|
140
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
148
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
141
|
if err != nil {
|
149
|
if err != nil {
|
142
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
150
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
@@ -148,7 +156,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
@@ -148,7 +156,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
148
|
transactionContext.RollbackTransaction()
|
156
|
transactionContext.RollbackTransaction()
|
149
|
}()
|
157
|
}()
|
150
|
|
158
|
|
151
|
- // 创建兑换活动
|
|
|
152
|
newActivity := &domain.ExchangeCashActivity{
|
159
|
newActivity := &domain.ExchangeCashActivity{
|
153
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
160
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
154
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
161
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
|
@@ -160,7 +167,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
@@ -160,7 +167,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
160
|
CreateTime: time.Now(),
|
167
|
CreateTime: time.Now(),
|
161
|
}
|
168
|
}
|
162
|
|
169
|
|
163
|
- // 兑换活动资源库
|
|
|
164
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
170
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
165
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
171
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
166
|
"transactionContext": transactionContext,
|
172
|
"transactionContext": transactionContext,
|
|
@@ -252,7 +258,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
@@ -252,7 +258,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
252
|
if activity == nil {
|
258
|
if activity == nil {
|
253
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
259
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
254
|
}
|
260
|
}
|
255
|
-
|
|
|
256
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
261
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
257
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
262
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
258
|
} else {
|
263
|
} else {
|
|
@@ -335,15 +340,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -335,15 +340,12 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
335
|
if activity == nil {
|
340
|
if activity == nil {
|
336
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
341
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
337
|
}
|
342
|
}
|
338
|
-
|
|
|
339
|
if activity == nil {
|
343
|
if activity == nil {
|
340
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
344
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
341
|
}
|
345
|
}
|
342
|
-
|
|
|
343
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
346
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
344
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
347
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
345
|
}
|
348
|
}
|
346
|
-
|
|
|
347
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
349
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
348
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
350
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
349
|
} else {
|
351
|
} else {
|
|
@@ -383,7 +385,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -383,7 +385,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
383
|
|
385
|
|
384
|
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
|
386
|
// TODO 新增兑换人员时,判断成员是否存在,以手机账号为判断依据
|
385
|
|
387
|
|
386
|
- // 创建兑换清单
|
|
|
387
|
newPerson := &domain.ExchangeCashPersonList{
|
388
|
newPerson := &domain.ExchangeCashPersonList{
|
388
|
EmployeeInfo: &domain.EmployeeInfo{
|
389
|
EmployeeInfo: &domain.EmployeeInfo{
|
389
|
EmployeeName: createExchangeCashPersonCommand.PersonName,
|
390
|
EmployeeName: createExchangeCashPersonCommand.PersonName,
|
|
@@ -402,7 +403,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -402,7 +403,6 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
402
|
} else {
|
403
|
} else {
|
403
|
exchangeCashPersonListRepository = value
|
404
|
exchangeCashPersonListRepository = value
|
404
|
}
|
405
|
}
|
405
|
-
|
|
|
406
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
406
|
if person, err := exchangeCashPersonListRepository.Save(newPerson); err != nil {
|
407
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
407
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
408
|
} else {
|
408
|
} else {
|
|
@@ -524,9 +524,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -524,9 +524,6 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
524
|
if person == nil {
|
524
|
if person == nil {
|
525
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
525
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
526
|
}
|
526
|
}
|
527
|
-
|
|
|
528
|
- beego.Info(person)
|
|
|
529
|
-
|
|
|
530
|
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
|
527
|
if personDeleted, err := exchangeCashPersonListRepository.Remove(person); err != nil {
|
531
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
528
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
532
|
} else {
|
529
|
} else {
|