| | |
| | | |
| | | |
| | | @Override |
| | | public void addGoods(ShoppingCart shoppingCart) { |
| | | public Long addGoods(ShoppingCart shoppingCart) { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | shoppingCart.setAppUserId(userid); |
| | | this.save(shoppingCart); |
| | | return shoppingCart.getId(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public ConfirmOrderVo confirmOrder(ConfirmOrder confirmOrder) { |
| | | Integer position = confirmOrder.getPosition(); |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | //直接购买商品 |
| | | if(2 == position){ |
| | | //先加入购物车 |
| | | String goodsJson = confirmOrder.getGoodsJson(); |
| | | JSONArray objects = JSON.parseArray(goodsJson); |
| | | Long id = objects.getJSONObject(0).getLong("id"); |
| | | Integer num1 = objects.getJSONObject(0).getInteger("num"); |
| | | ShoppingCart shoppingCart = new ShoppingCart(); |
| | | shoppingCart.setAppUserId(userid); |
| | | shoppingCart.setGoodsId(id.intValue()); |
| | | shoppingCart.setNumber(num1); |
| | | Long shoppingCarId = addGoods(shoppingCart); |
| | | confirmOrder.setGoodsJson("[{\"id\": " + shoppingCarId + ", \"num\": " + num1 + "}]"); |
| | | } |
| | | AppUser appUser = appUserClient.getAppUserById(userid); |
| | | Integer shopId = confirmOrder.getShopId(); |
| | | Shop shop = shopClient.getShopById(shopId).getData(); |
| | |
| | | confirmOrderVo.setResidualPoint(appUser.getLavePoint().intValue()); |
| | | //获取默认收货地址 |
| | | UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData(); |
| | | userAddress.setIdStr(userAddress.getId().toString()); |
| | | confirmOrderVo.setUserAddress(userAddress); |
| | | confirmOrderVo.setPaymentType(confirmOrder.getPaymentType()); |
| | | //获取用户优惠券,用户全部优惠券,不能使用的需要标识出来置灰展示 |
| | |
| | | paymentUserCoupon.setType(confirmOrder.getType()); |
| | | if(confirmOrder.getPaymentType() == 1){ |
| | | List<PaymentUserCouponVo> data = userCouponClient.getPaymentUserCoupon(paymentUserCoupon).getData(); |
| | | for (PaymentUserCouponVo couponInfo : data) { |
| | | List<Integer> forGoodIds = couponInfo.getForGoodIds(); |
| | | //全部商品适用 |
| | | if(null == forGoodIds){ |
| | | //满减券 |
| | | if(1 == couponInfo.getCouponType() && orderMoney.compareTo(couponInfo.getConditionAmount()) >= 0){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | //代金券和折扣券 |
| | | if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | }else{ |
| | | //部分商品适用 |
| | | BigDecimal goodsMoney = BigDecimal.ZERO; |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | Integer goodsId = myShoppingCartVo.getGoodsId(); |
| | | BigDecimal cash = myShoppingCartVo.getCash(); |
| | | if(forGoodIds.contains(goodsId)){ |
| | | goodsMoney = goodsMoney.add(cash); |
| | | if(null != data){ |
| | | for (PaymentUserCouponVo couponInfo : data) { |
| | | List<Integer> forGoodIds = couponInfo.getForGoodIds(); |
| | | //全部商品适用 |
| | | if(null == forGoodIds){ |
| | | //满减券 |
| | | if(1 == couponInfo.getCouponType() && orderMoney.compareTo(couponInfo.getConditionAmount()) >= 0){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | } |
| | | //满减 |
| | | if(1 == couponInfo.getCouponType() && couponInfo.getConditionAmount().compareTo(goodsMoney) <= 0){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | //代金券 |
| | | if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){ |
| | | couponInfo.setAvailable(true); |
| | | //代金券和折扣券 |
| | | if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | }else{ |
| | | //部分商品适用 |
| | | BigDecimal goodsMoney = BigDecimal.ZERO; |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | Integer goodsId = myShoppingCartVo.getGoodsId(); |
| | | BigDecimal cash = myShoppingCartVo.getCash(); |
| | | if(forGoodIds.contains(goodsId)){ |
| | | goodsMoney = goodsMoney.add(cash); |
| | | } |
| | | } |
| | | //满减 |
| | | if(1 == couponInfo.getCouponType() && couponInfo.getConditionAmount().compareTo(goodsMoney) <= 0){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | //代金券 |
| | | if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){ |
| | | couponInfo.setAvailable(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | for (ShoppingCart shoppingCart : list) { |
| | | Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData(); |
| | | MyShoppingCartVo vo = new MyShoppingCartVo(); |
| | | vo.setId(shoppingCart.getId()); |
| | | vo.setId(shoppingCart.getId().toString()); |
| | | vo.setGoodsId(goods.getId()); |
| | | vo.setHomePicture(goods.getHomePagePicture()); |
| | | vo.setName(goods.getName()); |
| | |
| | | //获取支付价格 |
| | | Price price = getPrice(appUser, shoppingCart.getGoodsId(), shopId); |
| | | if(null == price){ |
| | | price = new Price(); |
| | | //使用商品的基础价格 |
| | | price.setCash(1 == goods.getCashPayment() ? goods.getSellingPrice() : null); |
| | | price.setPoint(1 == goods.getPointPayment() ? goods.getIntegral() : null); |
| | |
| | | goodsShop.setGoodsId(shoppingCart.getGoodsId()); |
| | | goodsShop.setShopId(shopId); |
| | | GoodsShop goodsShop1 = goodsShopClient.getGoodsShop(goodsShop).getData(); |
| | | vo.setVerifiable(null == goodsShop1 ? false : true); |
| | | vo.setVerifiable(goods.getAppointStore() == 1 && null == goodsShop1 ? false : true); |
| | | //判断当前数量是否已经超出限购数量(需要计算已经购买的数量) |
| | | if(null == goods.getPurchaseLimit() || -1 == goods.getPurchaseLimit()){ |
| | | vo.setPurchaseLimit(false); |
| | |
| | | if(data.size() != goodsList.size()){ |
| | | String goodsName = ""; |
| | | for (Integer goodsId : goodsIds) { |
| | | if(!collect.contains(goodsId)){ |
| | | goodsName = goodsClient.getGoodsById(goodsId).getData().getName(); |
| | | Goods goods = goodsClient.getGoodsById(goodsId).getData(); |
| | | if(1 == goods.getAppointStore() && !collect.contains(goodsId)){ |
| | | goodsName = goods.getName(); |
| | | break; |
| | | } |
| | | } |
| | | return R.fail(goodsName + "不能在该门店核销"); |
| | | if(StringUtils.isNotEmpty(goodsName)){ |
| | | return R.fail(goodsName + "不能在该门店核销"); |
| | | } |
| | | } |
| | | //开始构建支付信息 |
| | | //现金支付的订单金额 |
| | |
| | | } |
| | | } |
| | | //判断运费支付是否足够 |
| | | if(2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | if(null != shoppingCartPayment.getFreightPaymentType() && 2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | BigDecimal balance = appUser.getBalance(); |
| | | if(balance.compareTo(expressFee) < 0){ |
| | | return R.fail("账户余额不足"); |
| | |
| | | } |
| | | for (int i = 0; i < objects.size(); i++) { |
| | | Long id = objects.getJSONObject(i).getLong("id"); |
| | | if(myShoppingCartVo.getId().equals(id)){ |
| | | if(myShoppingCartVo.getId().equals(id.toString())){ |
| | | ShoppingCart shoppingCart = this.getById(id); |
| | | Integer num1 = objects.getJSONObject(i).getInteger("num"); |
| | | orderGood.setNum(num1); |
| | | Goods goods1 = goodsClient.getGoodsById(myShoppingCartVo.getGoodsId()).getData(); |
| | | Goods goods1 = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData(); |
| | | orderGood.setGoodJson(JSON.toJSONString(goods1)); |
| | | break; |
| | | } |
| | |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | return R.ok(order.getId().toString()); |
| | | } |
| | | |
| | | |