|  |  |  | 
|---|
|  |  |  | package cc.mrbird.febs.mall.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.OrderStatusEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.*; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.AppContants; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.LoginUserUtil; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.MallUtils; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.RedisUtils; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.AddOrderDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.AddOrderItemDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.OrderListDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.PayOrderDto; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallOrderInfoService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.OrderDetailVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.OrderListVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.*; | 
|---|
|  |  |  | 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.IPayService; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.service.UnipayService; | 
|---|
|  |  |  | import cc.mrbird.febs.rabbit.producter.AgentProducer; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateTime; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUnit; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import cn.hutool.crypto.SecureUtil; | 
|---|
|  |  |  | import cn.hutool.json.JSONObject; | 
|---|
|  |  |  | import cn.hutool.json.JSONUtil; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.text.DecimalFormat; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Random; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author wzy | 
|---|
|  |  |  | 
|---|
|  |  |  | private final MallAddressInfoMapper mallAddressInfoMapper; | 
|---|
|  |  |  | private final MallOrderItemMapper mallOrderItemMapper; | 
|---|
|  |  |  | private final MallMemberMapper memberMapper; | 
|---|
|  |  |  | private final MallGoodsCommentMapper mallGoodsCommentMapper; | 
|---|
|  |  |  | private final IApiMallMemberWalletService memberWalletService; | 
|---|
|  |  |  | private final MallExpressInfoMapper expressInfoMapper; | 
|---|
|  |  |  | private final MallOrderRefundMapper mallOrderRefundMapper; | 
|---|
|  |  |  | private final MallOrderRefundOperationMapper mallOrderRefundOperationMapper; | 
|---|
|  |  |  | private final MallShoppingCartMapper mallShoppingCartMapper; | 
|---|
|  |  |  | private final IApiMallMemberService memberService; | 
|---|
|  |  |  | private final IMallMoneyFlowService mallMoneyFlowService; | 
|---|
|  |  |  | private final MallMoneyFlowMapper mallMoneyFlowMapper; | 
|---|
|  |  |  | private final RedisUtils redisUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final AgentProducer agentProducer; | 
|---|
|  |  |  | private final IPayService payService; | 
|---|
|  |  |  | private final IMallAchieveService mallAchieveService; | 
|---|
|  |  |  | private final UnipayService unipayService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final MallMemberBankSignMapper mallMemberBankSignMapper; | 
|---|
|  |  |  | private final MallMemberBankMapper mallMemberBankMapper; | 
|---|
|  |  |  | private final MallShopApplyMapper mallShopApplyMapper; | 
|---|
|  |  |  | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public Long createOrder(AddOrderDto addOrderDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据会员星级判断是否可以购买该商品 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallMember mallMember = memberMapper.selectById(member.getId()); | 
|---|
|  |  |  | String accountLevel = mallMember.getAccountLevel(); | 
|---|
|  |  |  | Integer memberLevelCode = MemberAccountLevelEnum.NORMAL.getMemberLevelCode(accountLevel); | 
|---|
|  |  |  | //获取商品星级 | 
|---|
|  |  |  | MallGoods goods = mallGoodsMapper.selectById(addOrderDto.getGoodsId()); | 
|---|
|  |  |  | String starRating = goods.getStarRating(); | 
|---|
|  |  |  | Integer goodsStarCode = StarRatingEnum.NORMAL.getGoodsStarCode(starRating); | 
|---|
|  |  |  | if(memberLevelCode < goodsStarCode){ | 
|---|
|  |  |  | throw new FebsException("会员等级不够"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (MallGoods.ISSALE_STATUS_DISABLED.equals(goods.getIsSale())) { | 
|---|
|  |  |  | throw new FebsException(goods.getGoodsName() + "已下架"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 存在未支付的订单无法下单 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Integer orderIng = this.baseMapper.selectOrderInfoByStatusAndMemberId(OrderStatusEnum.FINISH.getValue(), mallMember.getId()); | 
|---|
|  |  |  | if(1 <= orderIng){ | 
|---|
|  |  |  | throw new FebsException("请先完成未完成的订单"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallAddressInfo address = mallAddressInfoMapper.selectById(addOrderDto.getAddressId()); | 
|---|
|  |  |  | if (address == null) { | 
|---|
|  |  |  | throw new FebsException("地址不存在"); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 会员一天最多下单次数 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DataDictionaryCustom buyTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.BUY_TIMES.getType(), DataDictionaryEnum.BUY_TIMES.getCode()); | 
|---|
|  |  |  | Integer buyTimes = Integer.parseInt(buyTimesDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DateTime date = DateUtil.date(); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | String yyyyMMdd = sdf.format(date); | 
|---|
|  |  |  | Integer times = this.baseMapper.selectCountByCreateTimeAndMemberId(yyyyMMdd,member.getId()); | 
|---|
|  |  |  | if(buyTimes <= times){ | 
|---|
|  |  |  | throw new FebsException("今日任务完成,明天再来"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom allBuyTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.ALL_BUY_TIMES.getType(), DataDictionaryEnum.ALL_BUY_TIMES.getCode()); | 
|---|
|  |  |  | Integer allBuyTimes = Integer.parseInt(allBuyTimesDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer allBuyTimesNow = this.baseMapper.selectCountByCreateTime(yyyyMMdd); | 
|---|
|  |  |  | if(allBuyTimes <= allBuyTimesNow){ | 
|---|
|  |  |  | throw new FebsException("今日任务完成,明天再来"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum(); | 
|---|
|  |  |  | 
|---|
|  |  |  | orderInfo.setOrderTime(new Date()); | 
|---|
|  |  |  | orderInfo.setMemberId(member.getId()); | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue()); | 
|---|
|  |  |  | orderInfo.setName(address.getName()); | 
|---|
|  |  |  | orderInfo.setAddress(address.getArea() + address.getAddress()); | 
|---|
|  |  |  | orderInfo.setPhone(address.getPhone()); | 
|---|
|  |  |  | orderInfo.setLatitude(address.getLatitude()); | 
|---|
|  |  |  | orderInfo.setLongitude(address.getLongitude()); | 
|---|
|  |  |  | orderInfo.setRemark(addOrderDto.getRemark()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (CollUtil.isEmpty(addOrderDto.getItems())) { | 
|---|
|  |  |  | throw new FebsException("参数错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderInfo.setOrderType(addOrderDto.getOrderType()); | 
|---|
|  |  |  | //补贴金额 | 
|---|
|  |  |  | orderInfo.setSubsidyAmount(goods.getSubsidyAmount()); | 
|---|
|  |  |  | orderInfo.setCommentState(MallOrderInfo.COMMENT_STATE_NO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.insert(orderInfo); | 
|---|
|  |  |  | BigDecimal total = BigDecimal.ZERO; | 
|---|
|  |  |  | for (AddOrderItemDto item : addOrderDto.getItems()) { | 
|---|
|  |  |  | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); | 
|---|
|  |  |  | if (sku == null) { | 
|---|
|  |  |  | throw new FebsException("购买商品或sku不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MallGoodsSku> mallGoodsSkus = mallGoodsSkuMapper.selectSkuByGoodsId(goods.getId()); | 
|---|
|  |  |  | for (MallGoodsSku sku : mallGoodsSkus) { | 
|---|
|  |  |  | MallOrderItem orderItem = new MallOrderItem(); | 
|---|
|  |  |  | if (sku == null) { | 
|---|
|  |  |  | throw new FebsException("购买商品或sku不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (sku.getStock() < item.getCnt()) { | 
|---|
|  |  |  | throw new FebsException("库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sku.getStock() < 1) { | 
|---|
|  |  |  | throw new FebsException(sku.getSkuName() + "库存不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallOrderItem orderItem = new MallOrderItem(); | 
|---|
|  |  |  | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); | 
|---|
|  |  |  | orderItem.setAmount(amount); | 
|---|
|  |  |  | orderItem.setCnt(item.getCnt()); | 
|---|
|  |  |  | orderItem.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | orderItem.setPrice(sku.getPresentPrice()); | 
|---|
|  |  |  | orderItem.setGoodsId(sku.getGoodsId()); | 
|---|
|  |  |  | orderItem.setGoodsName(sku.getGoodsName()); | 
|---|
|  |  |  | orderItem.setSkuId(sku.getId()); | 
|---|
|  |  |  | orderItem.setStyleName(sku.getStyleName()); | 
|---|
|  |  |  | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(1)); | 
|---|
|  |  |  | orderItem.setAmount(amount); | 
|---|
|  |  |  | orderItem.setCnt(1); | 
|---|
|  |  |  | orderItem.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | orderItem.setPrice(sku.getPresentPrice()); | 
|---|
|  |  |  | orderItem.setGoodsId(sku.getGoodsId()); | 
|---|
|  |  |  | orderItem.setGoodsName(goods.getGoodsName()); | 
|---|
|  |  |  | orderItem.setSkuId(sku.getId()); | 
|---|
|  |  |  | orderItem.setStyleName(sku.getStyleName()); | 
|---|
|  |  |  | orderItem.setSkuName(sku.getSkuName()); | 
|---|
|  |  |  | orderItem.setSkuImage(sku.getSkuImage()); | 
|---|
|  |  |  | orderItem.setIsNormal(goods.getIsNormal()); | 
|---|
|  |  |  | orderItem.setCostPrice(sku.getCostPrice()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | total = total.add(amount); | 
|---|
|  |  |  | mallOrderItemMapper.insert(orderItem); | 
|---|
|  |  |  | sku.setStock(sku.getStock() - 1); | 
|---|
|  |  |  | sku.setSkuVolume(sku.getSkuVolume() + 1); | 
|---|
|  |  |  | mallGoodsSkuMapper.updateById(sku); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sku.setStock(sku.getStock() - item.getCnt()); | 
|---|
|  |  |  | mallGoodsSkuMapper.updateById(sku); | 
|---|
|  |  |  | if (1 == addOrderDto.getType() ) { | 
|---|
|  |  |  | mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallOrderItemMapper.insert(orderItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal presentPrice = new BigDecimal(goods.getPresentPrice()).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | orderInfo.setAmount(presentPrice); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); | 
|---|
|  |  |  | return orderInfo.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void cancelOrder(Long id) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id); | 
|---|
|  |  |  | if (orderInfo == null) { | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | //        String unipayStr = "{\"r1_MerchantNo\":\"888118000001971\",\"rd_Pic\":\"\",\"r6_FrpCode\":\"ALIPAY_H5\",\"r7_TrxNo\":\"100222082332490699\",\"r0_Version\":\"1.0\",\"r3_Amount\":\"0.01\",\"r4_Cur\":\"1\",\"r2_OrderNo\":\"2022082212510288174\",\"rb_CodeMsg\":\"\",\"hmac\":\"1659BB77DEDDF9956EA4D6DF227C3B14\",\"ra_Code\":100,\"rc_Result\":\"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title></title></head><body><script type='text/javascript'>location.href='https://qr.alipay.com/bax019737vbdwoisxcdp00a2';</script></body></html>\"}"; | 
|---|
|  |  |  | //        JSONObject jsonObject = JSONUtil.parseObj(unipayStr); | 
|---|
|  |  |  | //        String r7_trxNo = (String) jsonObject.get("r7_TrxNo"); | 
|---|
|  |  |  | //        System.out.println(r7_trxNo); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public String payOrder(PayOrderDto payOrderDto) { | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public Map<String, Object> payOrder(PayOrderDto payOrderDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), payOrderDto.getId()); | 
|---|
|  |  |  | if (orderInfo == null) { | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(payOrderDto.getId()); | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) { | 
|---|
|  |  |  | throw new FebsException("订单状态不能支付"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (payOrderDto.getType()) { | 
|---|
|  |  |  | String type = payOrderDto.getType(); | 
|---|
|  |  |  | type = type == "3" ? type : "3"; | 
|---|
|  |  |  | String payResultStr = ""; | 
|---|
|  |  |  | String rcResult = ""; | 
|---|
|  |  |  | switch (type) { | 
|---|
|  |  |  | case "1": | 
|---|
|  |  |  | // TODO 微信支付 | 
|---|
|  |  |  | 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("商品"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | unipayDtoWx.setProductName(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"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderInfo.setPayOrderNo(payResultStr); | 
|---|
|  |  |  | //                orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo()); | 
|---|
|  |  |  | //                orderInfo.setPayImage(payOrderDto.getPayImage()); | 
|---|
|  |  |  | orderInfo.setPayMethod("微信支付"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "2": | 
|---|
|  |  |  | // TODO 支付宝支付 | 
|---|
|  |  |  | //                if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { | 
|---|
|  |  |  | //                    payResultStr = orderInfo.getPayOrderNo(); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    payResultStr = payService.aliPay(orderInfo); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | UnipayDto unipayDto = new UnipayDto(); | 
|---|
|  |  |  | //                unipayDto.setAmount(new BigDecimal("0.01")); | 
|---|
|  |  |  | unipayDto.setAmount(orderInfo.getAmount()); | 
|---|
|  |  |  | unipayDto.setFrpCode("ALIPAY_H5"); | 
|---|
|  |  |  | unipayDto.setTradeMerchantNo("777184100385821"); | 
|---|
|  |  |  | unipayDto.setOrderNo(orderInfo.getOrderNo()); | 
|---|
|  |  |  | List<MallOrderItem> items = orderInfo.getItems(); | 
|---|
|  |  |  | if(CollUtil.isEmpty(items)){ | 
|---|
|  |  |  | unipayDto.setProductName("商品"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | unipayDto.setProductName(items.get(0).getGoodsName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String unipayStr = unipayService.unipay(unipayDto); | 
|---|
|  |  |  | if("fail" == unipayStr){ | 
|---|
|  |  |  | throw new FebsException("支付失败"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //                    JSONUtil.parseObj(unipayStr); | 
|---|
|  |  |  | JSONObject jsonObject = JSONUtil.parseObj(unipayStr); | 
|---|
|  |  |  | payResultStr = (String) jsonObject.get("r7_TrxNo"); | 
|---|
|  |  |  | rcResult = (String) jsonObject.get("rc_Result"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderInfo.setPayOrderNo(payResultStr); | 
|---|
|  |  |  | orderInfo.setPayMethod("支付宝支付"); | 
|---|
|  |  |  | //                agentProducer.sendOrderReturn(orderInfo.getId()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "3": | 
|---|
|  |  |  | return balancePay(orderInfo, payOrderDto.getTradePwd()); | 
|---|
|  |  |  | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); | 
|---|
|  |  |  | orderInfo.setPayMethod("余额支付"); | 
|---|
|  |  |  | //                orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); | 
|---|
|  |  |  | //订单支付成功后,订单直接变成待收货 | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.WAIT_FINISH.getValue()); | 
|---|
|  |  |  | //生成物流编号 | 
|---|
|  |  |  | String logisticsNo = MallUtils.getLogisticsNum(StrUtil.subSuf(payResultStr, payResultStr.length() - 2)); | 
|---|
|  |  |  | orderInfo.setPayTradeNo(logisticsNo); | 
|---|
|  |  |  | orderInfo.setPayTime(new Date()); | 
|---|
|  |  |  | orderInfo.setPayResult("1"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成下单的流水记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Long payFlowId = mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | member.getId(), | 
|---|
|  |  |  | orderInfo.getOrderNo(), | 
|---|
|  |  |  | orderInfo.getAmount().negate().setScale(2, BigDecimal.ROUND_DOWN), | 
|---|
|  |  |  | MallMoneyFlowTypeEnum.PAY.getCode(), | 
|---|
|  |  |  | MallMoneyFlow.STATUS_SUCCESS, | 
|---|
|  |  |  | MallMoneyFlow.IS_RETURN_N, | 
|---|
|  |  |  | member.getId(), | 
|---|
|  |  |  | FlowTypeEnum.BALANCE.getValue(), | 
|---|
|  |  |  | MallMoneyFlowTypeEnum.PAY.getName() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "4": | 
|---|
|  |  |  | if (orderInfo.getOrderType() != 2) { | 
|---|
|  |  |  | throw new FebsException("非积分订单,无法使用积分支付"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "prizeScore"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); | 
|---|
|  |  |  | orderInfo.setPayMethod("积分支付"); | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); | 
|---|
|  |  |  | orderInfo.setPayTime(new Date()); | 
|---|
|  |  |  | orderInfo.setPayResult("1"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal value = orderInfo.getAmount().setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | DecimalFormat decimalFormat = new DecimalFormat("0.00#"); | 
|---|
|  |  |  | String strVal = decimalFormat.format(value); | 
|---|
|  |  |  | agreementPayDto.setOrderAmount(new BigDecimal(strVal)); | 
|---|
|  |  |  | agreementPayDto.setOrderTime(DateUtil.now()); | 
|---|
|  |  |  | List<MallOrderItem> itemsGoods = orderInfo.getItems(); | 
|---|
|  |  |  | if(CollUtil.isEmpty(itemsGoods)){ | 
|---|
|  |  |  | agreementPayDto.setOrderDesc("商品"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | agreementPayDto.setOrderDesc(itemsGoods.get(0).getGoodsName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long bankId = payOrderDto.getBankId() == null ? 0L : payOrderDto.getBankId(); | 
|---|
|  |  |  | MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(bankId); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallMemberBank)){ | 
|---|
|  |  |  | throw new FebsException("银行卡未添加"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String bankNo = mallMemberBank.getBankNo(); | 
|---|
|  |  |  | MallMemberBankSign mallMemberBankSign = mallMemberBankSignMapper.selectOneByMemberIdAndBankCardNo(member.getId(), bankNo); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallMemberBankSign)){ | 
|---|
|  |  |  | throw new FebsException("银行卡未签约"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | agreementPayDto.setBankNo(bankNo); | 
|---|
|  |  |  | String agreementPayStr = unipayService.agreementPay(agreementPayDto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if("fail".equals(agreementPayStr)){ | 
|---|
|  |  |  | throw new FebsException("支付失败"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | JSONObject jsonObject = JSONUtil.parseObj(agreementPayStr); | 
|---|
|  |  |  | payResultStr = (String) jsonObject.get("biz_code"); | 
|---|
|  |  |  | String payBizMsg = (String) jsonObject.get("biz_msg"); | 
|---|
|  |  |  | if(!"JS000000".equals(payResultStr)){ | 
|---|
|  |  |  | throw new FebsException(payBizMsg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderInfo.setPayMethod("快捷协议支付"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("orderInfo", payResultStr); | 
|---|
|  |  |  | map.put("orderNo", orderInfo.getOrderNo()); | 
|---|
|  |  |  | map.put("orderId", orderInfo.getId()); | 
|---|
|  |  |  | map.put("rcResult", rcResult); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String balancePay(MallOrderInfo orderInfo, String tradePwd) { | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | String str = "{\"biz_code\":\"JS000000\",\"biz_msg\":\"成功\",\"data\":\"{\\\"order_status\\\":\\\"P2000\\\",\\\"jp_order_no\\\":\\\"100120220826446740396081496064\\\",\\\"err_msg\\\":\\\"短信验证码不符\\\",\\\"err_code\\\":\\\"CP110026\\\",\\\"sign_no\\\":\\\"\\\",\\\"mch_order_no\\\":\\\"NO_2022082618263952399\\\"}\",\"mch_no\":\"888118000001971\",\"rand_str\":\"an2w7ulf5ru6upkk5bdg441kdi3gnpvu\",\"resp_code\":\"SUCCESS\",\"sec_key\":\"\",\"sign\":\"NiJXRTSIZ9xZMUOwEHiEHdZXmgL2cHUU5WUa1NbMRRzui0DIiuZSW4e31LjnBxwVwmy3uuPMP+tqhY8VLyC8uCFOdGdZI7e72VuRvyvaiW7/sqCrsfgPOBEjiGE/CmSMRoEXv9HmqCyNBF6iHSEhQJql5Yge30dQdyB6xFfqjk0=\",\"sign_type\":\"2\"}"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject jsonObject = JSONUtil.parseObj(str); | 
|---|
|  |  |  | String payResultStr = (String) jsonObject.get("biz_code"); | 
|---|
|  |  |  | String signBizMsg = (String) jsonObject.get("biz_msg"); | 
|---|
|  |  |  | String signData = (String) jsonObject.get("data"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject signDatajsonObject = JSONUtil.parseObj(signData); | 
|---|
|  |  |  | String err_msg = (String) signDatajsonObject.get("err_msg"); | 
|---|
|  |  |  | if(ObjectUtil.isNotNull(signDatajsonObject.get("err_code"))){ | 
|---|
|  |  |  | System.out.println(err_msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String balancePay(MallOrderInfo orderInfo, String tradePwd, String field) { | 
|---|
|  |  |  | if (StrUtil.isBlank(tradePwd)) { | 
|---|
|  |  |  | throw new FebsException("支付密码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMember mallMember = memberMapper.selectById(orderInfo.getMemberId()); | 
|---|
|  |  |  | if (!mallMember.getTradePassword().equals(SecureUtil.md5(tradePwd))) { | 
|---|
|  |  |  | if (StrUtil.isBlank(mallMember.getTradePassword())) { | 
|---|
|  |  |  | throw new FebsException("未设置支付密码"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!SecureUtil.md5(tradePwd).equals(mallMember.getTradePassword())) { | 
|---|
|  |  |  | throw new FebsException("支付密码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | memberWalletService.reduceBalance(orderInfo.getAmount(), mallMember.getId()); | 
|---|
|  |  |  | int reduce = memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field); | 
|---|
|  |  |  | if (reduce == 2) { | 
|---|
|  |  |  | throw new FebsException("余额不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return orderInfo.getOrderNo(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<OrderListVo> findOrderList(OrderListDto orderListDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | IPage<MallOrderInfo> page = new Page<>(orderListDto.getPageNum(), orderListDto.getPageSize()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderListDto.setMemberId(member.getId()); | 
|---|
|  |  |  | IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectApiOrderListInPage(page, orderListDto); | 
|---|
|  |  |  | return MallOrderInfoConversion.INSTANCE.entitysToVos(mallOrderInfos.getRecords()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public OrderDetailVo findOrderDetailsById(Long id) { | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(id); | 
|---|
|  |  |  | if (orderInfo == null) { | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { | 
|---|
|  |  |  | MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); | 
|---|
|  |  |  | orderDetailVo.setExpressNo(expressInfo.getExpressNo()); | 
|---|
|  |  |  | orderDetailVo.setExpressCom(expressInfo.getExpressCom()); | 
|---|
|  |  |  | //        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()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        if (orderInfo.getStatus() == OrderStatusEnum.REFUNDING.getValue() || orderInfo.getStatus() == OrderStatusEnum.REFUNDED.getValue()) { | 
|---|
|  |  |  | //            MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(orderInfo.getId()); | 
|---|
|  |  |  | //            OrderRefundVo orderRefundVo = MallOrderRefundConversion.INSTANCE.entityToVo(orderRefund); | 
|---|
|  |  |  | //            orderDetailVo.setOrderRefund(orderRefundVo); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (OrderStatusEnum.WAIT_PAY.getValue() == orderInfo.getStatus()) { | 
|---|
|  |  |  | Date endTime = DateUtil.offsetMinute(orderInfo.getOrderTime(), 15); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false); | 
|---|
|  |  |  | orderDetailVo.setRemainTime(remainTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if(2 == deliverType){ | 
|---|
|  |  |  | //            MallShopApply mallShopApply = mallShopApplyMapper.selectById(orderInfo.getShopId()); | 
|---|
|  |  |  | //            if(ObjectUtil.isNotEmpty(mallShopApply)){ | 
|---|
|  |  |  | //                ApiShopApplyVo apiShopApplyVo = new ApiShopApplyVo(); | 
|---|
|  |  |  | //                apiShopApplyVo.setName(mallShopApply.getName()); | 
|---|
|  |  |  | //                apiShopApplyVo.setPhone(mallShopApply.getPhone()); | 
|---|
|  |  |  | //                apiShopApplyVo.setSaleArea(mallShopApply.getSaleArea()); | 
|---|
|  |  |  | //                apiShopApplyVo.setLatitude(mallShopApply.getLatitude()); | 
|---|
|  |  |  | //                apiShopApplyVo.setLongitude(mallShopApply.getLongitude()); | 
|---|
|  |  |  | //                apiShopApplyVo.setShopName(mallShopApply.getShopName()); | 
|---|
|  |  |  | //                apiShopApplyVo.setAddress(mallShopApply.getAddress()); | 
|---|
|  |  |  | //                orderDetailVo.setApiShopApplyVo(apiShopApplyVo); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | return orderDetailVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void confirmOrder(Long id) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id); | 
|---|
|  |  |  | if (orderInfo == null) { | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) { | 
|---|
|  |  |  | throw new FebsException("该状态不能确认收货"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); | 
|---|
|  |  |  | orderInfo.setReceivingTime(new Date()); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | //        /** | 
|---|
|  |  |  | //         * 通过支付流水记录,返回下单金额 | 
|---|
|  |  |  | //         */ | 
|---|
|  |  |  | //        MallMoneyFlow payFlow = mallMoneyFlowMapper.selectOneByMemberIdAndOrderNoAndTypeAndStatusAndIsReturn( | 
|---|
|  |  |  | //                member.getId(), | 
|---|
|  |  |  | //                orderInfo.getOrderNo(), | 
|---|
|  |  |  | //                MallMoneyFlowTypeEnum.PAY.getCode(), | 
|---|
|  |  |  | //                MallMoneyFlow.STATUS_SUCCESS, | 
|---|
|  |  |  | //                MallMoneyFlow.IS_RETURN_N); | 
|---|
|  |  |  | //        if(ObjectUtil.isNotEmpty(payFlow)){ | 
|---|
|  |  |  | //            memberWalletService.addBalance(payFlow.getAmount().negate(),payFlow.getRtMemberId()); | 
|---|
|  |  |  | //            payFlow.setIsReturn(MallMoneyFlow.IS_RETURN_Y); | 
|---|
|  |  |  | //            mallMoneyFlowMapper.updateById(payFlow); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        //产生补贴流水记录 | 
|---|
|  |  |  | //        agentProducer.sendDirectRewardMsg(orderInfo.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void delOrder(Long id) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id); | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setDelFlag(AppContants.DEL_FLAG_Y); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void applyRefund(AddRefundDto addRefundDto) { | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectById(addRefundDto.getId()); | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderInfo.getStatus() == OrderStatusEnum.REFUNDING.getValue()) { | 
|---|
|  |  |  | throw new FebsException("已提交退款, 请勿重复提交"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (orderInfo.getStatus() != OrderStatusEnum.WAIT_SHIPPING.getValue() && orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) { | 
|---|
|  |  |  | throw new FebsException("该订单不能退款"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer beforeStatus = orderInfo.getStatus(); | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.REFUNDING.getValue()); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(orderInfo.getId()); | 
|---|
|  |  |  | if (orderRefund == null) { | 
|---|
|  |  |  | orderRefund = new MallOrderRefund(); | 
|---|
|  |  |  | orderRefund.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | orderRefund.setMemberId(member.getId()); | 
|---|
|  |  |  | orderRefund.setDesp(addRefundDto.getDesp()); | 
|---|
|  |  |  | orderRefund.setReason(addRefundDto.getReason()); | 
|---|
|  |  |  | orderRefund.setType(addRefundDto.getType()); | 
|---|
|  |  |  | orderRefund.setRefundTime(new Date()); | 
|---|
|  |  |  | orderRefund.setBeforeStatus(beforeStatus); | 
|---|
|  |  |  | orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 未发货则退运费,发货了则不退 | 
|---|
|  |  |  | if (beforeStatus == 2) { | 
|---|
|  |  |  | orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage())); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | orderRefund.setAmount(orderInfo.getAmount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallOrderRefundMapper.insert(orderRefund); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | orderRefund.setDesp(addRefundDto.getDesp()); | 
|---|
|  |  |  | orderRefund.setReason(addRefundDto.getReason()); | 
|---|
|  |  |  | orderRefund.setType(addRefundDto.getType()); | 
|---|
|  |  |  | orderRefund.setRefundTime(new Date()); | 
|---|
|  |  |  | orderRefund.setBeforeStatus(beforeStatus); | 
|---|
|  |  |  | orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue()); | 
|---|
|  |  |  | // 未发货则退运费,发货了则不退 | 
|---|
|  |  |  | if (beforeStatus == 2) { | 
|---|
|  |  |  | orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage())); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | orderRefund.setAmount(orderInfo.getAmount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallOrderRefundMapper.updateById(orderRefund); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallOrderRefundOperation operation = new MallOrderRefundOperation(); | 
|---|
|  |  |  | operation.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | operation.setRefundId(orderRefund.getId()); | 
|---|
|  |  |  | operation.setContent(StrUtil.format("用户:{}提交退款申请", member.getName())); | 
|---|
|  |  |  | mallOrderRefundOperationMapper.insert(operation); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void refundExpress(RefundExpressDto refundExpressDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(refundExpressDto.getId()); | 
|---|
|  |  |  | if (!OrderRefundStatusEnum.AGREE.getValue().equals(orderRefund.getStatus())) { | 
|---|
|  |  |  | throw new FebsException("暂不能提交物流信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderRefund.setExpressNo(refundExpressDto.getExpressNo()); | 
|---|
|  |  |  | orderRefund.setExpressCom(refundExpressDto.getExpressCom()); | 
|---|
|  |  |  | orderRefund.setStatus(OrderRefundStatusEnum.EXPRESS_SUBMIT.getValue()); | 
|---|
|  |  |  | mallOrderRefundMapper.updateById(orderRefund); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallOrderRefundOperation operation = new MallOrderRefundOperation(); | 
|---|
|  |  |  | operation.setOrderId(refundExpressDto.getId()); | 
|---|
|  |  |  | operation.setRefundId(orderRefund.getId()); | 
|---|
|  |  |  | operation.setContent(StrUtil.format("用户:{}提交物流信息,快递公司:{},单号:{}", member.getName(), refundExpressDto.getExpressCom(), refundExpressDto.getExpressNo())); | 
|---|
|  |  |  | mallOrderRefundOperationMapper.insert(operation); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void autoCancelOrder(Long id) { | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectById(id); | 
|---|
|  |  |  | if (orderInfo == null) { | 
|---|
|  |  |  | log.error("自动取消订单参数错误:{}", id); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (orderInfo.getStatus() == OrderStatusEnum.WAIT_PAY.getValue()) { | 
|---|
|  |  |  | log.info("自动取消订单:{},{}", orderInfo.getMemberId(), id); | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); | 
|---|
|  |  |  | orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void goodsComment(ApiAddCommentDtos addCommentDtos) { | 
|---|
|  |  |  | Long orderId = addCommentDtos.getOrderId(); | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(orderId); | 
|---|
|  |  |  | if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { | 
|---|
|  |  |  | throw new FebsException("订单不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (OrderStatusEnum.FINISH.getValue() != orderInfo.getStatus()) { | 
|---|
|  |  |  | throw new FebsException("该状态不能评价"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (MallOrderInfo.COMMENT_STATE_YES == orderInfo.getCommentState()) { | 
|---|
|  |  |  | throw new FebsException("该状态不能评价"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setCommentState(MallOrderInfo.COMMENT_STATE_YES); | 
|---|
|  |  |  | this.baseMapper.updateById(orderInfo); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 通过支付流水记录,返回下单金额 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallMoneyFlow payFlow = mallMoneyFlowMapper.selectOneByMemberIdAndOrderNoAndTypeAndStatusAndIsReturn( | 
|---|
|  |  |  | member.getId(), | 
|---|
|  |  |  | orderInfo.getOrderNo(), | 
|---|
|  |  |  | MallMoneyFlowTypeEnum.PAY.getCode(), | 
|---|
|  |  |  | MallMoneyFlow.STATUS_SUCCESS, | 
|---|
|  |  |  | MallMoneyFlow.IS_RETURN_N); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(payFlow)){ | 
|---|
|  |  |  | memberWalletService.addBalance(payFlow.getAmount().negate(),payFlow.getRtMemberId()); | 
|---|
|  |  |  | payFlow.setIsReturn(MallMoneyFlow.IS_RETURN_Y); | 
|---|
|  |  |  | mallMoneyFlowMapper.updateById(payFlow); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //产生补贴流水记录 | 
|---|
|  |  |  | agentProducer.sendDirectRewardMsg(orderInfo.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ApiAddCommentDto> apiAddCommentDtos = addCommentDtos.getApiAddCommentDtos(); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(apiAddCommentDtos)){ | 
|---|
|  |  |  | for(ApiAddCommentDto apiAddCommentDto : apiAddCommentDtos){ | 
|---|
|  |  |  | Long skuId = apiAddCommentDto.getSkuId(); | 
|---|
|  |  |  | Long goodsId = apiAddCommentDto.getGoodsId(); | 
|---|
|  |  |  | List<MallGoodsSku> mallGoodsSkus = mallGoodsSkuMapper.selectSkuByGoodsId(goodsId); | 
|---|
|  |  |  | MallGoodsSku mallGoodsSku = mallGoodsSkus.get(0); | 
|---|
|  |  |  | MallGoods mallGoods = mallGoodsMapper.selectById(goodsId); | 
|---|
|  |  |  | MallGoodsComment mallGoodsComment = MallGoodsCommentConversion.INSTANCE.dtoToEntity(apiAddCommentDto); | 
|---|
|  |  |  | mallGoodsComment.setMemberId(member.getId()); | 
|---|
|  |  |  | mallGoodsComment.setOrderId(orderId); | 
|---|
|  |  |  | mallGoodsComment.setGoodsName(mallGoods.getGoodsName()); | 
|---|
|  |  |  | mallGoodsComment.setSkuName(mallGoodsSku.getSkuName()); | 
|---|
|  |  |  | mallGoodsComment.setStyleId(mallGoodsSku.getStyleId()); | 
|---|
|  |  |  | mallGoodsComment.setStyleName(mallGoodsSku.getStyleName()); | 
|---|
|  |  |  | mallGoodsComment.setShowState(MallGoodsComment.SHOW_STATE_ENABLE); | 
|---|
|  |  |  | mallGoodsCommentMapper.insert(mallGoodsComment); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse bangCardSign(BangCardSignDto bangCardSignDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | Long memberId = member.getId(); | 
|---|
|  |  |  | String bankCard = bangCardSignDto.getBankCard(); | 
|---|
|  |  |  | MallMemberBankSign mallMemberBankSign = mallMemberBankSignMapper.selectOneByMemberIdAndBankCardNo(memberId,bankCard); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMemberBankSign)){ | 
|---|
|  |  |  | return new FebsResponse().success().data(mallMemberBankSign); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse subsidyAmountInfo() { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | ApiMallSubsidyAmountInfoVo apiMallSubsidyAmountInfoVo = new ApiMallSubsidyAmountInfoVo(); | 
|---|
|  |  |  | DateTime today = DateUtil.date(); | 
|---|
|  |  |  | DateTime yesterday = DateUtil.yesterday(); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | String yyyyMMddToday = sdf.format(today); | 
|---|
|  |  |  | String yyyyMMddYesterday = sdf.format(yesterday); | 
|---|
|  |  |  | //今日补贴 | 
|---|
|  |  |  | BigDecimal todayAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(yyyyMMddToday,member.getId()); | 
|---|
|  |  |  | apiMallSubsidyAmountInfoVo.setTodayAmount(todayAmount); | 
|---|
|  |  |  | //累计接单 | 
|---|
|  |  |  | Integer todayTotalCnt = this.baseMapper.selectCountByCreateTimeAndMemberId(null,member.getId()); | 
|---|
|  |  |  | apiMallSubsidyAmountInfoVo.setTodayTotalCnt(todayTotalCnt); | 
|---|
|  |  |  | //昨日补贴 | 
|---|
|  |  |  | BigDecimal yesterdayAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(yyyyMMddYesterday,member.getId()); | 
|---|
|  |  |  | apiMallSubsidyAmountInfoVo.setYesterdayAmount(yesterdayAmount); | 
|---|
|  |  |  | //昨日累计接单 | 
|---|
|  |  |  | Integer totalYesterdayCnt = this.baseMapper.selectCountByCreateTimeAndMemberId(yyyyMMddYesterday,member.getId()); | 
|---|
|  |  |  | apiMallSubsidyAmountInfoVo.setTotalYesterdayCnt(totalYesterdayCnt); | 
|---|
|  |  |  | //获得总额 | 
|---|
|  |  |  | BigDecimal totalAmount = this.baseMapper.selectTodayAmountByCreateTimeAndMemberId(null,member.getId()); | 
|---|
|  |  |  | apiMallSubsidyAmountInfoVo.setTotalAmount(totalAmount); | 
|---|
|  |  |  | return new FebsResponse().success().data(apiMallSubsidyAmountInfoVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|