| | |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiShopApplyVo; |
| | | import cc.mrbird.febs.mall.vo.OrderDetailVo; |
| | | import cc.mrbird.febs.mall.vo.OrderListVo; |
| | | import cc.mrbird.febs.mall.vo.OrderRefundVo; |
| | | import cc.mrbird.febs.mall.vo.*; |
| | | import cc.mrbird.febs.pay.model.AgreementPayDto; |
| | | import cc.mrbird.febs.pay.model.AgreementSignDto; |
| | | import cc.mrbird.febs.pay.model.UnipayDto; |
| | | import cc.mrbird.febs.pay.service.IAliPayService; |
| | | import cc.mrbird.febs.pay.service.IPayService; |
| | | import cc.mrbird.febs.pay.service.UnipayService; |
| | | import cc.mrbird.febs.rabbit.producter.AgentProducer; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | private final MallOrderRefundMapper mallOrderRefundMapper; |
| | | private final MallOrderRefundOperationMapper mallOrderRefundOperationMapper; |
| | | private final MallShoppingCartMapper mallShoppingCartMapper; |
| | | private final IApiMallMemberService memberService; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | private final AgentProducer agentProducer; |
| | | private final IPayService payService; |
| | | private final IAliPayService payService; |
| | | private final IMallAchieveService mallAchieveService; |
| | | private final UnipayService unipayService; |
| | | private final IPayService wechatPayService; |
| | | |
| | | private final MallMemberBankSignMapper mallMemberBankSignMapper; |
| | | private final MallMemberBankMapper mallMemberBankMapper; |
| | | private final MallShopApplyMapper mallShopApplyMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallAchieveRecordMapper mallAchieveRecordMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | private final MallMqRecordMapper mallMqRecordMapper; |
| | | |
| | | private final MallShopMapper mallShopMapper; |
| | | |
| | | private final ICommonService commonService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | throw new FebsException("请选择门店"); |
| | | } |
| | | Long shopId = addOrderDto.getShopId(); |
| | | MallShopApply mallShopApply = mallShopApplyMapper.selectById(shopId); |
| | | MallShop mallShopApply = mallShopMapper.selectById(shopId); |
| | | if(ObjectUtil.isEmpty(mallShopApply)){ |
| | | throw new FebsException("请选择门店"); |
| | | } |
| | | if(MallShopApply.APPLY_AGREE != mallShopApply.getStatus()){ |
| | | throw new FebsException("请选择门店"); |
| | | } |
| | | orderInfo.setShopId(shopId); |
| | |
| | | orderItem.setSkuImage(sku.getSkuImage()); |
| | | orderItem.setIsNormal(mallGoods.getIsNormal()); |
| | | orderItem.setCostPrice(sku.getCostPrice()); |
| | | orderItem.setStaticMulti(mallGoods.getStaticMulti()); |
| | | orderItem.setGoodsLevel(mallGoods.getGoodsLevel()); |
| | | orderItem.setNormalBonus(mallGoods.getNormalBonus()); |
| | | orderItem.setNormalPer(mallGoods.getNormalPer()); |
| | | |
| | | |
| | | total = total.add(amount); |
| | | carriage = carriage.add(mallGoods.getCarriage()); |
| | |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | |
| | | /** |
| | | * 使用积分折扣现金 |
| | | */ |
| | | DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_CHANGE.getType(), |
| | | DataDictionaryEnum.SCORE_CHANGE.getCode() |
| | | ); |
| | | BigDecimal score = ObjectUtil.isEmpty(addOrderDto.getScore()) ? BigDecimal.ZERO : addOrderDto.getScore(); |
| | | orderInfo.setScoreCnt(score); |
| | | BigDecimal scoreChange = BigDecimal.ONE; |
| | | if(ObjectUtil.isNotEmpty(scoreChangeDic)){ |
| | | scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN); |
| | | } |
| | | //折扣现金 |
| | | BigDecimal scorePercentAmount = score.divide(scoreChange,BigDecimal.ROUND_DOWN).setScale(2,BigDecimal.ROUND_DOWN); |
| | | orderInfo.setScoreAmount(scorePercentAmount); |
| | | orderInfo.setAmount(total); |
| | | if(2 == deliverType){ |
| | | orderInfo.setDeliverType(2); |
| | |
| | | String rcResult = ""; |
| | | switch (payOrderDto.getType()) { |
| | | case "1": |
| | | UnipayDto unipayDtoWx = new UnipayDto(); |
| | | // unipayDto.setAmount(new BigDecimal("0.01")); |
| | | unipayDtoWx.setAmount(orderInfo.getAmount()); |
| | | unipayDtoWx.setFrpCode("WEIXIN_APP3"); |
| | | unipayDtoWx.setTradeMerchantNo("777180800385820"); |
| | | unipayDtoWx.setOrderNo(orderInfo.getOrderNo()); |
| | | List<MallOrderItem> itemsWx = orderInfo.getItems(); |
| | | if(CollUtil.isEmpty(itemsWx)){ |
| | | unipayDtoWx.setProductName("商品"); |
| | | orderInfo.setName("商品"); |
| | | }else{ |
| | | unipayDtoWx.setProductName(itemsWx.get(0).getGoodsName()); |
| | | orderInfo.setName(itemsWx.get(0).getGoodsName()); |
| | | } |
| | | String unipayStrWx = unipayService.unipay(unipayDtoWx); |
| | | if("fail" == unipayStrWx){ |
| | | throw new FebsException("支付失败"); |
| | | }else{ |
| | | // JSONUtil.parseObj(unipayStr); |
| | | JSONObject jsonObject = JSONUtil.parseObj(unipayStrWx); |
| | | payResultStr = (String) jsonObject.get("r7_TrxNo"); |
| | | rcResult = (String) jsonObject.get("rc_Result"); |
| | | } |
| | | |
| | | payResultStr = wechatPayService.pay(orderInfo); |
| | | orderInfo.setPayOrderNo(payResultStr); |
| | | // orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo()); |
| | | // orderInfo.setPayImage(payOrderDto.getPayImage()); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | orderInfo.setPayResult("2"); |
| | | break; |
| | | case "2": |
| | | // if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | boolean hasTc = false; |
| | | // 静态倍数 |
| | | List<MallOrderItem> orderItems = this.baseMapper.getMallOrderItemByOrderId(orderInfo.getId()); |
| | | if (CollUtil.isNotEmpty(orderItems)) { |
| | | for (MallOrderItem orderItem : orderItems) { |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(orderItem.getGoodsId()); |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId()); |
| | | if (mallGoods.getIsNormal() == 2) { |
| | | hasTc = true; |
| | | score = sku.getPresentPrice().multiply(mallGoods.getStaticMulti()).multiply(new BigDecimal(orderItem.getCnt())); |
| | | // BigDecimal staticMulti = mallGoods.getStaticMulti() == null ? BigDecimal.ZERO : mallGoods.getStaticMulti(); |
| | | // score = sku.getPresentPrice().multiply(staticMulti); |
| | | // 普通商品也及时结算,不再10天结算 |
| | | } else { |
| | | score = sku.getPresentPrice(); |
| | | } |
| | | // 商品级别 会员/代理/股东 |
| | | int goodsLevel = 0; |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | for (MallOrderItem item : orderInfo.getItems()) { |
| | | // 计算静态倍数 |
| | | if(item.getIsNormal() == 2) { |
| | | score = score.add(item.getPrice().multiply(item.getStaticMulti())); |
| | | } |
| | | |
| | | if (score.compareTo(BigDecimal.ZERO) > 0) { |
| | | memberWalletService.add(score, member.getId(), "score"); |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), score, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | |
| | | // 添加业绩 |
| | | mallAchieveService.add(orderItem.getId()); |
| | | } |
| | | // 判断会员层级 |
| | | if (item.getIsNormal() == 2 && goodsLevel < item.getGoodsLevel()) { |
| | | goodsLevel = item.getGoodsLevel(); |
| | | } |
| | | } |
| | | |
| | | // 购买套餐后,升级为普通会员 |
| | | if (hasTc) { |
| | | MallMember mallMember = memberMapper.selectById(member.getId()); |
| | | if (AgentLevelEnum.ZERO_LEVEL.name().equals(mallMember.getLevel())) { |
| | | mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); |
| | | memberMapper.updateById(mallMember); |
| | | // 根据用户购买的商品设置其等级 |
| | | member.setLevel(GoodsToLevelEnums.getLevelByAccountLevel(goodsLevel)); |
| | | member.setAccountLevel(goodsLevel); |
| | | this.memberMapper.updateById(member); |
| | | |
| | | memberWalletService.add(score, member.getId(), "score"); |
| | | |
| | | if (orderInfo.getScoreCnt().compareTo(BigDecimal.ZERO) > 0) { |
| | | int reduce = memberWalletService.reduce(orderInfo.getScoreCnt(), member.getId(), "prizeScore"); |
| | | if (reduce == 2) { |
| | | throw new FebsException("积分不足"); |
| | | } |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getScoreCnt().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | } |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), score, MoneyFlowTypeEnum.BUY_TC.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); |
| | | |
| | | //发送代理自动升级消息 |
| | | agentProducer.sendAutoLevelUpMsg(member.getId()); |
| | | //发送直推返利消息 |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | // 发送分红消息 |
| | | agentProducer.sendOrderBonus(orderInfo.getId()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | break; |
| | | case "5": |
| | | // AgreementSignDto agreementSignDto = new AgreementSignDto(); |
| | | // agreementSignDto.setOrderNo(orderInfo.getOrderNo()); |
| | | // agreementSignDto.setSmsCode(payOrderDto.getSmsCode()); |
| | | // String agreementSignStr = unipayService.agreementSign(agreementSignDto); |
| | | // if("fail".equals(agreementSignStr)){ |
| | | // throw new FebsException("支付失败"); |
| | | // }else{ |
| | | // JSONObject jsonObject = JSONUtil.parseObj(agreementSignStr); |
| | | // payResultStr = (String) jsonObject.get("biz_code"); |
| | | // String signData = (String) jsonObject.get("data"); |
| | | // String signBizMsg = (String) jsonObject.get("biz_msg"); |
| | | // |
| | | // JSONObject signDatajsonObject = JSONUtil.parseObj(signData); |
| | | // String err_msg = (String) signDatajsonObject.get("err_msg"); |
| | | // if(!"JS000000".equals(payResultStr)){ |
| | | // throw new FebsException(signBizMsg); |
| | | // } |
| | | // if(ObjectUtil.isNotNull(signDatajsonObject.get("err_code"))){ |
| | | // throw new FebsException(err_msg); |
| | | // } |
| | | // } |
| | | |
| | | AgreementPayDto agreementPayDto = new AgreementPayDto(); |
| | | agreementPayDto.setOrderNo(orderInfo.getOrderNo()); |
| | | |
| | |
| | | map.put("orderNo", orderInfo.getOrderNo()); |
| | | map.put("orderId", orderInfo.getId()); |
| | | map.put("rcResult", rcResult); |
| | | |
| | | return map; |
| | | } |
| | | |
| | |
| | | throw new FebsException("支付密码错误"); |
| | | } |
| | | |
| | | int reduce = memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field); |
| | | int reduce = memberWalletService.reduce(orderInfo.getAmount().subtract(orderInfo.getScoreAmount()).add(orderInfo.getCarriage()), mallMember.getId(), field); |
| | | if (reduce == 2) { |
| | | throw new FebsException("余额不足"); |
| | | } |
| | | |
| | | |
| | | return orderInfo.getOrderNo(); |
| | | } |
| | | |
| | |
| | | |
| | | OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo); |
| | | |
| | | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { |
| | | Integer deliverType = (ObjectUtil.isEmpty(orderInfo.getDeliverType()) ? new Integer(0):orderInfo.getDeliverType()); |
| | | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue() && 2 != deliverType) { |
| | | MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | |
| | | long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false); |
| | | orderDetailVo.setRemainTime(remainTime); |
| | | } |
| | | Integer deliverType = (ObjectUtil.isEmpty(orderInfo.getDeliverType()) ? new Integer(0):orderInfo.getDeliverType()); |
| | | if(2 == deliverType){ |
| | | MallShopApply mallShopApply = mallShopApplyMapper.selectById(orderInfo.getShopId()); |
| | | if(ObjectUtil.isNotEmpty(mallShopApply)){ |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse judgeCreateOrder(AddOrderDto addOrderDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | if (CollUtil.isEmpty(addOrderDto.getItems())) { |
| | | throw new FebsException("请选择购买商品"); |
| | | } |
| | | |
| | | boolean hasTc = false; |
| | | //总的折扣积分数量 |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if(ObjectUtil.isEmpty(sku)){ |
| | | throw new FebsException("商品已更新,请重新下单"); |
| | | } |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | if(ObjectUtil.isEmpty(mallGoods)){ |
| | | throw new FebsException("商品已更新,请重新下单"); |
| | | } |
| | | |
| | | /* |
| | | 获取单个商品的折扣积分数量 |
| | | = 现价 * 数量 * 折扣现金比例 |
| | | */ |
| | | BigDecimal scorePercent = new BigDecimal(mallGoods.getScorePercent()).multiply(BigDecimal.valueOf(0.01)); |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())).multiply(scorePercent); |
| | | total = total.add(amount); |
| | | } |
| | | |
| | | BigDecimal score = ObjectUtil.isEmpty(addOrderDto.getScore()) ? BigDecimal.ZERO : addOrderDto.getScore(); |
| | | |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | BigDecimal prizeScore = mallMemberWallet.getPrizeScore(); |
| | | if(prizeScore.compareTo(score) < 0){ |
| | | throw new FebsException("积分不足"); |
| | | } |
| | | |
| | | /** |
| | | * 使用积分折扣现金 |
| | | */ |
| | | DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_CHANGE.getType(), |
| | | DataDictionaryEnum.SCORE_CHANGE.getCode() |
| | | ); |
| | | |
| | | //最大折扣金额对应需要的总积分数目 |
| | | BigDecimal scorePercentMaxAmount = total; |
| | | BigDecimal scoreChange = BigDecimal.ONE; |
| | | if(ObjectUtil.isNotEmpty(scoreChangeDic)){ |
| | | scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN); |
| | | } |
| | | scorePercentMaxAmount = scorePercentMaxAmount.multiply(scoreChange).setScale(2,BigDecimal.ROUND_DOWN); |
| | | if(scorePercentMaxAmount.compareTo(score) < 0){ |
| | | throw new FebsException("最多可使用"+scorePercentMaxAmount+"积分"); |
| | | } |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public ApiScoreSetVo myScoreSet() { |
| | | ApiScoreSetVo apiScoreSetVo = new ApiScoreSetVo(); |
| | | DataDictionaryCustom scorePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_PERCENT.getType(), |
| | | DataDictionaryEnum.SCORE_PERCENT.getCode() |
| | | ); |
| | | DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_CHANGE.getType(), |
| | | DataDictionaryEnum.SCORE_CHANGE.getCode() |
| | | ); |
| | | apiScoreSetVo.setScorePercent(new BigDecimal(scorePercentDic.getValue()).multiply(BigDecimal.valueOf(0.01)).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | apiScoreSetVo.setScoreChange(new BigDecimal(scoreChangeDic.getValue()).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | return apiScoreSetVo; |
| | | } |
| | | |
| | | } |