| | |
| | | package com.matrix.system.shopXcx.api.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.matrix.biz.bean.BizUser; |
| | | import com.matrix.system.hive.bean.SysVipInfo; |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.component.redis.RedisUserLoginUtils; |
| | | import com.matrix.component.tools.WxUtils; |
| | |
| | | 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.bean.BusParameterSettings; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.common.dao.CustomerDataDictionaryDao; |
| | | 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.hive.dao.SysVipInfoDao; |
| | | import com.matrix.system.score.dao.ScoreVipDetailDao; |
| | | import com.matrix.system.shopXcx.api.action.PayThreadPool; |
| | | import com.matrix.system.shopXcx.api.pojo.AddShopOrderPOJO; |
| | | import com.matrix.system.shopXcx.api.pojo.OrderCouponGroup; |
| | | import com.matrix.system.shopXcx.api.pojo.OrderInfoQueryPOJO; |
| | | import com.matrix.system.shopXcx.api.pojo.OrderItemDto; |
| | | import com.matrix.system.shopXcx.api.pojo.ShopOrderDto; |
| | | import com.matrix.system.shopXcx.api.service.OrderCouponGroupService; |
| | | 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 java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author jyy |
| | |
| | | private ShopActivitiesGroupJoinUserDao shopActivitiesGroupJoinUserDao; |
| | | |
| | | @Autowired |
| | | OrderCouponGroupService orderCouponGroupService; |
| | | |
| | | @Autowired |
| | | CustomerDataDictionaryDao dataDictionaryDao; |
| | | @Value("${wx_pay_debug_onoff}") |
| | | private boolean isDebug; |
| | |
| | | @Autowired |
| | | private BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | @Autowired |
| | | private ScoreVipDetailDao scoreVipDetailDao; |
| | | |
| | | |
| | | @Autowired |
| | | private SysVipInfoDao sysVipInfoDao; |
| | | @Override |
| | | public BigDecimal calculationPostage(Integer addressId, BigDecimal payPrice) { |
| | | public BigDecimal calculationPostage(BigDecimal payPrice, Long companyId) { |
| | | 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); |
| | | BusParameterSettings yf = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.PACKAGE_PRICE, companyId); |
| | | BusParameterSettings myje = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.FREE_PACKAGE_PRICE, companyId); |
| | | if (yf != null && myje != null) { |
| | | if (Double.parseDouble(myje.getParamValue()) > payPrice.doubleValue()) { |
| | | postage = new BigDecimal(yf.getParamValue()); |
| | | } |
| | | |
| | | } |
| | | 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 |
| | | * @param shopOrderDto |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public AjaxResult createShopOrder(AddShopOrderPOJO addShopOrderPOJO) throws Exception { |
| | | BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); |
| | | public AjaxResult createShopOrder(ShopOrderDto shopOrderDto) throws Exception { |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | |
| | | |
| | | //校验收货地址 |
| | | ShopReceiveAddress shopReceiveAddress = shopReceiveAddressDao.selectById(addShopOrderPOJO.getReceiveAddrId()); |
| | | ShopReceiveAddress shopReceiveAddress = shopReceiveAddressDao.selectById(shopOrderDto.getReceiveAddrId()); |
| | | if (shopReceiveAddress == null) { |
| | | return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择正确的收获地址"); |
| | | } |
| | | |
| | | //计算订单优惠信息 |
| | | AjaxResult caculateResult= buildDiscountExplain(shopOrderDto); |
| | | DiscountExplain discountExplain= (DiscountExplain) caculateResult.getMapInfo().get("discountExplain"); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | if(discountExplain.getScorePay()!=null){ |
| | | //校验用户积分是否够用 |
| | | int score=scoreVipDetailDao.selectUserTotalScore(sysVipInfo.getId()); |
| | | if(score<discountExplain.getScorePay()){ |
| | | return AjaxResult.buildFailInstance("积分不足"); |
| | | } |
| | | } |
| | | |
| | | //计算订单优惠信息 |
| | | DiscountExplain discountExplain = buildDiscountExplain(cartList, addShopOrderPOJO.getCouponReceiveId(), shopReceiveAddress.getAddrId()); |
| | | |
| | | |
| | | ShopOrder shopOrder = new ShopOrder(); |
| | | shopOrder.setCompanyId(bizUser.getCompanyId()); |
| | | shopOrder.setStoreId(Integer.parseInt(addShopOrderPOJO.getShopId().toString())); |
| | | shopOrder.setCompanyId(sysVipInfo.getCompanyId()); |
| | | shopOrder.setStoreId(Integer.parseInt(shopOrderDto.getShopId().toString())); |
| | | //默认设置为产品类型 |
| | | shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS); |
| | | |
| | | List<ShopOrderDetails> details = new ArrayList<>(); |
| | | Integer cartCount = 0; |
| | | for (ShopShoppingCart shopShoppingCart : buyCart) { |
| | | Integer orderCount = 0; |
| | | for (OrderItemDto orderItemDto : shopOrderDto.getOrderItemList()) { |
| | | 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); |
| | | } |
| | | } |
| | | shopOrderDetails.setpId(orderItemDto.getProductId()); |
| | | shopOrderDetails.setsId(orderItemDto.getSkuId()); |
| | | shopOrderDetails.setCount(orderItemDto.getCount()); |
| | | if(ShopOrderDetails.PAYTYPE_MICRO==orderItemDto.getPayType()){ |
| | | shopOrderDetails.setPrice(orderItemDto.getShopSku().getPrice()); |
| | | }else{ |
| | | shopOrderDetails.setPrice(orderItemDto.getShopSku().getScorePrice()); |
| | | shopOrderDetails.setScoreCount(BigDecimal.valueOf(orderItemDto.getShopSku().getScoreCount())); |
| | | shopOrderDetails.setTotalScoreCount(shopOrderDetails.getScoreCount().multiply(BigDecimal.valueOf(shopOrderDetails.getCount()))); |
| | | } |
| | | shopOrderDetails.setTotalPrice(shopOrderDetails.getPrice().multiply(BigDecimal.valueOf(shopOrderDetails.getCount()))); |
| | | |
| | | shopOrderDetails.setPayType(orderItemDto.getPayType()); |
| | | |
| | | shopOrderDetails.setsTitle(orderItemDto.getShopProduct().getTitle() + orderItemDto.getShopSku().getName()); |
| | | |
| | | shopOrderDetails.setDiscountAmount(BigDecimal.ZERO); |
| | | |
| | | details.add(shopOrderDetails); |
| | | orderCount += shopOrderDetails.getCount(); |
| | | if(orderItemDto.getCartId()!=null){ |
| | | //删除用户购物车选中的产品 |
| | | shoppingCartDao.deleteById(orderItemDto.getCartId()); |
| | | } |
| | | |
| | | } |
| | | |
| | | //校验商品是否限购 |
| | | wxShopOrderUtil.verifyProductLimitInfo(details, bizUser.getOpenId()); |
| | | wxShopOrderUtil.verifyProductLimitInfo(details, sysVipInfo.getOpenId()); |
| | | //TODO 更新库存和销量 更新库存和销量[考虑和erp库存联动] |
| | | wxShopOrderUtil.updateProductAndSkuInfo(details); |
| | | //用户openId |
| | | shopOrder.setUserId(bizUser.getOpenId()); |
| | | shopOrder.setUserId(sysVipInfo.getId()); |
| | | shopOrder.setCreateBy("微信小程序生成"); |
| | | shopOrder.setUpdateBy("微信小程序生成"); |
| | | shopOrder.setCommodityPrice(discountExplain.getBillPrice()); |
| | | shopOrder.setPurchaseQuantity(cartCount); |
| | | shopOrder.setPurchaseQuantity(orderCount); |
| | | shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS); |
| | | //购买方式 |
| | | shopOrder.setShippingMethod(addShopOrderPOJO.getDeliverySelect()); |
| | | shopOrder.setShippingMethod(shopOrderDto.getDeliverySelect()); |
| | | //生成订单号 |
| | | shopOrder.setOrderNo(WxUtils.getOrderNum()); |
| | | //设置支付状态 |
| | |
| | | //客户姓名 |
| | | shopOrder.setUserName(shopReceiveAddress.getAddrLiaisonman()); |
| | | //备注 |
| | | shopOrder.setRemarks(addShopOrderPOJO.getRemarks()); |
| | | shopOrder.setRemarks(shopOrderDto.getRemarks()); |
| | | //删除标识 |
| | | shopOrder.setDelFlag(AppConstance.DATA_USEABLE); |
| | | //微信订单号 |
| | |
| | | //获取邮费 |
| | | shopOrder.setPostage(discountExplain.getPostage()); |
| | | shopOrder.setOrderMoney(discountExplain.getPayPrice()); |
| | | shopOrder.setScorePay(discountExplain.getScorePay()); |
| | | Gson g = new GsonBuilder().create(); |
| | | shopOrder.setDiscountExplain(g.toJson(discountExplain)); |
| | | shopOrder.setDiscountAmount(discountExplain.getActivity().add(discountExplain.getCoupon())); |
| | | shopOrder.setDiscountAmount(discountExplain.getActivityPrice().add(discountExplain.getCouponPrice())); |
| | | shopOrder.setCompanyId(HostInterceptor.getCompanyId()); |
| | | shopOrderDao.insert(shopOrder); |
| | | |
| | | wxShopOrderUtil.insertSendPackageInfo(shopOrder, addShopOrderPOJO.getDeliverySelect(), shopReceiveAddress); |
| | | wxShopOrderUtil.insertSendPackageInfo(shopOrder, shopOrderDto.getDeliverySelect(), shopReceiveAddress); |
| | | //给订单详情表添加订单ID |
| | | for (ShopOrderDetails shopOrderDetails : details) { |
| | | shopOrderDetails.setOrderId(shopOrder.getId()); |
| | |
| | | shopOrderDetailsDao.batchInsert(details); |
| | | } |
| | | //更新使用的优惠券状态 |
| | | if (addShopOrderPOJO.getCouponReceiveId() != null) { |
| | | if (shopOrderDto.getCouponReceiveId() != null) { |
| | | ShopCouponRecord record = new ShopCouponRecord(); |
| | | record.setIsUsing(AppConstance.MY_COUPON_USE); |
| | | record.setOrderId(shopOrder.getId()); |
| | | record.setId(addShopOrderPOJO.getCouponReceiveId()); |
| | | record.setId(shopOrderDto.getCouponReceiveId()); |
| | | shopCouponRecordDao.updateByModel(record); |
| | | } |
| | | |
| | | //删除用户购物车选中的产品 |
| | | shoppingCartDao.deleteUserSelectCart(bizUser.getOpenId()); |
| | | |
| | | |
| | | BrandWCPayRequestData payData = startPayment(shopOrder); |
| | |
| | | } |
| | | |
| | | @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()); |
| | | } |
| | | public AjaxResult buildDiscountExplain(ShopOrderDto shopOrderDto) { |
| | | |
| | | if(CollUtil.isEmpty(shopOrderDto.getOrderItemList())){ |
| | | return AjaxResult.buildFailInstance("请选择购买的明细"); |
| | | } |
| | | |
| | | discountExplain.setPostage(calculationPostage(receiveAddrId, discountExplain.getPayPrice())); |
| | | //订单计价说明 |
| | | DiscountExplain discountExplain = new DiscountExplain(); |
| | | //账单总金额 |
| | | BigDecimal billPrice = BigDecimal.ZERO; |
| | | //活动优惠金额 |
| | | BigDecimal activityTotal = BigDecimal.ZERO; |
| | | //优惠券惠金额 |
| | | BigDecimal couponPrice = BigDecimal.ZERO; |
| | | //支付总积分 |
| | | Integer scoreCount=0; |
| | | |
| | | //计算实际支付 |
| | | discountExplain.setPayPrice(discountExplain.getPayPrice().add(discountExplain.getPostage())); |
| | | return discountExplain; |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | |
| | | //计算购物车中物品的优惠信息 |
| | | List<OrderItemDto> orderItemDtos = shopOrderDto.getOrderItemList() |
| | | .stream().map(orderItemDto -> { |
| | | return orderCouponGroupService.buildOrderCouponElement(orderItemDto); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | //计算未优惠的总金额 |
| | | for (OrderItemDto orderItemDto :orderItemDtos ){ |
| | | if(orderItemDto.getPayType()==ShopShoppingCart.CAR_TYPE_MICRO){ |
| | | billPrice=billPrice.add(orderItemDto.getShopSku().getPrice().multiply(new BigDecimal(orderItemDto.getCount()))); |
| | | }else{ |
| | | billPrice=billPrice.add(orderItemDto.getShopSku().getScorePrice().multiply(new BigDecimal(orderItemDto.getCount()))); |
| | | scoreCount+=orderItemDto.getShopSku().getScoreCount()*orderItemDto.getCount(); |
| | | } |
| | | } |
| | | discountExplain.setScorePay(scoreCount); |
| | | |
| | | |
| | | //计算用户的产品可以参与的店铺优惠活动分组 |
| | | List<ShopCoupon> shopActiveList = new ArrayList<>();//记录用户可以参与的门店活动 |
| | | List<OrderCouponGroup> orderCouponGroupList = new ArrayList<>(); |
| | | int conditionsGroupCount = 0; |
| | | if (shopOrderDto.getJoinActive() == ShopOrderDto.JOIN_ACTIVE) {//用户参与优惠活动 |
| | | orderCouponGroupList = orderCouponGroupService.buildOrderCouponGroupList(orderItemDtos); |
| | | conditionsGroupCount = orderCouponGroupList.stream().map(orderCouponGroup -> { |
| | | if (orderCouponGroup.isSatisfactionCoupon()&&orderCouponGroup.getCoupon()!=null) { |
| | | shopActiveList.add(orderCouponGroup.getCoupon()); |
| | | return 1; |
| | | } else { |
| | | return 0; |
| | | } |
| | | }).mapToInt(Integer::intValue).sum(); |
| | | } |
| | | if(CollUtil.isNotEmpty(shopActiveList)){ |
| | | activityTotal=shopActiveList.stream().map(ShopCoupon:: getOffsetAmount).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | } |
| | | |
| | | //门店活动优惠金额 |
| | | discountExplain.setActivityPrice(activityTotal); |
| | | |
| | | |
| | | List<CouponReceiveInfoVO> usefulCoupon = new ArrayList<>(); |
| | | CouponReceiveInfoVO shopCoupon = new CouponReceiveInfoVO(); |
| | | //满足店铺活动的订单不能使用优惠券 |
| | | if (conditionsGroupCount > 0) { |
| | | //计算可用优惠券 |
| | | usefulCoupon = wxShopCouponService.getCartVoCouponList(sysVipInfo.getCompanyId(), orderItemDtos); |
| | | //获取用户使用的优惠券 |
| | | if (shopOrderDto.getCouponReceiveId() == null) { |
| | | //如果用户没有选择优惠券则默认选优惠金额最高的 |
| | | //计算使用优惠券后的价格 |
| | | if (CollectionUtils.isNotEmpty(usefulCoupon)) { |
| | | //根据优惠券ID用户ID查询优惠券信息 |
| | | shopCoupon = usefulCoupon.get(0); |
| | | } |
| | | } else if (shopOrderDto.getCouponReceiveId() != 1) { |
| | | //用户选择了优惠券 |
| | | shopCoupon = shopCouponRecordDao.selectMyCouponByReceiveId(shopOrderDto.getCouponReceiveId()); |
| | | } else { |
| | | //用户不使用优惠券 |
| | | } |
| | | //计算优惠券 |
| | | if (shopCoupon.getCouponId() != null) { |
| | | couponPrice=shopCoupon.getOffsetAmount(); |
| | | } |
| | | //优惠券金额 |
| | | discountExplain.setCouponPrice(couponPrice); |
| | | } |
| | | |
| | | |
| | | |
| | | //计算运费 |
| | | discountExplain.setPostage(calculationPostage(discountExplain.getPayPrice(), HostInterceptor.getCompanyId())); |
| | | |
| | | |
| | | |
| | | //账单总金额 |
| | | discountExplain.setBillPrice(billPrice.add(discountExplain.getPostage())); |
| | | |
| | | BigDecimal payPrice=discountExplain.getBillPrice().subtract(activityTotal).subtract(couponPrice); |
| | | //应付金额 |
| | | discountExplain.setPayPrice(payPrice.doubleValue()>0?payPrice:BigDecimal.ONE); |
| | | |
| | | AjaxResult result = AjaxResult.buildSuccessInstance(""); |
| | | //结算金额信息 |
| | | result.putInMap("discountExplain", discountExplain); |
| | | //用户优惠券 |
| | | result.putInMap("usefulCoupon", usefulCoupon); |
| | | //用户选中的优惠券 |
| | | result.putInMap("shopCoupon", shopCoupon); |
| | | |
| | | //店铺优惠活动 |
| | | result.putInMap("shopActiveList", shopActiveList); |
| | | |
| | | return result; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | if (!shopOrder.getPayResult().equals(ShopOrder.ORDER_PAY_STATUS_WAIT)) { |
| | | throw new GlobleException("该订单不是待支付状态!"); |
| | | } |
| | | |
| | | if(shopOrder.getScorePay()!=null){ |
| | | //校验用户积分是否够用 |
| | | int score=scoreVipDetailDao.selectUserTotalScore(shopOrder.getUserId()); |
| | | if(score<shopOrder.getScorePay()){ |
| | | return AjaxResult.buildFailInstance("积分不足"); |
| | | } |
| | | } |
| | | |
| | | BrandWCPayRequestData payData = startPayment(shopOrder); |
| | | AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(payData)); |
| | | result.putInMap("orderId", shopOrder.getId()); |
| | |
| | | BigDecimal money = new BigDecimal(shopOrder.getOrderMoney().toString()); |
| | | BrandWCPayRequestData payData; |
| | | String productNames = wxShopOrderUtil.getProductNames(shopOrder.getUserId(), shopOrder.getId()); |
| | | SysVipInfo vipInfo=sysVipInfoDao.selectById(shopOrder.getUserId()); |
| | | |
| | | LogUtil.debug(String.valueOf(isDebug)); |
| | | if (isDebug) { |
| | | payData = weixinServiceUtil.createOrder("[测试]" + productNames, shopOrder.getOrderNo(), |
| | | 1, shopOrder.getUserId(), String.valueOf(shopOrder.getId())); |
| | | 1, vipInfo.getOpenId(), String.valueOf(shopOrder.getId())); |
| | | } else { |
| | | payData = weixinServiceUtil.createOrder(productNames, shopOrder.getOrderNo(), |
| | | unit.multiply(money).intValue(), shopOrder.getUserId(), String.valueOf(shopOrder.getId())); |
| | | unit.multiply(money).intValue(),vipInfo.getOpenId(), String.valueOf(shopOrder.getId())); |
| | | } |
| | | ShopOrder updateParam = new ShopOrder(); |
| | | updateParam.setId(shopOrder.getId()); |
| | |
| | | */ |
| | | @Override |
| | | public AjaxResult getMyOrderInfo(OrderInfoQueryPOJO orderInfoQueryPOJO) { |
| | | BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | orderInfoQueryPOJO.setSort("update_time"); |
| | | if (orderInfoQueryPOJO.getOffset() >= 1) { |
| | | orderInfoQueryPOJO.setOffset((orderInfoQueryPOJO.getOffset() - 1) * orderInfoQueryPOJO.getLimit()); |
| | | } |
| | | List<ShopOrder> result = shopOrderDao.selectMyOrderByStatus(bizUser.getOpenId(), orderInfoQueryPOJO); |
| | | List<ShopOrder> result = shopOrderDao.selectMyOrderByStatus(sysVipInfo.getId(), orderInfoQueryPOJO); |
| | | return new AjaxResult(AjaxResult.STATUS_SUCCESS, result); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public AjaxResult getOrderInfoById(Integer orderId) { |
| | | BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); |
| | | ShopOrder shopOrder = shopOrderDao.selectOrderInfoById(bizUser.getOpenId(), orderId); |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | ShopOrder shopOrder = shopOrderDao.selectOrderInfoById(sysVipInfo.getId(), orderId); |
| | | return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(shopOrder)); |
| | | } |
| | | |
| | |
| | | } |
| | | if (shopOrder.getDiscountAmount() != null && shopOrder.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) { |
| | | ShopCouponRecord shopCouponRecord = new ShopCouponRecord(); |
| | | BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); |
| | | shopCouponRecord.setUserId(bizUser.getOpenId()); |
| | | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); |
| | | shopCouponRecord.setUserId(sysVipInfo.getId()); |
| | | shopCouponRecord.setOrderId(orderId); |
| | | List<ShopCouponRecord> recordList = shopCouponRecordDao.selectByModel(shopCouponRecord); |
| | | if (CollectionUtils.isNotEmpty(recordList)) { |