|
@@ -36,6 +36,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -36,6 +36,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
36
|
defer func() {
|
36
|
defer func() {
|
37
|
transactionContext.RollbackTransaction()
|
37
|
transactionContext.RollbackTransaction()
|
38
|
}()
|
38
|
}()
|
|
|
39
|
+
|
39
|
var cashPoolRepository domain.CashPoolRepository
|
40
|
var cashPoolRepository domain.CashPoolRepository
|
40
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
41
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
41
|
"transactionContext": transactionContext,
|
42
|
"transactionContext": transactionContext,
|
|
@@ -44,16 +45,27 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -44,16 +45,27 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
44
|
} else {
|
45
|
} else {
|
45
|
cashPoolRepository = value
|
46
|
cashPoolRepository = value
|
46
|
}
|
47
|
}
|
47
|
- count, _, err := cashPoolRepository.Find(map[string]interface{}{
|
48
|
+
|
|
|
49
|
+ var employeeRepository domain.EmployeeRepository
|
|
|
50
|
+ if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
|
51
|
+ "transactionContext": transactionContext,
|
|
|
52
|
+ }); err != nil {
|
|
|
53
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
54
|
+ } else {
|
|
|
55
|
+ employeeRepository = value
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ // 增加公司id判断
|
|
|
59
|
+ count, _, err := employeeRepository.Find(map[string]interface{}{
|
48
|
"companyId": createCashPoolCommand.CompanyId,
|
60
|
"companyId": createCashPoolCommand.CompanyId,
|
49
|
})
|
61
|
})
|
50
|
- if count == 0 {
|
|
|
51
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
52
|
- }
|
|
|
53
|
if err != nil {
|
62
|
if err != nil {
|
54
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
63
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
55
|
}
|
64
|
}
|
56
|
- // 计算系统平均兑换汇率
|
65
|
+ if count == 0 {
|
|
|
66
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id")
|
|
|
67
|
+ }
|
|
|
68
|
+
|
57
|
var employeeDao *dao.EmployeeDao
|
69
|
var employeeDao *dao.EmployeeDao
|
58
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
70
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
59
|
"transactionContext": transactionContext,
|
71
|
"transactionContext": transactionContext,
|
|
@@ -62,18 +74,29 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -62,18 +74,29 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
62
|
} else {
|
74
|
} else {
|
63
|
employeeDao = value
|
75
|
employeeDao = value
|
64
|
}
|
76
|
}
|
|
|
77
|
+
|
65
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
|
78
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId)
|
66
|
if err != nil {
|
79
|
if err != nil {
|
67
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
80
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
68
|
}
|
81
|
}
|
|
|
82
|
+ if systemSuMoneyStatistics == nil {
|
|
|
83
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
84
|
+ }
|
|
|
85
|
+
|
69
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
86
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
70
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
87
|
systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
|
|
88
|
+
|
71
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
|
89
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(createCashPoolCommand.CompanyId)
|
72
|
if err != nil {
|
90
|
if err != nil {
|
73
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
91
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
74
|
}
|
92
|
}
|
|
|
93
|
+ if systemCashStatistics == nil {
|
|
|
94
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
|
|
95
|
+ }
|
|
|
96
|
+
|
75
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
97
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
76
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
98
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
99
|
+
|
77
|
// 计算系统平均兑换汇率
|
100
|
// 计算系统平均兑换汇率
|
78
|
var rate float64
|
101
|
var rate float64
|
79
|
if systemExchangedSuMoney == 0 {
|
102
|
if systemExchangedSuMoney == 0 {
|
|
@@ -81,6 +104,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -81,6 +104,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
81
|
} else {
|
104
|
} else {
|
82
|
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
|
105
|
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64) // 平均兑换汇率
|
83
|
}
|
106
|
}
|
|
|
107
|
+
|
84
|
// 新建现金池
|
108
|
// 新建现金池
|
85
|
newCashPool := &domain.CashPool{
|
109
|
newCashPool := &domain.CashPool{
|
86
|
CompanyId: createCashPoolCommand.CompanyId,
|
110
|
CompanyId: createCashPoolCommand.CompanyId,
|
|
@@ -92,6 +116,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
|
@@ -92,6 +116,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co |
92
|
Rate: rate,
|
116
|
Rate: rate,
|
93
|
CreateTime: time.Now(),
|
117
|
CreateTime: time.Now(),
|
94
|
}
|
118
|
}
|
|
|
119
|
+
|
95
|
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
|
120
|
if cashPool, err := cashPoolRepository.Save(newCashPool); err != nil {
|
96
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
121
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
97
|
} else {
|
122
|
} else {
|
|
@@ -117,7 +142,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
@@ -117,7 +142,7 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
117
|
defer func() {
|
142
|
defer func() {
|
118
|
transactionContext.RollbackTransaction()
|
143
|
transactionContext.RollbackTransaction()
|
119
|
}()
|
144
|
}()
|
120
|
- // 统计系统素币
|
145
|
+
|
121
|
var employeeDao *dao.EmployeeDao
|
146
|
var employeeDao *dao.EmployeeDao
|
122
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
147
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
123
|
"transactionContext": transactionContext,
|
148
|
"transactionContext": transactionContext,
|
|
@@ -126,6 +151,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
@@ -126,6 +151,8 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
126
|
} else {
|
151
|
} else {
|
127
|
employeeDao = value
|
152
|
employeeDao = value
|
128
|
}
|
153
|
}
|
|
|
154
|
+
|
|
|
155
|
+ // 计算系统素币
|
129
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
|
156
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(getCashPoolQuery.CompanyId)
|
130
|
if err != nil {
|
157
|
if err != nil {
|
131
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
158
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -133,8 +160,10 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
@@ -133,8 +160,10 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
133
|
if systemSuMoneyStatistics == nil {
|
160
|
if systemSuMoneyStatistics == nil {
|
134
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
161
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
135
|
}
|
162
|
}
|
136
|
- systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
137
|
- systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64)
|
163
|
+
|
|
|
164
|
+ systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64) // 平台已兑换素币
|
|
|
165
|
+ systemUnExchangeSuMoney := systemSuMoneyStatistics["systemUnExchangeSuMoney"].(float64) // 平台未兑换素币
|
|
|
166
|
+
|
138
|
var cashPoolRepository domain.CashPoolRepository
|
167
|
var cashPoolRepository domain.CashPoolRepository
|
139
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
168
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
140
|
"transactionContext": transactionContext,
|
169
|
"transactionContext": transactionContext,
|
|
@@ -143,12 +172,14 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
|
@@ -143,12 +172,14 @@ func (cashPoolService *CashPoolService) GetCashPool(getCashPoolQuery *query.GetC |
143
|
} else {
|
172
|
} else {
|
144
|
cashPoolRepository = value
|
173
|
cashPoolRepository = value
|
145
|
}
|
174
|
}
|
|
|
175
|
+
|
146
|
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); err != nil {
|
176
|
if count, cashPools, err := cashPoolRepository.Find(tool_funs.SimpleStructToMap(getCashPoolQuery)); err != nil {
|
147
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
177
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
148
|
} else {
|
178
|
} else {
|
149
|
if err := transactionContext.CommitTransaction(); err != nil {
|
179
|
if err := transactionContext.CommitTransaction(); err != nil {
|
150
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
180
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
151
|
}
|
181
|
}
|
|
|
182
|
+
|
152
|
if count == 0 {
|
183
|
if count == 0 {
|
153
|
return map[string] interface{} {
|
184
|
return map[string] interface{} {
|
154
|
"cashPoolId": 0,
|
185
|
"cashPoolId": 0,
|
|
@@ -182,20 +213,24 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
@@ -182,20 +213,24 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
182
|
defer func() {
|
213
|
defer func() {
|
183
|
transactionContext.RollbackTransaction()
|
214
|
transactionContext.RollbackTransaction()
|
184
|
}()
|
215
|
}()
|
|
|
216
|
+
|
|
|
217
|
+ // 时间格式化
|
185
|
var timeNow = time.Now()
|
218
|
var timeNow = time.Now()
|
186
|
var deadline = createExchangeCashActivityCommand.Deadline
|
219
|
var deadline = createExchangeCashActivityCommand.Deadline
|
187
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
220
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
188
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
221
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
222
|
+
|
189
|
newActivity := &domain.ExchangeCashActivity{
|
223
|
newActivity := &domain.ExchangeCashActivity{
|
190
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
224
|
ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
|
191
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
225
|
CompanyId: createExchangeCashActivityCommand.CompanyId,
|
192
|
ExchangedCash: 0,
|
226
|
ExchangedCash: 0,
|
193
|
ExchangedSuMoney: 0,
|
227
|
ExchangedSuMoney: 0,
|
194
|
- Deadline: time.Date(deadline.Year(), deadline.Month(), deadline.Day(), deadline.Hour(), deadline.Minute(), 0, 0, time.Local),
|
|
|
195
|
- CountDown: int64(t2.Sub(t1).Hours() / 24),
|
228
|
+ Deadline: time.Date(deadline.Year(), deadline.Month(), deadline.Day(), deadline.Hour(), deadline.Minute(), deadline.Second(), 0, time.Local),
|
|
|
229
|
+ CountDown: int64(t2.Sub(t1).Hours() / 24), // 计算活动截止倒计时
|
196
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
230
|
Rate: createExchangeCashActivityCommand.ExchangeRate,
|
197
|
CreateTime: time.Now(),
|
231
|
CreateTime: time.Now(),
|
198
|
}
|
232
|
}
|
|
|
233
|
+
|
199
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
234
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
200
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
235
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
201
|
"transactionContext": transactionContext,
|
236
|
"transactionContext": transactionContext,
|
|
@@ -204,6 +239,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
|
@@ -204,6 +239,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang |
204
|
} else {
|
239
|
} else {
|
205
|
exchangeCashActivityRepository = value
|
240
|
exchangeCashActivityRepository = value
|
206
|
}
|
241
|
}
|
|
|
242
|
+
|
207
|
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
|
243
|
if activity, err := exchangeCashActivityRepository.Save(newActivity); err != nil {
|
208
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
244
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
209
|
} else {
|
245
|
} else {
|
|
@@ -229,6 +265,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
@@ -229,6 +265,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
229
|
defer func() {
|
265
|
defer func() {
|
230
|
transactionContext.RollbackTransaction()
|
266
|
transactionContext.RollbackTransaction()
|
231
|
}()
|
267
|
}()
|
|
|
268
|
+
|
232
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
269
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
233
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
270
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
234
|
"transactionContext": transactionContext,
|
271
|
"transactionContext": transactionContext,
|
|
@@ -237,19 +274,23 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
|
@@ -237,19 +274,23 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivityDeadline(listExc |
237
|
} else {
|
274
|
} else {
|
238
|
exchangeActivityRepository = value
|
275
|
exchangeActivityRepository = value
|
239
|
}
|
276
|
}
|
|
|
277
|
+
|
240
|
if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil {
|
278
|
if _, activities, err := exchangeActivityRepository.FindAll(tool_funs.SimpleStructToMap(listExchangeCashActivityDeadlineQuery)); err != nil {
|
241
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
279
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
242
|
} else {
|
280
|
} else {
|
243
|
if err := transactionContext.CommitTransaction(); err != nil {
|
281
|
if err := transactionContext.CommitTransaction(); err != nil {
|
244
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
282
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
245
|
}
|
283
|
}
|
|
|
284
|
+
|
246
|
var deadlines []interface{}
|
285
|
var deadlines []interface{}
|
247
|
for _, activity := range activities {
|
286
|
for _, activity := range activities {
|
248
|
deadlines = append(deadlines, activity.Deadline)
|
287
|
deadlines = append(deadlines, activity.Deadline)
|
249
|
}
|
288
|
}
|
|
|
289
|
+
|
250
|
if len(deadlines) == 0 {
|
290
|
if len(deadlines) == 0 {
|
251
|
deadlines = []interface{}{}
|
291
|
deadlines = []interface{}{}
|
252
|
}
|
292
|
}
|
|
|
293
|
+
|
253
|
return map[string]interface{}{
|
294
|
return map[string]interface{}{
|
254
|
"deadlines": deadlines,
|
295
|
"deadlines": deadlines,
|
255
|
}, nil
|
296
|
}, nil
|
|
@@ -271,6 +312,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
@@ -271,6 +312,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
271
|
defer func() {
|
312
|
defer func() {
|
272
|
transactionContext.RollbackTransaction()
|
313
|
transactionContext.RollbackTransaction()
|
273
|
}()
|
314
|
}()
|
|
|
315
|
+
|
274
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
316
|
var exchangeActivityRepository domain.ExchangeActivityRepository
|
275
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
317
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
276
|
"transactionContext": transactionContext,
|
318
|
"transactionContext": transactionContext,
|
|
@@ -279,30 +321,37 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
|
@@ -279,30 +321,37 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas |
279
|
} else {
|
321
|
} else {
|
280
|
exchangeActivityRepository = value
|
322
|
exchangeActivityRepository = value
|
281
|
}
|
323
|
}
|
|
|
324
|
+
|
282
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
|
325
|
if count, activities, err := exchangeActivityRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashActivityQuery)); err != nil {
|
283
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
326
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
284
|
} else {
|
327
|
} else {
|
285
|
- // 更新兑换活动结束倒计时
|
328
|
+ // TODO 更新兑换活动结束倒计时,增加倒计时结束判断
|
286
|
for _, activity := range activities {
|
329
|
for _, activity := range activities {
|
|
|
330
|
+
|
287
|
var timeNow = time.Now()
|
331
|
var timeNow = time.Now()
|
288
|
var deadline = activity.Deadline
|
332
|
var deadline = activity.Deadline
|
289
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
333
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
290
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
334
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
335
|
+
|
291
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
336
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
292
|
ExchangeCashActivityId: activity.ActivityId,
|
337
|
ExchangeCashActivityId: activity.ActivityId,
|
293
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
338
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
294
|
}
|
339
|
}
|
|
|
340
|
+
|
295
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
341
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
296
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
342
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
297
|
}
|
343
|
}
|
|
|
344
|
+
|
298
|
_, err := exchangeActivityRepository.Save(activity)
|
345
|
_, err := exchangeActivityRepository.Save(activity)
|
299
|
if err != nil {
|
346
|
if err != nil {
|
300
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
347
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
301
|
}
|
348
|
}
|
302
|
}
|
349
|
}
|
|
|
350
|
+
|
303
|
if err := transactionContext.CommitTransaction(); err != nil {
|
351
|
if err := transactionContext.CommitTransaction(); err != nil {
|
304
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
352
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
305
|
}
|
353
|
}
|
|
|
354
|
+
|
306
|
return map[string]interface{}{
|
355
|
return map[string]interface{}{
|
307
|
"count": count,
|
356
|
"count": count,
|
308
|
"activities": activities,
|
357
|
"activities": activities,
|
|
@@ -325,6 +374,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
@@ -325,6 +374,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
325
|
defer func() {
|
374
|
defer func() {
|
326
|
transactionContext.RollbackTransaction()
|
375
|
transactionContext.RollbackTransaction()
|
327
|
}()
|
376
|
}()
|
|
|
377
|
+
|
328
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
378
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
329
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
379
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
330
|
"transactionContext": transactionContext,
|
380
|
"transactionContext": transactionContext,
|
|
@@ -333,6 +383,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
@@ -333,6 +383,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
333
|
} else {
|
383
|
} else {
|
334
|
exchangeCashActivityRepository = value
|
384
|
exchangeCashActivityRepository = value
|
335
|
}
|
385
|
}
|
|
|
386
|
+
|
336
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
|
387
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": removeExchangeCashActivityCommand.ActivityId})
|
337
|
if err != nil {
|
388
|
if err != nil {
|
338
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
389
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -340,6 +391,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
|
@@ -340,6 +391,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashActivity(removeExchang |
340
|
if activity == nil {
|
391
|
if activity == nil {
|
341
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
392
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashActivityCommand.ActivityId)))
|
342
|
}
|
393
|
}
|
|
|
394
|
+
|
343
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
395
|
if activityDeleted, err := exchangeCashActivityRepository.Remove(activity); err != nil {
|
344
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
396
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
345
|
} else {
|
397
|
} else {
|
|
@@ -365,6 +417,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
@@ -365,6 +417,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
365
|
defer func() {
|
417
|
defer func() {
|
366
|
transactionContext.RollbackTransaction()
|
418
|
transactionContext.RollbackTransaction()
|
367
|
}()
|
419
|
}()
|
|
|
420
|
+
|
368
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
421
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
369
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
422
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
370
|
"transactionContext": transactionContext,
|
423
|
"transactionContext": transactionContext,
|
|
@@ -373,6 +426,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
@@ -373,6 +426,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
373
|
} else {
|
426
|
} else {
|
374
|
exchangeCashActivityRepository = value
|
427
|
exchangeCashActivityRepository = value
|
375
|
}
|
428
|
}
|
|
|
429
|
+
|
376
|
// 需要更新兑换活动结束倒计时
|
430
|
// 需要更新兑换活动结束倒计时
|
377
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
|
431
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": getExchangeCashActivityQuery.ExchangeCashActivityId})
|
378
|
if err != nil {
|
432
|
if err != nil {
|
|
@@ -381,22 +435,26 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
|
@@ -381,22 +435,26 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA |
381
|
if activity == nil {
|
435
|
if activity == nil {
|
382
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
|
436
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getExchangeCashActivityQuery.ExchangeCashActivityId)))
|
383
|
}
|
437
|
}
|
|
|
438
|
+
|
384
|
var timeNow = time.Now()
|
439
|
var timeNow = time.Now()
|
385
|
var deadline = activity.Deadline
|
440
|
var deadline = activity.Deadline
|
386
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
441
|
var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
|
387
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
442
|
var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
|
|
|
443
|
+
|
388
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
444
|
updateExchangeCashActivity := &command.UpdateExchangeCashActivityCommand {
|
389
|
ExchangeCashActivityId: activity.ActivityId,
|
445
|
ExchangeCashActivityId: activity.ActivityId,
|
390
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
446
|
CountDown: int64(t2.Sub(t1).Hours() / 24),
|
391
|
}
|
447
|
}
|
|
|
448
|
+
|
392
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
449
|
if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivity)); err != nil {
|
393
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
450
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
394
|
}
|
451
|
}
|
|
|
452
|
+
|
395
|
activityFound, err := exchangeCashActivityRepository.Save(activity)
|
453
|
activityFound, err := exchangeCashActivityRepository.Save(activity)
|
396
|
if err != nil {
|
454
|
if err != nil {
|
397
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
455
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
398
|
}
|
456
|
}
|
399
|
- // 返回兑换现金活动
|
457
|
+
|
400
|
if activityFound == nil {
|
458
|
if activityFound == nil {
|
401
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
459
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
402
|
} else {
|
460
|
} else {
|
|
@@ -422,6 +480,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -422,6 +480,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
422
|
defer func() {
|
480
|
defer func() {
|
423
|
transactionContext.RollbackTransaction()
|
481
|
transactionContext.RollbackTransaction()
|
424
|
}()
|
482
|
}()
|
|
|
483
|
+
|
425
|
// 更新兑换活动
|
484
|
// 更新兑换活动
|
426
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
485
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
427
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
486
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
@@ -431,6 +490,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -431,6 +490,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
431
|
} else {
|
490
|
} else {
|
432
|
exchangeCashActivityRepository = value
|
491
|
exchangeCashActivityRepository = value
|
433
|
}
|
492
|
}
|
|
|
493
|
+
|
434
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
|
494
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": updateExchangeCashActivityCommand.ExchangeCashActivityId})
|
435
|
if err != nil {
|
495
|
if err != nil {
|
436
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
496
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -438,9 +498,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -438,9 +498,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
438
|
if activity == nil {
|
498
|
if activity == nil {
|
439
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
499
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
440
|
}
|
500
|
}
|
441
|
- if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
442
|
- return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
443
|
- }
|
501
|
+
|
444
|
// 更新兑换活动兑换汇率
|
502
|
// 更新兑换活动兑换汇率
|
445
|
if updateExchangeCashActivityCommand.ExchangeRate != 0 {
|
503
|
if updateExchangeCashActivityCommand.ExchangeRate != 0 {
|
446
|
// 获取当前现金池
|
504
|
// 获取当前现金池
|
|
@@ -452,6 +510,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -452,6 +510,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
452
|
} else {
|
510
|
} else {
|
453
|
cashPoolRepository = value
|
511
|
cashPoolRepository = value
|
454
|
}
|
512
|
}
|
|
|
513
|
+
|
455
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
514
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
456
|
"companyId": activity.CompanyId,
|
515
|
"companyId": activity.CompanyId,
|
457
|
})
|
516
|
})
|
|
@@ -461,6 +520,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -461,6 +520,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
461
|
if len(cashPools) == 0 {
|
520
|
if len(cashPools) == 0 {
|
462
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
521
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
463
|
}
|
522
|
}
|
|
|
523
|
+
|
464
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
524
|
// 判断兑换活动清单中现金总金额是否超过平台未兑换现金值
|
465
|
var cashPoolDao *dao.CashPoolDao
|
525
|
var cashPoolDao *dao.CashPoolDao
|
466
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
526
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
|
@@ -470,6 +530,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -470,6 +530,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
470
|
} else {
|
530
|
} else {
|
471
|
cashPoolDao = value
|
531
|
cashPoolDao = value
|
472
|
}
|
532
|
}
|
|
|
533
|
+
|
473
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId)
|
534
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activity.ActivityId)
|
474
|
if err != nil {
|
535
|
if err != nil {
|
475
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
536
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -477,10 +538,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -477,10 +538,13 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
477
|
if activitySuMoneyStatistics == nil {
|
538
|
if activitySuMoneyStatistics == nil {
|
478
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
539
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
479
|
}
|
540
|
}
|
|
|
541
|
+
|
480
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
542
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
543
|
+
|
481
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
544
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPools[0].UnExchangeCash {
|
482
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
545
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
483
|
}
|
546
|
}
|
|
|
547
|
+
|
484
|
// 批量更新兑换清单中已兑换现金值
|
548
|
// 批量更新兑换清单中已兑换现金值
|
485
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
549
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
486
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
550
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
@@ -490,24 +554,29 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -490,24 +554,29 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
490
|
} else {
|
554
|
} else {
|
491
|
exchangeCashPersonListRepository = value
|
555
|
exchangeCashPersonListRepository = value
|
492
|
}
|
556
|
}
|
|
|
557
|
+
|
493
|
_, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
558
|
_, people, err := exchangeCashPersonListRepository.Find(map[string]interface{}{
|
494
|
"exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
|
559
|
"exchangeCashActivityId": updateExchangeCashActivityCommand.ExchangeCashActivityId,
|
495
|
})
|
560
|
})
|
496
|
if err != nil {
|
561
|
if err != nil {
|
497
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
562
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
498
|
}
|
563
|
}
|
499
|
- // 更新兑换清单,更新已兑换现金值
|
564
|
+
|
|
|
565
|
+ // 批量更新兑换清单,更新已兑换现金值
|
500
|
for _, person := range people {
|
566
|
for _, person := range people {
|
501
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
567
|
updateExchangeCashPerson := &command.UpdateExchangeCashPersonCommand {
|
502
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * person.ExchangedSuMoney,
|
568
|
ExchangedCash: updateExchangeCashActivityCommand.ExchangeRate * person.ExchangedSuMoney,
|
503
|
}
|
569
|
}
|
|
|
570
|
+
|
504
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
|
571
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPerson)); err != nil {
|
505
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
572
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
506
|
}
|
573
|
}
|
|
|
574
|
+
|
507
|
if _, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
575
|
if _, err := exchangeCashPersonListRepository.Save(person);err != nil {
|
508
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
576
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
509
|
}
|
577
|
}
|
510
|
}
|
578
|
}
|
|
|
579
|
+
|
511
|
// 计算系统平均兑换汇率并更新现金池
|
580
|
// 计算系统平均兑换汇率并更新现金池
|
512
|
var employeeDao *dao.EmployeeDao
|
581
|
var employeeDao *dao.EmployeeDao
|
513
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
582
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -517,6 +586,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -517,6 +586,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
517
|
} else {
|
586
|
} else {
|
518
|
employeeDao = value
|
587
|
employeeDao = value
|
519
|
}
|
588
|
}
|
|
|
589
|
+
|
520
|
// 获取平台素币状况
|
590
|
// 获取平台素币状况
|
521
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
591
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
522
|
if err != nil {
|
592
|
if err != nil {
|
|
@@ -525,7 +595,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -525,7 +595,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
525
|
if systemSuMoneyStatistics == nil {
|
595
|
if systemSuMoneyStatistics == nil {
|
526
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
596
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
527
|
}
|
597
|
}
|
|
|
598
|
+
|
528
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
599
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
|
|
600
|
+
|
529
|
// 获取平台现金状况
|
601
|
// 获取平台现金状况
|
530
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
|
602
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activity.CompanyId)
|
531
|
if err != nil {
|
603
|
if err != nil {
|
|
@@ -534,8 +606,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -534,8 +606,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
534
|
if systemCashStatistics == nil {
|
606
|
if systemCashStatistics == nil {
|
535
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
607
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
536
|
}
|
608
|
}
|
|
|
609
|
+
|
537
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
610
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
538
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
611
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
612
|
+
|
539
|
// 平均兑换汇率
|
613
|
// 平均兑换汇率
|
540
|
var rate float64
|
614
|
var rate float64
|
541
|
if systemExchangedSuMoney == 0 {
|
615
|
if systemExchangedSuMoney == 0 {
|
|
@@ -543,16 +617,19 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -543,16 +617,19 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
543
|
} else {
|
617
|
} else {
|
544
|
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
618
|
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
545
|
}
|
619
|
}
|
546
|
- // 更新现金池
|
620
|
+
|
547
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
621
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
548
|
CashPoolId: cashPools[0].CashPoolId,
|
622
|
CashPoolId: cashPools[0].CashPoolId,
|
549
|
ExchangedCash: systemUnExchangeCash,
|
623
|
ExchangedCash: systemUnExchangeCash,
|
550
|
UnExchangeCash: systemUnExchangeCash,
|
624
|
UnExchangeCash: systemUnExchangeCash,
|
551
|
Rate: rate,
|
625
|
Rate: rate,
|
552
|
}
|
626
|
}
|
|
|
627
|
+
|
|
|
628
|
+ // 更新现金池
|
553
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
629
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
554
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
630
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
555
|
}
|
631
|
}
|
|
|
632
|
+
|
556
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
633
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
557
|
if err != nil {
|
634
|
if err != nil {
|
558
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
635
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -560,13 +637,22 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
|
@@ -560,13 +637,22 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang |
560
|
if cashPoolUpdated == nil {
|
637
|
if cashPoolUpdated == nil {
|
561
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
638
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
562
|
}
|
639
|
}
|
|
|
640
|
+
|
|
|
641
|
+ // 更新兑换活动已兑换现金
|
|
|
642
|
+ updateExchangeCashActivityCommand.ExchangedCash = updateExchangeCashActivityCommand.ExchangeRate * activity.ExchangedSuMoney
|
|
|
643
|
+ }
|
|
|
644
|
+
|
|
|
645
|
+ if err := activity.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
|
|
646
|
+ return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
563
|
}
|
647
|
}
|
|
|
648
|
+
|
564
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
649
|
if activityUpdated, err := exchangeCashActivityRepository.Save(activity); err != nil {
|
565
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
650
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
566
|
} else {
|
651
|
} else {
|
567
|
if err := transactionContext.CommitTransaction(); err != nil {
|
652
|
if err := transactionContext.CommitTransaction(); err != nil {
|
568
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
653
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
569
|
}
|
654
|
}
|
|
|
655
|
+
|
570
|
return activityUpdated, nil
|
656
|
return activityUpdated, nil
|
571
|
}
|
657
|
}
|
572
|
}
|
658
|
}
|
|
@@ -586,6 +672,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -586,6 +672,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
586
|
defer func() {
|
672
|
defer func() {
|
587
|
transactionContext.RollbackTransaction()
|
673
|
transactionContext.RollbackTransaction()
|
588
|
}()
|
674
|
}()
|
|
|
675
|
+
|
589
|
// 获取兑换活动兑换汇率
|
676
|
// 获取兑换活动兑换汇率
|
590
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
677
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
591
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
678
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
|
@@ -595,11 +682,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -595,11 +682,14 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
595
|
} else {
|
682
|
} else {
|
596
|
exchangeCashActivityRepository = value
|
683
|
exchangeCashActivityRepository = value
|
597
|
}
|
684
|
}
|
|
|
685
|
+
|
598
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
686
|
activity, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
599
|
if err != nil {
|
687
|
if err != nil {
|
600
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
688
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
601
|
}
|
689
|
}
|
|
|
690
|
+
|
602
|
rate := activity.Rate
|
691
|
rate := activity.Rate
|
|
|
692
|
+
|
603
|
// 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
|
693
|
// 根据uid/手机账号判断成员是否存在,素币是否超过本人持有的真实素币
|
604
|
var employeeRepository domain.EmployeeRepository
|
694
|
var employeeRepository domain.EmployeeRepository
|
605
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
695
|
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
|
|
@@ -609,6 +699,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -609,6 +699,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
609
|
} else {
|
699
|
} else {
|
610
|
employeeRepository = value
|
700
|
employeeRepository = value
|
611
|
}
|
701
|
}
|
|
|
702
|
+
|
612
|
getEmployee := map[string]interface{}{}
|
703
|
getEmployee := map[string]interface{}{}
|
613
|
if createExchangeCashPersonCommand.PersonAccount == "" {
|
704
|
if createExchangeCashPersonCommand.PersonAccount == "" {
|
614
|
getEmployee = map[string]interface{}{
|
705
|
getEmployee = map[string]interface{}{
|
|
@@ -619,7 +710,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -619,7 +710,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
619
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
710
|
"account": createExchangeCashPersonCommand.PersonAccount,
|
620
|
}
|
711
|
}
|
621
|
}
|
712
|
}
|
622
|
- fmt.Print(getEmployee, "\n")
|
713
|
+
|
623
|
employee, err := employeeRepository.FindOne(getEmployee)
|
714
|
employee, err := employeeRepository.FindOne(getEmployee)
|
624
|
if err != nil {
|
715
|
if err != nil {
|
625
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
716
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -627,9 +718,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -627,9 +718,11 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
627
|
if employee == nil {
|
718
|
if employee == nil {
|
628
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
719
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的员工")
|
629
|
}
|
720
|
}
|
|
|
721
|
+
|
630
|
if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
722
|
if employee.SuMoney < createExchangeCashPersonCommand.ExchangedSuMoney {
|
631
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
723
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "当前兑换素币超过本人持有的素币值")
|
632
|
}
|
724
|
}
|
|
|
725
|
+
|
633
|
// 新增兑换清单
|
726
|
// 新增兑换清单
|
634
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
727
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
635
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
728
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
@@ -639,6 +732,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -639,6 +732,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
639
|
} else {
|
732
|
} else {
|
640
|
exchangeCashPersonListRepository = value
|
733
|
exchangeCashPersonListRepository = value
|
641
|
}
|
734
|
}
|
|
|
735
|
+
|
642
|
newPerson := &domain.ExchangeCashPersonList{
|
736
|
newPerson := &domain.ExchangeCashPersonList{
|
643
|
EmployeeInfo: &domain.EmployeeInfo{
|
737
|
EmployeeInfo: &domain.EmployeeInfo{
|
644
|
Uid: employee.EmployeeInfo.Uid,
|
738
|
Uid: employee.EmployeeInfo.Uid,
|
|
@@ -649,10 +743,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -649,10 +743,12 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
649
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
743
|
ExchangedSuMoney: createExchangeCashPersonCommand.ExchangedSuMoney,
|
650
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
|
744
|
ExchangedCash: createExchangeCashPersonCommand.ExchangedSuMoney * rate,
|
651
|
}
|
745
|
}
|
|
|
746
|
+
|
652
|
person, err := exchangeCashPersonListRepository.Save(newPerson)
|
747
|
person, err := exchangeCashPersonListRepository.Save(newPerson)
|
653
|
if err != nil {
|
748
|
if err != nil {
|
654
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
749
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
655
|
}
|
750
|
}
|
|
|
751
|
+
|
656
|
// 生成素币流水,更新个人素币
|
752
|
// 生成素币流水,更新个人素币
|
657
|
var operationSuMoneyService service.OperationSuMoneyService
|
753
|
var operationSuMoneyService service.OperationSuMoneyService
|
658
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
754
|
if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
@@ -662,6 +758,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -662,6 +758,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
662
|
} else {
|
758
|
} else {
|
663
|
operationSuMoneyService = value
|
759
|
operationSuMoneyService = value
|
664
|
}
|
760
|
}
|
|
|
761
|
+
|
665
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
762
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
666
|
Uid: person.EmployeeInfo.Uid,
|
763
|
Uid: person.EmployeeInfo.Uid,
|
667
|
Operator: createExchangeCashPersonCommand.Operator,
|
764
|
Operator: createExchangeCashPersonCommand.Operator,
|
|
@@ -669,7 +766,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -669,7 +766,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
669
|
OperationType: 3,
|
766
|
OperationType: 3,
|
670
|
OperationDescription: "素币兑换现金",
|
767
|
OperationDescription: "素币兑换现金",
|
671
|
}
|
768
|
}
|
|
|
769
|
+
|
672
|
fmt.Print(operationSuMoneyCommand, "\n")
|
770
|
fmt.Print(operationSuMoneyCommand, "\n")
|
|
|
771
|
+
|
673
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
772
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
674
|
if err != nil {
|
773
|
if err != nil {
|
675
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
774
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -677,8 +776,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -677,8 +776,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
677
|
if task == nil {
|
776
|
if task == nil {
|
678
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
777
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
679
|
}
|
778
|
}
|
680
|
- fmt.Print(task, "\n")
|
|
|
681
|
- // 更新兑换活动
|
779
|
+
|
682
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
780
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
683
|
"transactionContext": transactionContext,
|
781
|
"transactionContext": transactionContext,
|
684
|
}); err != nil {
|
782
|
}); err != nil {
|
|
@@ -686,6 +784,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -686,6 +784,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
686
|
} else {
|
784
|
} else {
|
687
|
exchangeCashActivityRepository = value
|
785
|
exchangeCashActivityRepository = value
|
688
|
}
|
786
|
}
|
|
|
787
|
+
|
|
|
788
|
+ // 获取相关兑换活动
|
689
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
789
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": createExchangeCashPersonCommand.ExchangeCashActivityId})
|
690
|
if err != nil {
|
790
|
if err != nil {
|
691
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
791
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -693,14 +793,18 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -693,14 +793,18 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
693
|
if activityFound == nil {
|
793
|
if activityFound == nil {
|
694
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
794
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
695
|
}
|
795
|
}
|
|
|
796
|
+
|
696
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
797
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
697
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
798
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
698
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
|
799
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + person.ExchangedSuMoney,
|
699
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
800
|
ExchangedCash: activityFound.ExchangedCash - person.ExchangedCash,
|
700
|
}
|
801
|
}
|
|
|
802
|
+
|
|
|
803
|
+ // 更新兑换活动
|
701
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
804
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
702
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
805
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
703
|
}
|
806
|
}
|
|
|
807
|
+
|
704
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
808
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
705
|
if err != nil {
|
809
|
if err != nil {
|
706
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
810
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -708,7 +812,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -708,7 +812,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
708
|
if activityUpdated == nil {
|
812
|
if activityUpdated == nil {
|
709
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
813
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(createExchangeCashPersonCommand.ExchangeCashActivityId)))
|
710
|
}
|
814
|
}
|
711
|
- // 获取兑换清单素币状况
|
815
|
+
|
712
|
var cashPoolDao *dao.CashPoolDao
|
816
|
var cashPoolDao *dao.CashPoolDao
|
713
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
817
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
714
|
"transactionContext": transactionContext,
|
818
|
"transactionContext": transactionContext,
|
|
@@ -717,6 +821,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -717,6 +821,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
717
|
} else {
|
821
|
} else {
|
718
|
cashPoolDao = value
|
822
|
cashPoolDao = value
|
719
|
}
|
823
|
}
|
|
|
824
|
+
|
|
|
825
|
+ // 获取兑换活动素币兑换情况
|
720
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId)
|
826
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.CompanyId)
|
721
|
if err != nil {
|
827
|
if err != nil {
|
722
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
828
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -724,7 +830,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -724,7 +830,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
724
|
if activitySuMoneyStatistics == nil {
|
830
|
if activitySuMoneyStatistics == nil {
|
725
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
831
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
726
|
}
|
832
|
}
|
|
|
833
|
+
|
727
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
834
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
835
|
+
|
728
|
// 现金池操作
|
836
|
// 现金池操作
|
729
|
var employeeDao *dao.EmployeeDao
|
837
|
var employeeDao *dao.EmployeeDao
|
730
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
838
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -734,6 +842,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -734,6 +842,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
734
|
} else {
|
842
|
} else {
|
735
|
employeeDao = value
|
843
|
employeeDao = value
|
736
|
}
|
844
|
}
|
|
|
845
|
+
|
737
|
// 获取平台现金状况
|
846
|
// 获取平台现金状况
|
738
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
847
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
739
|
if err != nil {
|
848
|
if err != nil {
|
|
@@ -742,12 +851,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -742,12 +851,15 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
742
|
if systemCashStatistics == nil {
|
851
|
if systemCashStatistics == nil {
|
743
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
852
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
744
|
}
|
853
|
}
|
|
|
854
|
+
|
745
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
855
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
746
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
856
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
857
|
+
|
747
|
// 判断兑换的现金是否超过现金池未兑换现金
|
858
|
// 判断兑换的现金是否超过现金池未兑换现金
|
748
|
- if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
859
|
+ if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemUnExchangeCash {
|
749
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
860
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
750
|
}
|
861
|
}
|
|
|
862
|
+
|
751
|
// 获取平台素币状况
|
863
|
// 获取平台素币状况
|
752
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
864
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activity.CompanyId)
|
753
|
if err != nil {
|
865
|
if err != nil {
|
|
@@ -756,8 +868,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -756,8 +868,9 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
756
|
if systemSuMoneyStatistics == nil {
|
868
|
if systemSuMoneyStatistics == nil {
|
757
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
869
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
758
|
}
|
870
|
}
|
|
|
871
|
+
|
759
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
872
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
760
|
- // 更新现金池
|
873
|
+
|
761
|
var cashPoolRepository domain.CashPoolRepository
|
874
|
var cashPoolRepository domain.CashPoolRepository
|
762
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
875
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
763
|
"transactionContext": transactionContext,
|
876
|
"transactionContext": transactionContext,
|
|
@@ -766,6 +879,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -766,6 +879,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
766
|
} else {
|
879
|
} else {
|
767
|
cashPoolRepository = value
|
880
|
cashPoolRepository = value
|
768
|
}
|
881
|
}
|
|
|
882
|
+
|
769
|
// 获取现金池
|
883
|
// 获取现金池
|
770
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
884
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
771
|
"companyId": activity.CompanyId,
|
885
|
"companyId": activity.CompanyId,
|
|
@@ -773,9 +887,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -773,9 +887,10 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
773
|
if err != nil {
|
887
|
if err != nil {
|
774
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
888
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
775
|
}
|
889
|
}
|
776
|
- if cashPools == nil {
|
890
|
+ if len(cashPools) == 0 {
|
777
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
891
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activity.CompanyId)))
|
778
|
}
|
892
|
}
|
|
|
893
|
+
|
779
|
// 计算平均兑换汇率
|
894
|
// 计算平均兑换汇率
|
780
|
var newRate float64
|
895
|
var newRate float64
|
781
|
if systemExchangedSuMoney == 0 {
|
896
|
if systemExchangedSuMoney == 0 {
|
|
@@ -783,16 +898,19 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -783,16 +898,19 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
783
|
} else {
|
898
|
} else {
|
784
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
899
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
785
|
}
|
900
|
}
|
786
|
- // 更新现金池
|
901
|
+
|
787
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
902
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
788
|
CashPoolId: cashPools[0].CashPoolId,
|
903
|
CashPoolId: cashPools[0].CashPoolId,
|
789
|
ExchangedCash: systemUnExchangeCash,
|
904
|
ExchangedCash: systemUnExchangeCash,
|
790
|
UnExchangeCash: systemUnExchangeCash,
|
905
|
UnExchangeCash: systemUnExchangeCash,
|
791
|
Rate: newRate,
|
906
|
Rate: newRate,
|
792
|
}
|
907
|
}
|
|
|
908
|
+
|
|
|
909
|
+ // 更新现金池
|
793
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
910
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
794
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
911
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
795
|
}
|
912
|
}
|
|
|
913
|
+
|
796
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
914
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
797
|
if err != nil {
|
915
|
if err != nil {
|
798
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
916
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -800,6 +918,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
|
@@ -800,6 +918,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC |
800
|
if cashPoolUpdated == nil {
|
918
|
if cashPoolUpdated == nil {
|
801
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
919
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
802
|
}
|
920
|
}
|
|
|
921
|
+
|
803
|
if err := transactionContext.CommitTransaction(); err != nil {
|
922
|
if err := transactionContext.CommitTransaction(); err != nil {
|
804
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
923
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
805
|
}
|
924
|
}
|
|
@@ -821,6 +940,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
|
@@ -821,6 +940,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
821
|
defer func() {
|
940
|
defer func() {
|
822
|
transactionContext.RollbackTransaction()
|
941
|
transactionContext.RollbackTransaction()
|
823
|
}()
|
942
|
}()
|
|
|
943
|
+
|
824
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
944
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
825
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
945
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
826
|
"transactionContext": transactionContext,
|
946
|
"transactionContext": transactionContext,
|
|
@@ -829,6 +949,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
|
@@ -829,6 +949,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer |
829
|
} else {
|
949
|
} else {
|
830
|
exchangeCashPersonListRepository = value
|
950
|
exchangeCashPersonListRepository = value
|
831
|
}
|
951
|
}
|
|
|
952
|
+
|
832
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId})
|
953
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"listId": getExchangeCashPersonQuery.ExchangeCashPersonId})
|
833
|
if err != nil {
|
954
|
if err != nil {
|
834
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
955
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -858,6 +979,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
@@ -858,6 +979,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
858
|
defer func() {
|
979
|
defer func() {
|
859
|
transactionContext.RollbackTransaction()
|
980
|
transactionContext.RollbackTransaction()
|
860
|
}()
|
981
|
}()
|
|
|
982
|
+
|
861
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
983
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
862
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
984
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
863
|
"transactionContext": transactionContext,
|
985
|
"transactionContext": transactionContext,
|
|
@@ -866,6 +988,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
|
@@ -866,6 +988,7 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP |
866
|
} else {
|
988
|
} else {
|
867
|
exchangeCashPersonListRepository = value
|
989
|
exchangeCashPersonListRepository = value
|
868
|
}
|
990
|
}
|
|
|
991
|
+
|
869
|
// TODO 增加总榜单查询
|
992
|
// TODO 增加总榜单查询
|
870
|
if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
|
993
|
if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
|
871
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
994
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -895,6 +1018,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -895,6 +1018,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
895
|
defer func() {
|
1018
|
defer func() {
|
896
|
transactionContext.RollbackTransaction()
|
1019
|
transactionContext.RollbackTransaction()
|
897
|
}()
|
1020
|
}()
|
|
|
1021
|
+
|
898
|
// 移除兑换素币清单
|
1022
|
// 移除兑换素币清单
|
899
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1023
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
900
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1024
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
|
@@ -904,6 +1028,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -904,6 +1028,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
904
|
} else {
|
1028
|
} else {
|
905
|
exchangeCashPersonListRepository = value
|
1029
|
exchangeCashPersonListRepository = value
|
906
|
}
|
1030
|
}
|
|
|
1031
|
+
|
|
|
1032
|
+ // 获取待删除人员
|
907
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
|
1033
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": removeExchangeCashPersonCommand.ListId})
|
908
|
if err != nil {
|
1034
|
if err != nil {
|
909
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1035
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -911,35 +1037,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -911,35 +1037,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
911
|
if person == nil {
|
1037
|
if person == nil {
|
912
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
1038
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeExchangeCashPersonCommand.ListId)))
|
913
|
}
|
1039
|
}
|
914
|
- personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
915
|
- if err != nil {
|
|
|
916
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
917
|
- }
|
|
|
918
|
- // 还原个人素币值,生成素币流水
|
|
|
919
|
- var operationSuMoneyService service.OperationSuMoneyService
|
|
|
920
|
- if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
921
|
- "transactionContext": transactionContext,
|
|
|
922
|
- }); err != nil {
|
|
|
923
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
924
|
- } else {
|
|
|
925
|
- operationSuMoneyService = value
|
|
|
926
|
- }
|
|
|
927
|
- operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
928
|
- Uid: person.EmployeeInfo.Uid,
|
|
|
929
|
- Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
930
|
- SuMoney: person.ExchangedSuMoney,
|
|
|
931
|
- OperationType: 1,
|
|
|
932
|
- OperationDescription: "素币兑换现金调整",
|
|
|
933
|
- }
|
|
|
934
|
- fmt.Print(removeExchangeCashPersonCommand.Operator, "\n")
|
|
|
935
|
- task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
936
|
- if err != nil {
|
|
|
937
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
938
|
- }
|
|
|
939
|
- if task == nil {
|
|
|
940
|
- return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
941
|
- }
|
|
|
942
|
- // 更新兑换活动兑换情况
|
1040
|
+
|
|
|
1041
|
+
|
943
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1042
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
944
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
1043
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
945
|
"transactionContext": transactionContext,
|
1044
|
"transactionContext": transactionContext,
|
|
@@ -948,6 +1047,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -948,6 +1047,8 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
948
|
} else {
|
1047
|
} else {
|
949
|
exchangeCashActivityRepository = value
|
1048
|
exchangeCashActivityRepository = value
|
950
|
}
|
1049
|
}
|
|
|
1050
|
+
|
|
|
1051
|
+ // 获取相关兑换活动
|
951
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
1052
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
952
|
if err != nil {
|
1053
|
if err != nil {
|
953
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1054
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -955,14 +1056,18 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -955,14 +1056,18 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
955
|
if activityFound == nil {
|
1056
|
if activityFound == nil {
|
956
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
1057
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
957
|
}
|
1058
|
}
|
|
|
1059
|
+
|
958
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1060
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
959
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1061
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
960
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
1062
|
ExchangedSuMoney: activityFound.ExchangedSuMoney - person.ExchangedSuMoney,
|
961
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
1063
|
ExchangedCash: activityFound.ExchangedCash + person.ExchangedCash,
|
962
|
}
|
1064
|
}
|
|
|
1065
|
+
|
|
|
1066
|
+ // 更新兑换活动
|
963
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1067
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
964
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1068
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
965
|
}
|
1069
|
}
|
|
|
1070
|
+
|
966
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1071
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
967
|
if err != nil {
|
1072
|
if err != nil {
|
968
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1073
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -970,6 +1075,35 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -970,6 +1075,35 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
970
|
if activityUpdated == nil {
|
1075
|
if activityUpdated == nil {
|
971
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
1076
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
972
|
}
|
1077
|
}
|
|
|
1078
|
+
|
|
|
1079
|
+ // 还原个人素币值,生成素币流水,描述修改成和活动相关
|
|
|
1080
|
+ var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1081
|
+ if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1082
|
+ "transactionContext": transactionContext,
|
|
|
1083
|
+ }); err != nil {
|
|
|
1084
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1085
|
+ } else {
|
|
|
1086
|
+ operationSuMoneyService = value
|
|
|
1087
|
+ }
|
|
|
1088
|
+
|
|
|
1089
|
+ operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
|
|
1090
|
+ Uid: person.EmployeeInfo.Uid,
|
|
|
1091
|
+ Operator: removeExchangeCashPersonCommand.Operator,
|
|
|
1092
|
+ SuMoney: person.ExchangedSuMoney,
|
|
|
1093
|
+ OperationType: 1,
|
|
|
1094
|
+ OperationDescription: activityFound.ExchangeActivityName + "现金调整",
|
|
|
1095
|
+ }
|
|
|
1096
|
+
|
|
|
1097
|
+ fmt.Print(removeExchangeCashPersonCommand.Operator, "\n")
|
|
|
1098
|
+
|
|
|
1099
|
+ task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
|
|
1100
|
+ if err != nil {
|
|
|
1101
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1102
|
+ }
|
|
|
1103
|
+ if task == nil {
|
|
|
1104
|
+ return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
|
|
1105
|
+ }
|
|
|
1106
|
+
|
973
|
// 更新现金池
|
1107
|
// 更新现金池
|
974
|
var employeeDao *dao.EmployeeDao
|
1108
|
var employeeDao *dao.EmployeeDao
|
975
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1109
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
|
@@ -979,6 +1113,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -979,6 +1113,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
979
|
} else {
|
1113
|
} else {
|
980
|
employeeDao = value
|
1114
|
employeeDao = value
|
981
|
}
|
1115
|
}
|
|
|
1116
|
+
|
982
|
// 获取平台现金状况
|
1117
|
// 获取平台现金状况
|
983
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1118
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
984
|
if err != nil {
|
1119
|
if err != nil {
|
|
@@ -987,8 +1122,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -987,8 +1122,10 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
987
|
if systemCashStatistics == nil {
|
1122
|
if systemCashStatistics == nil {
|
988
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1123
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
989
|
}
|
1124
|
}
|
|
|
1125
|
+
|
990
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
1126
|
systemExchangedCash := systemCashStatistics["systemExchangedCash"].(float64)
|
991
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
1127
|
systemUnExchangeCash := systemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
1128
|
+
|
992
|
// 获取平台素币状况
|
1129
|
// 获取平台素币状况
|
993
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1130
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
994
|
if err != nil {
|
1131
|
if err != nil {
|
|
@@ -997,8 +1134,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -997,8 +1134,9 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
997
|
if systemSuMoneyStatistics == nil {
|
1134
|
if systemSuMoneyStatistics == nil {
|
998
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1135
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
999
|
}
|
1136
|
}
|
|
|
1137
|
+
|
1000
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
1138
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
1001
|
- // 更新现金池
|
1139
|
+
|
1002
|
var cashPoolRepository domain.CashPoolRepository
|
1140
|
var cashPoolRepository domain.CashPoolRepository
|
1003
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
1141
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
1004
|
"transactionContext": transactionContext,
|
1142
|
"transactionContext": transactionContext,
|
|
@@ -1007,6 +1145,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1007,6 +1145,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1007
|
} else {
|
1145
|
} else {
|
1008
|
cashPoolRepository = value
|
1146
|
cashPoolRepository = value
|
1009
|
}
|
1147
|
}
|
|
|
1148
|
+
|
1010
|
// 获取现金池
|
1149
|
// 获取现金池
|
1011
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
1150
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
1012
|
"companyId": activityFound.CompanyId,
|
1151
|
"companyId": activityFound.CompanyId,
|
|
@@ -1017,6 +1156,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1017,6 +1156,7 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1017
|
if cashPools == nil {
|
1156
|
if cashPools == nil {
|
1018
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
1157
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
1019
|
}
|
1158
|
}
|
|
|
1159
|
+
|
1020
|
// 计算平均兑换汇率
|
1160
|
// 计算平均兑换汇率
|
1021
|
var newRate float64
|
1161
|
var newRate float64
|
1022
|
if systemExchangedSuMoney == 0 {
|
1162
|
if systemExchangedSuMoney == 0 {
|
|
@@ -1024,16 +1164,19 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1024,16 +1164,19 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1024
|
} else {
|
1164
|
} else {
|
1025
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
1165
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
1026
|
}
|
1166
|
}
|
1027
|
- // 更新现金池
|
1167
|
+
|
1028
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1168
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1029
|
CashPoolId: cashPools[0].CashPoolId,
|
1169
|
CashPoolId: cashPools[0].CashPoolId,
|
1030
|
ExchangedCash: systemUnExchangeCash,
|
1170
|
ExchangedCash: systemUnExchangeCash,
|
1031
|
UnExchangeCash: systemUnExchangeCash,
|
1171
|
UnExchangeCash: systemUnExchangeCash,
|
1032
|
Rate: newRate,
|
1172
|
Rate: newRate,
|
1033
|
}
|
1173
|
}
|
|
|
1174
|
+
|
|
|
1175
|
+ // 更新现金池
|
1034
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1176
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1035
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1177
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1036
|
}
|
1178
|
}
|
|
|
1179
|
+
|
1037
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
1180
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
1038
|
if err != nil {
|
1181
|
if err != nil {
|
1039
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1182
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1041,10 +1184,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
|
@@ -1041,10 +1184,17 @@ func (cashPoolService *CashPoolService) RemoveExchangeCashPerson(removeExchangeC |
1041
|
if cashPoolUpdated == nil {
|
1184
|
if cashPoolUpdated == nil {
|
1042
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1185
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1043
|
}
|
1186
|
}
|
|
|
1187
|
+
|
|
|
1188
|
+ personDeleted, err := exchangeCashPersonListRepository.Remove(person)
|
|
|
1189
|
+ if err != nil {
|
|
|
1190
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1191
|
+ } else {
|
1044
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1192
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1045
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1193
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1046
|
}
|
1194
|
}
|
|
|
1195
|
+
|
1047
|
return personDeleted, nil
|
1196
|
return personDeleted, nil
|
|
|
1197
|
+ }
|
1048
|
}
|
1198
|
}
|
1049
|
|
1199
|
|
1050
|
// 更新兑换清单
|
1200
|
// 更新兑换清单
|
|
@@ -1063,15 +1213,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1063,15 +1213,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1063
|
defer func() {
|
1213
|
defer func() {
|
1064
|
transactionContext.RollbackTransaction()
|
1214
|
transactionContext.RollbackTransaction()
|
1065
|
}()
|
1215
|
}()
|
1066
|
- // 更新兑换清单
|
|
|
1067
|
- var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1068
|
- if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1069
|
- "transactionContext": transactionContext,
|
|
|
1070
|
- }); err != nil {
|
|
|
1071
|
- return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1072
|
- } else {
|
|
|
1073
|
- operationSuMoneyService = value
|
|
|
1074
|
- }
|
1216
|
+
|
1075
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1217
|
var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository
|
1076
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1218
|
if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{
|
1077
|
"transactionContext": transactionContext,
|
1219
|
"transactionContext": transactionContext,
|
|
@@ -1080,6 +1222,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1080,6 +1222,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1080
|
} else {
|
1222
|
} else {
|
1081
|
exchangeCashPersonListRepository = value
|
1223
|
exchangeCashPersonListRepository = value
|
1082
|
}
|
1224
|
}
|
|
|
1225
|
+
|
|
|
1226
|
+ // 获取兑换清单
|
1083
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": updateExchangeCashPersonCommand.ListId})
|
1227
|
person, err := exchangeCashPersonListRepository.FindOne(map[string]interface{}{"id": updateExchangeCashPersonCommand.ListId})
|
1084
|
if err != nil {
|
1228
|
if err != nil {
|
1085
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1229
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1087,11 +1231,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1087,11 +1231,14 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1087
|
if person == nil {
|
1231
|
if person == nil {
|
1088
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
1232
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashPersonCommand.ListId)))
|
1089
|
}
|
1233
|
}
|
|
|
1234
|
+
|
|
|
1235
|
+ // TODO 更新兑换清单,个人已兑换现金计算
|
1090
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
1236
|
if err := person.Update(tool_funs.SimpleStructToMap(updateExchangeCashPersonCommand)); err != nil {
|
1091
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1237
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1092
|
}
|
1238
|
}
|
|
|
1239
|
+
|
1093
|
fmt.Print(person, "\n")
|
1240
|
fmt.Print(person, "\n")
|
1094
|
- // 更新兑换活动
|
1241
|
+
|
1095
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1242
|
var exchangeCashActivityRepository domain.ExchangeActivityRepository
|
1096
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
1243
|
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
|
1097
|
"transactionContext": transactionContext,
|
1244
|
"transactionContext": transactionContext,
|
|
@@ -1100,6 +1247,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1100,6 +1247,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1100
|
} else {
|
1247
|
} else {
|
1101
|
exchangeCashActivityRepository = value
|
1248
|
exchangeCashActivityRepository = value
|
1102
|
}
|
1249
|
}
|
|
|
1250
|
+
|
|
|
1251
|
+ // 获取相关兑换活动
|
1103
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
1252
|
activityFound, err := exchangeCashActivityRepository.FindOne(map[string]interface{}{"activityId": person.ExchangeCashActivityId})
|
1104
|
if err != nil {
|
1253
|
if err != nil {
|
1105
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1254
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1107,14 +1256,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1107,14 +1256,18 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1107
|
if activityFound == nil {
|
1256
|
if activityFound == nil {
|
1108
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
1257
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(person.ExchangeCashActivityId)))
|
1109
|
}
|
1258
|
}
|
|
|
1259
|
+
|
1110
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1260
|
updateExchangeCashActivityCommand := &command.UpdateExchangeCashActivityCommand{
|
1111
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1261
|
ExchangeCashActivityId: person.ExchangeCashActivityId,
|
1112
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1262
|
ExchangedSuMoney: activityFound.ExchangedSuMoney + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney),
|
1113
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1263
|
ExchangedCash: activityFound.ExchangedCash + (updateExchangeCashPersonCommand.ExchangedSuMoney - person.ExchangedSuMoney) * activityFound.Rate,
|
1114
|
}
|
1264
|
}
|
|
|
1265
|
+
|
|
|
1266
|
+ // 更新兑换活动
|
1115
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1267
|
if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {
|
1116
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1268
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1117
|
}
|
1269
|
}
|
|
|
1270
|
+
|
1118
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1271
|
activityUpdated, err := exchangeCashActivityRepository.Save(activityFound)
|
1119
|
if err != nil {
|
1272
|
if err != nil {
|
1120
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1273
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1122,7 +1275,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1122,7 +1275,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1122
|
if activityUpdated == nil {
|
1275
|
if activityUpdated == nil {
|
1123
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
1276
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateExchangeCashActivityCommand.ExchangeCashActivityId)))
|
1124
|
}
|
1277
|
}
|
1125
|
- // 判断是否超过平台未兑换现金
|
1278
|
+
|
|
|
1279
|
+
|
1126
|
var cashPoolDao *dao.CashPoolDao
|
1280
|
var cashPoolDao *dao.CashPoolDao
|
1127
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
1281
|
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
|
1128
|
"transactionContext": transactionContext,
|
1282
|
"transactionContext": transactionContext,
|
|
@@ -1131,6 +1285,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1131,6 +1285,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1131
|
} else {
|
1285
|
} else {
|
1132
|
cashPoolDao = value
|
1286
|
cashPoolDao = value
|
1133
|
}
|
1287
|
}
|
|
|
1288
|
+
|
|
|
1289
|
+ // 统计活动已兑换素币
|
1134
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
1290
|
activitySuMoneyStatistics, err := cashPoolDao.CalculateActivityExchangedSuMoney(activityFound.ActivityId)
|
1135
|
if err != nil {
|
1291
|
if err != nil {
|
1136
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1292
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1138,7 +1294,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1138,7 +1294,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1138
|
if activitySuMoneyStatistics == nil {
|
1294
|
if activitySuMoneyStatistics == nil {
|
1139
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
1295
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的企业")
|
1140
|
}
|
1296
|
}
|
|
|
1297
|
+
|
1141
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
1298
|
activitySuMoney := activitySuMoneyStatistics["activityExchangedSuMoney"].(float64)
|
|
|
1299
|
+
|
|
|
1300
|
+ // 统计平台现金兑换情况
|
1142
|
var employeeDao *dao.EmployeeDao
|
1301
|
var employeeDao *dao.EmployeeDao
|
1143
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1302
|
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
|
1144
|
"transactionContext": transactionContext,
|
1303
|
"transactionContext": transactionContext,
|
|
@@ -1147,21 +1306,22 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1147,21 +1306,22 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1147
|
} else {
|
1306
|
} else {
|
1148
|
employeeDao = value
|
1307
|
employeeDao = value
|
1149
|
}
|
1308
|
}
|
|
|
1309
|
+
|
1150
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1310
|
systemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1151
|
- fmt.Print(activitySuMoney , "\n")
|
|
|
1152
|
- fmt.Print(updateExchangeCashActivityCommand.ExchangeRate, "\n")
|
|
|
1153
|
- fmt.Print(systemCashStatistics["systemUnExchangeCash"].(float64), "\n")
|
1311
|
+
|
|
|
1312
|
+ // 判断是否超过平台未兑换现金
|
1154
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
1313
|
if activitySuMoney * updateExchangeCashActivityCommand.ExchangeRate > systemCashStatistics["systemUnExchangeCash"].(float64) {
|
1155
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
1314
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池的未兑换现金")
|
1156
|
}
|
1315
|
}
|
1157
|
- // 更新员工素币,生成素币兑换流水记录
|
1316
|
+
|
1158
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1317
|
operationSuMoneyCommand := &command.OperationSuMoneyCommand{
|
1159
|
Uid: person.EmployeeInfo.Uid,
|
1318
|
Uid: person.EmployeeInfo.Uid,
|
1160
|
Operator: updateExchangeCashPersonCommand.Operator,
|
1319
|
Operator: updateExchangeCashPersonCommand.Operator,
|
1161
|
SuMoney: 0,
|
1320
|
SuMoney: 0,
|
1162
|
OperationType: 0,
|
1321
|
OperationType: 0,
|
1163
|
- OperationDescription: "参与兑换素币活动",
|
1322
|
+ OperationDescription: activityUpdated.ExchangeActivityName + "素币调整",
|
1164
|
}
|
1323
|
}
|
|
|
1324
|
+
|
1165
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
1325
|
if updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney > 0 {
|
1166
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
1326
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
1167
|
operationSuMoneyCommand.OperationType = 5
|
1327
|
operationSuMoneyCommand.OperationType = 5
|
|
@@ -1169,7 +1329,17 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1169,7 +1329,17 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1169
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
1329
|
operationSuMoneyCommand.SuMoney = math.Abs(updateExchangeCashActivityCommand.ExchangedSuMoney - person.ExchangedSuMoney)
|
1170
|
operationSuMoneyCommand.OperationType = 3
|
1330
|
operationSuMoneyCommand.OperationType = 3
|
1171
|
}
|
1331
|
}
|
1172
|
- fmt.Print(updateExchangeCashPersonCommand.Operator, "\n")
|
1332
|
+
|
|
|
1333
|
+ var operationSuMoneyService service.OperationSuMoneyService
|
|
|
1334
|
+ if value, err := factory.CreateOperationSuMoneyService(map[string]interface{}{
|
|
|
1335
|
+ "transactionContext": transactionContext,
|
|
|
1336
|
+ }); err != nil {
|
|
|
1337
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
1338
|
+ } else {
|
|
|
1339
|
+ operationSuMoneyService = value
|
|
|
1340
|
+ }
|
|
|
1341
|
+
|
|
|
1342
|
+ // 更新员工素币,生成素币兑换流水记录
|
1173
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
1343
|
task, err := operationSuMoneyService.Operation(operationSuMoneyCommand.Uid, operationSuMoneyCommand.Operator, operationSuMoneyCommand.SuMoney, operationSuMoneyCommand.OperationType, operationSuMoneyCommand.OperationDescription)
|
1174
|
if err != nil {
|
1344
|
if err != nil {
|
1175
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1345
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1177,7 +1347,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1177,7 +1347,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1177
|
if task == nil {
|
1347
|
if task == nil {
|
1178
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1348
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(operationSuMoneyCommand.Uid)))
|
1179
|
}
|
1349
|
}
|
1180
|
- // 更新现金池
|
1350
|
+
|
|
|
1351
|
+ // 重新获取系统现金兑换情况
|
1181
|
newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1352
|
newSystemCashStatistics, err := employeeDao.CalculateSystemCash(activityFound.CompanyId)
|
1182
|
if err != nil {
|
1353
|
if err != nil {
|
1183
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1354
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1185,8 +1356,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1185,8 +1356,10 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1185
|
if systemCashStatistics == nil {
|
1356
|
if systemCashStatistics == nil {
|
1186
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1357
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1187
|
}
|
1358
|
}
|
|
|
1359
|
+
|
1188
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
1360
|
systemExchangedCash := newSystemCashStatistics["systemExchangedCash"].(float64)
|
1189
|
systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
1361
|
systemUnExchangeCash := newSystemCashStatistics["systemUnExchangeCash"].(float64)
|
|
|
1362
|
+
|
1190
|
// 获取平台素币状况
|
1363
|
// 获取平台素币状况
|
1191
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1364
|
systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(activityFound.CompanyId)
|
1192
|
if err != nil {
|
1365
|
if err != nil {
|
|
@@ -1195,8 +1368,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1195,8 +1368,9 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1195
|
if systemSuMoneyStatistics == nil {
|
1368
|
if systemSuMoneyStatistics == nil {
|
1196
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1369
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司")
|
1197
|
}
|
1370
|
}
|
|
|
1371
|
+
|
1198
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
1372
|
systemExchangedSuMoney := systemSuMoneyStatistics["systemExchangedSuMoney"].(float64)
|
1199
|
- // 更新现金池
|
1373
|
+
|
1200
|
var cashPoolRepository domain.CashPoolRepository
|
1374
|
var cashPoolRepository domain.CashPoolRepository
|
1201
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
1375
|
if value, err := factory.CreateCashPoolRepository(map[string] interface{} {
|
1202
|
"transactionContext": transactionContext,
|
1376
|
"transactionContext": transactionContext,
|
|
@@ -1205,6 +1379,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1205,6 +1379,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1205
|
} else {
|
1379
|
} else {
|
1206
|
cashPoolRepository = value
|
1380
|
cashPoolRepository = value
|
1207
|
}
|
1381
|
}
|
|
|
1382
|
+
|
1208
|
// 获取现金池
|
1383
|
// 获取现金池
|
1209
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
1384
|
_, cashPools, err := cashPoolRepository.Find(map[string]interface{}{
|
1210
|
"companyId": activityFound.CompanyId,
|
1385
|
"companyId": activityFound.CompanyId,
|
|
@@ -1215,6 +1390,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1215,6 +1390,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1215
|
if cashPools == nil {
|
1390
|
if cashPools == nil {
|
1216
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
1391
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(activityFound.CompanyId)))
|
1217
|
}
|
1392
|
}
|
|
|
1393
|
+
|
1218
|
// 计算平均兑换汇率
|
1394
|
// 计算平均兑换汇率
|
1219
|
var newRate float64
|
1395
|
var newRate float64
|
1220
|
if systemExchangedSuMoney == 0 {
|
1396
|
if systemExchangedSuMoney == 0 {
|
|
@@ -1222,16 +1398,19 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1222,16 +1398,19 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1222
|
} else {
|
1398
|
} else {
|
1223
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
1399
|
newRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", systemExchangedCash / systemExchangedSuMoney), 64)
|
1224
|
}
|
1400
|
}
|
1225
|
- // 更新现金池
|
1401
|
+
|
1226
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1402
|
updateCashPoolCommand := &command.UpdateCashPoolCommand{
|
1227
|
CashPoolId: cashPools[0].CashPoolId,
|
1403
|
CashPoolId: cashPools[0].CashPoolId,
|
1228
|
ExchangedCash: systemUnExchangeCash,
|
1404
|
ExchangedCash: systemUnExchangeCash,
|
1229
|
UnExchangeCash: systemUnExchangeCash,
|
1405
|
UnExchangeCash: systemUnExchangeCash,
|
1230
|
Rate: newRate,
|
1406
|
Rate: newRate,
|
1231
|
}
|
1407
|
}
|
|
|
1408
|
+
|
|
|
1409
|
+ // 更新现金池
|
1232
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1410
|
if err := cashPools[0].Update(tool_funs.SimpleStructToMap(updateCashPoolCommand)); err != nil {
|
1233
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1411
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
1234
|
}
|
1412
|
}
|
|
|
1413
|
+
|
1235
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
1414
|
cashPoolUpdated, err := cashPoolRepository.Save(cashPools[0])
|
1236
|
if err != nil {
|
1415
|
if err != nil {
|
1237
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
1416
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
@@ -1246,6 +1425,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
|
@@ -1246,6 +1425,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC |
1246
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1425
|
if err := transactionContext.CommitTransaction(); err != nil {
|
1247
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1426
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
1248
|
}
|
1427
|
}
|
|
|
1428
|
+
|
1249
|
return personUpdated, nil
|
1429
|
return personUpdated, nil
|
1250
|
}
|
1430
|
}
|
1251
|
}
|
1431
|
}
|