|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.api.tools; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.common.bean.CustomerDataDictionary; | 
|---|
|  |  |  | import com.matrix.system.common.dao.CustomerDataDictionaryDao; | 
|---|
|  |  |  | import com.matrix.biz.service.BizUserService; | 
|---|
|  |  |  | import com.matrix.component.tools.WxTempLateMsgUtil; | 
|---|
|  |  |  | import com.matrix.core.exception.GlobleException; | 
|---|
|  |  |  | import com.matrix.core.tools.LogUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.system.common.bean.CustomerDataDictionary; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.AddShopOrderPOJO; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysVipInfoService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.OrderItemDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.OrderPostageInfoPOJO; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.OrderProductSkuPOJO; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.ShopOrderDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.WxShopMemberDayService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.*; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author jyy | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopMemberDayService wxShopMemberDayService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BizUserService bizUserService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopScoreRecordDao shopScoreRecordDao; | 
|---|
|  |  |  | private SysVipInfoService sysVipInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理产品规格信息 | 
|---|
|  |  |  | * @param addShopOrderPOJO | 
|---|
|  |  |  | * @param shopOrderDto | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<ShopOrderDetails> processProductSkuInfo(ShopOrder shopOrder, AddShopOrderPOJO addShopOrderPOJO, | 
|---|
|  |  |  | public List<ShopOrderDetails> processProductSkuInfo(ShopOrder shopOrder, ShopOrderDto shopOrderDto, | 
|---|
|  |  |  | ShopCoupon shopCoupon) { | 
|---|
|  |  |  | List<ShopOrderDetails> resList = new ArrayList<>(); | 
|---|
|  |  |  | List<OrderProductSkuPOJO> skuList = addShopOrderPOJO.getSkuList(); | 
|---|
|  |  |  | List<OrderItemDto> skuList = shopOrderDto.getOrderItemList(); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(skuList)) { | 
|---|
|  |  |  | return resList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //设置购买数量 | 
|---|
|  |  |  | int total = 0; | 
|---|
|  |  |  | BigDecimal commodityMoney = new BigDecimal("0"); | 
|---|
|  |  |  | for (OrderProductSkuPOJO orderProductSkuPOJO : skuList) { | 
|---|
|  |  |  | ids.add(orderProductSkuPOJO.getSkuId()); | 
|---|
|  |  |  | total += orderProductSkuPOJO.getCount(); | 
|---|
|  |  |  | for (OrderItemDto orderItemDto : skuList) { | 
|---|
|  |  |  | ids.add(orderItemDto.getSkuId()); | 
|---|
|  |  |  | total += orderItemDto.getCount(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | shopOrder.setPurchaseQuantity(total); | 
|---|
|  |  |  | List<ShopSku> contrastList = shopSkuDao.selectByIds(ids); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal couponTotalMoney = new BigDecimal("0"); | 
|---|
|  |  |  | Double discountRate = wxShopMemberDayService.getMemberDay(); | 
|---|
|  |  |  | for (OrderProductSkuPOJO orderProductSkuPOJO : skuList) { | 
|---|
|  |  |  | for (OrderItemDto orderItemDto : skuList) { | 
|---|
|  |  |  | boolean isExist = false; | 
|---|
|  |  |  | for (ShopSku shopSku : contrastList) { | 
|---|
|  |  |  | if (shopSku.getId().equals(orderProductSkuPOJO.getSkuId())) { | 
|---|
|  |  |  | if (shopSku.getId().equals(orderItemDto.getSkuId())) { | 
|---|
|  |  |  | isExist = true; | 
|---|
|  |  |  | ShopOrderDetails shopOrderDetails = new ShopOrderDetails(); | 
|---|
|  |  |  | shopOrderDetails.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | 
|---|
|  |  |  | shopOrderDetails.setpId(shopSku.getPId()); | 
|---|
|  |  |  | shopOrderDetails.setsId(shopSku.getId()); | 
|---|
|  |  |  | shopOrderDetails.setPrice(shopSku.getPrice()); | 
|---|
|  |  |  | shopOrderDetails.setCount(orderProductSkuPOJO.getCount()); | 
|---|
|  |  |  | shopOrderDetails.setCount(orderItemDto.getCount()); | 
|---|
|  |  |  | BigDecimal price = new BigDecimal(shopSku.getPrice().toString()); | 
|---|
|  |  |  | BigDecimal count = new BigDecimal(orderProductSkuPOJO.getCount().toString()); | 
|---|
|  |  |  | BigDecimal count = new BigDecimal(orderItemDto.getCount().toString()); | 
|---|
|  |  |  | shopOrderDetails.setsTitle(shopSku.getName()); | 
|---|
|  |  |  | resList.add(shopOrderDetails); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增发货信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int insertSendPackageInfo(ShopOrder shopOrder, String shippingMethod, ShopReceiveAddress receiveAddress) { | 
|---|
|  |  |  | public int insertSendPackageInfo(ShopOrder shopOrder, Integer shippingMethod, ShopReceiveAddress receiveAddress) { | 
|---|
|  |  |  | ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo(); | 
|---|
|  |  |  | shopDeliveryInfo.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopDeliveryInfo.setUpdateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | shopDeliveryInfo.setOrderId(shopOrder.getId()); | 
|---|
|  |  |  | shopDeliveryInfo.setOrderNo(shopOrder.getOrderNo()); | 
|---|
|  |  |  | shopDeliveryInfo.setUserId(shopOrder.getUserId()); | 
|---|
|  |  |  | shopDeliveryInfo.setDeliveryWay(shippingMethod); | 
|---|
|  |  |  | if(ShopOrder.SHIPPING_METHOD_WL==shippingMethod){ | 
|---|
|  |  |  | shopDeliveryInfo.setDeliveryWay("物流配送"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | shopDeliveryInfo.setDeliveryWay("门店自提"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shopDeliveryInfo.setShopId(shopOrder.getStoreId().longValue()); | 
|---|
|  |  |  | shopDeliveryInfo.setCompanyId(shopOrder.getCompanyId()); | 
|---|
|  |  |  | StringBuffer receiveAddrStr = new StringBuffer(); | 
|---|
|  |  |  | if (receiveAddress != null) { | 
|---|
|  |  |  | receiveAddrStr.append(receiveAddress.getAddrProvince()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发货后给客户发送微信提醒 | 
|---|
|  |  |  | * @param deliveryInfo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int deliverSuccessSendWxMsgToUser(ShopDeliveryInfo deliveryInfo) { | 
|---|
|  |  |  | ShopOrder order = shopOrderDao.selectById(deliveryInfo.getOrderId()); | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | throw new GlobleException("没有找到需要发货的订单信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> msg = new ArrayList<>(); | 
|---|
|  |  |  | msg.add(order.getOrderNo()); | 
|---|
|  |  |  | //设置商品名称 | 
|---|
|  |  |  | msg.add(getProductNames(order.getUserId(), order.getId())); | 
|---|
|  |  |  | msg.add(deliveryInfo.getReceiveAddress()); | 
|---|
|  |  |  | msg.add(deliveryInfo.getLogisticsCompany()); | 
|---|
|  |  |  | msg.add(deliveryInfo.getWaybillNo()); | 
|---|
|  |  |  | String formId = order.getWxOrderNo().split("=")[1]; | 
|---|
|  |  |  | String page = "pages/logistics/logistics?inform=1&id=" + order.getId(); | 
|---|
|  |  |  | int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(), | 
|---|
|  |  |  | page, WxTempLateMsgUtil.ORDER_DELIVERY, formId); | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 订单付款成功后给客户发送微信提醒 | 
|---|
|  |  |  | * @param order | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int paySuccessSendWxMsgToUser(ShopOrder order) { | 
|---|
|  |  |  | List<String> msg = new ArrayList<>(); | 
|---|
|  |  |  | msg.add(order.getOrderNo()); | 
|---|
|  |  |  | msg.add(new BigDecimal(order.getOrderMoney().toString()).toString() + "元"); | 
|---|
|  |  |  | msg.add(dateFormat.format(order.getOrderTime())); | 
|---|
|  |  |  | msg.add(getProductNames(order.getUserId(), order.getId())); | 
|---|
|  |  |  | String formId = order.getWxOrderNo().split("=")[1]; | 
|---|
|  |  |  | String page = "pages/orderDetails/orderDetails?inform=1&id=" + order.getId(); | 
|---|
|  |  |  | return WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(), page, WxTempLateMsgUtil.ORDER_PAY_SUCCESS, formId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户ID和订单ID获取所购买商品名称 | 
|---|
|  |  |  | * @param openId 用户openId | 
|---|
|  |  |  | * @param orderId 订单ID | 
|---|
|  |  |  | * @return 所含商品名称(多个以","隔开) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String getProductNames(String openId, Integer orderId) { | 
|---|
|  |  |  | ShopOrder orderDetail = shopOrderDao.selectOrderInfoById(openId, orderId); | 
|---|
|  |  |  | public String getProductNames(Long userId, Integer orderId) { | 
|---|
|  |  |  | ShopOrder orderDetail = shopOrderDao.selectOrderInfoById(userId, orderId); | 
|---|
|  |  |  | List<ShopOrderDetails> details = orderDetail.getDetails(); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(details)) { | 
|---|
|  |  |  | return ""; | 
|---|