|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.api.tools; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.common.bean.CustomerDataDictionary; | 
|---|
|  |  |  | 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.ShopOrderDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.pojo.OrderPostageInfoPOJO; | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  | private SysVipInfoService sysVipInfoService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日"); | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增发货信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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 ""; | 
|---|