admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderServiceImpl.java
@@ -1,98 +1,98 @@
package com.yeshi.fanli.service.impl.order;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.OrderService;
@Service
public class OrderServiceImpl implements OrderService {
   @Resource
   private ConfigService configService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private OrderMapper orderMapper;
   @Resource
   private HongBaoOrderService hongBaoOrderService;
   // @Transactional(propagation = Propagation.NESTED, rollbackFor =
   // Exception.class)
   public boolean addOrder(Order order) throws Exception {
      order.setVersion(2);
      WriteLock writeLock = orderLock.writeLock();
      // 保存订单
      // long oid;
      try {
         writeLock.lock();
         Order find = findOrderByOrderIdAndType(order.getOrderId(), order.getOrderType());
         if (find != null) {
            return false;
         }
         Integer orderType = order.getOrderType();
         if (orderType == null) {
            orderType = Order.ORDER_TYPE_TAOBAO;
         }
         // 查找是否存在分享赚订单
         if (hongBaoOrderService.countByOrderNoAndHongBaoType(order.getOrderId(), HongBaoV2.TYPE_SHARE_GOODS, orderType) > 0)
            return false;
         orderMapper.insertSelective(order);
      } finally {
         writeLock.unlock();
      }
      // UserInfo userInfo = order.getUserInfo();
      // // 发红包啦
      // HongBao hongBao = HongBaoFactory.createHongBao(new BigDecimal(0),
      // oid, null,
      // order.getUserInfo(), Constant.TAOBAO);
      // hongBaoService.save(hongBao);
      // // 看是不是被传销进来的
      // UserInfo boss1 = threeSaleSerivce.getBoss(userInfo.getId());
      // if (boss1 != null) {
      // // 给上线发个红包
      // HongBao oneSaleHongBao = HongBaoFactory.createHongBao(new
      // BigDecimal(0), null,
      // hongBao, boss1, Constant.ONESALE);
      // hongBaoService.save(oneSaleHongBao);
      // // 继续看是不是被传销进来的
      // UserInfo boss2 = threeSaleSerivce.getBoss(boss1.getId());
      // if (boss2 != null) {
      // // 再发个红包给传销头头
      // HongBao twoSaleHongBao = HongBaoFactory.createHongBao(new
      // BigDecimal(0), null,
      // hongBao, boss2, Constant.TWOSALE);
      // hongBaoService.save(twoSaleHongBao);
      // }
      // }
      return true;
   }
   @Override
   public Order findOrderByOrderIdAndType(String orderId, int type) {
      Order order = orderMapper.selectOrderByOrderIdAndOrderType(orderId, type);
      return order;
   }
   @Override
   public Order getSystemOrderByUid(int type, long uid) {
      List<Order> list = orderMapper.listByUidAndOrderTypeAndBeiZhu(uid, type, "系统添加");
      if (list != null && list.size() > 0)
         return list.get(0);
      return null;
   }
}
package com.yeshi.fanli.service.impl.order;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
@Service
public class OrderServiceImpl implements OrderService {
   @Resource
   private ConfigService configService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private OrderMapper orderMapper;
   @Resource
   private HongBaoOrderService hongBaoOrderService;
   // @Transactional(propagation = Propagation.NESTED, rollbackFor =
   // Exception.class)
   public boolean addOrder(Order order) throws Exception {
      order.setVersion(2);
      WriteLock writeLock = orderLock.writeLock();
      // 保存订单
      // long oid;
      try {
         writeLock.lock();
         Order find = findOrderByOrderIdAndType(order.getOrderId(), order.getOrderType());
         if (find != null) {
            return false;
         }
         Integer orderType = order.getOrderType();
         if (orderType == null) {
            orderType = Order.ORDER_TYPE_TAOBAO;
         }
         // 查找是否存在分享赚订单
         if (hongBaoOrderService.countByOrderNoAndHongBaoType(order.getOrderId(), HongBaoV2.TYPE_SHARE_GOODS, orderType) > 0)
            return false;
         orderMapper.insertSelective(order);
      } finally {
         writeLock.unlock();
      }
      // UserInfo userInfo = order.getUserInfo();
      // // 发红包啦
      // HongBao hongBao = HongBaoFactory.createHongBao(new BigDecimal(0),
      // oid, null,
      // order.getUserInfo(), Constant.TAOBAO);
      // hongBaoService.save(hongBao);
      // // 看是不是被传销进来的
      // UserInfo boss1 = threeSaleSerivce.getBoss(userInfo.getId());
      // if (boss1 != null) {
      // // 给上线发个红包
      // HongBao oneSaleHongBao = HongBaoFactory.createHongBao(new
      // BigDecimal(0), null,
      // hongBao, boss1, Constant.ONESALE);
      // hongBaoService.save(oneSaleHongBao);
      // // 继续看是不是被传销进来的
      // UserInfo boss2 = threeSaleSerivce.getBoss(boss1.getId());
      // if (boss2 != null) {
      // // 再发个红包给传销头头
      // HongBao twoSaleHongBao = HongBaoFactory.createHongBao(new
      // BigDecimal(0), null,
      // hongBao, boss2, Constant.TWOSALE);
      // hongBaoService.save(twoSaleHongBao);
      // }
      // }
      return true;
   }
   @Override
   public Order findOrderByOrderIdAndType(String orderId, int type) {
      Order order = orderMapper.selectOrderByOrderIdAndOrderType(orderId, type);
      return order;
   }
   @Override
   public Order getSystemOrderByUid(int type, long uid) {
      List<Order> list = orderMapper.listByUidAndOrderTypeAndBeiZhu(uid, type, "系统添加");
      if (list != null && list.size() > 0)
         return list.get(0);
      return null;
   }
}