|
@@ -15,10 +15,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.szwl.constant.HuifuConstant;
|
|
|
-import com.szwl.constant.JoinpayConstant;
|
|
|
-import com.szwl.constant.ResponseCodesEnum;
|
|
|
-import com.szwl.constant.ShouQianBaConstant;
|
|
|
+import com.szwl.constant.*;
|
|
|
import com.szwl.feign.bean.OrderFeign;
|
|
|
import com.szwl.feign.bean.SzwlFeign;
|
|
|
import com.szwl.mapper.TOrderMapper;
|
|
@@ -27,6 +24,7 @@ import com.szwl.model.bo.JsonMessage;
|
|
|
import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
import com.szwl.model.entity.*;
|
|
|
+import com.szwl.model.utils.CodeUtil;
|
|
|
import com.szwl.model.utils.HttpClientUtils;
|
|
|
import com.szwl.model.utils.PushUtils;
|
|
|
import com.szwl.model.utils.RSAUtil;
|
|
@@ -103,6 +101,12 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
TSqbConfigService sqbConfigService;
|
|
|
|
|
|
@Autowired
|
|
|
+ THuifuMchService huifuMchService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TJoinpayMchService joinpayMchService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private TOrderDetailsService orderDetailsService;
|
|
|
|
|
|
@Override
|
|
@@ -162,10 +166,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
|
|
|
/**
|
|
|
* 处理退款回调通知
|
|
|
- *
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public String wechatRefund(HttpServletRequest request, HttpServletResponse response) {
|
|
@@ -210,9 +210,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
|
|
|
/**
|
|
|
* 汇聚查询退款状态
|
|
|
- *
|
|
|
- * @param refundTrxNo
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public JSONObject queryRefund(String refundTrxNo) {
|
|
@@ -973,7 +970,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseModel sqbRefund(TOrder torder) {
|
|
|
+ public ResponseModel<?> sqbRefund(TOrder torder) {
|
|
|
// 退款金额: refusePrice
|
|
|
BigDecimal refusePrice = torder.getPrice().setScale(2, RoundingMode.HALF_DOWN);
|
|
|
// 退款数量: refundNumber
|
|
@@ -1102,15 +1099,240 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
return R.fail(ResponseCodesEnum.B0001, "申请退款失败,请联系管理员");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public JsonMessage scanpay(String code, String clientId, String productName, String frpCode, String pri) {
|
|
|
+ TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
|
|
|
+ if (equipment == null || equipment.getId() == null) {
|
|
|
+ return JsonMessage.error("找不到设备");
|
|
|
+ }
|
|
|
+ // 验证优惠码,code为空则不选用优惠码
|
|
|
+ TPromoCode promoCode = new TPromoCode();
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ //有优惠码,需要对优惠码进行验证
|
|
|
+ ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
|
|
|
+ promoCode = tPromoCodeResponseModel.getData();
|
|
|
+ String checkCode = checkCode(promoCode, equipment);
|
|
|
+ if (StringUtils.isNotEmpty(checkCode)) {
|
|
|
+ return JsonMessage.success(checkCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 支付方式
|
|
|
+ if (!ConfigConsts.ALIPAY_NATIVE.equals(frpCode) && !ConfigConsts.WECHAT_NATIVE.equals(frpCode)) {
|
|
|
+ return JsonMessage.error("参数错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long equipmentId = equipment.getId();
|
|
|
+ // 查找商品
|
|
|
+ ResponseModel<TProduct> product1 = szwlFeign.getProduct(String.valueOf(equipmentId), productName);
|
|
|
+ TProduct product = product1.getData();
|
|
|
+ if (product == null) {
|
|
|
+ return JsonMessage.error("找不到商品");
|
|
|
+ }
|
|
|
+ BigDecimal price = product.getRmbPrice();
|
|
|
+ if (StringUtils.isNotEmpty(pri)) {
|
|
|
+ price = new BigDecimal(pri);
|
|
|
+ }
|
|
|
+ // 计算折扣后的价格
|
|
|
+ if (StringUtils.isNotEmpty(code)) {
|
|
|
+ BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
|
|
|
+ if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
|
|
|
+ if (price.compareTo(discount) > 0) {
|
|
|
+ // 如果 price 大于 discount,从 price 中减去 discount
|
|
|
+ price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ } else {
|
|
|
+ // 如果 price 小于等于 discount,将 price 设置为 0
|
|
|
+ return JsonMessage.success("0");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断价格是否小于等于0
|
|
|
+ if (BigDecimal.ZERO.compareTo(price) >= 0) {
|
|
|
+ return JsonMessage.error("商品价格异常");
|
|
|
+ }
|
|
|
+ // 生成订单编号
|
|
|
+ Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
|
|
|
+ String sn = orderService.initSn(client6);
|
|
|
+ // 获取关联设备的分销
|
|
|
+ TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
|
|
|
+ if (proportion == null || proportion.getId() == null) {
|
|
|
+ return JsonMessage.error("设备商家未完成分销设置");
|
|
|
+ }
|
|
|
+ TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
|
|
|
+ if (admin == null) {
|
|
|
+ return JsonMessage.error("找不到设备商家");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付方式:0或null为汇聚,1为汇付支付
|
|
|
+ String payPlatform = admin.getPayPlatform();
|
|
|
+ String companyType = admin.getCompanyType();
|
|
|
+ // 汇聚分账参数
|
|
|
+ JSONArray altInfo = new JSONArray();
|
|
|
+ // 汇付分账明细参数
|
|
|
+ JSONObject acctSplitBunch = new JSONObject();
|
|
|
+ if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
|
|
|
+ if (!(acctSplitBunch.size() > 0)) {
|
|
|
+ return JsonMessage.error("设备商家未注册结算账号");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ altInfo = getAltInfo(proportion, price);
|
|
|
+ if (!(altInfo.size() > 0)) {
|
|
|
+ return JsonMessage.error("设备商家未注册结算账号");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ String productDesc = "";
|
|
|
+ String commonParameter = "";
|
|
|
+ String returnUrl = null;
|
|
|
+ String notifyUrl = JoinpayConstant.Notify_Url;
|
|
|
+ String isShowPic = "1";
|
|
|
+ String openId = null;
|
|
|
+ String authCode = null;
|
|
|
+ String appid = null;
|
|
|
+ String transactionModel = null;
|
|
|
+ String tradeMerchantNo = admin.getTradeMerchantNo();
|
|
|
+ String buyerId = null;
|
|
|
+ String isAlt = "1";
|
|
|
+ String altType = "11";
|
|
|
+ String altUrl = null;
|
|
|
+ BigDecimal marketingAmount = null;
|
|
|
+ if (StringUtils.isNotEmpty(pri)) {
|
|
|
+ productName = "棉花糖";
|
|
|
+ }
|
|
|
+ Integer productNumber = 1;
|
|
|
+ TOrder order = new TOrder();
|
|
|
+ order.setId(IDGenerator.orderID());
|
|
|
+ order.setCreateDate(new Date());
|
|
|
+ order.setModifyDate(new Date());
|
|
|
+ order.setAdminId(admin.getId());
|
|
|
+ order.setSn(sn);
|
|
|
+ order.setProductId(product.getId());
|
|
|
+ order.setProductNo(product.getNo());
|
|
|
+ order.setProductName(productName);
|
|
|
+ order.setPrice(price);
|
|
|
+ order.setClientId(equipment.getClientId());
|
|
|
+ order.setEquipmentId(equipmentId);
|
|
|
+ order.setFrpCode(frpCode);
|
|
|
+ order.setAltInfo(altInfo.toString());
|
|
|
+ order.setStatus(0);
|
|
|
+ order.setType(admin.getType());
|
|
|
+ order.setProductNumber(productNumber);
|
|
|
+ order.setCompanyType(admin.getCompanyType());
|
|
|
+ order.setMachineType(equipment.getMachineType());
|
|
|
+ if (admin.getType() == 0) {
|
|
|
+ order.setAdminProportion(proportion.getAdminProportion());
|
|
|
+ order.setAgencyProportion(proportion.getAgencyProportion());
|
|
|
+ order.setAgencyId(proportion.getAgencyId());
|
|
|
+ }
|
|
|
+ if (admin.getType() == 1) {
|
|
|
+ order.setAdminProportion(proportion.getAdminProportion());
|
|
|
+ order.setAgencyProportion(proportion.getAgencyProportion());
|
|
|
+ order.setAgencyId(proportion.getAgencyId());
|
|
|
+ order.setMerchantProportion(proportion.getMerchantProportion());
|
|
|
+ order.setMerchantId(proportion.getMerchantId());
|
|
|
+ }
|
|
|
+ if (admin.getType() == 2) {
|
|
|
+ order.setAdminProportion(proportion.getAdminProportion());
|
|
|
+ order.setAgencyProportion(proportion.getAgencyProportion());
|
|
|
+ order.setAgencyId(proportion.getAgencyId());
|
|
|
+ order.setMerchantProportion(proportion.getMerchantProportion());
|
|
|
+ order.setMerchantId(proportion.getMerchantId());
|
|
|
+ order.setPersonageProportion(proportion.getPersonageProportion());
|
|
|
+ order.setPersonageId(proportion.getPersonageId());
|
|
|
+ }
|
|
|
+
|
|
|
+ order.setPayPlatform(payPlatform);
|
|
|
+ // 订单明细表
|
|
|
+ TOrderDetails orderDetails = new TOrderDetails();
|
|
|
+ orderDetails.setId(HuifuUtils.initDetailsId());
|
|
|
+ orderDetails.setAdminId(admin.getId());
|
|
|
+ orderDetails.setEquipmentId(equipmentId);
|
|
|
+ orderDetails.setCreateDate(new Date());
|
|
|
+ orderDetails.setOrderSn(sn);
|
|
|
+ orderDetails.setPrice(price);
|
|
|
+ orderDetails.setProductName(productName);
|
|
|
+ orderDetails.setProductNo(product.getNo());
|
|
|
+ orderDetails.setProductNumber(productNumber);
|
|
|
+ orderDetails.setAmount(price);
|
|
|
+ orderDetails.setRefundStatus("0");
|
|
|
+ orderDetails.setCompanyType(companyType);
|
|
|
+ orderDetails.setMachineType(equipment.getMachineType());
|
|
|
+
|
|
|
+ String productName1 = productName + "-" + equipment.getName() + "-" + client6;
|
|
|
+ String result = null;
|
|
|
+ if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
|
|
|
+ // 汇付分账参数
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch.toString());
|
|
|
+ if (frpCode.equals(ConfigConsts.WECHAT_NATIVE)) {
|
|
|
+ //添加到汇付临时表
|
|
|
+ if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
|
|
|
+ result = HuifuConstant.SC_JUMP_URL + "/#/payWechat?sn=" + sn;
|
|
|
+ } else {
|
|
|
+ result = HuifuConstant.SZ_JUMP_URL + "/#/payWechat?sn=" + sn;
|
|
|
+ }
|
|
|
+ log.info("返回链接:{}", result);
|
|
|
+ String qrcode = CodeUtil.toQrcode(result);
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn", sn);
|
|
|
+ kindData.put("rd_Pic", qrcode);
|
|
|
+ orderService.save(order);
|
|
|
+ orderDetailsService.save(orderDetails);
|
|
|
+ return JsonMessage.success(kindData.toString());
|
|
|
+ }
|
|
|
+ // 汇付支付
|
|
|
+ try {
|
|
|
+ result = huifuMchService.uniPay(
|
|
|
+ sn, amount, productName1, productDesc,
|
|
|
+ notifyUrl, frpCode, openId, appid, acctSplitBunch, companyType
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JsonMessage.error("申请支付失败");
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(result)) {
|
|
|
+ return JsonMessage.error("找不到支付图片");
|
|
|
+ }
|
|
|
+ String qrcode = CodeUtil.toQrcode(result);
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn", sn);
|
|
|
+ kindData.put("rd_Pic", qrcode);
|
|
|
+ orderService.save(order);
|
|
|
+ orderDetailsService.save(orderDetails);
|
|
|
+ return JsonMessage.success(kindData.toString());
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ result = joinpayMchService.uniPay(
|
|
|
+ sn, amount, productName1, productDesc,
|
|
|
+ commonParameter, returnUrl, notifyUrl, frpCode,
|
|
|
+ isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
|
|
|
+ buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
|
|
|
+ );
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JsonMessage.error("申请支付失败");
|
|
|
+ }
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ // 汇聚支付支付申请返回支付二维码图片
|
|
|
+ String rdPic = resultJson.getString("rd_Pic");
|
|
|
+ if (StringUtils.isBlank(rdPic)) {
|
|
|
+ return JsonMessage.error("找不到支付图片");
|
|
|
+ }
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn", sn);
|
|
|
+ kindData.put("rd_Pic", rdPic);
|
|
|
+ orderService.save(order);
|
|
|
+ orderDetailsService.save(orderDetails);
|
|
|
+ return JsonMessage.success(kindData.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送微信消息
|
|
|
- *
|
|
|
- * @param accessToken
|
|
|
- * @param restTemplate
|
|
|
- * @param sendBody
|
|
|
- * @return
|
|
|
*/
|
|
|
- private String sendMessage(String accessToken, RestTemplate restTemplate, Map<String, Object> sendBody) {
|
|
|
+ private void sendMessage(String accessToken, RestTemplate restTemplate, Map<String, Object> sendBody) {
|
|
|
String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
|
|
|
ResponseEntity<String> forEntity = restTemplate.postForEntity(sendUrl, sendBody, String.class);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(forEntity.getBody());
|
|
@@ -1118,7 +1340,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
String msgId = jsonObject.getString("msgid");
|
|
|
System.out.println("messageCode : " + messageCode + ", msgId: " + msgId);
|
|
|
log.info("微信推送结果:{}", "messageCode : " + messageCode + ", msgId: " + msgId);
|
|
|
- return messageCode;
|
|
|
}
|
|
|
|
|
|
public void processRefund(Map<String, Object> bodyMap) {
|
|
@@ -1191,11 +1412,44 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 验证优惠码
|
|
|
+ */
|
|
|
+ public String checkCode(TPromoCode promoCode, TEquipment equipment) {
|
|
|
+ //有优惠码,需要对优惠码进行验证
|
|
|
+ if (promoCode == null || promoCode.getId() == null) {
|
|
|
+ //不存在
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ Date lastUseDate = promoCode.getLastUseDate();
|
|
|
+ if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
|
|
|
+ promoCode.setIsUse("2");
|
|
|
+ szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
|
|
|
+ //过期
|
|
|
+ return "4";
|
|
|
+ }
|
|
|
+ if (promoCode.getIsUse().equals("1")) {
|
|
|
+ //被使用
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+ if (!promoCode.getAdminId().equals("1")) {
|
|
|
+ if (!String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
|
|
|
+ //不是本机
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (promoCode.getDiscount() == null) {
|
|
|
+ //旧优惠码
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ if (promoCode.getDiscount() == 0) {
|
|
|
+ //0折
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 汇聚分销明细
|
|
|
- *
|
|
|
- * @param proportion
|
|
|
- * @param price
|
|
|
- * @return
|
|
|
*/
|
|
|
public JSONArray getAltInfo(TProportion proportion, BigDecimal price) {
|
|
|
// 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
|
|
@@ -1332,10 +1586,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
|
|
|
/**
|
|
|
* 汇付分销明细
|
|
|
- *
|
|
|
- * @param proportion
|
|
|
- * @param price
|
|
|
- * @return
|
|
|
*/
|
|
|
public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price, String companyType) {
|
|
|
|