puzhibing
2023-08-01 98bc380ae322eaac2ee7e21d0c565e30eacce2b5
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
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.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;
 
 
 
    /**
     * 申请开票操作
     * @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://专车
                    break;
                case 2://出租车
                    OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                    sum.add(new BigDecimal(orderTaxi.getPayMoney()));
                    break;
                case 3://跨城出行
                    break;
                case 4://同城小件物流
                    break;
                case 5://跨城小件物流
                    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);
    }
}