|
|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.controller.AppBaseController;
|
|
|
import com.fs.common.config.FSSysConfig;
|
|
|
@@ -18,7 +19,12 @@ import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.core.config.WxMaConfiguration;
|
|
|
+import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
+import com.fs.course.mapper.FsCoursePlaySourceConfigMapper;
|
|
|
import com.fs.erp.service.IErpOrderService;
|
|
|
+import com.fs.his.domain.FsPayConfig;
|
|
|
+import com.fs.his.domain.MerchantAppConfig;
|
|
|
+import com.fs.his.mapper.MerchantAppConfigMapper;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
|
import com.fs.hisStore.domain.*;
|
|
|
@@ -50,6 +56,8 @@ import com.github.pagehelper.PageInfo;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -65,6 +73,8 @@ import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import static com.fs.hisStore.constants.UserAppsLockConstant.LOCK_KEY_PAY;
|
|
|
+
|
|
|
|
|
|
@Api("商城接口")
|
|
|
@RestController
|
|
|
@@ -104,6 +114,11 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
private IFsStoreAfterSalesScrmService afterSalesService;
|
|
|
@Autowired
|
|
|
private IFsStoreProductPackageScrmService productPackageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCoursePlaySourceConfigMapper fsCoursePlaySourceConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private MerchantAppConfigMapper merchantAppConfigMapper;
|
|
|
@Autowired
|
|
|
IPayService ybPayService;
|
|
|
@Autowired
|
|
|
@@ -115,6 +130,8 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
@Autowired
|
|
|
@Qualifier("wdtErpOrderServiceImpl")
|
|
|
private IErpOrderService wdtOrderService;
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
@Autowired
|
|
|
@Qualifier("k9OrderScrmServiceImpl")
|
|
|
@@ -269,199 +286,253 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
return R.ok().put("data",dto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description: 小程序 自己下单 制单
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2026/4/29 19:57
|
|
|
+ */
|
|
|
@Login
|
|
|
@ApiOperation("创建订单")
|
|
|
@PostMapping("/create")
|
|
|
public R create(@Validated @RequestBody FsStoreOrderCreateParam param, HttpServletRequest request){
|
|
|
- String userId=getUserId();
|
|
|
+ String appId=request.getParameter("appId");
|
|
|
+ if(StringUtils.isNotBlank(appId)){
|
|
|
+ param.setAppId(appId);
|
|
|
+ }
|
|
|
param.setIsUserApp(false);
|
|
|
return orderService.createOrder(Long.parseLong(getUserId()),param);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Login
|
|
|
@ApiOperation("支付")
|
|
|
@PostMapping("/pay")
|
|
|
- @Transactional
|
|
|
- //@Synchronized
|
|
|
public R pay(HttpServletRequest request, @Validated @RequestBody FsStoreOrderPayParam param)
|
|
|
{
|
|
|
- logger.info("支付开始{}",param);
|
|
|
- FsStoreOrderScrm order=orderService.selectFsStoreOrderById(param.getOrderId());
|
|
|
- if(order==null){
|
|
|
- return R.error("订单不存在");
|
|
|
- }
|
|
|
- if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
|
|
|
- return R.error("订单状态不正确");
|
|
|
- }
|
|
|
- String orderId=redisCache.getCacheObject("isPaying:"+order.getId());
|
|
|
- if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
- return R.error("正在支付中...");
|
|
|
- }
|
|
|
+ Long orderId = param.getOrderId();
|
|
|
+ logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
|
|
|
|
|
|
- FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
- if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
|
|
|
- //已改价处理
|
|
|
- if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
- //改过价不做处理
|
|
|
+ RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));
|
|
|
+ R result = null;
|
|
|
|
|
|
+ try {
|
|
|
+ boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ if (!locked) {
|
|
|
+ logger.warn("订单正在处理中,获取锁失败, 订单号: {}", orderId);
|
|
|
+ return R.error("订单正在处理中,请勿重复提交");
|
|
|
}
|
|
|
- else{
|
|
|
- String config=configService.selectConfigByKey("his.store");
|
|
|
- StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
|
|
|
- if(param.getPayType().equals(1)){
|
|
|
- order.setPayType("1");
|
|
|
- order.setPayMoney(order.getPayPrice());
|
|
|
- order.setPayDelivery(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- else if(param.getPayType().equals(2)){
|
|
|
- order.setPayType("2");
|
|
|
- BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
- payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
|
|
|
- order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
- order.setPayMoney(payMoney);
|
|
|
- }
|
|
|
- else if(param.getPayType().equals(3)){
|
|
|
- //货到付款
|
|
|
- order.setPayType("3");
|
|
|
- BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getId());
|
|
|
- BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
- if (amount != null){
|
|
|
- payMoney=amount;
|
|
|
- }
|
|
|
- order.setPayMoney(payMoney);
|
|
|
- order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
-// order.setPayMoney(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- orderService.updateFsStoreOrder(order);
|
|
|
- }
|
|
|
- String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
-// order.setOrderCode(orderCode);
|
|
|
-// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
- if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
- String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
- FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
- FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
- storePayment.setCompanyId(order.getCompanyId());
|
|
|
- storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
- storePayment.setPayMode(fsPayConfig.getType());
|
|
|
- storePayment.setStatus(0);
|
|
|
- storePayment.setPayCode(payCode);
|
|
|
- storePayment.setPayMoney(order.getPayMoney());
|
|
|
- storePayment.setCreateTime(new Date());
|
|
|
- storePayment.setPayTypeCode("weixin");
|
|
|
- storePayment.setBusinessType(2);
|
|
|
- storePayment.setRemark("商城订单支付");
|
|
|
- storePayment.setOpenId(user.getMaOpenId());
|
|
|
- storePayment.setUserId(user.getUserId());
|
|
|
- storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
- storePayment.setOrderId(order.getId());
|
|
|
- storePayment.setAppId(param.getAppId());
|
|
|
- fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
-
|
|
|
- if (fsPayConfig.getType().equals("hf")){
|
|
|
- HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
- o.setTradeType("T_MINIAPP");
|
|
|
- o.setOpenid(user.getMaOpenId());
|
|
|
- o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
- o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
- o.setGoodsDesc("商城订单支付");
|
|
|
- if (param != null && StringUtils.isNotBlank(param.getAppId())) {
|
|
|
- o.setAppId(param.getAppId());
|
|
|
- }
|
|
|
- try {
|
|
|
- HuiFuUtils.doDiv(o,order.getCompanyId());
|
|
|
- //存储分账明细
|
|
|
- HuiFuUtils.saveDivItem(o, order.getOrderCode(), storePayment.getPayCode());
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("-------------分账出错:{}", e.getMessage());
|
|
|
- }
|
|
|
- HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
- if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
- FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
- mt.setPaymentId(storePayment.getPaymentId());
|
|
|
- mt.setTradeNo(result.getHf_seq_id());
|
|
|
- fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
- redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
- Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
- String s = (String) resultMap.get("package");
|
|
|
- resultMap.put("packageValue",s);
|
|
|
- return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
- }
|
|
|
- else{
|
|
|
- return R.error(result.getResp_desc());
|
|
|
- }
|
|
|
- }else if (fsPayConfig.getType().equals("wx")){
|
|
|
- WxPayConfig payConfig = new WxPayConfig();
|
|
|
- payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
- payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
- payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
- payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
- payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
- payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
- payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
- wxPayService.setConfig(payConfig);
|
|
|
- WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
- orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
- orderRequest.setBody("商城订单支付");
|
|
|
- orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
- orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
- //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
- orderRequest.setTradeType("JSAPI");
|
|
|
- orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
- //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
- try {
|
|
|
- WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
- return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType",param.getPayType());
|
|
|
- } catch (WxPayException e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new CustomException("支付失败" + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(order.getPayType().equals("1") && order.getPayMoney().compareTo(BigDecimal.ZERO) ==0 ){// 判断0金额订单
|
|
|
- logger.info("订单支付金额0,{}", order.getId());
|
|
|
- FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
- storePayment.setCompanyId(order.getCompanyId());
|
|
|
- storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
-// storePayment.setPayMode(fsPayConfig.getType());
|
|
|
- storePayment.setStatus(1);
|
|
|
- storePayment.setPayCode(payCode);
|
|
|
- storePayment.setPayMoney(order.getPayMoney());
|
|
|
- storePayment.setCreateTime(new Date());
|
|
|
- storePayment.setPayTypeCode("weixin");
|
|
|
- storePayment.setBusinessType(2);
|
|
|
- storePayment.setRemark("商城订单支付");
|
|
|
- storePayment.setOpenId(user.getRealName());
|
|
|
- storePayment.setUserId(user.getUserId());
|
|
|
- storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
- storePayment.setOrderId(order.getId());
|
|
|
- storePayment.setAppId(param.getAppId());
|
|
|
- fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
-
|
|
|
- FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
- storeOrder.setId(order.getId());
|
|
|
- storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
- storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
- storeOrder.setPayTime(new Date());
|
|
|
- orderService.updateFsStoreOrder(storeOrder);
|
|
|
- // 添加订单审核
|
|
|
- addOrderAudit(order);
|
|
|
-
|
|
|
- return R.ok().put("payType",4);
|
|
|
- }
|
|
|
-// else if(order.getPayType().equals("3")){
|
|
|
- else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
- //货到付款
|
|
|
- orderService.payConfirm(2,order.getId(),null,null,null,null);
|
|
|
- return R.ok().put("payType",param.getPayType());
|
|
|
+
|
|
|
+ result = orderService.pay(param);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("获取支付锁的过程被中断, 订单号: {}", orderId, e);
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ return R.error("支付处理被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("支付过程中发生异常, 订单号: {}", orderId, e);
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ logger.debug("支付锁已释放, 订单号: {}", orderId);
|
|
|
}
|
|
|
- return R.error();
|
|
|
- }
|
|
|
- else{
|
|
|
- return R.error("用户OPENID不存在");
|
|
|
}
|
|
|
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
+// @Login
|
|
|
+// @ApiOperation("支付")
|
|
|
+// @PostMapping("/pay")
|
|
|
+// @Transactional
|
|
|
+// //@Synchronized
|
|
|
+// public R pay(HttpServletRequest request, @Validated @RequestBody FsStoreOrderPayParam param)
|
|
|
+// {
|
|
|
+// logger.info("支付开始{}",param);
|
|
|
+// FsStoreOrderScrm order=orderService.selectFsStoreOrderById(param.getOrderId());
|
|
|
+// if(order==null){
|
|
|
+// return R.error("订单不存在");
|
|
|
+// }
|
|
|
+// if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
|
|
|
+// return R.error("订单状态不正确");
|
|
|
+// }
|
|
|
+// String orderId=redisCache.getCacheObject("isPaying:"+order.getId());
|
|
|
+// if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
+// return R.error("正在支付中...");
|
|
|
+// }
|
|
|
+//
|
|
|
+// FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
+// if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
|
|
|
+// //已改价处理
|
|
|
+// if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
+// //改过价不做处理
|
|
|
+//
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// String config=configService.selectConfigByKey("his.store");
|
|
|
+// StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
|
|
|
+// if(param.getPayType().equals(1)){
|
|
|
+// order.setPayType("1");
|
|
|
+// order.setPayMoney(order.getPayPrice());
|
|
|
+// order.setPayDelivery(BigDecimal.ZERO);
|
|
|
+// }
|
|
|
+// else if(param.getPayType().equals(2)){
|
|
|
+// order.setPayType("2");
|
|
|
+// BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
|
|
|
+// payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
|
|
|
+// order.setPayDelivery(order.getPayPrice().subtract(payMoney));
|
|
|
+// order.setPayMoney(payMoney);
|
|
|
+// }
|
|
|
+// else if(param.getPayType().equals(3)){
|
|
|
+// //货到付款
|
|
|
+// order.setPayType("3");
|
|
|
+// BigDecimal amount=redisCache.getCacheObject("orderAmount:"+order.getId());
|
|
|
+// BigDecimal payMoney = BigDecimal.ZERO;
|
|
|
+// if (amount != null){
|
|
|
+// payMoney=amount;
|
|
|
+// }
|
|
|
+// order.setPayMoney(payMoney);
|
|
|
+// order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
+//// order.setPayMoney(BigDecimal.ZERO);
|
|
|
+// }
|
|
|
+// orderService.updateFsStoreOrder(order);
|
|
|
+// }
|
|
|
+// String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+//// order.setOrderCode(orderCode);
|
|
|
+//// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
+// if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
+// String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
+// FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+// FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+// storePayment.setCompanyId(order.getCompanyId());
|
|
|
+// storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+// storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+// storePayment.setStatus(0);
|
|
|
+// storePayment.setPayCode(payCode);
|
|
|
+// storePayment.setPayMoney(order.getPayMoney());
|
|
|
+// storePayment.setCreateTime(new Date());
|
|
|
+// storePayment.setPayTypeCode("weixin");
|
|
|
+// storePayment.setBusinessType(2);
|
|
|
+// storePayment.setRemark("商城订单支付");
|
|
|
+// storePayment.setOpenId(user.getMaOpenId());
|
|
|
+// storePayment.setUserId(user.getUserId());
|
|
|
+// storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+// storePayment.setOrderId(order.getId());
|
|
|
+// storePayment.setAppId(param.getAppId());
|
|
|
+// fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+//
|
|
|
+// if (fsPayConfig.getType().equals("hf")){
|
|
|
+// HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+// o.setTradeType("T_MINIAPP");
|
|
|
+// o.setOpenid(user.getMaOpenId());
|
|
|
+// o.setReqSeqId("store-"+storePayment.getPayCode());
|
|
|
+// o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+// o.setGoodsDesc("商城订单支付");
|
|
|
+// if (param != null && StringUtils.isNotBlank(param.getAppId())) {
|
|
|
+// o.setAppId(param.getAppId());
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// HuiFuUtils.doDiv(o,order.getCompanyId());
|
|
|
+// //存储分账明细
|
|
|
+// HuiFuUtils.saveDivItem(o, order.getOrderCode(), storePayment.getPayCode());
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error("-------------分账出错:{}", e.getMessage());
|
|
|
+// }
|
|
|
+// HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+// if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
+// FsStorePaymentScrm mt=new FsStorePaymentScrm();
|
|
|
+// mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+// mt.setTradeNo(result.getHf_seq_id());
|
|
|
+// fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
+// redisCache.setCacheObject("isPaying:"+order.getId(),order.getId().toString(),1, TimeUnit.MINUTES);
|
|
|
+// Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+// String s = (String) resultMap.get("package");
|
|
|
+// resultMap.put("packageValue",s);
|
|
|
+// return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// return R.error(result.getResp_desc());
|
|
|
+// }
|
|
|
+// }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+// WxPayConfig payConfig = new WxPayConfig();
|
|
|
+// payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+// payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
+// payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
+// payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+// payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+// payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
+// payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+// wxPayService.setConfig(payConfig);
|
|
|
+// WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+// orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+// orderRequest.setBody("商城订单支付");
|
|
|
+// orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
+// orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
+// //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
+// orderRequest.setTradeType("JSAPI");
|
|
|
+// orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
+// //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+// try {
|
|
|
+// WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
+// return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType",param.getPayType());
|
|
|
+// } catch (WxPayException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// throw new CustomException("支付失败" + e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }else if(order.getPayType().equals("1") && order.getPayMoney().compareTo(BigDecimal.ZERO) ==0 ){// 判断0金额订单
|
|
|
+// logger.info("订单支付金额0,{}", order.getId());
|
|
|
+// FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
+// storePayment.setCompanyId(order.getCompanyId());
|
|
|
+// storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
+//// storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+// storePayment.setStatus(1);
|
|
|
+// storePayment.setPayCode(payCode);
|
|
|
+// storePayment.setPayMoney(order.getPayMoney());
|
|
|
+// storePayment.setCreateTime(new Date());
|
|
|
+// storePayment.setPayTypeCode("weixin");
|
|
|
+// storePayment.setBusinessType(2);
|
|
|
+// storePayment.setRemark("商城订单支付");
|
|
|
+// storePayment.setOpenId(user.getRealName());
|
|
|
+// storePayment.setUserId(user.getUserId());
|
|
|
+// storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+// storePayment.setOrderId(order.getId());
|
|
|
+// storePayment.setAppId(param.getAppId());
|
|
|
+// fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
+//
|
|
|
+// FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
+// storeOrder.setId(order.getId());
|
|
|
+// storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
+// storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
+// storeOrder.setPayTime(new Date());
|
|
|
+// orderService.updateFsStoreOrder(storeOrder);
|
|
|
+// // 添加订单审核
|
|
|
+// addOrderAudit(order);
|
|
|
+//
|
|
|
+// return R.ok().put("payType",4);
|
|
|
+// }
|
|
|
+//// else if(order.getPayType().equals("3")){
|
|
|
+// else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
+// //货到付款
|
|
|
+// orderService.payConfirm(2,order.getId(),null,null,null,null);
|
|
|
+// return R.ok().put("payType",param.getPayType());
|
|
|
+// }
|
|
|
+// return R.error();
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// return R.error("用户OPENID不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
private void addOrderAudit(FsStoreOrderScrm order) {
|
|
|
if (!getAuditSwitch()) {
|
|
|
return;
|
|
|
@@ -682,12 +753,17 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Login
|
|
|
@ApiOperation("亲友支付")
|
|
|
@PostMapping("/otherPayment")
|
|
|
- @Transactional
|
|
|
public R otherPayment(@Validated @RequestBody FsStoreOrderOtherPayParam param, HttpServletRequest request){
|
|
|
- final WxMaService wxService = WxMaConfiguration.getMaService(properties.getConfigs().get(0).getAppid());
|
|
|
+ String appId=request.getHeader("appId");
|
|
|
+ if (StringUtils.isEmpty(appId)){
|
|
|
+ appId=properties.getConfigs().get(0).getAppid(); // 兼容线上版本,后面去掉
|
|
|
+ }
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
try {
|
|
|
String ip = IpUtil.getRequestIp();
|
|
|
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
|
|
|
@@ -721,8 +797,21 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
return R.error("正在支付中...");
|
|
|
}
|
|
|
|
|
|
- String json = configService.selectConfigByKey(STORE_PAY_CONF);
|
|
|
- FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigMapper.selectOne(new LambdaQueryWrapper<FsCoursePlaySourceConfig>()
|
|
|
+ .eq(FsCoursePlaySourceConfig::getAppid, appId));
|
|
|
+ if (fsCoursePlaySourceConfig == null) {
|
|
|
+ throw new CustomException("未找到appId对应的小程序配置: " + param.getAppId());
|
|
|
+ }
|
|
|
+ Long merchantConfigId = fsCoursePlaySourceConfig.getMerchantConfigId();
|
|
|
+ if (merchantConfigId == null || merchantConfigId <= 0) {
|
|
|
+ throw new CustomException("小程序没有配置商户信息");
|
|
|
+ }
|
|
|
+ MerchantAppConfig merchantAppConfig = merchantAppConfigMapper.selectMerchantAppConfigById(fsCoursePlaySourceConfig.getMerchantConfigId());
|
|
|
+ if(merchantAppConfig == null){
|
|
|
+ throw new CustomException("未找到商户信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(merchantAppConfig.getDataJson(), FsPayConfig.class);
|
|
|
String payCode = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
//易宝支付
|
|
|
FsStorePaymentScrm storePayment=new FsStorePaymentScrm();
|
|
|
@@ -730,7 +819,7 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
storePayment.setStatus(0);
|
|
|
storePayment.setPayCode(payCode);
|
|
|
- storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setPayMode(merchantAppConfig.getMerchantType());
|
|
|
storePayment.setPayMoney(order.getPayMoney());
|
|
|
storePayment.setCreateTime(new Date());
|
|
|
storePayment.setPayTypeCode("weixin");
|
|
|
@@ -743,7 +832,7 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
storePayment.setAppId(param.getAppId());
|
|
|
fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
|
|
|
- if (fsPayConfig.getType().equals("hf")){
|
|
|
+ if (merchantAppConfig.getMerchantType().equals("hf")){
|
|
|
HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
o.setTradeType("T_MINIAPP");
|
|
|
o.setOpenid(user.getMaOpenId());
|
|
|
@@ -774,15 +863,15 @@ public class StoreOrderScrmController extends AppBaseController {
|
|
|
else{
|
|
|
return R.error(result.getResp_desc());
|
|
|
}
|
|
|
- }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+ }else if (merchantAppConfig.getMerchantType().equals("wx")){
|
|
|
//创建微信订单
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
- payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
+ payConfig.setAppId(fsCoursePlaySourceConfig.getAppid());
|
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
- payConfig.setKeyPath(null);
|
|
|
+ payConfig.setKeyPath(fsPayConfig.getKeyPath());
|
|
|
payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
wxPayService.setConfig(payConfig);
|
|
|
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|