|
@@ -1,4 +1,5 @@
|
|
|
package com.txz.cif.web;
|
|
|
+
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
@@ -14,6 +15,7 @@ import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.txz.cif.core.AuthService;
|
|
|
import com.txz.cif.web.para.RecordParam;
|
|
|
+import com.txz.cif.web.vo.PaymentPriceVO;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -25,198 +27,212 @@ import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
-* Created by CodeGenerator on 2025/07/15.
|
|
|
-*/
|
|
|
+ * Created by CodeGenerator on 2025/07/15.
|
|
|
+ */
|
|
|
@Api(tags = "[api]充值记录")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/recharge/record")
|
|
|
public class RechargeRecordApiController {
|
|
|
-
|
|
|
- private static Logger log = LoggerFactory.getLogger(RechargeRecordApiController.class);
|
|
|
-
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(RechargeRecordApiController.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private RechargeRecordService rechargeRecordService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private GoodsService goodsService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private AuthService authService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private BizLogService bizLogService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SequenceService sequenceService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private PaymentChannelService paymentChannelService;
|
|
|
-
|
|
|
- @GetMapping("/goodsList")
|
|
|
- @ApiOperation(value = "充值商品",httpMethod = "GET")
|
|
|
- public Result<List<Goods>> goodsList() {
|
|
|
- Condition c = new Condition(Goods.class);
|
|
|
- c.createCriteria().andEqualTo("status",1);
|
|
|
- List<Goods> goods = goodsService.findByCondition(c);
|
|
|
- return ResultGenerator.genSuccessResult(goods);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @GetMapping("/add")
|
|
|
- @ApiOperation(value = "创建充值订单",httpMethod = "GET")
|
|
|
- public Result add(@RequestParam Integer goodsId,@RequestParam Long methodId, HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if(goodsId == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
- try {
|
|
|
- Goods goods = goodsService.findById(goodsId);
|
|
|
- if (goods == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
- }
|
|
|
- if (goods.getStatus() != 1){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.STATUS_IS_NULL);
|
|
|
- }
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (user == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
- }
|
|
|
- PaymentChannel paymentChannel = paymentChannelService.paymentChannelReturnsByWeight(methodId);
|
|
|
-
|
|
|
-// long id = IdUtil.getSnowflake(1, 1).nextId();
|
|
|
- String orderNo = sequenceService.genSerialNumber("recharge_rule",null);
|
|
|
- RechargeRecord rechargeRecord = RechargeRecord.builder()
|
|
|
- .discount(goods.getDiscount())
|
|
|
- .amount(goods.getAmount())
|
|
|
- .currency("BDT").userId(userId)
|
|
|
- .userName(user.getName()).userPhone(user.getPhoneNo())
|
|
|
- .bank(user.getBank())
|
|
|
- .methodId(methodId)
|
|
|
- .channelId(paymentChannel == null? null:paymentChannel.getId())
|
|
|
- .bankAccount(user.getBankAccount())
|
|
|
- .bankAccountName(user.getBankAccountName())
|
|
|
- .orderNo(orderNo).goodsId(goodsId)
|
|
|
- .createUser(user.getName())
|
|
|
- .status(1).createTime(DateUtil.date())
|
|
|
- .build();
|
|
|
- rechargeRecordService.save(rechargeRecord);
|
|
|
- //TODO 发起第三方支付
|
|
|
-
|
|
|
-
|
|
|
- try{
|
|
|
- //新增日志
|
|
|
- bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
- .type(1).createTime(DateUtil.date()).createUser(user.getName())
|
|
|
- .memo("提交充值订单").build());
|
|
|
- }catch (Exception e){
|
|
|
- log.error("新增充值提交订单日志失败",e);
|
|
|
- }
|
|
|
- return ResultGenerator.genSuccessResult(rechargeRecord);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("新增对象操作异常e:{}",e);
|
|
|
- return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GoodsService goodsService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AuthService authService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizLogService bizLogService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SequenceService sequenceService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PaymentChannelService paymentChannelService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PaymentMethodService paymentMethodService;
|
|
|
+
|
|
|
+ @GetMapping("/goodsList/{methodId:^\\d+$}")
|
|
|
+ @ApiOperation(value = "充值商品", httpMethod = "GET")
|
|
|
+ public Result<PaymentPriceVO> goodsList(@PathVariable("methodId") Long methodId) {
|
|
|
+ Condition c = new Condition(Goods.class);
|
|
|
+ c.createCriteria().andEqualTo("status", 1);
|
|
|
+ c.createCriteria().andEqualTo("methodId", methodId);
|
|
|
+ c.setOrderByClause("amount asc");
|
|
|
+ List<Goods> goods = goodsService.findByCondition(c);
|
|
|
+
|
|
|
+ PaymentMethod paymentMethod = paymentMethodService.findById(methodId);
|
|
|
+ return Result.success(PaymentPriceVO.builder()
|
|
|
+ .list(goods)
|
|
|
+ .miniPrice(paymentMethod.getMiniPrice())
|
|
|
+ .maxPrice(paymentMethod.getMaxPrice())
|
|
|
+ .build()
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
- @GetMapping("/callback")
|
|
|
- @ApiOperation(value = "三方回调",httpMethod = "GET")
|
|
|
- public Result<RechargeRecord> detail(@RequestParam String data) {
|
|
|
- //TODO 回调成功
|
|
|
- JSONObject json = JSONUtil.parseObj(data);
|
|
|
- String orderNo = json.getStr("orderNo");
|
|
|
- RechargeRecord record = rechargeRecordService.findBy("orderNo", orderNo);
|
|
|
- if (record == null){
|
|
|
- return ResultGenerator.genFailResult("订单未找到");
|
|
|
- }
|
|
|
- if (StrUtil.equals("1",json.getStr("status"))){
|
|
|
- rechargeRecordService.success(record);
|
|
|
- } else {
|
|
|
- rechargeRecordService.fail(record);
|
|
|
- }
|
|
|
- try{
|
|
|
- //新增充值回调日志
|
|
|
- bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
- .type(3).createTime(DateUtil.date()).createUser("第三方")
|
|
|
- .memo("充值回调").build());
|
|
|
- }catch (Exception e){
|
|
|
- log.error("新增充值回调日志失败",e);
|
|
|
- }
|
|
|
- return ResultGenerator.genSuccessResult();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/add")
|
|
|
+ @ApiOperation(value = "创建充值订单", httpMethod = "GET")
|
|
|
+ public Result add(@RequestParam BigDecimal amount, @RequestParam Long methodId, HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ // if (goodsId == null) {
|
|
|
+ // return ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ // }
|
|
|
+ try {
|
|
|
+ // Goods goods = goodsService.findById(goodsId);
|
|
|
+ // if (goods == null) {
|
|
|
+ // return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
+ // }
|
|
|
+ // if (goods.getStatus() != 1) {
|
|
|
+ // return ResultGenerator.genFailResult(ResultCode.STATUS_IS_NULL);
|
|
|
+ // }
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ PaymentChannel paymentChannel = paymentChannelService.paymentChannelReturnsByWeight(methodId);
|
|
|
+
|
|
|
+ // long id = IdUtil.getSnowflake(1, 1).nextId();
|
|
|
+ String orderNo = sequenceService.genSerialNumber("recharge_rule", null);
|
|
|
+ RechargeRecord rechargeRecord = RechargeRecord.builder()
|
|
|
+ .discount(BigDecimal.ZERO)
|
|
|
+ .amount(amount)
|
|
|
+ .currency("BDT").userId(userId)
|
|
|
+ .userName(user.getName()).userPhone(user.getPhoneNo())
|
|
|
+ .bank(user.getBank())
|
|
|
+ .methodId(methodId)
|
|
|
+ .channelId(paymentChannel == null ? null : paymentChannel.getId())
|
|
|
+ .bankAccount(user.getBankAccount())
|
|
|
+ .bankAccountName(user.getBankAccountName())
|
|
|
+ .orderNo(orderNo)
|
|
|
+ .goodsId(-1)
|
|
|
+ .createUser(user.getName())
|
|
|
+ .status(1).createTime(DateUtil.date())
|
|
|
+ .build();
|
|
|
+ rechargeRecordService.save(rechargeRecord);
|
|
|
+ // TODO 发起第三方支付
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 新增日志
|
|
|
+ bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
+ .type(1).createTime(DateUtil.date()).createUser(user.getName())
|
|
|
+ .memo("提交充值订单").build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增充值提交订单日志失败", e);
|
|
|
+ }
|
|
|
+ return ResultGenerator.genSuccessResult(rechargeRecord);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/callback")
|
|
|
+ @ApiOperation(value = "三方回调", httpMethod = "GET")
|
|
|
+ public Result<RechargeRecord> detail(@RequestParam String data) {
|
|
|
+ // TODO 回调成功
|
|
|
+ JSONObject json = JSONUtil.parseObj(data);
|
|
|
+ String orderNo = json.getStr("orderNo");
|
|
|
+ RechargeRecord record = rechargeRecordService.findBy("orderNo", orderNo);
|
|
|
+ if (record == null) {
|
|
|
+ return ResultGenerator.genFailResult("订单未找到");
|
|
|
+ }
|
|
|
+ if (StrUtil.equals("1", json.getStr("status"))) {
|
|
|
+ rechargeRecordService.success(record);
|
|
|
+ } else {
|
|
|
+ rechargeRecordService.fail(record);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 新增充值回调日志
|
|
|
+ bizLogService.save(BizLog.builder().bizType(1).bizNo(orderNo)
|
|
|
+ .type(3).createTime(DateUtil.date()).createUser("第三方")
|
|
|
+ .memo("充值回调").build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增充值回调日志失败", e);
|
|
|
+ }
|
|
|
+ return ResultGenerator.genSuccessResult();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/detail")
|
|
|
- @ApiOperation(value = "rechargeRecord获取详情",httpMethod = "GET")
|
|
|
+ @ApiOperation(value = "rechargeRecord获取详情", httpMethod = "GET")
|
|
|
public Result<RechargeRecord> detail(@RequestParam Integer id) {
|
|
|
- if(id == null){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
|
|
|
- }
|
|
|
-
|
|
|
- RechargeRecord rechargeRecord = null;
|
|
|
- try {
|
|
|
- rechargeRecord = rechargeRecordService.findById(id);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询对象操作异常e:{}",e);
|
|
|
- return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
+ if (id == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ RechargeRecord rechargeRecord = null;
|
|
|
+ try {
|
|
|
+ rechargeRecord = rechargeRecordService.findById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
return ResultGenerator.genSuccessResult(rechargeRecord);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@PostMapping("/list")
|
|
|
- @ApiOperation(value = "rechargeRecord获取列表",httpMethod = "POST")
|
|
|
- public Result<List<RechargeRecord>> list(@RequestBody RecordParam param, HttpServletRequest request) {
|
|
|
- Long userId = authService.getTokenUserId(request);
|
|
|
- if (userId == null ){
|
|
|
- ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
- }
|
|
|
- PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
-
|
|
|
- Condition condition = new Condition(RechargeRecord.class);
|
|
|
- Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("userId", userId);
|
|
|
- if (StrUtil.isNotBlank(param.getChannel())){
|
|
|
- criteria.andEqualTo("channel", param.getChannel());
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(param.getUserName())){
|
|
|
- criteria.andEqualTo("userName", param.getUserName());
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(param.getUserPhone())){
|
|
|
- criteria.andEqualTo("userPhone", param.getUserPhone());
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(param.getOrderNo())){
|
|
|
- criteria.andEqualTo("orderNo", param.getOrderNo());
|
|
|
- }
|
|
|
- if (param.getStatus() != null){
|
|
|
- criteria.andEqualTo("status", param.getStatus());
|
|
|
- }
|
|
|
- if (param.getTimeType() != null){
|
|
|
- if (param.getTimeType() ==1 ){
|
|
|
- if (StrUtil.isNotBlank(param.getStartTime())){
|
|
|
- criteria.andBetween("createTime", param.getStartTime(),param.getEndTime());
|
|
|
- }
|
|
|
- } else if (param.getTimeType() ==2 ){
|
|
|
- if (StrUtil.isNotBlank(param.getStartTime())){
|
|
|
- criteria.andBetween("successTime", param.getStartTime(),param.getEndTime());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- PageInfo pageInfo = null;
|
|
|
- try {
|
|
|
- condition.setOrderByClause("create_time desc");
|
|
|
- List<RechargeRecord> list = rechargeRecordService.findByCondition(condition);
|
|
|
- pageInfo = new PageInfo(list);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询对象操作异常e:{}",e);
|
|
|
- return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
- }
|
|
|
+ @ApiOperation(value = "rechargeRecord获取列表", httpMethod = "POST")
|
|
|
+ public Result<List<RechargeRecord>> list(@RequestBody RecordParam param, HttpServletRequest request) {
|
|
|
+ Long userId = authService.getTokenUserId(request);
|
|
|
+ if (userId == null) {
|
|
|
+ ResultGenerator.genFailResult(ResultCode.OAUTH_INVALID_ACCESS_TOKEN);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
+
|
|
|
+ Condition condition = new Condition(RechargeRecord.class);
|
|
|
+ Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("userId", userId);
|
|
|
+ if (StrUtil.isNotBlank(param.getChannel())) {
|
|
|
+ criteria.andEqualTo("channel", param.getChannel());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(param.getUserName())) {
|
|
|
+ criteria.andEqualTo("userName", param.getUserName());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(param.getUserPhone())) {
|
|
|
+ criteria.andEqualTo("userPhone", param.getUserPhone());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(param.getOrderNo())) {
|
|
|
+ criteria.andEqualTo("orderNo", param.getOrderNo());
|
|
|
+ }
|
|
|
+ if (param.getStatus() != null) {
|
|
|
+ criteria.andEqualTo("status", param.getStatus());
|
|
|
+ }
|
|
|
+ if (param.getTimeType() != null) {
|
|
|
+ if (param.getTimeType() == 1) {
|
|
|
+ if (StrUtil.isNotBlank(param.getStartTime())) {
|
|
|
+ criteria.andBetween("createTime", param.getStartTime(), param.getEndTime());
|
|
|
+ }
|
|
|
+ } else if (param.getTimeType() == 2) {
|
|
|
+ if (StrUtil.isNotBlank(param.getStartTime())) {
|
|
|
+ criteria.andBetween("successTime", param.getStartTime(), param.getEndTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ condition.setOrderByClause("create_time desc");
|
|
|
+ List<RechargeRecord> list = rechargeRecordService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
+ }
|
|
|
}
|