Commit ec816c7d by 吕明尚

新增权益订单下单和扫呗调用

parent d00b3add
......@@ -9,7 +9,8 @@ import share.common.utils.StringUtils;
public enum OrderTypeEnum {
RESERVER(1,"reserver","预定"),
RENEW(2,"renew","续费"),
RECHARGE(3,"recharge","充值");
RECHARGE(3, "recharge", "充值"),
RIGHTS(4, "rights", "权益");
private Integer code;
private String value;
......
package share.web.controller.system;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import share.common.annotation.Log;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.core.domain.R;
import share.common.core.page.TableDataInfo;
import share.common.core.redis.RedisUtil;
import share.common.enums.BusinessType;
import share.common.utils.JsonConvertUtil;
import share.common.utils.poi.ExcelUtil;
import share.system.domain.EquityMembersOrder;
import share.system.domain.vo.EquityMembersOrderVo;
import share.system.request.CreateEquityMembersRequest;
import share.system.response.RechargePayResultResponse;
import share.system.service.EquityMembersOrderService;
import javax.servlet.http.HttpServletResponse;
......@@ -21,11 +28,14 @@ import java.util.List;
* @author wuwenlong
* @date 2024-06-24
*/
@Slf4j
@RestController
@RequestMapping("/equityMembersOrder")
public class EquityMembersOrderController extends BaseController {
@Autowired
private EquityMembersOrderService equityMembersOrderService;
@Autowired
private RedisUtil redisUtil;
/**
* 查询权益会员订单列表
......@@ -82,4 +92,17 @@ public class EquityMembersOrderController extends BaseController {
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(equityMembersOrderService.deleteEquityMembersOrderByIds(ids));
}
@Log(title = "权益会员下单", businessType = BusinessType.DELETE)
@PostMapping("/createEquityMembers")
public R<RechargePayResultResponse> createOrder(@RequestBody @Validated CreateEquityMembersRequest request) {
if ("1".equals(redisUtil.frontInOutLogSwitch())) {
log.info("SOrderController method preOrder 入参 {}", JsonConvertUtil.write2JsonStr(request));
}
RechargePayResultResponse response = equityMembersOrderService.createEquityMembers(request);
if ("1".equals(redisUtil.frontInOutLogSwitch())) {
log.info("SOrderController method preOrder 出参 {}", JsonConvertUtil.write2JsonStr(response));
}
return R.ok(response);
}
}
......@@ -92,8 +92,8 @@ public class RechargeController extends BaseController {
return toAjax(rechargeService.deleteRechargeByIds(ids));
}
@Log(title = "充值", businessType = BusinessType.DELETE)
@PostMapping("/recharge")
@Log(title = "充值下单", businessType = BusinessType.DELETE)
@PostMapping("/createRecharge")
public R<RechargePayResultResponse> createOrder(@RequestBody @Validated CreateRechargeRequest request) {
if ("1".equals(redisUtil.frontInOutLogSwitch())) {
log.info("SOrderController method preOrder 入参 {}", JsonConvertUtil.write2JsonStr(request));
......
......@@ -75,7 +75,7 @@ public class EquityMembersOrder extends BaseEntity {
* 支付状态(0:未支付,1:已支付)
*/
@Excel(name = "支付状态(0:未支付,1:已支付)")
private Long payStatus;
private Integer payStatus;
/**
* 支付时间
......
......@@ -23,7 +23,7 @@ public class AttachVo {
this.userId = userId;
}
@ApiModelProperty(value = "业务类型, 订单 = order, 充值 = recharge", required = true)
@ApiModelProperty(value = "业务类型, 订单 = order, 充值 = recharge, 权益 = ", required = true)
private String type = "order";
@ApiModelProperty(value = "用户id", required = true)
......
package share.system.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "CreateEquityMembersRequest对象", description = "下单请求对象")
public class CreateEquityMembersRequest {
@ApiModelProperty(value = "支付类型(1:微信,2:支付宝)", required = true)
@NotNull(message = "支付类型不能为空")
private Integer payType;
@ApiModelProperty(value = "权益会员订单配置id")
@NotNull(message = "权益会员订单配置id")
private Long equityMembersConfigId;
}
......@@ -3,6 +3,8 @@ package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.EquityMembersOrder;
import share.system.domain.vo.EquityMembersOrderVo;
import share.system.request.CreateEquityMembersRequest;
import share.system.response.RechargePayResultResponse;
import java.util.List;
......@@ -60,4 +62,6 @@ public interface EquityMembersOrderService extends IService<EquityMembersOrder>
* @return 结果
*/
public int deleteEquityMembersOrderById(Long id);
RechargePayResultResponse createEquityMembers(CreateEquityMembersRequest request);
}
package share.system.service;
import share.system.domain.EquityMembersOrder;
import share.system.domain.Recharge;
import share.system.domain.SOrder;
import share.system.response.OrderPayResultResponse;
......@@ -32,4 +33,6 @@ public interface OrderPayService {
*/
RechargePayResultResponse saobeiRechargePayment(Recharge recharge);
RechargePayResultResponse saobeiEquityMembersOrderPayment(EquityMembersOrder equityMembersOrder);
}
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.DateUtils;
import share.common.utils.bean.BeanUtils;
import share.system.domain.EquityMembersOrder;
import share.system.domain.EquityMembersOrderConfig;
import share.system.domain.SConsumer;
import share.system.domain.vo.EquityMembersOrderVo;
import share.system.domain.vo.FrontTokenComponent;
import share.system.mapper.EquityMembersOrderMapper;
import share.system.request.CreateEquityMembersRequest;
import share.system.response.RechargePayResultResponse;
import share.system.service.EquityMembersOrderConfigService;
import share.system.service.EquityMembersOrderService;
import share.system.service.OrderPayService;
import share.system.service.SConsumerService;
import java.util.List;
......@@ -21,6 +35,12 @@ import java.util.List;
public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrderMapper, EquityMembersOrder> implements EquityMembersOrderService {
@Autowired
private EquityMembersOrderMapper equityMembersOrderMapper;
@Autowired
private SConsumerService sConsumerService;
@Autowired
private EquityMembersOrderConfigService equityMembersOrderConfigService;
@Autowired
private OrderPayService orderPayService;
/**
* 查询权益会员订单
......@@ -89,4 +109,36 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde
public int deleteEquityMembersOrderById(Long id) {
return equityMembersOrderMapper.deleteEquityMembersOrderById(id);
}
@Override
public RechargePayResultResponse createEquityMembers(CreateEquityMembersRequest request) {
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
if (ObjectUtil.isNull(user)) {
throw new BaseException("您的登录已过期,请先登录");
}
if (StringUtils.isEmpty(user.getPhone())) {
user = sConsumerService.getById(user.getId());
if (StringUtils.isEmpty(user.getPhone())) {
throw new BaseException("请绑定手机号");
}
}
EquityMembersOrder equityMembersOrder = generatEquityMembersOrder(request, user);
save(equityMembersOrder);
RechargePayResultResponse response = orderPayService.saobeiEquityMembersOrderPayment(equityMembersOrder);
return response;
}
private EquityMembersOrder generatEquityMembersOrder(CreateEquityMembersRequest request, SConsumer user) {
EquityMembersOrder equityMembersOrder = new EquityMembersOrder();
BeanUtils.copyProperties(request, equityMembersOrder);
EquityMembersOrderConfig equityMembersOrderConfig = equityMembersOrderConfigService.selectEquityMembersOrderConfigById(request.getEquityMembersConfigId());
if (ObjectUtil.isEmpty(equityMembersOrderConfig)) {
throw new BaseException("权益模板异常");
}
equityMembersOrder.setConsumerId(user.getId());
equityMembersOrder.setEquityOrderNo(BaseUtil.getOrderNo("QY"));
equityMembersOrder.setPayPrice(equityMembersOrderConfig.getRequiredAmount());
equityMembersOrder.setPayStatus(YesNoEnum.no.getIndex());
return equityMembersOrder;
}
}
......@@ -20,6 +20,7 @@ import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.DateUtil;
import share.common.utils.JsonConvertUtil;
import share.system.domain.EquityMembersOrder;
import share.system.domain.Recharge;
import share.system.domain.SConsumerToken;
import share.system.domain.SOrder;
......@@ -58,6 +59,8 @@ public class OrderPayServiceImpl implements OrderPayService {
private SaobeiService saobeiService;
@Autowired
private RechargeService rechargeService;
@Autowired
private EquityMembersOrderService equityMembersOrderService;
/**
* 获取域名
......@@ -324,4 +327,83 @@ public class OrderPayServiceImpl implements OrderPayService {
return vo;
}
/**
* 充值支付(扫呗-微信支付)
*
* @param equityMembersOrder 支付参数
* @return
*/
@Override
public RechargePayResultResponse saobeiEquityMembersOrderPayment(EquityMembersOrder equityMembersOrder) {
RechargePayResultResponse response = new RechargePayResultResponse();
response.setRechargeNo(equityMembersOrder.getEquityOrderNo());
response.setPayType(PayTypeEnum.getEnumByCode(equityMembersOrder.getPayType().intValue()).getValue());
response.setStatus(YesNoEnum.no.getFlag());
// 扫呗支付
ConcurrentHashMap<String, String> unifiedorder = saobeiUnifiedEquityMembersOrder(equityMembersOrder);
WxPayJsResultVo vo = new WxPayJsResultVo();
vo.setAppId(unifiedorder.get("appId"));
vo.setNonceStr(unifiedorder.get("nonceStr"));
vo.setPackages(unifiedorder.get("package"));
vo.setSignType(unifiedorder.get("signType"));
vo.setTimeStamp(unifiedorder.get("timeStamp"));
vo.setPaySign(unifiedorder.get("paySign"));
// 更新商户订单号
equityMembersOrder.setOutTradeNo(unifiedorder.get("outTradeNo"));
equityMembersOrder.setTerminalTrace(unifiedorder.get("terminalTrace"));
equityMembersOrderService.updateById(equityMembersOrder);
response.setJsConfig(vo);
return response;
}
private ConcurrentHashMap<String, String> saobeiUnifiedEquityMembersOrder(EquityMembersOrder equityMembersOrder) {
// 获取用户openId
SConsumerToken userToken = consumerTokenService.getTokenByUserId(equityMembersOrder.getConsumerId());
if (ObjectUtil.isNull(userToken)) {
throw new BaseException("该用户没有openId");
}
// 获取appid、mch_id
// 微信签名key
String appId = weChatConfig.getAppId();
String mchId = weChatConfig.getMchId();
String signKey = weChatConfig.getSignKey();
// 获取扫呗微信预下单对象
SaobeiMiniPayRequestVo unifiedorderVo = getSaobeiUnifiedEquityMembersOrderVo(equityMembersOrder, userToken.getToken(), appId, mchId, signKey);
// 预下单(统一下单)
SaobeiMiniPayResponse response = saobeiService.wechatMinipay(unifiedorderVo);
logger.info("SaobeiMiniPayResponse :", JsonConvertUtil.write2JsonStr(response));
// 组装前端预下单参数
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("appId", response.getAppId());
map.put("nonceStr", response.getNonceStr());
map.put("package", response.getPackage_str());
map.put("signType", response.getSignType());
map.put("timeStamp", response.getTimeStamp());
map.put("paySign", response.getPaySign());
map.put("prepayTime", DateUtil.nowDateTimeStr());
map.put("outTradeNo", response.getOut_trade_no());
map.put("terminalTrace", unifiedorderVo.getTerminal_trace());
return map;
}
private SaobeiMiniPayRequestVo getSaobeiUnifiedEquityMembersOrderVo(EquityMembersOrder equityMembersOrder, String openid, String appId, String mchId, String signKey) {
AttachVo attachVo = new AttachVo(OrderTypeEnum.RIGHTS.getValue(), equityMembersOrder.getConsumerId());
SaobeiMiniPayRequestVo vo = new SaobeiMiniPayRequestVo();
vo.setSub_appid(appId);
vo.setMerchant_no(saobeiConfig.getMerchantNo());
vo.setTerminal_id(saobeiConfig.getTerminalId());
vo.setAttach(JSONObject.toJSONString(attachVo));
vo.setTerminal_trace(BaseUtil.getOrderNo("WXNO"));
vo.setTerminal_time(DateUtil.nowDate(Constants.DATE_TIME_FORMAT_NUM));
vo.setOrder_body(StrUtil.concat(true, "开通" + equityMembersOrder.getPayPrice().toString(), "权益会员"));
// 订单中使用的是BigDecimal,这里要转为Integer类型
vo.setTotal_fee(String.valueOf(equityMembersOrder.getPayPrice().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue()));
vo.setNotify_url(apiDomain + PayConstants.SAOBEI_PAY_NOTIFY_API_URI);
vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_JS);
vo.setOpen_id(openid);
vo.setDevice_no("WEB");
return vo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment