|
@@ -1,5 +1,9 @@
|
|
|
package com.fs.live.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
@@ -8,21 +12,86 @@ import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
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.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyDept;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.service.ICompanyDeptService;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
+import com.fs.core.config.WxPayProperties;
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
+import com.fs.course.domain.FsUserVipOrder;
|
|
|
+import com.fs.course.param.FsUserLiveOrderPayUParam;
|
|
|
+import com.fs.erp.domain.ErpOrder;
|
|
|
+import com.fs.erp.domain.ErpOrderItem;
|
|
|
+import com.fs.erp.domain.ErpOrderPayment;
|
|
|
+import com.fs.erp.dto.ErpOrderResponse;
|
|
|
+import com.fs.erp.service.IErpOrderService;
|
|
|
+import com.fs.his.config.FsSysConfig;
|
|
|
+import com.fs.his.domain.*;
|
|
|
+import com.fs.his.dto.*;
|
|
|
+import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
|
+import com.fs.his.enums.FsStoreOrderStatusEnum;
|
|
|
+import com.fs.his.enums.ShipperCodeEnum;
|
|
|
+import com.fs.his.mapper.FsStoreProductAttrValueMapper;
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.service.IFsExpressService;
|
|
|
+import com.fs.his.service.IFsStoreProductService;
|
|
|
+import com.fs.his.service.IFsUserAddressService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
-import com.fs.live.domain.Live;
|
|
|
-import com.fs.live.mapper.LiveMapper;
|
|
|
+import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.hisapi.param.CreateOrderParam;
|
|
|
+import com.fs.hisapi.param.RecipeDetailParam;
|
|
|
+import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
+import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
+import com.fs.huifuPay.service.HuiFuService;
|
|
|
+import com.fs.live.domain.*;
|
|
|
+import com.fs.live.mapper.*;
|
|
|
+import com.fs.live.param.LiveOrderConfirmParam;
|
|
|
+import com.fs.live.vo.LiveGoodsVo;
|
|
|
import com.fs.live.vo.LiveOrderVo;
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
+import com.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.mapper.SysConfigMapper;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.tzBankPay.TzBankService.TzBankService;
|
|
|
+import com.fs.tzBankPay.doman.PayCreateOrder;
|
|
|
+import com.fs.tzBankPay.doman.PayCreateOrderResult;
|
|
|
+import com.fs.tzBankPay.doman.PayType;
|
|
|
+import com.fs.tzBankPay.doman.TzBankResult;
|
|
|
+import com.fs.ybPay.domain.CreateWxOrderResult;
|
|
|
+import com.fs.ybPay.dto.WxJspayDTO;
|
|
|
+import com.fs.ybPay.service.IPayService;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.list.TreeList;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.fs.live.mapper.LiveOrderMapper;
|
|
|
-import com.fs.live.domain.LiveOrder;
|
|
|
import com.fs.live.service.ILiveOrderService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
|
|
|
|
/**
|
|
|
* 订单Service业务层处理
|
|
@@ -31,13 +100,86 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
* @date 2025-07-08
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder> implements ILiveOrderService {
|
|
|
|
|
|
private final RedisCache redisCache;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private LiveMapper liveMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxPayProperties wxPayProperties;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IPayService payService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxPayService wxPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveGoodsMapper liveGoodsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsExpressService expressService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveOrderItemMapper liveOrderItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductService fsStoreProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FsUserMapper userMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("erpOrderServiceImpl")
|
|
|
+ private IErpOrderService gyOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConfigUtil configUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CloudHostProper cloudHostProper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ICompanyUserService companyUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICompanyDeptService companyDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsStoreProductAttrValueMapper fsStoreProductAttrValueMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsUserAddressService fsUserAddressService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveOrderPaymentMapper liveOrderPaymentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TzBankService tzBankService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HuiFuService huiFuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveOrderPaymentErrorMapper liveOrderPaymentErrorMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
+
|
|
|
public LiveOrderServiceImpl(RedisCache redisCache) {
|
|
|
this.redisCache = redisCache;
|
|
|
}
|
|
@@ -45,6 +187,480 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
@Autowired
|
|
|
private IFsUserService fsUserService;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void pushLiveOrder(LiveOrder order) throws ParseException {
|
|
|
+ //判断是否开启erp
|
|
|
+ FsSysConfig sysConfig = configUtil.getSysConfig();
|
|
|
+ Integer erpOpen = sysConfig.getErpOpen();
|
|
|
+ if (erpOpen==null || erpOpen==0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ IErpOrderService erpOrderService = gyOrderService;
|
|
|
+ if(order.getStatus()!=2) return;
|
|
|
+ ErpOrder erpOrder=new ErpOrder();
|
|
|
+ if (order.getCompanyId()!=null){
|
|
|
+ erpOrder.setVip_code(order.getUserId() +order.getCompanyId().toString());
|
|
|
+ }else {
|
|
|
+ erpOrder.setVip_code(order.getUserId());
|
|
|
+ }
|
|
|
+ erpOrder.setPlatform_code(order.getOrderCode());
|
|
|
+ erpOrder.setShop_code(sysConfig.getErpShopCode());
|
|
|
+ erpOrder.setSeller_memo(order.getRemark());
|
|
|
+
|
|
|
+ List<ErpOrderPayment> payments=new ArrayList<>();
|
|
|
+ ErpOrderPayment payment=new ErpOrderPayment();
|
|
|
+ payment.setPay_type_code("weixin");
|
|
|
+ payment.setPayment(order.getPayMoney().doubleValue());
|
|
|
+ if(order.getPayTime()!=null){
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String timeString = sdf.format(order.getPayTime());
|
|
|
+ Date date = sdf.parse(timeString); // 时间格式转为时间戳
|
|
|
+ long timeLong = date.getTime();
|
|
|
+ payment.setPaytime(new Timestamp(timeLong));
|
|
|
+ }
|
|
|
+ payments.add(payment);
|
|
|
+
|
|
|
+ if (!("金牛明医".equals(cloudHostProper.getCompanyName()))){
|
|
|
+ if (order.getPayRemain().compareTo(new BigDecimal(0)) == 0) {
|
|
|
+ //没有物流代收
|
|
|
+ //大于100发发顺丰云配
|
|
|
+ if(order.getPayMoney().compareTo(new BigDecimal(100))>0){
|
|
|
+ //发互联网医院SF.0235488558_241101
|
|
|
+ FsExpress express=expressService.selectFsExpressByOmsCode("SF.0235488558_241101");
|
|
|
+ erpOrder.setExpress_code(express.getOmsCode());
|
|
|
+ order.setDeliveryName(express.getName());
|
|
|
+ order.setDeliveryCode(express.getCode());
|
|
|
+ }else {
|
|
|
+ //发ztpdd
|
|
|
+ FsExpress express=expressService.selectFsExpressByOmsCode("CDYJFYD.400011111705_241230");
|
|
|
+ erpOrder.setExpress_code(express.getOmsCode());
|
|
|
+ order.setDeliveryName(express.getName());
|
|
|
+ order.setDeliveryCode(express.getCode());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FsExpress express = new FsExpress();
|
|
|
+ if (order.getCompanyId()!=null){
|
|
|
+ Company company = companyService.selectCompanyById(order.getCompanyId());
|
|
|
+ if (company != null && StringUtils.isNotEmpty(company.getOmsCode())){
|
|
|
+ express = expressService.selectFsExpressByOmsCode(company.getOmsCode());
|
|
|
+ }else {
|
|
|
+ express=expressService.selectFsExpressByOmsCode("SF.0235469535");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ express=expressService.selectFsExpressByOmsCode("SF.0235469535");
|
|
|
+ }
|
|
|
+ //物流代发互联网医院顺
|
|
|
+ erpOrder.setExpress_code(express.getOmsCode());
|
|
|
+ order.setDeliveryName(express.getName());
|
|
|
+ order.setDeliveryCode(express.getCode());
|
|
|
+ //物流代收金额
|
|
|
+ ErpOrderPayment codPayment = new ErpOrderPayment();
|
|
|
+ codPayment.setPay_type_code("cod");
|
|
|
+ BigDecimal toal = order.getPayRemain();
|
|
|
+ codPayment.setPayment(toal.doubleValue());
|
|
|
+ payments.add(codPayment);
|
|
|
+ erpOrder.setCod(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ erpOrder.setPayments(payments);
|
|
|
+ if(order.getCompanyId()!=null){
|
|
|
+ Company company=companyService.selectCompanyById(order.getCompanyId());
|
|
|
+ if(company!=null){
|
|
|
+ erpOrder.setSeller_memo(company.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(order.getCompanyUserId()!=null){
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(order.getCompanyUserId());
|
|
|
+ if(companyUser!=null){
|
|
|
+ CompanyDept dept=companyDeptService.selectCompanyDeptById(companyUser.getDeptId());
|
|
|
+ if(dept!=null){
|
|
|
+ List<String> names=companyDeptService.selectCompanyDeptNamesByIds(dept.getAncestors());
|
|
|
+ if(names!=null&&names.size()>0){
|
|
|
+ //写备注
|
|
|
+ erpOrder.setSeller_memo(erpOrder.getSeller_memo()+"-"+StringUtils.join(names, ",")+","+dept.getDeptName() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ erpOrder.setSeller_memo(erpOrder.getSeller_memo()+"-"+companyUser.getNickName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ErpRemarkDTO remarkDTO=new ErpRemarkDTO();
|
|
|
+ remarkDTO.setTotalPrice(order.getTotalPrice());
|
|
|
+ remarkDTO.setPayPrice(order.getPayPrice());
|
|
|
+ remarkDTO.setDeliveryMoney(order.getPayDelivery());
|
|
|
+ remarkDTO.setPayMoney(order.getPayMoney());
|
|
|
+ remarkDTO.setCouponMoney(order.getDiscountMoney());
|
|
|
+ remarkDTO.setOrderId(order.getOrderCode());
|
|
|
+ remarkDTO.setYdMoney(order.getPayPrice().subtract(order.getPayMoney().subtract(order.getPayDelivery())));
|
|
|
+
|
|
|
+ if(order.getPayTime()!=null){
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format = sdf.format(order.getPayTime());
|
|
|
+ remarkDTO.setPayTime(format);
|
|
|
+ }
|
|
|
+
|
|
|
+ erpOrder.setSeller_memo(erpOrder.getSeller_memo()+JSONUtil.toJsonStr(remarkDTO));
|
|
|
+ erpOrder.setOrder_type_code("order");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ erpOrder.setDeal_datetime(sdf.format(new Date()));
|
|
|
+ FsStoreOrderItem itemMap=new FsStoreOrderItem();
|
|
|
+ itemMap.setOrderId(order.getOrderId());
|
|
|
+ List<LiveOrderItem> liveOrderItems = liveOrderItemMapper.selectLiveOrderItemByOrderId(order.getOrderId());
|
|
|
+ List<ErpOrderItem> details=new ArrayList<>();
|
|
|
+ for (LiveOrderItem liveOrderItem : liveOrderItems) {
|
|
|
+ FsStoreCartDTO cartDTO= JSONUtil.toBean(liveOrderItem.getJsonInfo(),FsStoreCartDTO.class);
|
|
|
+ ErpOrderItem item=new ErpOrderItem();
|
|
|
+ item.setItem_code(cartDTO.getBarCode().trim());
|
|
|
+ item.setPrice(cartDTO.getPrice().toString());
|
|
|
+ item.setQty(cartDTO.getNum());
|
|
|
+ item.setRefund(0);
|
|
|
+ details.add(item);
|
|
|
+ }
|
|
|
+ // todo yhq
|
|
|
+ erpOrder.setDetails(details);
|
|
|
+ erpOrder.setReceiver_name(order.getUserName().replaceAll("[^\\u4e00-\\u9fa5a-zA-Z0-9]", ""));
|
|
|
+ //2025.6.27 金牛要求erp推送电话可以设置默认 不影响其他推送
|
|
|
+ String phone = null;
|
|
|
+ if (order.getUserPhone().length()>11){
|
|
|
+ phone = decryptPhone(order.getUserPhone());
|
|
|
+ }else {
|
|
|
+ phone = order.getUserPhone();
|
|
|
+ }
|
|
|
+ if(phone.length()>11){
|
|
|
+ erpOrder.setReceiver_phone(phone);
|
|
|
+ } else{
|
|
|
+ erpOrder.setReceiver_mobile(phone);
|
|
|
+ }
|
|
|
+ String[] address=order.getUserAddress().split(" ");
|
|
|
+ if (address.length<3){
|
|
|
+ String kdnAddress = fsUserAddressService.getKdnAddress(order.getUserAddress());
|
|
|
+ Map<String,Object> addDAta = (Map<String,Object>)JSON.parse(kdnAddress);
|
|
|
+ Map<String, String> add = (Map<String, String>)addDAta.get("Data");
|
|
|
+ erpOrder.setReceiver_province(add.get("ProvinceName"));
|
|
|
+ erpOrder.setReceiver_city(add.get("CityName"));
|
|
|
+ erpOrder.setReceiver_district(add.get("ExpAreaName"));
|
|
|
+ erpOrder.setReceiver_address(add.get("StreetName")+add.get("Address"));
|
|
|
+ }else {
|
|
|
+ erpOrder.setReceiver_province(address[0]);
|
|
|
+ erpOrder.setReceiver_city(address[1]);
|
|
|
+ erpOrder.setReceiver_district(address[2]);
|
|
|
+ //处理地址多空隔问题
|
|
|
+ if(address.length>3){
|
|
|
+ StringBuffer addrs=new StringBuffer();
|
|
|
+ for(int i=3;i<address.length;i++){
|
|
|
+ addrs.append(address[i]);
|
|
|
+ }
|
|
|
+ erpOrder.setReceiver_address(addrs.toString());
|
|
|
+ }
|
|
|
+ else if(address.length==3){
|
|
|
+ erpOrder.setReceiver_address(address[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ erpOrder.setReceiver_address(erpOrder.getReceiver_address().replace("+","加"));
|
|
|
+ erpOrder.setReceiver_address(erpOrder.getReceiver_address().replace("\n",""));
|
|
|
+ ErpOrderResponse response= erpOrderService.addOrder(erpOrder);
|
|
|
+ log.info("ErpCreate:"+order.getOrderCode()+":"+JSONUtil.toJsonStr(response));
|
|
|
+ if(response.getSuccess()){
|
|
|
+
|
|
|
+ //支付成功后 将订单号写入待发货的REDIS中
|
|
|
+ redisCache.setCacheObject("delivery"+":"+response.getCode(),order.getOrderCode());
|
|
|
+ //写入外部订单号
|
|
|
+ order.setExtendOrderId(response.getCode());
|
|
|
+ baseMapper.updateLiveOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R aliPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if(user!=null){
|
|
|
+ if(order.getPayMoney().compareTo(new BigDecimal(0))==1){
|
|
|
+ // todo yhq
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
+// String payCode = String.valueOf(UUID.randomUUID());
|
|
|
+ if(StringUtils.isEmpty(payCode)){
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
+ PayConfigDTO payConfigDTO = JSONUtil.toBean(json, PayConfigDTO.class);
|
|
|
+ LiveOrderPayment storePayment=new LiveOrderPayment();
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(payConfigDTO.getType());
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ // todo yhq
|
|
|
+// storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setPayMoney(new BigDecimal("0.01"));
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("alipay");
|
|
|
+ storePayment.setBusinessType(5);
|
|
|
+ storePayment.setRemark("直播订单支付");
|
|
|
+// storePayment.setOpenId(user.getMpOpenId());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessId(order.getOrderId().toString());
|
|
|
+ if(liveOrderPaymentMapper.insertLiveOrderPayment(storePayment)>0){
|
|
|
+
|
|
|
+ if (payConfigDTO.getType().equals("yb")) {
|
|
|
+ return R.error("支付暂不可用!");
|
|
|
+ } else if (payConfigDTO.getType().equals("tz")) {
|
|
|
+ PayCreateOrder o = new PayCreateOrder();
|
|
|
+ o.setOrderNo("appLive" + storePayment.getPayCode()); // 业务系统订单号
|
|
|
+ o.setTrxAmt(storePayment.getPayMoney().doubleValue()); // 交易金额
|
|
|
+ o.setBusinessCstNo(order.getUserId().toString()); // 业务平台客户号
|
|
|
+ String phone="";
|
|
|
+ if (user.getPhone()!=null&&user.getPhone().length()>4){
|
|
|
+ phone=user.getPhone().substring(user.getPhone().length()-4);
|
|
|
+ }
|
|
|
+ o.setPayerName("微信用户"+phone);
|
|
|
+ o.setGoodsInfo("直播订单支付"); // 订单信息
|
|
|
+// o.setOpenId(user.getMpOpenId());
|
|
|
+ o.setOrderType(5);
|
|
|
+ o.setOrderId(order.getOrderId().toString());
|
|
|
+ o.setPayType(Arrays.asList(PayType.支付宝条码支付.getCode()));
|
|
|
+ TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(o);
|
|
|
+ LiveOrderPayment mt=new LiveOrderPayment();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getBody().getOrderFlowNo());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "tz");
|
|
|
+ }else if (payConfigDTO.getType().equals("hf")) {
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("A_NATIVE");
|
|
|
+// o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("appLive-"+storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("直播订单支付");
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ LiveOrderPayment mt=new LiveOrderPayment();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.payConfirm(order.getOrderCode(),"","","",2);
|
|
|
+ return R.ok().put("isPay",1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R payConfirm(String orderSn, String payCode, String tradeNo, String payType, Integer type) {
|
|
|
+ Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
|
|
+ try {
|
|
|
+ LiveOrder order=null;
|
|
|
+ if(type.equals(1)){
|
|
|
+ LiveOrderPayment storePayment = liveOrderPaymentMapper.selectLiveOrderPaymentByPaymentCode(payCode);
|
|
|
+ if (storePayment!=null){
|
|
|
+ if(storePayment.getStatus().equals(0)){
|
|
|
+ LiveOrderPayment paymentMap=new LiveOrderPayment();
|
|
|
+ paymentMap.setPaymentId(storePayment.getPaymentId());
|
|
|
+ paymentMap.setStatus(1);
|
|
|
+ paymentMap.setPayTime(new Date());
|
|
|
+ paymentMap.setTradeNo(tradeNo);
|
|
|
+ if(payType.equals(PayType.微信小程序支付.getCode())){
|
|
|
+ paymentMap.setPayTypeCode(PayType.微信小程序支付.name());
|
|
|
+ }
|
|
|
+ else if(payType.equals(PayType.支付宝条码支付.getCode())){
|
|
|
+ paymentMap.setPayTypeCode(PayType.支付宝条码支付.name());
|
|
|
+ }
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
+ order=baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getBusinessId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ log.info("支付单号不存在:"+payCode);
|
|
|
+ return R.error("支付单号不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(type.equals(2)){
|
|
|
+ order=baseMapper.selectFsUserVipOrderByOrderCode(orderSn);
|
|
|
+ }
|
|
|
+ if(order.getStatus()!=0){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ order.setStatus(2);
|
|
|
+ order.setPayTime(new Date());
|
|
|
+ baseMapper.updateLiveOrder(order);
|
|
|
+ return R.ok();
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("支付错误:"+e.getMessage());
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
|
|
|
+ LiveOrderPaymentError err = new LiveOrderPaymentError();
|
|
|
+ err.setOrderNo(orderSn);
|
|
|
+ err.setOrderFlowNo(tradeNo);
|
|
|
+ err.setStatus(0);
|
|
|
+ err.setMsg(e.getMessage());
|
|
|
+ err.setCreateTime(DateUtils.getNowDate());
|
|
|
+ liveOrderPaymentErrorMapper.insertLiveOrderPaymentError(err);
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R wxPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus()!=1){
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())) {
|
|
|
+ if (order.getPayMoney().compareTo(new BigDecimal(0)) == 0) {
|
|
|
+ this.payConfirm(order.getOrderCode(), "", "", "", 2);
|
|
|
+ return R.ok().put("isPay", 1);
|
|
|
+ } else {
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
+ PayConfigDTO payConfigDTO = JSONUtil.toBean(json, PayConfigDTO.class);
|
|
|
+ payConfigDTO.setType("wx");
|
|
|
+ // todo yhq
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
+// String payCode = String.valueOf(UUID.randomUUID());
|
|
|
+ payCode = payCode.substring(0, payCode.lastIndexOf('-'));
|
|
|
+ if(StringUtils.isEmpty(payCode)){
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ LiveOrderPayment storePayment = new LiveOrderPayment();
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(payConfigDTO.getType());
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ // todo yhq
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setPayMoney(new BigDecimal("0.01"));
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(5);
|
|
|
+ storePayment.setRemark("直播商品订单支付");
|
|
|
+ storePayment.setOpenId(user.getMaOpenId());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessId(order.getOrderId().toString());
|
|
|
+ if (liveOrderPaymentMapper.insertLiveOrderPayment(storePayment) > 0) {
|
|
|
+ if (payConfigDTO.getType().equals("wx")) {
|
|
|
+ //创建微信订单
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
+ FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ 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(null);
|
|
|
+ payConfig.setNotifyUrl(wxPayProperties.getNotifyUrl());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setBody("直播商品订单支付");
|
|
|
+ orderRequest.setOutTradeNo("appLive-" + 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);
|
|
|
+ log.info("订单结果:"+orderResult);
|
|
|
+ return R.ok().put("data", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
+ }
|
|
|
+ } else if (payConfigDTO.getType().equals("yb")) {
|
|
|
+ WxJspayDTO p = new WxJspayDTO();
|
|
|
+ // 使用setter方法为对象赋值
|
|
|
+ p.setPayMoney(storePayment.getPayMoney().toString());
|
|
|
+ p.setLowOrderId("appLive-" + storePayment.getPayCode());
|
|
|
+ p.setBody("直播商品订单支付");
|
|
|
+ p.setIsMinipg("1");
|
|
|
+ p.setOpenId(user.getMaOpenId());
|
|
|
+ p.setAttach("");
|
|
|
+ p.setStoreid("0");
|
|
|
+ CreateWxOrderResult wxOrder = payService.createWxOrder(p);
|
|
|
+ if (wxOrder.getStatus().equals("100")) {
|
|
|
+ LiveOrderPayment mt = new LiveOrderPayment();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(wxOrder.getUpOrderId());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", wxOrder).put("type", "yb");
|
|
|
+ } else {
|
|
|
+ throw new CustomException("支付失败");
|
|
|
+ }
|
|
|
+ } else if (payConfigDTO.getType().equals("tz")) {
|
|
|
+ PayCreateOrder o = new PayCreateOrder();
|
|
|
+ o.setOrderNo("appLive" + storePayment.getPayCode()); // 业务系统订单号
|
|
|
+ o.setTrxAmt(storePayment.getPayMoney().doubleValue()); // 交易金额
|
|
|
+ o.setBusinessCstNo(order.getUserId().toString()); // 业务平台客户号
|
|
|
+ String phone = "";
|
|
|
+ if (user.getPhone() != null && user.getPhone().length() > 4) {
|
|
|
+ phone = user.getPhone().substring(user.getPhone().length() - 4);
|
|
|
+ }
|
|
|
+ o.setPayerName("微信用户" + phone);
|
|
|
+ o.setGoodsInfo("直播商品订单支付"); // 订单信息
|
|
|
+ o.setOpenId(user.getMaOpenId());
|
|
|
+ o.setOrderType(5);
|
|
|
+ o.setOrderId(order.getOrderId().toString());
|
|
|
+ TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(o);
|
|
|
+ LiveOrderPayment mt = new LiveOrderPayment();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getBody().getOrderFlowNo());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "tz");
|
|
|
+ } else if (payConfigDTO.getType().equals("hf")) {
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setReqSeqId("appLive-" + storePayment.getPayCode());
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
+ o.setGoodsDesc("直播商品订单支付");
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
+ LiveOrderPayment mt = new LiveOrderPayment();
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.error("用户OPENID不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int tuiOrder(Long orderId) {
|
|
|
+ LiveOrder liveOrder = new LiveOrder();
|
|
|
+ liveOrder.setOrderId(orderId);
|
|
|
+ try {
|
|
|
+ pushLiveOrder(liveOrder);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询订单
|
|
|
*
|
|
@@ -194,6 +810,184 @@ public class LiveOrderServiceImpl extends ServiceImpl<LiveOrderMapper, LiveOrder
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R syncExpress(Long id) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(id));
|
|
|
+ String lastFourNumber = "";
|
|
|
+ if (order.getDeliveryCode().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ lastFourNumber = order.getUserPhone();
|
|
|
+ if (lastFourNumber.length() == 11) {
|
|
|
+ lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
+ }else if(lastFourNumber.length() >11){
|
|
|
+ String jm = decryptPhone(lastFourNumber);
|
|
|
+ lastFourNumber = StrUtil.sub(jm, jm.length(), -4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExpressInfoDTO dto=expressService.getExpressInfo(order.getOrderCode(),order.getDeliveryCode(),order.getDeliverySn(),lastFourNumber);
|
|
|
+ log.info("快递鸟查询dto:{}", JSONUtil.toJsonStr(dto));
|
|
|
+ if (!dto.isSuccess()){
|
|
|
+ return R.error(dto.getReason());
|
|
|
+ }
|
|
|
+ if("0".equals(dto.getStateEx())&&"0".equals(dto.getState())){
|
|
|
+ lastFourNumber = "19923690275";
|
|
|
+ if (order.getDeliveryCode().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ lastFourNumber = order.getUserPhone();
|
|
|
+ if (lastFourNumber.length() == 11) {
|
|
|
+ lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dto=expressService.getExpressInfo(order.getOrderCode(),order.getDeliveryCode(),order.getDeliverySn(),lastFourNumber);
|
|
|
+ }
|
|
|
+ LiveOrder updateEntity = new LiveOrder();
|
|
|
+ updateEntity.setOrderId(order.getOrderId());
|
|
|
+ updateEntity.setDeliveryStatus(Integer.parseInt(dto.getState()));
|
|
|
+ updateEntity.setDeliveryType(dto.getStateEx());
|
|
|
+ baseMapper.updateLiveOrder(updateEntity);
|
|
|
+ //如果是正常签收,更新订单状态
|
|
|
+ if(dto.getState().equals("3")&&(dto.getStateEx().equals("301")||dto.getStateEx().equals("302")||dto.getStateEx().equals("304")||dto.getStateEx().equals("311"))){
|
|
|
+ this.getGoods(order.getOrderId());
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getGoods(Long orderId) {
|
|
|
+ // todo yhq
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
+ if (order==null)throw new CustomException("订单不存在");
|
|
|
+ if (order.getStatus()!= FsStoreOrderStatusEnum.STATUS_3.getValue())throw new CustomException("非法更改");
|
|
|
+ LiveOrder updateEntity = new LiveOrder();
|
|
|
+ updateEntity.setOrderId(order.getOrderId());
|
|
|
+ updateEntity.setUpdateTime(new DateTime());
|
|
|
+ updateEntity.setFinishTime(new Date());
|
|
|
+ updateEntity.setStatus(FsStoreOrderStatusEnum.STATUS_4.getValue());
|
|
|
+ log.info("确认收货:"+orderId);
|
|
|
+// logger.info("确认收货:"+orderId);
|
|
|
+// if (order.getCompanyId()!=null&&order.getTuiMoneyStatus()==0&&order.getPayType()==1){
|
|
|
+// logger.info("分佣:"+orderId);
|
|
|
+// companyService.addCompanyMoney(order);
|
|
|
+// o1.setTuiMoneyTime(new Date());
|
|
|
+// }
|
|
|
+// fsUserWatchService.addUserWatch(order);
|
|
|
+// int i = fsStoreOrderMapper.updateFsStoreOrder(o1);
|
|
|
+// fsStoreOrderLogsService.create(order.getOrderId(), FsStoreOrderLogEnum.FINISH_ORDER.getValue(),
|
|
|
+// FsStoreOrderLogEnum.FINISH_ORDER.getDesc());
|
|
|
+
|
|
|
+ int i = baseMapper.updateLiveOrder(updateEntity);
|
|
|
+
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateDeliveryOrder(Long orderId, String deliveryId, String deliverCode, String expressName) {
|
|
|
+ LiveOrder existOrder = baseMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
+ if (existOrder != null) {
|
|
|
+ FsExpress fsExpress = expressService.selectFsExpressByOmsCode(deliverCode);
|
|
|
+ if (fsExpress != null) {
|
|
|
+ LiveOrder updateEntity = new LiveOrder();
|
|
|
+ updateEntity.setOrderId(existOrder.getOrderId());
|
|
|
+ updateEntity.setDeliveryName(expressName);
|
|
|
+ updateEntity.setDeliverySn(deliveryId);
|
|
|
+ updateEntity.setDeliverySendTime(new Date());
|
|
|
+ baseMapper.updateLiveOrder(updateEntity);
|
|
|
+ // 订阅物流回调
|
|
|
+ String lastFourNumber = "";
|
|
|
+ if (fsExpress.getCode().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ lastFourNumber = existOrder.getUserPhone();
|
|
|
+ if (lastFourNumber.length() == 11) {
|
|
|
+ lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ expressService.subscribeEspress(existOrder.getOrderCode(),fsExpress.getCode(),deliveryId,lastFourNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<LiveGoodsVo> selectLiveOrderItemList(String orderId) {
|
|
|
+ LiveOrder liveOrder = baseMapper.selectLiveOrderByOrderId(orderId);
|
|
|
+ return liveGoodsMapper.selectProductListByOrder(liveOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R createLiveOrder(LiveOrder liveOrder) {
|
|
|
+// FsUser user=userMapper.selectFsUserByUserId(Long.valueOf(liveOrder.getUserId()));
|
|
|
+// if(user.getStatus()!=1){
|
|
|
+// return R.error("非法用户操作");
|
|
|
+// }
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
+ return R.error("订单已过期");
|
|
|
+ }
|
|
|
+ if(liveOrder.getLiveId() == null) return R.error("直播ID不能为空");
|
|
|
+ if(liveOrder.getProductId() == null) return R.error("购物商品ID不能为空");
|
|
|
+ if(liveOrder.getUserName() == null) return R.error("用户名不能为空");
|
|
|
+ if(liveOrder.getUserPhone() == null) return R.error("用户手机号不能为空");
|
|
|
+ if(liveOrder.getUserAddress() == null) return R.error("用户地址不能为空");
|
|
|
+ if(liveOrder.getTotalNum() == null) return R.error("商品数量不能为空");
|
|
|
+
|
|
|
+ Live live = liveMapper.selectLiveByLiveId(liveOrder.getLiveId());
|
|
|
+ if(live == null) return R.error("直播不存在");
|
|
|
+ FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductByProductId(liveOrder.getProductId());
|
|
|
+ LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
+ if(fsStoreProduct == null || goods == null) return R.error("商品不存在");
|
|
|
+ if(fsStoreProduct.getIsShow() == 0 || goods.getStatus() == 0) return R.error("商品已下架");
|
|
|
+
|
|
|
+// liveOrderItemMapper
|
|
|
+
|
|
|
+
|
|
|
+ //todo yhq
|
|
|
+ liveOrder.setOrderCode(OrderCodeUtils.getOrderSn());
|
|
|
+
|
|
|
+// liveOrder.setOrderCode(String.valueOf(UUID.randomUUID()));
|
|
|
+ liveOrder.setCreateTime(new Date());
|
|
|
+ liveOrder.setUpdateTime(new Date());
|
|
|
+ liveOrder.setStatus(FsStoreOrderStatusEnum.STATUS_1.getValue());
|
|
|
+ liveOrder.setPayType("1");
|
|
|
+ liveOrder.setTotalPrice(fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum())));
|
|
|
+ liveOrder.setPayMoney(liveOrder.getTotalPrice());
|
|
|
+ try {
|
|
|
+ if (baseMapper.insertLiveOrder(liveOrder) > 0) {
|
|
|
+ FsStoreOrderItemDTO dto=new FsStoreOrderItemDTO();
|
|
|
+ dto.setImage(fsStoreProduct.getImgUrl());
|
|
|
+ dto.setSku(String.valueOf(fsStoreProduct.getStoreId()));
|
|
|
+ dto.setBarCode(fsStoreProduct.getBarCode());
|
|
|
+ dto.setPrice(fsStoreProduct.getPrice());
|
|
|
+ dto.setNum(Long.valueOf(liveOrder.getTotalNum()));
|
|
|
+
|
|
|
+ LiveOrderItem liveOrderItem = new LiveOrderItem();
|
|
|
+ liveOrderItem.setOrderCode(liveOrder.getOrderCode());
|
|
|
+ liveOrderItem.setOrderId(liveOrder.getOrderId());
|
|
|
+ liveOrderItem.setProductId(liveOrder.getProductId());
|
|
|
+ liveOrderItem.setNum(Long.valueOf(liveOrder.getTotalNum()));
|
|
|
+ liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
|
|
|
+ liveOrderItemMapper.insertLiveOrderItem(liveOrderItem);
|
|
|
+ return R.ok("下单成功").put("order",liveOrder);
|
|
|
+ } else {
|
|
|
+ return R.error("订单创建失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常处理
|
|
|
+ return R.error("订单创建失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R confirmOrder(LiveOrderConfirmParam param) {
|
|
|
+ String uuid = IdUtil.randomUUID();
|
|
|
+ redisCache.setCacheObject("orderKey:"+uuid,uuid,200, TimeUnit.MINUTES);
|
|
|
+ return R.ok().put("orderKey",uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<LiveOrder> selectNotPushedLiveOrder() {
|
|
|
+ return baseMapper.selectNotPushedLiveOrder();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 订单操作记录
|
|
|
* */
|