| package com.matrix.system.shopXcx.api.service.impl; | 
|   | 
| import com.google.gson.Gson; | 
| import com.google.gson.GsonBuilder; | 
| import com.matrix.biz.bean.BizUser; | 
| import com.matrix.system.common.bean.BusParameterSettings; | 
| import com.matrix.system.common.bean.CustomerDataDictionary; | 
| import com.matrix.system.common.dao.BusParameterSettingsDao; | 
| import com.matrix.system.common.dao.CustomerDataDictionaryDao; | 
| import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.component.tools.WxUtils; | 
| import com.matrix.component.wechat.externalInterface.protocol.paramProtocol.BrandWCPayRequestData; | 
| import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; | 
| import com.matrix.core.exception.GlobleException; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.tools.LogUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.system.common.constance.AppConstance; | 
| import com.matrix.system.common.interceptor.HostInterceptor; | 
| import com.matrix.system.constance.Dictionary; | 
| import com.matrix.system.hive.bean.ShoppingGoods; | 
| import com.matrix.system.hive.dao.ShoppingGoodsDao; | 
| import com.matrix.system.shopXcx.api.action.PayThreadPool; | 
| import com.matrix.system.shopXcx.api.pojo.AddShopOrderPOJO; | 
| import com.matrix.system.shopXcx.api.pojo.OrderInfoQueryPOJO; | 
| import com.matrix.system.shopXcx.api.service.ShoppingCartService; | 
| import com.matrix.system.shopXcx.api.service.WXShopOrderService; | 
| import com.matrix.system.shopXcx.api.service.WxShopCouponService; | 
| import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil; | 
| import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil; | 
| import com.matrix.system.shopXcx.api.vo.CouponReceiveInfoVO; | 
| import com.matrix.system.shopXcx.api.vo.ShopCartBillVo; | 
| import com.matrix.system.shopXcx.api.vo.ShopCartVo; | 
| import com.matrix.system.shopXcx.bean.*; | 
| import com.matrix.system.shopXcx.dao.*; | 
| import com.matrix.system.shopXcx.dto.DiscountExplain; | 
| import org.apache.commons.collections.CollectionUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.math.BigDecimal; | 
| import java.util.*; | 
|   | 
| /** | 
|  * @author jyy | 
|  * @description 订单服务层 | 
|  * @date 2019-06-10 10:58 | 
|  */ | 
| @Service | 
| public class WXShopOrderServiceImpl implements WXShopOrderService { | 
|     @Autowired | 
|     private WxShopOrderUtil wxShopOrderUtil; | 
|     @Autowired | 
|     private WxShopCouponUtil wxShopCouponUtil; | 
|     @Autowired | 
|     private RedisUserLoginUtils redisUserLoginUtils; | 
|     @Autowired | 
|     private WeixinServiceUtil weixinServiceUtil; | 
|     @Autowired | 
|     private ShopSkuDao shopSkuDao; | 
|     @Autowired | 
|     private ShopReceiveAddressDao shopReceiveAddressDao; | 
|     @Autowired | 
|     private ShopOrderDao shopOrderDao; | 
|     @Autowired | 
|     private ShopOrderDetailsDao shopOrderDetailsDao; | 
|     @Autowired | 
|     private ShopCouponDao shopCouponDao; | 
|     @Autowired | 
|     private ShopProductDao shopProductDao; | 
|     @Autowired | 
|     private ShopCouponRecordDao shopCouponRecordDao; | 
|     @Autowired | 
|     ShoppingGoodsDao shoppingGoodsDao; | 
|     @Autowired | 
|     ShoppingCartService shoppingCartService; | 
|   | 
|     @Autowired | 
|     WxShopCouponService wxShopCouponService; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupJoinDao shopActivitiesGroupJoinDao; | 
|   | 
|     @Autowired | 
|     private ShopShoppingCartDao shoppingCartDao; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupJoinUserDao shopActivitiesGroupJoinUserDao; | 
|   | 
|     @Autowired | 
|     CustomerDataDictionaryDao dataDictionaryDao; | 
|     @Value("${wx_pay_debug_onoff}") | 
|     private boolean isDebug; | 
|   | 
|     @Autowired | 
|     private BusParameterSettingsDao busParameterSettingsDao; | 
|   | 
|     @Override | 
|     public BigDecimal calculationPostage(Integer addressId, BigDecimal payPrice) { | 
|         BigDecimal postage = BigDecimal.ZERO; | 
|         if (addressId != null) { | 
|             ShopReceiveAddress shopReceiveAddress = shopReceiveAddressDao.selectById(addressId); | 
|   | 
|   | 
|             BusParameterSettings sn= busParameterSettingsDao.selectCompanyParamByCode(AppConstance.IN_PROVINCE_PACKAGE_LIST,17L); | 
|   | 
|   | 
|             BusParameterSettings pydq= busParameterSettingsDao.selectCompanyParamByCode(AppConstance.SECOND_PROVINCE_PACKAGE_LIST,17L); | 
|   | 
|   | 
|   | 
|             if (sn.getParamValue().indexOf(shopReceiveAddress.getAddrProvince()) > -1) { | 
|                 //省内邮费计算 | 
|                 postage = getPostageByDataBictionary(AppConstance.IN_PROVINCE_PACKAGE_PRICE, payPrice); | 
|             } else if (pydq.getParamValue().indexOf(shopReceiveAddress.getAddrProvince()) > -1) { | 
|                 //偏远地区 | 
|                 postage = getPostageByDataBictionary(AppConstance.SECOND_OUT_PROVINCE_PACKAGE_PRICE, payPrice); | 
|             } else { | 
|                 //其他地区 | 
|                 postage = getPostageByDataBictionary(AppConstance.FIRST_OUT_PROVINCE_PACKAGE_PRICE, payPrice); | 
|             } | 
|   | 
|         } | 
|         return postage; | 
|     } | 
|   | 
|     //todo 根据数据字典计算运费  运费设置为0 后面再改配置在改计算规则 | 
|     private BigDecimal getPostageByDataBictionary(String code, BigDecimal payPrice) { | 
|   | 
|         /*CustomerDataDictionary dd = dataDictionaryDao.selectByTypeCode(code); | 
|   | 
|   | 
|         BigDecimal postage = BigDecimal.ZERO; | 
|         if (StringUtils.isNotBlank(dd.getValue())) { | 
|             if (StringUtils.isNotBlank(dd.getExtValue()) | 
|                     && payPrice.compareTo(new BigDecimal(dd.getExtValue())) >= 0) { | 
|                 //达到条件免邮 | 
|                 postage = BigDecimal.ZERO; | 
|             } else { | 
|                 postage = new BigDecimal(dd.getValue()); | 
|             } | 
|         }*/ | 
|         return BigDecimal.ZERO; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 创建订单 | 
|      * | 
|      * @param addShopOrderPOJO | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     @Override | 
|     public AjaxResult createShopOrder(AddShopOrderPOJO addShopOrderPOJO) throws Exception { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|   | 
|   | 
|         //校验收货地址 | 
|         ShopReceiveAddress shopReceiveAddress = shopReceiveAddressDao.selectById(addShopOrderPOJO.getReceiveAddrId()); | 
|         if (shopReceiveAddress == null) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择正确的收获地址"); | 
|         } | 
|   | 
|   | 
|         List<ShopCartVo> cartList = shoppingCartService.findUserCartList(addShopOrderPOJO.getShopId()); | 
|         //购物车不能为空 | 
|         if (CollectionUtils.isEmpty(cartList)) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择您需要购买的产品"); | 
|         } | 
|   | 
|   | 
|         //取出购物车中选中的产品 | 
|         List<ShopShoppingCart> buyCart = new ArrayList<>(); | 
|         //取出购物车中没有参加店铺活动的产品,和参加了店铺活动但是活动没有达到标准的产品,用来计算是否可以使用优惠券 | 
|         List<ShopShoppingCart> notCouponuyCart = new ArrayList<>(); | 
|         for (ShopCartVo shopCartVo : cartList) { | 
|             for (ShopShoppingCart shopShoppingCart : shopCartVo.getCartList()) { | 
|                 if (shopShoppingCart.getIsSelected() == 1) { | 
|                     buyCart.add(shopShoppingCart); | 
|                     if (shopCartVo.getCoupon() == null || !shopCartVo.isSatisfactionCoupon()) { | 
|                         notCouponuyCart.add(shopShoppingCart); | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|         //计算订单优惠信息 | 
|         DiscountExplain discountExplain = buildDiscountExplain(cartList, addShopOrderPOJO.getCouponReceiveId(), shopReceiveAddress.getAddrId()); | 
|   | 
|   | 
|         ShopOrder shopOrder = new ShopOrder(); | 
|         shopOrder.setCompanyId(bizUser.getCompanyId()); | 
|         shopOrder.setStoreId(Integer.parseInt(addShopOrderPOJO.getShopId().toString())); | 
|         shopOrder.setOrderType(ShopOrder.ORDER_TYPE_SERVICE); | 
|   | 
|         List<ShopOrderDetails> details = new ArrayList<>(); | 
|         Integer cartCount = 0; | 
|         for (ShopShoppingCart shopShoppingCart : buyCart) { | 
|             ShopOrderDetails shopOrderDetails = new ShopOrderDetails(); | 
|             shopOrderDetails.setCreateBy(AppConstance.SYSTEM_USER); | 
|             shopOrderDetails.setUpdateBy(AppConstance.SYSTEM_USER); | 
|             shopOrderDetails.setpId(shopShoppingCart.getCartProductId()); | 
|             shopOrderDetails.setsId(shopShoppingCart.getCartSkuId()); | 
|             shopOrderDetails.setPrice(shopShoppingCart.getPrice()); | 
|             shopOrderDetails.setCount(shopShoppingCart.getCartNumber()); | 
|             shopOrderDetails.setsTitle(shopShoppingCart.getTitle() + shopShoppingCart.getName()); | 
|             shopOrderDetails.setDiscountAmount(BigDecimal.ZERO); | 
|             shopOrderDetails.setTotalPrice(shopOrderDetails.getPrice().multiply(BigDecimal.valueOf(shopOrderDetails.getCount()))); | 
|             details.add(shopOrderDetails); | 
|             cartCount += shopOrderDetails.getCount(); | 
|   | 
|             //查询绑定的产品是否为家居产品,如果已经含家具产品则不再比较 | 
|             if (ShopOrder.ORDER_TYPE_GOODS != shopOrder.getOrderType()) { | 
|                 ShopSku shopSku = shopSkuDao.selectById(shopShoppingCart.getCartSkuId()); | 
|                 String stokCode = shopSku.getStockCode(); | 
|                 if (StringUtils.isNotBlank(stokCode)) { | 
|                     ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(Long.parseLong(stokCode)); | 
|                     if (shoppingGoods != null) { | 
|                         //根据购买的产品设置订单类型 | 
|                         if (Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(shoppingGoods.getGoodType())) { | 
|                             shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS); | 
|                         } else { | 
|   | 
|                         } | 
|                     } else { | 
|                         shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS); | 
|                     } | 
|                 } | 
|             } | 
|   | 
|   | 
|         } | 
|   | 
|         //校验商品是否限购 | 
|         wxShopOrderUtil.verifyProductLimitInfo(details, bizUser.getOpenId()); | 
|         //TODO 更新库存和销量 更新库存和销量[考虑和erp库存联动] | 
|         wxShopOrderUtil.updateProductAndSkuInfo(details); | 
|         //用户openId | 
|         shopOrder.setUserId(bizUser.getOpenId()); | 
|         shopOrder.setCreateBy("微信小程序生成"); | 
|         shopOrder.setUpdateBy("微信小程序生成"); | 
|         shopOrder.setCommodityPrice(discountExplain.getBillPrice()); | 
|         shopOrder.setPurchaseQuantity(cartCount); | 
|         //购买方式 | 
|         shopOrder.setShippingMethod(addShopOrderPOJO.getDeliverySelect()); | 
|         //生成订单号 | 
|         shopOrder.setOrderNo(WxUtils.getOrderNum()); | 
|         //设置支付状态 | 
|         shopOrder.setPayStatus(ShopOrder.ORDER_STATUS_WAIT_PAY); | 
|         //设置订单状态 | 
|         shopOrder.setOrderStatus(ShopOrder.ORDER_PAY_STATUS_WAIT); | 
|   | 
|         //设置退款费用(注:下次优化从数据字典表获取) | 
|         shopOrder.setRefundCharge(BigDecimal.ZERO); | 
|         //客户电话 | 
|         shopOrder.setUserTel(shopReceiveAddress.getAddrTelephone()); | 
|         //客户姓名 | 
|         shopOrder.setUserName(shopReceiveAddress.getAddrLiaisonman()); | 
|         //备注 | 
|         shopOrder.setRemarks(addShopOrderPOJO.getRemarks()); | 
|         //删除标识 | 
|         shopOrder.setDelFlag(AppConstance.DATA_USEABLE); | 
|         //微信订单号 | 
|         shopOrder.setWxOrderNo(""); | 
|         //微信支付结果 | 
|         shopOrder.setPayResult(ShopOrder.ORDER_WX_STATUS_WAIT_PAY); | 
|         //如果没有提交购买方式或配送方式不是物流 | 
|         //获取邮费 | 
|         shopOrder.setPostage(discountExplain.getPostage()); | 
|         shopOrder.setOrderMoney(discountExplain.getPayPrice()); | 
|         Gson g = new GsonBuilder().create(); | 
|         shopOrder.setDiscountExplain(g.toJson(discountExplain)); | 
|         shopOrder.setDiscountAmount(discountExplain.getActivity().add(discountExplain.getCoupon())); | 
|         shopOrder.setCompanyId(HostInterceptor.getCompanyId()); | 
|         shopOrderDao.insert(shopOrder); | 
|   | 
|         wxShopOrderUtil.insertSendPackageInfo(shopOrder, addShopOrderPOJO.getDeliverySelect(), shopReceiveAddress); | 
|         //给订单详情表添加订单ID | 
|         for (ShopOrderDetails shopOrderDetails : details) { | 
|             shopOrderDetails.setOrderId(shopOrder.getId()); | 
|         } | 
|         if (CollectionUtils.isNotEmpty(details)) { | 
|             shopOrderDetailsDao.batchInsert(details); | 
|         } | 
|         //更新使用的优惠券状态 | 
|         if (addShopOrderPOJO.getCouponReceiveId() != null) { | 
|             ShopCouponRecord record = new ShopCouponRecord(); | 
|             record.setIsUsing(AppConstance.MY_COUPON_USE); | 
|             record.setOrderId(shopOrder.getId()); | 
|             record.setId(addShopOrderPOJO.getCouponReceiveId()); | 
|             shopCouponRecordDao.updateByModel(record); | 
|         } | 
|   | 
|         //删除用户购物车选中的产品 | 
|         shoppingCartDao.deleteUserSelectCart(bizUser.getOpenId()); | 
|   | 
|   | 
|         BrandWCPayRequestData payData = startPayment(shopOrder); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(payData)); | 
|         result.putInMap("orderId", shopOrder.getId()); | 
|   | 
|         return result; | 
|     } | 
|   | 
|     @Override | 
|     public DiscountExplain buildDiscountExplain(List<ShopCartVo> cartList, Integer receiveId, Integer receiveAddrId) { | 
|         ShopCartBillVo shopCartBill = shoppingCartService.buildShopCartBillVo(cartList); | 
|         DiscountExplain discountExplain = new DiscountExplain(); | 
|         discountExplain.setActivity(shopCartBill.getBillCouponTotal()); | 
|         discountExplain.setBillPrice(shopCartBill.getSrcTotal()); | 
|         discountExplain.setPayPrice(shopCartBill.getBillTotal()); | 
|         //计算优惠券 | 
|         if (receiveId != null) { | 
|             CouponReceiveInfoVO couponReceiveInfoVO = shopCouponRecordDao.selectMyCouponByReceiveId(receiveId); | 
|             if (couponReceiveInfoVO != null) { | 
|                 BigDecimal payPrice = discountExplain.getPayPrice().subtract(couponReceiveInfoVO.getOffsetAmount()); | 
|                 payPrice = payPrice.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : payPrice; | 
|                 discountExplain.setPayPrice(payPrice); | 
|                 discountExplain.setCoupon(couponReceiveInfoVO.getOffsetAmount()); | 
|             } | 
|         } | 
|   | 
|         discountExplain.setPostage(calculationPostage(receiveAddrId, discountExplain.getPayPrice())); | 
|   | 
|         //计算实际支付 | 
|         discountExplain.setPayPrice(discountExplain.getPayPrice().add(discountExplain.getPostage())); | 
|         return discountExplain; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 根据订单ID结算订单 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public AjaxResult orderSettlement(int orderId) throws Exception { | 
|         ShopOrder shopOrder = shopOrderDao.selectById(orderId); | 
|         if (shopOrder == null) { | 
|             throw new GlobleException("订单不存在!"); | 
|         } | 
|         if (!shopOrder.getPayResult().equals(ShopOrder.ORDER_PAY_STATUS_WAIT)) { | 
|             throw new GlobleException("该订单不是待支付状态!"); | 
|         } | 
|         BrandWCPayRequestData payData = startPayment(shopOrder); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(payData)); | 
|         result.putInMap("orderId", shopOrder.getId()); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 开始付款 | 
|      * | 
|      * @param shopOrder | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public BrandWCPayRequestData startPayment(ShopOrder shopOrder) throws Exception { | 
|         BigDecimal unit = new BigDecimal("100"); | 
|         BigDecimal money = new BigDecimal(shopOrder.getOrderMoney().toString()); | 
|         BrandWCPayRequestData payData; | 
|         String productNames = wxShopOrderUtil.getProductNames(shopOrder.getUserId(), shopOrder.getId()); | 
|         LogUtil.debug(String.valueOf(isDebug)); | 
|         if (isDebug) { | 
|             payData = weixinServiceUtil.createOrder("[测试]" + productNames, shopOrder.getOrderNo(), | 
|                     1, shopOrder.getUserId(), String.valueOf(shopOrder.getId())); | 
|         } else { | 
|             payData = weixinServiceUtil.createOrder(productNames, shopOrder.getOrderNo(), | 
|                     unit.multiply(money).intValue(), shopOrder.getUserId(), String.valueOf(shopOrder.getId())); | 
|         } | 
|         ShopOrder updateParam = new ShopOrder(); | 
|         updateParam.setId(shopOrder.getId()); | 
|         updateParam.setWxOrderNo(payData.getPrepay_id()); | 
|         shopOrderDao.updateByModel(updateParam); | 
|         return payData; | 
|     } | 
|   | 
|     /** | 
|      * 根据订单状态等条件获取我的订单列表 | 
|      * | 
|      * @param orderInfoQueryPOJO | 
|      * @return | 
|      */ | 
|     @Override | 
|     public AjaxResult getMyOrderInfo(OrderInfoQueryPOJO orderInfoQueryPOJO) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         orderInfoQueryPOJO.setSort("update_time"); | 
|         if (orderInfoQueryPOJO.getOffset() >= 1) { | 
|             orderInfoQueryPOJO.setOffset((orderInfoQueryPOJO.getOffset() - 1) * orderInfoQueryPOJO.getLimit()); | 
|         } | 
|         List<ShopOrder> result = shopOrderDao.selectMyOrderByStatus(bizUser.getOpenId(), orderInfoQueryPOJO); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, result); | 
|     } | 
|   | 
|     /** | 
|      * 根据订单ID查询订单详情 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      */ | 
|     @Override | 
|     public AjaxResult getOrderInfoById(Integer orderId) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         ShopOrder shopOrder = shopOrderDao.selectOrderInfoById(bizUser.getOpenId(), orderId); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(shopOrder)); | 
|     } | 
|   | 
|     /** | 
|      * 取消待付款订单 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     @Override | 
|     public AjaxResult cancelOrderWhenWaitPay(Integer orderId) { | 
|         updateStockAndVolumeById(orderId); | 
|         ShopOrder shopOrder = shopOrderDao.selectById(orderId); | 
|         //如果订单不是待付款状态 | 
|         if (ShopOrder.ORDER_PAY_STATUS_WAIT != shopOrder.getOrderStatus()) { | 
|             throw new GlobleException("该订单不是待付款状态!"); | 
|         } | 
|         if (shopOrder.getDiscountAmount() != null && shopOrder.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) { | 
|             ShopCouponRecord shopCouponRecord = new ShopCouponRecord(); | 
|             BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|             shopCouponRecord.setUserId(bizUser.getOpenId()); | 
|             shopCouponRecord.setOrderId(orderId); | 
|             List<ShopCouponRecord> recordList = shopCouponRecordDao.selectByModel(shopCouponRecord); | 
|             if (CollectionUtils.isNotEmpty(recordList)) { | 
|                 for (ShopCouponRecord record : recordList) { | 
|                     Map<String, Object> modifyMap = new HashMap<>(); | 
|                     modifyMap.put("id", record.getId()); | 
|                     modifyMap.put("orderId", 0); | 
|                     modifyMap.put("isUsing", AppConstance.MY_COUPON_NOT_USE); | 
|                     shopCouponRecordDao.updateByMap(modifyMap); | 
|                 } | 
|             } | 
|         } | 
|   | 
|         ShopActivitiesGroupJoinUser joinUser = shopActivitiesGroupJoinUserDao.selectGroupJoinUserByOrderId(orderId.longValue()); | 
|         if (joinUser != null) { | 
|             joinUser.setIsHasCancel(ShopActivitiesGroupJoinUser.IS_HAS_CANCEL_Y); | 
|             shopActivitiesGroupJoinUserDao.updateByModel(joinUser); | 
|             if (joinUser.getIsHead() == ShopActivitiesGroupJoinUser.USER_IS_HEAD_Y) { | 
|                 ShopActivitiesGroupJoin groupJoin = new ShopActivitiesGroupJoin(); | 
|                 groupJoin.setId(joinUser.getGjId()); | 
|                 groupJoin.setGjStatus(ShopActivitiesGroupJoin.ACTIVITIES_JOIN_FAIL); | 
|                 shopActivitiesGroupJoinDao.updateByModel(groupJoin); | 
|             } | 
|         } | 
|   | 
|         //构建需要修改订单信息Map | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("id", orderId); | 
|         modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_CANCEL); | 
|         shopOrderDao.updateByMap(modifyMap); | 
|   | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "订单取消成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 删除已取消订单 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      */ | 
|     @Override | 
|     public AjaxResult delOrderById(Integer orderId) { | 
|         ShopOrder order = shopOrderDao.selectById(orderId); | 
|         if (order == null) { | 
|             throw new GlobleException("没有找到该订单!"); | 
|         } | 
|         if (!order.getOrderStatus().equals(ShopOrder.ORDER_STATUS_CANCEL)) { | 
|             throw new GlobleException("该订单不是取消状态,不能删除!"); | 
|         } | 
|   | 
|         //构建需要修改订单信息Map | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("id", order.getId()); | 
|         modifyMap.put("delFlag", AppConstance.DATA_DISABLE); | 
|         shopOrderDao.updateByMap(modifyMap); | 
|   | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 订单确认收货 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      */ | 
|     @Override | 
|     public AjaxResult confirmPackageById(Integer orderId) { | 
|         ShopOrder shopOrder = shopOrderDao.selectById(orderId); | 
|         //如果不是待收货状态 | 
|         if (ShopOrder.ORDER_STATUS_WAIT_RECEIVE != shopOrder.getOrderStatus()) { | 
|             throw new GlobleException("该订单不是待收货状态!"); | 
|         } | 
|         shopOrder.setOrderStatus(ShopOrder.ORDER_STATUS_WAIT_REMARK); | 
|         shopOrderDao.updateByModel(shopOrder); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "订单收货成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 加库存减销量 | 
|      * | 
|      * @param orderId | 
|      * @return wlz | 
|      */ | 
|     @Override | 
|     public AjaxResult updateStockAndVolumeById(Integer orderId) { | 
|         //通过订单ID查询订单详情 | 
|         List<ShopOrderDetails> shopOrderDetails = shopOrderDetailsDao.selectByOrderId(orderId); | 
|         if (CollectionUtils.isNotEmpty(shopOrderDetails)) { | 
|             for (ShopOrderDetails orderDetails : shopOrderDetails) { | 
|                 Integer count = orderDetails.getCount(); | 
|                 Integer pId = orderDetails.getpId(); | 
|                 Integer sId = orderDetails.getsId(); | 
|                 ShopProduct shopProduct = shopProductDao.selectById(pId); | 
|                 //获取此产品的总展示销量和真实销量 | 
|                 Integer dsVolume = shopProduct.getDsVolume(); | 
|                 Integer rsVolume = shopProduct.getRsVolume(); | 
|                 //退货减销量 | 
|                 Integer updateDs = dsVolume - count; | 
|                 Integer updateRs = rsVolume - count; | 
|                 Map<String, Object> modifyMap = new HashMap<>(); | 
|                 modifyMap.put("id", pId); | 
|                 modifyMap.put("dsVolume", updateDs); | 
|                 modifyMap.put("rsVolume", updateRs); | 
|                 shopProductDao.updateByMap(modifyMap); | 
|   | 
|                 //加库存 | 
|                 ShopSku shopSku = shopSkuDao.selectById(sId); | 
|                 Integer stock = shopSku.getStock(); | 
|                 Integer updateStock = stock + count; | 
|                 Map<String, Object> modifyStock = new HashMap<>(); | 
|                 modifyStock.put("id", sId); | 
|                 modifyStock.put("stock", updateStock); | 
|                 shopSkuDao.updateByMap(modifyStock); | 
|             } | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "加库存减销量修改成功!"); | 
|     } | 
|   | 
|     /** | 
|      * 查询订单支付状态 | 
|      * | 
|      * @param orderId | 
|      * @return | 
|      */ | 
|     @Autowired | 
|     RabiitMqTemplate rabiitMqTemplate; | 
|   | 
|     @Override | 
|     public AjaxResult findOrderPayStatus(Integer orderId) { | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, ""); | 
|         result.putInMap("status", "err"); | 
|         result.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:005)"); | 
|   | 
|         ShopOrder order = shopOrderDao.selectById(orderId); | 
|         if (order.getPayStatus().equals(ShopOrder.ORDER_PAY_STATUS_SUCCESS)) { | 
|             result.putInMap("status", "success"); | 
|             result.putInMap("msg", "支付成功"); | 
|   | 
|         } else if (order.getPayStatus().equals(ShopOrder.ORDER_PAY_STATUS_FAIL)) { | 
|             result.putInMap("status", "err"); | 
|             result.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息"); | 
|         } else { | 
|   | 
|             LogUtil.debug("订单等待支付中={}。。。", orderId); | 
|             PayThreadPool.waitThread(orderId, new Object()); | 
|             result = PayThreadPool.getThreadResult(orderId); | 
|             LogUtil.debug("订单支付完成={}。。。", orderId); | 
|   | 
|         } | 
|         ShopActivitiesGroupJoin groupBuyStatus = shopActivitiesGroupJoinDao.selectGroupBuyByOrderId(orderId); | 
|         if (groupBuyStatus != null) { | 
|             result.putInMap("groupBuyStatus", groupBuyStatus.getGjStatus()); | 
|             result.putInMap("gjId", groupBuyStatus.getId()); | 
|         } | 
|         return result; | 
|     } | 
|   | 
| } |