luodangjia
2024-05-30 a3990d3644885c51f4ea0fc7a27c1097f4808bfb
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
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.CharteredCar.model.OrderCharteredCar;
import com.stylefeng.guns.modular.CharteredCar.server.IOrderCharteredCarService;
import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
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 com.stylefeng.guns.modular.transfer.model.OrderTransferCar;
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 crossCityService;
    @Autowired
    private IOrderCharteredCarService orderCharteredCarService;
 
 
    /**
     * 申请开票操作
     * @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 privateCar= orderPrivateCarService.selectById(orderId);
                    sum.add(new BigDecimal(privateCar.getPayMoney()));
                    break;
                case 2://出租车
                    OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                    sum.add(new BigDecimal(orderTaxi.getPayMoney()));
                    break;
                case 3://跨城出行
                    OrderCrossCity orderCrossCity = crossCityService.selectById(orderId);
                    sum.add(new BigDecimal(orderCrossCity.getPayMoney()));
                    break;
                case 4://同城小件物流
                    break;
                case 5://跨城小件物流
                    break;
//                    case 6://包车
//                        OrderCharteredCar   orderCharteredCar = orderCharteredCarService.selectById(orderId);
//                        sum.add(new BigDecimal(orderCharteredCar.getPayMoney()));
//                    break;
                case 7://接送机
                    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://专车
                    break;
                case 2://出租车
                    OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                    orderTaxi.setInvoiceId(invoice.getId());
                    orderTaxiService.updateById(orderTaxi);
                    break;
                case 3://跨城出行
                    break;
                case 4://同城小件物流
                    break;
                case 5://跨城小件物流
                    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);
    }
}