admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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.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;
    }
 
}