package cc.mrbird.febs.mall.service.impl;
|
|
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.properties.XcxProperties;
|
import cc.mrbird.febs.common.utils.*;
|
import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion;
|
import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion;
|
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.*;
|
import cc.mrbird.febs.mall.vo.ApiCouponAmountMapVo;
|
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.pay.model.BrandWCPayRequestData;
|
import cc.mrbird.febs.pay.service.IPayService;
|
import cc.mrbird.febs.pay.service.IXcxPayService;
|
import cc.mrbird.febs.pay.util.WeixinServiceUtil;
|
import cc.mrbird.febs.rabbit.producter.AgentProducer;
|
import cc.mrbird.febs.vip.service.IMallVipConfigService;
|
import cn.hutool.core.collection.CollUtil;
|
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.JSONUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
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.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author wzy
|
* @date 2021-09-18
|
**/
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
public class ApiMallOrderInfoServiceImpl extends ServiceImpl<MallOrderInfoMapper, MallOrderInfo> implements IApiMallOrderInfoService {
|
|
private final MallGoodsMapper mallGoodsMapper;
|
private final MallGoodsSkuMapper mallGoodsSkuMapper;
|
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 RedisUtils redisUtils;
|
|
private final AgentProducer agentProducer;
|
private final IPayService payService;
|
private final IXcxPayService iXcxPayService;
|
private final IMallAchieveService mallAchieveService;
|
private final MallRefundMapper mallRefundMapper;
|
private final MallTeamLeaderMapper mallTeamLeaderMapper;
|
private final MallMemberMapper mallMemberMapper;
|
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
|
private final MallLeaderAchieveMapper mallLeaderAchieveMapper;
|
private final IApiMallTeamLeaderService iApiMallTeamLeaderService;
|
private final IMallElectronicFenceService iMallElectronicFenceService;
|
private final MallElectronicFenceMapper mallElectronicFenceMapper;
|
private final MallMemberCouponMapper mallMemberCouponMapper;
|
private final MallGoodsCouponMapper mallGoodsCouponMapper;
|
private final CouponGoodsMapper couponGoodsMapper;
|
|
private final IMallVipConfigService mallVipConfigService;
|
private final MallActivityMapper mallActivityMapper;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Long createOrder(AddOrderDto addOrderDto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
MallMember member = mallMemberMapper.selectById(memberId);
|
|
//订单范围内才允许下单
|
MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId());
|
if(ObjectUtil.isEmpty(address)){
|
throw new FebsException("请重新选择收货地址信息");
|
}
|
|
String orderNo = MallUtils.getOrderNum();
|
MallOrderInfo orderInfo = new MallOrderInfo();
|
orderInfo.setOrderNo(orderNo);
|
orderInfo.setOrderTime(new Date());
|
orderInfo.setMemberId(member.getId());
|
orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue());
|
orderInfo.setRemark(addOrderDto.getRemark());
|
orderInfo.setOrderType(addOrderDto.getOrderType());
|
orderInfo.setDeliveryType(2);
|
if (CollUtil.isEmpty(addOrderDto.getItems())) {
|
throw new FebsException("参数错误");
|
}
|
this.baseMapper.insert(orderInfo);
|
|
BigDecimal total = BigDecimal.ZERO;
|
/**
|
* 根据传入的优惠卷ID和商品明细集合计算出每个商品获取的实际支付金额
|
*/
|
Map<Long, BigDecimal> couponAmountMap = new HashMap<>();
|
MallMemberCoupon mallMemberCoupon = new MallMemberCoupon();
|
if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
|
Long memberCouponId = addOrderDto.getMemberCouponId();
|
mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
|
if(ObjectUtil.isEmpty(mallMemberCoupon)){
|
throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
|
}
|
Integer state = mallMemberCoupon.getState();
|
if(1 != state){
|
throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
|
}
|
List<AddOrderItemDto> items = addOrderDto.getItems();
|
couponAmountMap = getCouponAmountMap(memberCouponId, items);
|
}
|
for (AddOrderItemDto item : addOrderDto.getItems()) {
|
MallOrderItem orderItem = new MallOrderItem();
|
|
// 积分商品提交订单
|
if (addOrderDto.getOrderType() == 2) {
|
MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId());
|
if (mallGoods.getStock() < item.getCnt()) {
|
throw new FebsException(mallGoods.getGoodsName() + "库存不足");
|
}
|
|
if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
|
throw new FebsException(mallGoods.getGoodsName() + "已下架");
|
}
|
|
BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt()));
|
orderItem.setAmount(amount);
|
orderItem.setCnt(item.getCnt());
|
orderItem.setOrderId(orderInfo.getId());
|
orderItem.setPrice(mallGoods.getScore());
|
orderItem.setGoodsId(mallGoods.getId());
|
orderItem.setGoodsName(mallGoods.getGoodsName());
|
orderItem.setStyleName(mallGoods.getGoodsName());
|
orderItem.setSkuName(mallGoods.getGoodsName());
|
orderItem.setSkuImage(mallGoods.getThumb());
|
orderItem.setState(1);
|
|
if (addOrderDto.getType() == 1) {
|
LambdaQueryWrapper<MallShoppingCart> delQuery = new LambdaQueryWrapper<>();
|
delQuery.eq(MallShoppingCart::getGoodsId, item.getSkuId())
|
.eq(MallShoppingCart::getMemberId, member.getId());
|
mallShoppingCartMapper.delete(delQuery);
|
}
|
total = total.add(amount);
|
} else {
|
MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
|
if (sku == null) {
|
throw new FebsException("购买商品或sku不存在");
|
}
|
|
// if("样品".equals(sku.getSample())){
|
// List<MallOrderItem> items = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId());
|
// if (CollUtil.isNotEmpty(items)) {
|
// throw new FebsException("样品一个用户只能购买一次");
|
// }
|
// Integer cnt = item.getCnt();
|
// if(1 < cnt){
|
// throw new FebsException("样品只能购买一件");
|
// }
|
//
|
// }
|
|
if (sku.getStock() < item.getCnt()) {
|
throw new FebsException(sku.getSkuName() + "库存不足");
|
}
|
|
MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
|
// 零撸专区购买
|
if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) {
|
List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId());
|
if (CollUtil.isNotEmpty(items)) {
|
throw new FebsException("无法重复领取同一个商品");
|
}
|
}
|
|
if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
|
throw new FebsException(mallGoods.getGoodsName() + "已下架");
|
}
|
//商品库存销量计算
|
Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt());
|
if(1 != goodsResult){
|
throw new FebsException(mallGoods.getGoodsName() + "库存不足");
|
}
|
|
BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
|
//是否使用优惠卷
|
if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
|
Long memberCouponId = addOrderDto.getMemberCouponId();
|
if(ObjectUtil.isNotEmpty(couponAmountMap.get(item.getSkuId()))){
|
BigDecimal skuCouponAmount = couponAmountMap.get(item.getSkuId());//使用折扣卷后的应该支付的钱
|
if(skuCouponAmount.compareTo(BigDecimal.ZERO) > 0){
|
amount = skuCouponAmount;
|
}
|
orderItem.setMemberCouponId(memberCouponId);
|
}
|
}
|
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.setState(1);
|
if(ObjectUtil.isNotEmpty(member.getReferrerId())){
|
orderItem.setMemberInviteId(member.getReferrerId());
|
}
|
if(ObjectUtil.isNotEmpty(addOrderDto.getMemberInviteId())){
|
orderItem.setMemberInviteId(addOrderDto.getMemberInviteId());
|
}
|
|
orderItem.setStyleName(sku.getStyleName());
|
orderItem.setSkuName(sku.getSkuName());
|
orderItem.setSkuImage(sku.getSkuImage());
|
orderItem.setIsNormal(mallGoods.getIsNormal());
|
orderItem.setCostPrice(sku.getCostPrice());
|
|
total = total.add(amount);
|
//规格的库存销量
|
Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt());
|
if(1 != skuResult){
|
throw new FebsException(sku.getSkuName() + "库存不足");
|
}
|
if (addOrderDto.getType() == 1) {
|
mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId());
|
}
|
}
|
mallOrderItemMapper.insert(orderItem);
|
}
|
|
mallMemberCoupon.setState(2);
|
mallMemberCouponMapper.updateById(mallMemberCoupon);
|
//运费
|
BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount();
|
orderInfo.setCarriage(delivaryAmount);
|
|
total = total.add(delivaryAmount);
|
orderInfo.setAmount(total);
|
orderInfo.setAddressId(address.getId());
|
orderInfo.setName(address.getName());
|
orderInfo.setPhone(address.getPhone());
|
orderInfo.setIsHome(addOrderDto.getIsHome());
|
|
if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) {
|
throw new FebsException("请添加地址");
|
}
|
orderInfo.setAddress(address.getProvince()+address.getCity()+address.getArea() + address.getAddress());
|
orderInfo.setLatitude(address.getLatitude());
|
orderInfo.setLongitude(address.getLongitude());
|
this.baseMapper.updateById(orderInfo);
|
//过期时间修改成24小时
|
agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 24 * 60 * 60 * 1000L);
|
return orderInfo.getId();
|
}
|
|
/**
|
* 根据传入的优惠卷ID和商品明细集合计算出每个商品获取的实际支付金额
|
* @param memberCouponId 优惠卷ID
|
* @param items 商品明细
|
* @return Map<Long,BigDecimal> skuId,实际支付金额
|
*/
|
@Override
|
public Map<Long,BigDecimal> getCouponAmountMap(Long memberCouponId,List<AddOrderItemDto> items){
|
HashMap<Long,BigDecimal> couponAmountMap = new HashMap<>();
|
// 获取优惠券信息
|
Optional<MallMemberCoupon> optionalMallMemberCoupon = Optional.ofNullable(mallMemberCouponMapper.selectById(memberCouponId));
|
MallMemberCoupon mallMemberCoupon = optionalMallMemberCoupon.orElse(null);
|
|
if (mallMemberCoupon == null || mallMemberCoupon.getState() != 1) {
|
return couponAmountMap;
|
}
|
|
Set<Long> intersection = items.stream().map(AddOrderItemDto::getSkuId).collect(Collectors.toSet());//订单中的全部skuIds
|
|
if (intersection.isEmpty()) {
|
return couponAmountMap;
|
}
|
|
// 获取订单详情的ID和amount的map
|
Map<Long, AddOrderItemDto> itemMap = items.stream()
|
.collect(Collectors.toMap(AddOrderItemDto::getSkuId, item -> item));
|
|
List<MallGoodsSku> skus = mallGoodsSkuMapper.selectList(
|
new LambdaQueryWrapper<MallGoodsSku>()
|
.select(MallGoodsSku::getId, MallGoodsSku::getPresentPrice)
|
.in(MallGoodsSku::getId, intersection)
|
);
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
Map<Long, BigDecimal> skuMap = new HashMap<>();
|
|
for (MallGoodsSku mallGoodsSku : skus) {
|
Long id = mallGoodsSku.getId();
|
BigDecimal presentPrice = mallGoodsSku.getPresentPrice();
|
AddOrderItemDto addOrderItemDto = itemMap.get(id);
|
if (addOrderItemDto != null) {
|
BigDecimal skuAmount = presentPrice.multiply(BigDecimal.valueOf(addOrderItemDto.getCnt()));
|
totalAmount = totalAmount.add(skuAmount);
|
skuMap.put(id, skuAmount);
|
}
|
}
|
|
// 计算每个商品利用优惠卷打折的具体金额
|
Optional<MallGoodsCoupon> optionalMallGoodsCoupon = Optional.ofNullable(mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId()));
|
MallGoodsCoupon mallGoodsCoupon = optionalMallGoodsCoupon.orElse(null);
|
if (mallGoodsCoupon == null) {
|
return couponAmountMap;
|
}
|
|
BigDecimal costAmount = mallGoodsCoupon.getCostAmount();
|
BigDecimal realAmount = mallGoodsCoupon.getRealAmount();
|
|
if (totalAmount.compareTo(costAmount) < 0) {
|
return couponAmountMap;
|
}
|
for (Map.Entry<Long,BigDecimal> entry : skuMap.entrySet()) {
|
Long keySkuId = entry.getKey();
|
BigDecimal valueSkuAmount = entry.getValue();
|
BigDecimal divide = valueSkuAmount.divide(totalAmount, 4, RoundingMode.DOWN);//每个商品占符合满减的总额的比例
|
Integer type = mallGoodsCoupon.getType();
|
if(MallGoodsCoupon.TYPE_ONE == type){
|
BigDecimal bigDecimalOne = realAmount.multiply(divide).setScale(2, RoundingMode.DOWN);//每个SKU的减免金额(比例*减免金额)
|
BigDecimal skuRealAmountOne = valueSkuAmount.subtract(bigDecimalOne.max(BigDecimal.ZERO));//实际支付金额
|
couponAmountMap.put(keySkuId, skuRealAmountOne);
|
continue;
|
}
|
if(MallGoodsCoupon.TYPE_TWO == type){
|
BigDecimal divideTime = totalAmount.divide(costAmount, 0, RoundingMode.DOWN);//累计减免次数
|
BigDecimal multiply = divideTime.multiply(realAmount);//实际减免金额
|
BigDecimal bigDecimalTwo = multiply.multiply(divide).setScale(2, RoundingMode.DOWN);//每个SKU的减免金额(比例*实际减免金额)
|
BigDecimal skuRealAmountTwo = valueSkuAmount.subtract(bigDecimalTwo.max(BigDecimal.ZERO));//实际支付金额
|
couponAmountMap.put(keySkuId, skuRealAmountTwo);
|
continue;
|
}
|
}
|
return couponAmountMap;
|
}
|
|
public static void main(String[] args) {
|
List<Integer> a = new ArrayList<>();
|
a.add(1);
|
a.add(2);
|
a.add(3);
|
List<Integer> b = new ArrayList<>();
|
b.add(3);
|
b.add(4);
|
b.add(5);
|
boolean b1 = a.retainAll(b);
|
System.out.println(b1);
|
System.out.println(a);
|
System.out.println(b);
|
List<Integer> intersection = a.stream()
|
.filter(item -> b.contains(item))
|
.collect(Collectors.toList());
|
|
System.out.println(intersection);
|
|
}
|
|
|
@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 || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
|
throw new FebsException("订单不存在");
|
}
|
|
if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) {
|
throw new FebsException("订单不是待付款, 无法取消");
|
}
|
|
orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
|
orderInfo.setCancelType(MallOrderInfo.CANCEL_BY_SELF);
|
this.baseMapper.updateById(orderInfo);
|
|
if (orderInfo.getOrderType() == 2) {
|
// mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount(), MoneyFlowTypeEnum.REFUND.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue());
|
// memberWalletService.add(orderInfo.getAmount(), member.getId(), "prizeScore");
|
return;
|
}
|
|
List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId());
|
if(CollUtil.isNotEmpty(mallOrderItemList)){
|
for(MallOrderItem mallOrderItem : mallOrderItemList){
|
MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId());
|
if (sku == null) {
|
throw new FebsException("购买商品或sku不存在");
|
}
|
|
if (sku.getStock() < mallOrderItem.getCnt()) {
|
throw new FebsException(sku.getSkuName() + "库存不足");
|
}
|
|
MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
|
Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt());
|
if(1 != goodsResult){
|
throw new FebsException(mallGoods.getGoodsName() + "库存不足");
|
}
|
|
Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt());
|
if(1 != skuResult){
|
throw new FebsException(sku.getSkuName() + "库存不足");
|
}
|
Long memberCouponId = mallOrderItem.getMemberCouponId();
|
MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
|
if(ObjectUtil.isNotEmpty(mallMemberCoupon)){
|
mallMemberCoupon.setState(1);
|
mallMemberCouponMapper.updateById(mallMemberCoupon);
|
}
|
}
|
}
|
|
}
|
|
/**
|
* 根据用户ID和订单ID获取所购买商品名称
|
* @return 所含商品名称(多个以","隔开)
|
*/
|
public String getProductNames(Long memberId, Long orderId) {
|
MallOrderInfo mallOrderInfo = this.baseMapper.selectOrderByMemberIdAndId(memberId, orderId);
|
List<MallOrderItem> details = mallOrderInfo.getItems();
|
if (CollectionUtils.isEmpty(details)) {
|
return "";
|
}
|
StringBuffer productNameBuffer = new StringBuffer();
|
Integer maxLength = 30;
|
for (int i = 0; i< details.size(); i++) {
|
MallOrderItem mallOrderItem = details.get(i);
|
String goodsName = mallOrderItem.getGoodsName();
|
if (goodsName == null) {
|
continue;
|
}
|
if (i == 0 && goodsName.length() > maxLength) {
|
productNameBuffer.append(goodsName.substring(0, maxLength) + "...");
|
break;
|
}
|
if ((productNameBuffer.length() + goodsName.length()) > maxLength) {
|
productNameBuffer.append("等");
|
break;
|
}
|
productNameBuffer.append(goodsName + ",");
|
}
|
String productNames = productNameBuffer.toString();
|
if (productNames.endsWith(",")) {
|
productNames = productNames.substring(0, productNames.length() - 1);
|
}
|
if (productNames.endsWith(",等")) {
|
productNames = productNames.substring(0, productNames.length() - 2) + "等";
|
}
|
return productNames;
|
}
|
|
@Override
|
@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 || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
|
throw new FebsException("订单不存在");
|
}
|
|
if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) {
|
throw new FebsException("订单状态不能支付");
|
}
|
|
String payResultStr = "";
|
String wxResultStr = "";
|
switch (payOrderDto.getType()) {
|
case "1":
|
BrandWCPayRequestData brandWCPayRequestData = null;
|
try {
|
brandWCPayRequestData = iXcxPayService.startPayment(orderInfo);
|
} catch (Exception e) {
|
throw new FebsException("支付失败");
|
}
|
wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData);
|
payResultStr = brandWCPayRequestData.getPrepay_id();
|
orderInfo.setPayMethod("微信支付");
|
break;
|
case "2":
|
if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) {
|
payResultStr = orderInfo.getPayOrderNo();
|
} else {
|
payResultStr = payService.aliPay(orderInfo);
|
}
|
|
orderInfo.setPayOrderNo(payResultStr);
|
orderInfo.setPayMethod("支付宝支付");
|
agentProducer.sendOrderReturn(orderInfo.getId());
|
break;
|
case "3":
|
payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance");
|
|
orderInfo.setPayOrderNo(orderInfo.getOrderNo());
|
orderInfo.setPayMethod("余额支付");
|
orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue());
|
orderInfo.setPayTime(new Date());
|
orderInfo.setPayResult("1");
|
orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue());
|
|
mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2);
|
|
agentProducer.sendOrderCoupon(orderInfo.getId());
|
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(), ScoreFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue(), null, 2);
|
break;
|
default:
|
|
}
|
//订单支付成功产生一个提货码
|
String takeCode = ShareCodeUtil.toSerialCode(orderInfo.getId());
|
orderInfo.setTakeCode(takeCode);
|
|
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("wxResultStr", wxResultStr);
|
|
return map;
|
}
|
|
private String balancePay(MallOrderInfo orderInfo, String tradePwd, String field) {
|
if (StrUtil.isBlank(tradePwd)) {
|
throw new FebsException("支付密码错误");
|
}
|
|
MallMember mallMember = memberMapper.selectById(orderInfo.getMemberId());
|
if (StrUtil.isBlank(mallMember.getTradePassword())) {
|
throw new FebsException("未设置支付密码");
|
}
|
|
if (!SecureUtil.md5(tradePwd).equals(mallMember.getTradePassword())) {
|
throw new FebsException("支付密码错误");
|
}
|
|
int reduce = memberWalletService.reduce(orderInfo.getAmount(), mallMember.getId(), field);
|
if (reduce == 2) {
|
throw new FebsException("余额不足");
|
}
|
return orderInfo.getOrderNo();
|
}
|
|
|
@Override
|
public List<OrderListVo> findOrderList(OrderListDto orderListDto) {
|
log.info("订单查询");
|
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);
|
IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectNewApiOrderListInPage(page, orderListDto);
|
if (CollUtil.isNotEmpty(mallOrderInfos.getRecords())) {
|
mallOrderInfos.getRecords().forEach(item -> {
|
item.setItems(mallOrderItemMapper.selectListByOrderId(item.getId()));
|
});
|
}
|
return MallOrderInfoConversion.INSTANCE.entitysToVos(mallOrderInfos.getRecords());
|
}
|
|
@Override
|
public OrderDetailVo findOrderDetailsById(Long id) {
|
MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(id);
|
// if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
|
if (ObjectUtil.isNull(orderInfo)) {
|
throw new FebsException("订单不存在");
|
}
|
List<MallOrderItem> items = orderInfo.getItems();
|
if(CollUtil.isNotEmpty(items)){
|
for(MallOrderItem mallOrderItem : items){
|
mallOrderItem.setItemAmount(mallOrderItemMapper.selectById(mallOrderItem.getId()).getAmount());
|
}
|
}
|
|
OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo);
|
|
MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId());
|
if(ObjectUtil.isNotEmpty(expressInfo)){
|
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(), 1440);
|
|
long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false);
|
orderDetailVo.setRemainTime(remainTime);
|
}
|
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 || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
|
throw new FebsException("订单不存在");
|
}
|
|
if (orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) {
|
throw new FebsException("该状态不能确认收货");
|
}
|
|
// if (orderInfo.getDeliveryState() != OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()) {
|
// throw new FebsException("还未送至自提点");
|
// }
|
|
List<MallRefundEntity> mallRefundEntities = mallRefundMapper.selectByItemIdAndOrderIdAndState(null, orderInfo.getId(), 3);
|
if(CollUtil.isNotEmpty(mallRefundEntities)){
|
throw new FebsException("请先处理退款商品");
|
}
|
|
orderInfo.setStatus(OrderStatusEnum.FINISH.getValue());
|
orderInfo.setReceivingTime(new Date());
|
this.baseMapper.updateById(orderInfo);
|
//普通订单才产生积分,积分订单不产生积分
|
if(1 == orderInfo.getOrderType()){
|
agentProducer.sendGetScoreMsg(orderInfo.getId());
|
}
|
//生成一条团长提成记录
|
// Long orderInfoId = orderInfo.getId();
|
// List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId);
|
// if(CollUtil.isNotEmpty(mallOrderItemList)){
|
//
|
// MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(orderInfo.getTakeUniqueCode());
|
// Integer profitSwitch = mallTeamLeader.getProfitSwitch()==null?2:mallTeamLeader.getProfitSwitch();
|
// BigDecimal bonusPercent =new BigDecimal(mallTeamLeader.getBonusPercent()==null?"0":mallTeamLeader.getBonusPercent());
|
//
|
// if(1 == profitSwitch){
|
// for(MallOrderItem mallOrderItem : mallOrderItemList){
|
// Integer state = mallOrderItem.getState() == null ? 1 : mallOrderItem.getState();
|
// if(1 == state){
|
// MallLeaderAchieve mallLeaderAchieve = new MallLeaderAchieve();
|
// mallLeaderAchieve.setMemberId(orderInfo.getMemberId());
|
// mallLeaderAchieve.setOrderNo(orderInfo.getOrderNo());
|
// mallLeaderAchieve.setOrderItemId(mallOrderItem.getId());
|
// BigDecimal itemAmount = mallOrderItem.getAmount();
|
// mallLeaderAchieve.setAmount(itemAmount);
|
// BigDecimal bigDecimal = bonusPercent.multiply(itemAmount).setScale(2, BigDecimal.ROUND_DOWN);
|
// mallLeaderAchieve.setProfitAmount(bigDecimal);
|
// mallLeaderAchieve.setUniqueCode(orderInfo.getTakeUniqueCode());
|
// mallLeaderAchieve.setState(MallLeaderAchieve.STATE_ONE);
|
// mallLeaderAchieveMapper.insert(mallLeaderAchieve);
|
// }
|
// }
|
// }
|
// }
|
}
|
|
@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);
|
|
List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId());
|
if(CollUtil.isNotEmpty(mallOrderItemList)){
|
for(MallOrderItem mallOrderItem : mallOrderItemList){
|
MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId());
|
if (sku == null) {
|
throw new FebsException("购买商品或sku不存在");
|
}
|
|
// if (sku.getStock() < mallOrderItem.getCnt()) {
|
// throw new FebsException(sku.getSkuName() + "库存不足");
|
// }
|
|
MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
|
Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt());
|
if(1 != goodsResult){
|
throw new FebsException(mallGoods.getGoodsName() + "库存不足");
|
}
|
|
Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt());
|
if(1 != skuResult){
|
throw new FebsException(sku.getSkuName() + "库存不足");
|
}
|
}
|
}
|
}
|
}
|
|
@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);
|
|
List<ApiAddCommentDto> apiAddCommentDtos = addCommentDtos.getApiAddCommentDtos();
|
if(CollUtil.isNotEmpty(apiAddCommentDtos)){
|
for(ApiAddCommentDto apiAddCommentDto : apiAddCommentDtos){
|
Long skuId = apiAddCommentDto.getSkuId();
|
MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(skuId);
|
Long goodsId = apiAddCommentDto.getGoodsId();
|
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);
|
}
|
}
|
}
|
|
@Autowired
|
private WeixinServiceUtil weixinServiceUtil;
|
private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
|
|
@Override
|
@Transactional
|
public FebsResponse refundOrder(Long id) {
|
MallMember member = LoginUserUtil.getLoginUser();
|
MallOrderInfo mallOrderInfo = this.baseMapper.selectById(id);
|
if(ObjectUtil.isEmpty(mallOrderInfo)){
|
return new FebsResponse().fail().message("订单不存在");
|
}
|
Integer status = mallOrderInfo.getStatus();
|
if(OrderStatusEnum.WAIT_SHIPPING.getValue() != status){
|
return new FebsResponse().fail().message("订单不是待发货状态");
|
}
|
Integer deliveryState = mallOrderInfo.getDeliveryState();
|
if(1 != deliveryState){
|
return new FebsResponse().fail().message("订单不是待配送状态");
|
}
|
//根据子订单生成退款记录
|
List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(id);
|
if(CollUtil.isEmpty(mallOrderItemList)){
|
return new FebsResponse().fail().message("订单不存在");
|
}
|
for(MallOrderItem mallOrderItem : mallOrderItemList){
|
QueryWrapper<MallRefundEntity> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("member_id",member.getId());
|
objectQueryWrapper.eq("order_id",mallOrderInfo.getId());
|
objectQueryWrapper.eq("item_id",mallOrderItem.getId());
|
MallRefundEntity mallRefund = mallRefundMapper.selectOne(objectQueryWrapper);
|
MallRefundEntity mallRefundEntity = new MallRefundEntity();
|
if(ObjectUtil.isEmpty(mallRefund)){
|
mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_RITEM"+mallOrderItem.getId());
|
mallRefundEntity.setMemberId(member.getId());
|
mallRefundEntity.setOrderId(mallOrderInfo.getId());
|
mallRefundEntity.setItemId(mallOrderItem.getId());
|
if("余额支付".equals(mallOrderInfo.getPayMethod())){
|
mallRefundEntity.setType(3);
|
}else if("微信支付".equals(mallOrderInfo.getPayMethod())){
|
mallRefundEntity.setType(1);
|
}else{
|
mallRefundEntity.setType(3);
|
}
|
mallRefundEntity.setState(3);
|
mallRefundEntity.setAmount(mallOrderItem.getAmount());
|
mallRefundMapper.insert(mallRefundEntity);
|
}else{
|
if(mallRefund.getState() == 1){
|
return new FebsResponse().fail().message("订单已退款");
|
}
|
if(mallRefund.getState() == 2 || mallRefund.getState() == 3){
|
mallRefundEntity.setId(mallRefund.getId());
|
mallRefundEntity.setRefundNo(mallRefund.getRefundNo());
|
mallRefundEntity.setMemberId(mallRefund.getMemberId());
|
mallRefundEntity.setOrderId(mallRefund.getOrderId());
|
mallRefundEntity.setItemId(mallRefund.getItemId());
|
mallRefundEntity.setType(mallRefund.getType());
|
mallRefundEntity.setState(3);
|
mallRefundEntity.setAmount(mallRefund.getAmount());
|
mallRefundMapper.updateById(mallRefundEntity);
|
}
|
}
|
ApiLeaderRefundOrderDto apiLeaderRefundOrderDto = new ApiLeaderRefundOrderDto();
|
apiLeaderRefundOrderDto.setOrderId(mallOrderInfo.getId());
|
apiLeaderRefundOrderDto.setItemId(mallOrderItem.getId());
|
apiLeaderRefundOrderDto.setAgreeState(1);
|
apiLeaderRefundOrderDto.setAgreeType(1);
|
iApiMallTeamLeaderService.leaderRefundOrder(apiLeaderRefundOrderDto);
|
}
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public FebsResponse applyRefundOrder(ApplyRefundOrderDto applyRefundOrderDto) {
|
Long orderId = applyRefundOrderDto.getOrderId();
|
Long itemId = applyRefundOrderDto.getItemId();
|
MallMember member = LoginUserUtil.getLoginUser();
|
MallOrderInfo mallOrderInfo = this.baseMapper.selectById(orderId);
|
if(ObjectUtil.isEmpty(mallOrderInfo)){
|
return new FebsResponse().fail().message("订单不存在");
|
}
|
|
List<MallRefundEntity> mallRefundEntitieSuccess = mallRefundMapper.selectByItemIdAndOrderIdAndState(itemId,orderId,1);
|
List<MallRefundEntity> mallRefundEntitiesIng = mallRefundMapper.selectByItemIdAndOrderIdAndState(itemId,orderId,3);
|
if(CollUtil.isNotEmpty(mallRefundEntitieSuccess) || CollUtil.isNotEmpty(mallRefundEntitiesIng)){
|
return new FebsResponse().fail().message("该订单无法申请退款");
|
}
|
|
MallRefundEntity mallRefundEntity = new MallRefundEntity();
|
MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(itemId);
|
if(ObjectUtil.isNotEmpty(mallOrderItem)){
|
mallOrderItem.setState(2);
|
mallOrderItemMapper.updateById(mallOrderItem);
|
mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_RITEM"+itemId);
|
mallRefundEntity.setItemId(itemId);
|
}else{
|
|
mallRefundEntity.setRefundNo(mallOrderInfo.getOrderNo()+"_R"+orderId);
|
}
|
mallRefundEntity.setRefundReason(applyRefundOrderDto.getRefundReason());
|
mallRefundEntity.setRefundRemark(applyRefundOrderDto.getRefundRemark());
|
mallRefundEntity.setRefundPic(applyRefundOrderDto.getRefundPic());
|
mallRefundEntity.setMemberId(member.getId());
|
mallRefundEntity.setState(3);
|
mallRefundEntity.setType(applyRefundOrderDto.getType());
|
mallRefundEntity.setOrderId(orderId);
|
mallRefundEntity.setAmount(mallOrderItem.getAmount());
|
mallRefundMapper.insert(mallRefundEntity);
|
return new FebsResponse().success().message("已申请");
|
}
|
|
@Override
|
public FebsResponse cancelRefundOrder(Long id) {
|
MallRefundEntity mallRefundEntity = mallRefundMapper.selectById(id);
|
mallRefundEntity.setState(2);
|
mallRefundMapper.updateById(mallRefundEntity);
|
Long itemId = mallRefundEntity.getItemId();
|
MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(itemId);
|
mallOrderItem.setState(1);
|
mallOrderItemMapper.updateById(mallOrderItem);
|
return new FebsResponse().success().message("已取消");
|
}
|
|
@Override
|
public FebsResponse createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
MallMember member = memberMapper.selectById(memberId);
|
List<AddOrderItemDto> items = apiCreateOrderVerifyDto.getItems();
|
if(CollUtil.isEmpty(items)){
|
return new FebsResponse().fail().message("请先挑选商品");
|
}
|
for (AddOrderItemDto item : apiCreateOrderVerifyDto.getItems()) {
|
MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
|
if (sku == null) {
|
return new FebsResponse().fail().message("购买商品或sku不存在");
|
}
|
if (sku.getStock() < item.getCnt()) {
|
return new FebsResponse().fail().message(sku.getSkuName() + "库存不足");
|
}
|
|
MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
|
if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
|
return new FebsResponse().fail().message(mallGoods.getGoodsName() + "已下架");
|
}
|
if(GoodsTypeEnum.HUO_DONG.getValue() == mallGoods.getIsNormal()){
|
//活动商品判断是否在活动进行中
|
MallActivity mallActivity = mallActivityMapper.selectById(mallGoods.getActivityId());
|
if(mallActivity == null || mallActivity.getState() != 2){
|
return new FebsResponse().fail().message("活动不在进行中");
|
}
|
}
|
|
}
|
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public FebsResponse chooseCoupon(ApiChooseCouponDto chooseCouponDto) {
|
Map<Long, BigDecimal> couponAmountMap = getCouponAmountMap(chooseCouponDto.getMemberCouponId(), chooseCouponDto.getItems());
|
ArrayList<ApiCouponAmountMapVo> objects = new ArrayList<>();
|
for (Map.Entry<Long,BigDecimal> entry : couponAmountMap.entrySet()) {
|
Long keySkuId = entry.getKey();
|
BigDecimal valueSkuAmount = entry.getValue();
|
ApiCouponAmountMapVo apiCouponAmountMapVo = new ApiCouponAmountMapVo();
|
apiCouponAmountMapVo.setId(keySkuId);
|
apiCouponAmountMapVo.setAmount(valueSkuAmount);
|
objects.add(apiCouponAmountMapVo);
|
}
|
return new FebsResponse().success().data(objects);
|
}
|
|
}
|