充值功能 (未完成)
This commit is contained in:
parent
9c9db1c79b
commit
07bed0ab0d
|
|
@ -5,9 +5,12 @@ import com.github.binarywang.wxpay.config.WxPayConfig;
|
|||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import com.mdd.common.entity.setting.DevPayConfig;
|
||||
import com.mdd.common.entity.system.SystemConfig;
|
||||
import com.mdd.common.mapper.setting.DevPayConfigMapper;
|
||||
import com.mdd.common.mapper.system.SystemConfigMapper;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.common.util.MapUtils;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
|
|
@ -25,6 +28,9 @@ public class WxPayConfiguration {
|
|||
@Resource
|
||||
DevPayConfigMapper devPayConfigMapper;
|
||||
|
||||
@Resource
|
||||
SystemConfigMapper systemConfigMapper;
|
||||
|
||||
/**
|
||||
* 微信小程序支付配置
|
||||
*
|
||||
|
|
@ -39,8 +45,13 @@ public class WxPayConfiguration {
|
|||
.eq("way", 2)
|
||||
.last("limit 1"));
|
||||
|
||||
SystemConfig systemConfig = systemConfigMapper.selectOne(new QueryWrapper<SystemConfig>()
|
||||
.eq("type", "mp_channel")
|
||||
.eq("name", "appId")
|
||||
.last("limit 1"));
|
||||
|
||||
Map<String, String> params = MapUtils.jsonToMap(config.getParams().toString());
|
||||
String appId = ConfigUtils.get("mp_channel", "appId", "");
|
||||
String appId = StringUtils.isNull(systemConfig) ? "" : systemConfig.getValue();
|
||||
String mchId = params.get("mch_id");
|
||||
String paySignKey = params.get("pay_sign_key");
|
||||
byte[] privateKey = params.getOrDefault("private_key", "").getBytes();
|
||||
|
|
@ -72,8 +83,13 @@ public class WxPayConfiguration {
|
|||
.eq("way", 2)
|
||||
.last("limit 1"));
|
||||
|
||||
SystemConfig systemConfig = systemConfigMapper.selectOne(new QueryWrapper<SystemConfig>()
|
||||
.eq("type", "oa_channel")
|
||||
.eq("name", "appId")
|
||||
.last("limit 1"));
|
||||
|
||||
Map<String, String> params = MapUtils.jsonToMap(config.getParams().toString());
|
||||
String appId = ConfigUtils.get("oa_channel", "appId", "");
|
||||
String appId = StringUtils.isNull(systemConfig) ? "" : systemConfig.getValue();
|
||||
String mchId = params.get("mch_id");
|
||||
String paySignKey = params.get("pay_sign_key");
|
||||
byte[] privateKey = params.getOrDefault("private_key", "").getBytes();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
package com.mdd.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@ApiModel("充值订单实体类")
|
||||
public class RechargeOrder {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
@ApiModelProperty("ID")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty("订单编号")
|
||||
private String orderSn;
|
||||
|
||||
@ApiModelProperty("支付编号")
|
||||
private String paySn;
|
||||
|
||||
@ApiModelProperty("支付方式: [2=微信支付, 3=支付宝支付]")
|
||||
private Integer payWay;
|
||||
|
||||
@ApiModelProperty("支付状态: [0=待支付, 1=已支付]")
|
||||
private Integer payStatus;
|
||||
|
||||
@ApiModelProperty("支付时间")
|
||||
private Long payTime;
|
||||
|
||||
@ApiModelProperty("充值金额")
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
@ApiModelProperty("下单终端")
|
||||
private Integer orderTerminal;
|
||||
|
||||
@ApiModelProperty("交易流水")
|
||||
private String transactionId;
|
||||
|
||||
@ApiModelProperty("退款状态: [0=未退款 , 1=已退款]")
|
||||
private Integer refundStatus;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private Long updateTime;
|
||||
|
||||
@ApiModelProperty("删除时间")
|
||||
private Long deleteTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.mdd.common.mapper;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.RechargeOrder;
|
||||
|
||||
/**
|
||||
* 充值订单Mapper
|
||||
*/
|
||||
public interface RechargeOrderMapper extends IBaseMapper<RechargeOrder> {
|
||||
}
|
||||
|
|
@ -1,25 +1,47 @@
|
|||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IRechargeService;
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.models.auth.In;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/recharge")
|
||||
@Api(tags = "充值管理")
|
||||
public class RechargeController {
|
||||
|
||||
@Resource
|
||||
IRechargeService iRechargeService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult<Object> list() {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @param rechargeValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@PostMapping("/placeOrder")
|
||||
public AjaxResult<Object> placeOrder() {
|
||||
return AjaxResult.success();
|
||||
public AjaxResult<Object> placeOrder(@Validated @RequestBody RechargeValidate rechargeValidate) {
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
|
||||
Map<String, Object> result = iRechargeService.placeOrder(userId, terminal, rechargeValidate);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import io.swagger.models.auth.In;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 充值余额接口服务类
|
||||
*/
|
||||
public interface IRechargeService {
|
||||
|
||||
Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.entity.RechargeOrder;
|
||||
import com.mdd.common.mapper.RechargeOrderMapper;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import com.mdd.front.service.IRechargeService;
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 充值余额服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class RechargeServiceImpl implements IRechargeService {
|
||||
|
||||
@Resource
|
||||
RechargeOrderMapper rechargeOrderMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate) {
|
||||
RechargeOrder order = new RechargeOrder();
|
||||
order.setUserId(userId);
|
||||
order.setOrderTerminal(terminal);
|
||||
order.setOrderSn(this.randMakeOrderSn());
|
||||
order.setPayWay(rechargeValidate.getPayWay());
|
||||
order.setPayStatus(0);
|
||||
order.setRefundStatus(0);
|
||||
order.setOrderAmount(rechargeValidate.getOrderAmount());
|
||||
order.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
order.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
order.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
rechargeOrderMapper.insert(order);
|
||||
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("id", order.getId());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一订单号
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
private String randMakeOrderSn() {
|
||||
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "YmdHis");
|
||||
String sn;
|
||||
while (true) {
|
||||
sn = date + ToolUtils.randomInt(12);
|
||||
RechargeOrder snModel = rechargeOrderMapper.selectOne(
|
||||
new QueryWrapper<RechargeOrder>()
|
||||
.select("id")
|
||||
.eq("sn", sn)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.mdd.front.validate;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@ApiModel("新用户更新信息参数")
|
||||
public class RechargeValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "payWay参数缺失")
|
||||
private Integer payWay;
|
||||
|
||||
@NotNull(message = "orderAmount参数缺失")
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue