|
@@ -11,6 +11,7 @@ import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.fs.api.param.OrderListParam;
|
|
|
import com.fs.api.vo.OrderListVO;
|
|
|
import com.fs.api.vo.ProductListVO;
|
|
@@ -23,7 +24,9 @@ import com.fs.common.event.TemplateListenEnum;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.ip.IpUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyDept;
|
|
@@ -69,7 +72,9 @@ import com.fs.hisapi.domain.ApiResponse;
|
|
|
import com.fs.hisapi.param.CreateOrderParam;
|
|
|
import com.fs.hisapi.param.RecipeDetailParam;
|
|
|
import com.fs.hisapi.service.HisApiService;
|
|
|
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.pay.pay.dto.RefundDTO;
|
|
@@ -82,6 +87,7 @@ import com.fs.hisStore.enums.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.ybPay.domain.RefundResult;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
|
|
@@ -136,6 +142,7 @@ import static com.fs.hisStore.constants.StoreConstants.DELIVERY;
|
|
|
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
|
|
|
@Slf4j
|
|
|
public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
+ private static final String STORE_PAY_CONF = "his.pay";
|
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
@Autowired
|
|
@@ -3706,6 +3713,150 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R pay(FsStoreOrderPayParam param) {
|
|
|
+ FsStoreOrderScrm order=this.selectFsStoreOrderById(param.getOrderId());
|
|
|
+ if(order==null){
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if(order.getStatus()!= OrderInfoEnum.STATUS_0.getValue()){
|
|
|
+ return R.error("订单状态不正确");
|
|
|
+ }
|
|
|
+ String orderId=redisCache.getCacheObject("isPaying:"+param.getOrderId());
|
|
|
+ if(StringUtils.isNotEmpty(orderId)&&orderId.equals(order.getId().toString())){
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+
|
|
|
+ FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
+ if(user!=null){
|
|
|
+ //已改价处理
|
|
|
+ if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
+ //改过价不做处理
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ String config=configService.selectConfigByKey("his.store");
|
|
|
+ com.fs.store.config.StoreConfig storeConfig= JSONUtil.toBean(config, com.fs.store.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);
|
|
|
+ }
|
|
|
+ this.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.getRealName());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
+ storePayment.setOrderId(order.getId());
|
|
|
+ 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("商城订单支付");
|
|
|
+ o.setAppId(param.getAppId());
|
|
|
+ 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());
|
|
|
+ mt.setAppId(param.getAppId());
|
|
|
+ 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("3")){
|
|
|
+ else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
+ //货到付款
|
|
|
+ this.payConfirm(2,order.getId(),null,null,null,null);
|
|
|
+ return R.ok().put("payType",param.getPayType());
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cancelPay(FsStoreOrderPayParam param) {
|
|
|
+ redisCache.deleteObject("isPaying:"+param.getOrderId());
|
|
|
+ }
|
|
|
+
|
|
|
private static final DateTimeFormatter CST_FORMATTER = DateTimeFormatter
|
|
|
.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
|
|
|
.withZone(ZoneId.of("Asia/Shanghai"));
|