package com.hnust.malldemo.controller;
import com.hnust.malldemo.common.BaseResponse;
import com.hnust.malldemo.common.ErrorCode;
import com.hnust.malldemo.model.dto.orders.OrdersAddRequest;
import com.hnust.malldemo.model.dto.wallet.WalletChangeRequest;
import com.hnust.malldemo.model.dto.wallet.WalletQueryRequest;
import com.hnust.malldemo.model.dto.wallet.WithdrawalRequest;
import com.hnust.malldemo.model.entity.Records;
import com.hnust.malldemo.model.vo.RecordVO;
import com.hnust.malldemo.model.vo.WalletVO;
import com.hnust.malldemo.service.BankService;
import com.hnust.malldemo.service.OrdersService;
import com.hnust.malldemo.service.RecordsService;
import com.hnust.malldemo.service.WalletService;
import com.hnust.malldemo.utils.ResultUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author 兰利军
*/
@RestController
@RequestMapping("/wallet")
public class ConsumeController {
@Resource
private WalletService walletService;
@Resource
private RecordsService recordsService;
@Resource
private OrdersService ordersService;
/**
* 查询用户钱包余额
* @param walletQueryRequest
* @return
*/
@PostMapping("/searchWalletBalance")
public BaseResponse<WalletVO> searchUserBalance(@RequestBody WalletQueryRequest walletQueryRequest){
String userName = walletQueryRequest.getUserName();
String payPassword = walletQueryRequest.getPayPassword();
WalletVO walletVO = walletService.searchUserBalance(userName, payPassword);
return walletVO != null ? ResultUtils.success(walletVO) : ResultUtils.error(ErrorCode.PARAMS_ERROR,"用户不存在");
}
/**
* 用户钱包消费和退款,type表示,0-消费,1-退款
* @param walletChangeRequest
* @return
*/
@PostMapping("/consume")
public BaseResponse<String> balanceChange(@RequestBody WalletChangeRequest walletChangeRequest){
// 用户名
String username = walletChangeRequest.getUsername();
// 类型,0-消费,1-退款
Integer type = walletChangeRequest.getType();
// 对应金额
Double money = walletChangeRequest.getMoney();
Boolean isSuccessful = walletService.balanceChange(username,type,money);
return isSuccessful ? ResultUtils.success(null) : ResultUtils.error(ErrorCode.SYSTEM_ERROR,"钱包余额不足");
}
/**
* 查询用户钱包金额变动
* @param userName
* @return
*/
@GetMapping("/searchRecords/{userName}")
public BaseResponse<List<RecordVO>> searchRecords(@PathVariable String userName){
List<RecordVO> recordsList = recordsService.searchRecords(userName);
return ResultUtils.success(recordsList);
}
/**
* 订单记录
* @param ordersAddRequest
* @return
*/
@PostMapping("/addOrders")
public BaseResponse<Records> addOrder(@RequestBody OrdersAddRequest ordersAddRequest){
Boolean successful = ordersService.addOrder(ordersAddRequest);
return successful ? ResultUtils.success(null) : ResultUtils.error(ErrorCode.OPERATION_ERROR,"操作失败,请稍后再试!");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java后端面试题.zip (37个子文件)
open_1111111111111111111111150415202545243254
pom.xml 2KB
src
sql
db.sql 3KB
test
java
com
hnust
malldemo
MallDemoApplicationTests.java 221B
main
resources
mapper
WalletMapper.xml 1KB
RecordsMapper.xml 874B
OrdersMapper.xml 903B
BankMapper.xml 1KB
application.yml 496B
java
com
hnust
malldemo
MallDemoApplication.java 327B
mapper
RecordsMapper.java 440B
BankMapper.java 413B
OrdersMapper.java 423B
WalletMapper.java 624B
controller
ConsumeController.java 3KB
utils
ResultUtils.java 1KB
service
OrdersService.java 593B
WalletService.java 886B
impl
WalletServiceImpl.java 2KB
OrdersServiceImpl.java 1KB
BankServiceImpl.java 542B
RecordsServiceImpl.java 2KB
BankService.java 385B
RecordsService.java 627B
common
BaseResponse.java 750B
ErrorCode.java 919B
model
entity
Records.java 811B
Wallet.java 876B
Orders.java 967B
Bank.java 951B
dto
orders
OrdersAddRequest.java 387B
wallet
WithdrawalRequest.java 473B
WalletChangeRequest.java 346B
WalletQueryRequest.java 281B
vo
WalletVO.java 177B
RecordVO.java 530B
exception
GlobalExceptionHandler.java 1KB
BusinessException.java 819B
共 37 条
- 1
资源评论
极致人生-010
- 粉丝: 4379
- 资源: 3086
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功