| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.*; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.BalanceChangeRecord; |
| | | import com.ruoyi.account.api.model.UserAddress; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.account.api.vo.CouponInfoVo; |
| | | import com.ruoyi.account.api.vo.PaymentUserCoupon; |
| | | import com.ruoyi.account.api.vo.PaymentUserCouponVo; |
| | |
| | | |
| | | @Resource |
| | | private CommissionService commissionService; |
| | | |
| | | @Resource |
| | | private VipSettingClient vipSettingClient; |
| | | |
| | | @Resource |
| | | private UserChangeLogClient userChangeLogClient; |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | @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()); |
| | | //获取用户优惠券,用户全部优惠券,不能使用的需要标识出来置灰展示 |
| | |
| | | */ |
| | | @Override |
| | | public R shoppingCartPayment(ShoppingCartPayment shoppingCartPayment) { |
| | | Integer position = shoppingCartPayment.getPosition(); |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | //直接购买商品 |
| | | if(2 == position){ |
| | | //先加入购物车 |
| | | String goodsJson = shoppingCartPayment.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); |
| | | shoppingCartPayment.setGoodsJson("[{\"id\": " + shoppingCarId + ", \"num\": " + num1 + "}]"); |
| | | } |
| | | AppUser appUser = appUserClient.getAppUserById(userid); |
| | | Integer shopId = shoppingCartPayment.getShopId(); |
| | | String goodsJson = shoppingCartPayment.getGoodsJson(); |
| | |
| | | //积分支付的订单积分 |
| | | Integer orderPoint = 0; |
| | | if(3 != shoppingCartPayment.getPaymentType()){ |
| | | orderMoney = goodsList.stream().map(MyShoppingCartVo::getCash).reduce(BigDecimal::add).get(); |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | orderMoney = orderMoney.add(myShoppingCartVo.getCash().multiply(new BigDecimal(myShoppingCartVo.getNumber()))); |
| | | } |
| | | }else{ |
| | | orderPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getPoint).sum(); |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | orderPoint += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber()); |
| | | } |
| | | if(appUser.getLavePoint().intValue() < orderPoint){ |
| | | return R.fail("账户剩余积分不足"); |
| | | } |
| | |
| | | } |
| | | |
| | | //可获得的消费积分 |
| | | int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum(); |
| | | int earnPoint = 0; |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | earnPoint += (myShoppingCartVo.getEarnSpendingPoints() * myShoppingCartVo.getNumber()); |
| | | } |
| | | if(null != shoppingCartPayment.getUserAddressId()){ |
| | | userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData(); |
| | | } |
| | |
| | | order.setGoodName(goodName.substring(0, goodName.length() - 1)); |
| | | Goods goods = goodsClient.getGoodsById(goodsList.get(0).getGoodsId()).getData(); |
| | | order.setOrderType(goods.getType()); |
| | | order.setOrderStatus(1); |
| | | order.setOrderStatus(goods.getType() == 1 ? 3 : 1); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | order.setOrderNumber("QJS" + getNumber(3) + sdf.format(new Date())); |
| | | order.setTotalAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN)); |
| | |
| | | if(earnPoint > 0){ |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setLastShopTime(LocalDateTime.now()); |
| | | appUserClient.editAppUserById(appUser); |
| | | //构建余额明细变动记录 |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | | //检查消费积分满足后升级会员 |
| | | vipUpgrade(appUser); |
| | | } |
| | | //积分支付 |
| | | if(3 == shoppingCartPayment.getPaymentType()){ |
| | |
| | | appUser.setLavePoint(lavePoint - orderPoint); |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setLastShopTime(LocalDateTime.now()); |
| | | appUserClient.editAppUserById(appUser); |
| | | //检查消费积分满足后升级会员 |
| | | vipUpgrade(appUser); |
| | | |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(4); |
| | |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | return R.ok(order.getId().toString()); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员等级变化 |
| | | * @param appUser |
| | | */ |
| | | public void vipUpgrade(AppUser appUser){ |
| | | Integer shopPoint = appUser.getShopPoint(); |
| | | Integer vipId = appUser.getVipId(); |
| | | //钻石会员 |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | | Integer vipLevelUpShopRole = vipSetting3.getVipLevelUpShopRole(); |
| | | Integer vipLevelUpShop = vipSetting3.getVipLevelUpShop(); |
| | | if(1 == vipLevelUpShopRole && appUser.getVipId() < 3 && shopPoint >= vipLevelUpShop){ |
| | | appUser.setVipId(3); |
| | | appUserClient.editAppUserById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogClient.saveUserChangeLog(userChangeLog); |
| | | return; |
| | | } |
| | | //黄金会员 |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | vipLevelUpShopRole = vipSetting2.getVipLevelUpShopRole(); |
| | | vipLevelUpShop = vipSetting2.getVipLevelUpShop(); |
| | | if(1 == vipLevelUpShopRole && appUser.getVipId() < 2 && shopPoint >= vipLevelUpShop){ |
| | | appUser.setVipId(2); |
| | | appUserClient.editAppUserById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogClient.saveUserChangeLog(userChangeLog); |
| | | } |
| | | } |
| | | } |