xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.InvoiceMapper;
import com.stylefeng.guns.modular.system.model.Invoice;
import com.stylefeng.guns.modular.system.service.IInvoiceService;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
 
@Service
public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> implements IInvoiceService {
 
    @Resource
    private InvoiceMapper invoiceMapper;
 
    @Autowired
    private IOrderTaxiService orderTaxiService;
 
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
 
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
 
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
 
 
 
    /**
     * 申请开票操作
     * @param invoice
     * @param order
     * @throws Exception
     */
    @Override
    public void invoicing(Invoice invoice, String order, Integer uid) throws Exception {
        JSONArray jsonArray = JSON.parseArray(order);
        BigDecimal sum = new BigDecimal(0);
        for(int i = 0; i < jsonArray.size(); i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Integer orderType = jsonObject.getIntValue("type");
            Integer orderId = jsonObject.getIntValue("id");
            switch (orderType){
                case 1://专车
                    OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                    sum=sum.add(new BigDecimal(orderPrivateCar.getPayMoney()));
                    break;
                case 2://出租车
                    OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                    sum=sum.add(new BigDecimal(orderTaxi.getPayMoney()));
                    break;
                case 3://跨城出行
                    OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                    sum=sum.add(new BigDecimal(orderCrossCity.getPayMoney()));
                    break;
                case 4://同城小件物流
                    OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                    sum=sum.add(new BigDecimal(orderLogistics.getPayMoney()));
                    break;
                case 5://跨城小件物流
                    OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                    sum=sum.add(new BigDecimal(orderLogistics1.getPayMoney()));
                    break;
            }
        }
 
        invoice.setOrderNum(jsonArray.size());
        invoice.setMoney(sum.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
        invoice.setUserId(uid);
        invoice.setInsertTime(new Date());
        invoice.setState(1);
        this.insert(invoice);
        // TODO: 2020/6/9 调用开发票第三方SDK
 
 
        for(int i = 0; i < jsonArray.size(); i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Integer orderType = jsonObject.getIntValue("type");
            Integer orderId = jsonObject.getIntValue("id");
            switch (orderType){
                case 1://专车
                    OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                    orderPrivateCar.setInvoiceId(invoice.getId());
                    orderPrivateCarService.updateById(orderPrivateCar);
                    break;
                case 2://出租车
                    OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                    orderTaxi.setInvoiceId(invoice.getId());
                    orderTaxiService.updateById(orderTaxi);
                    break;
                case 3://跨城出行
                    OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                    orderCrossCity.setInvoiceId(invoice.getId());
                    orderCrossCityService.updateById(orderCrossCity);
                    break;
                case 4://同城小件物流
                    OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                    orderLogistics.setInvoiceId(invoice.getId());
                    orderLogisticsService.updateById(orderLogistics);
                    break;
                case 5://跨城小件物流
                    OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                    orderLogistics1.setInvoiceId(invoice.getId());
                    orderLogisticsService.updateById(orderLogistics1);
                    break;
            }
        }
 
    }
 
 
    /**
     * 获取发票历史记录
     * @param pageNum
     * @param size
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryMyInvoice(Integer pageNum, Integer size, Integer uid) throws Exception {
        pageNum = (pageNum - 1) * size;
        return invoiceMapper.queryMyInvoice(pageNum, size, uid);
    }
}