@@ -11,7 +11,11 @@ import {
11
11
} from '@nestjs/common'
12
12
import { ApiBearerAuth , ApiOperation , ApiTags } from '@nestjs/swagger'
13
13
import { IRequest , IResponse } from 'src/utils/interface'
14
- import { ApiResponseObject , ResponseUtil } from 'src/utils/response'
14
+ import {
15
+ ApiResponseArray ,
16
+ ApiResponseObject ,
17
+ ResponseUtil ,
18
+ } from 'src/utils/response'
15
19
import { AccountService } from './account.service'
16
20
import {
17
21
CreateChargeOrderDto ,
@@ -35,6 +39,7 @@ import { SystemDatabase } from 'src/system-database'
35
39
import { Account } from './entities/account'
36
40
import { AccountTransaction } from './entities/account-transaction'
37
41
import { JwtAuthGuard } from 'src/authentication/jwt.auth.guard'
42
+ import { AccountChargeReward } from './entities/account-charge-reward'
38
43
39
44
@ApiTags ( 'Account' )
40
45
@Controller ( 'accounts' )
@@ -112,6 +117,18 @@ export class AccountController {
112
117
} )
113
118
}
114
119
120
+ /**
121
+ * Get charge reward list
122
+ */
123
+ @ApiOperation ( { summary : 'Get charge reward list' } )
124
+ @ApiResponseArray ( AccountChargeReward )
125
+ @UseGuards ( JwtAuthGuard )
126
+ @Get ( 'charge-reward' )
127
+ async getChargeRewardList ( ) {
128
+ const rewards = await this . accountService . findAllChargeRewards ( )
129
+ return ResponseUtil . ok ( rewards )
130
+ }
131
+
115
132
/**
116
133
* WeChat payment notify
117
134
*/
@@ -178,12 +195,23 @@ export class AccountController {
178
195
return
179
196
}
180
197
181
- // get & update account balance
198
+ // get max reward
199
+ const reward = await db
200
+ . collection < AccountChargeReward > ( 'AccountChargeReward' )
201
+ . findOne (
202
+ {
203
+ amount : { $lte : order . amount } ,
204
+ } ,
205
+ { sort : { amount : - 1 } } ,
206
+ )
207
+
208
+ const realAmount = reward ? reward . amount + order . amount : order . amount
209
+
182
210
const ret = await db
183
211
. collection < Account > ( 'Account' )
184
212
. findOneAndUpdate (
185
213
{ _id : order . accountId } ,
186
- { $inc : { balance : order . amount } } ,
214
+ { $inc : { balance : realAmount } } ,
187
215
{ session, returnDocument : 'after' } ,
188
216
)
189
217
@@ -194,6 +222,7 @@ export class AccountController {
194
222
{
195
223
accountId : order . accountId ,
196
224
amount : order . amount ,
225
+ reward : reward ?. reward ,
197
226
balance : ret . value . balance ,
198
227
message : 'Recharge by WeChat Pay' ,
199
228
orderId : order . _id ,
0 commit comments