| | |
| | | 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 org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | 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;
|
| | | }
|
| | |
|
| | | // 查找是否存在分享赚订单
|
| | | if (hongBaoOrderService.countByOrderNoAndHongBaoType(order.getOrderId(), HongBaoV2.TYPE_SHARE_GOODS) > 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;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public List<Order> setOrderState(final String orderid, final int orderType) {
|
| | | List<Order> orderList = orderMapper.selectOrderByOrderIdAndOrderType(orderid, orderType);
|
| | | if (orderList != null)
|
| | | for (Order order : orderList) {
|
| | | if (order.getDrawbackTime() == null || order.getDrawbackTime() <= 0) {
|
| | | Order updateOrder = new Order();
|
| | | updateOrder.setId(order.getId());
|
| | | updateOrder.setDrawbackTime(java.lang.System.currentTimeMillis());
|
| | | updateOrder.setState(Order.STATE_SHIXIAO);
|
| | | orderMapper.updateByPrimaryKeySelective(updateOrder);
|
| | | order.setDrawbackTime(updateOrder.getDrawbackTime());
|
| | | order.setState(updateOrder.getState());
|
| | | }
|
| | | }
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Order findOrderByOrderIdAndType(String orderId, int type) {
|
| | | List<Order> list = orderMapper.selectOrderByOrderIdAndOrderType(orderId, type);
|
| | | if (list.size() > 0) {
|
| | | return list.get(0);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @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; |
| | | } |
| | | |
| | | } |