puzhibing
2023-05-30 6d05cda0141cbd42a9b8810e539f5dcd8df506f0
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.stylefeng.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.controller.resp.RevenueExpenditureResp;
import com.stylefeng.guns.modular.system.controller.resp.TDriverCommissionResp;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
import com.stylefeng.guns.modular.system.model.TCashWithdrawal;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.service.ITCashWithdrawalService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.TRevenue;
import com.stylefeng.guns.modular.system.service.ITRevenueService;
 
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-03-13 09:49:19
 */
@Controller
@RequestMapping("/tRevenue")
public class TRevenueController extends BaseController {
 
    private String PREFIX = "/system/tRevenue/";
 
    @Autowired
    private ITRevenueService tRevenueService;
 
 
    @Autowired
    private ITCashWithdrawalService cashWithdrawalService;
 
 
 
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tRevenue.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tRevenue_add")
    public String tRevenueAdd() {
        return PREFIX + "tRevenue_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tRevenue_update/{tRevenueId}")
    public String tRevenueUpdate(@PathVariable Integer tRevenueId, Model model) {
        TRevenue tRevenue = tRevenueService.selectById(tRevenueId);
        model.addAttribute("item",tRevenue);
        LogObjectHolder.me().set(tRevenue);
        return PREFIX + "tRevenue_edit.html";
    }
 
    /**
     * 跳转到佣金提现详情
     */
    @RequestMapping("/commissionDetail")
    public String commissionDetail(String code, Model model) {
        tRevenueService.commissionDetail(code,model);
        return PREFIX + "tRevenueCommissionDetail.html";
    }
 
    /**
     * 跳转到余额提现详情
     */
    @RequestMapping("/balanceDetail")
    public String balanceDetail(String code, Model model) {
        tRevenueService.balanceDetail(code,model);
        return PREFIX + "tRevenueBalanceDetail.html";
    }
 
    /**
     * 跳转到支付订单详情
     */
    @RequestMapping("/orderDetail")
    public String orderDetail(String code, Model model) {
        tRevenueService.orderDetail(code,model);
        return PREFIX + "tRevenueOrderDetail.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String code,Integer businessType,Integer payType,String driverName,String businessTime) {
        return tRevenueService.getPageList(code,businessType,payType,driverName,businessTime);
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list-back")
    @ResponseBody
    public Object listBack(String condition) {
        return tRevenueService.selectList(null);
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TRevenue tRevenue) {
        tRevenueService.insert(tRevenue);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tRevenueId) {
        tRevenueService.deleteById(tRevenueId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TRevenue tRevenue) {
        tRevenueService.updateById(tRevenue);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tRevenueId}")
    @ResponseBody
    public Object detail(@PathVariable("tRevenueId") Integer tRevenueId) {
        return tRevenueService.selectById(tRevenueId);
    }
 
    @ApiOperation(value = "导出收支明细列表",notes="导出收支明细列表")
    @RequestMapping(value = "/export")
    @ResponseBody
    public void export(String code,Integer businessType,Integer payType,String driverName,String businessTime, HttpServletResponse response) {
        try {
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyyMMdd");
            String time1 = format.format(date);
            String fileName = "RevenueExpenditureDetailsInfo"+time1+".xls";
            String[] title = new String[] {"订单号","交易时间","交易类型","司机姓名","司机电话",
                    "支付类型","金额","佣金提成","优惠券","余额","状态"};
            List<RevenueExpenditureResp> pageList = tRevenueService.getPageList(code, businessType, payType, driverName, businessTime);
 
            String[][] values = new String[pageList.size()][];
            for (int i = 0; i < pageList.size(); i++) {
                RevenueExpenditureResp d = pageList.get(i);
                values[i] = new String[title.length];
                values[i][0] = d.getCode();
                values[i][1] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d.getBusinessTime());
                Integer businessType1 = d.getBusinessType();
                if(1 == businessType1){
                    values[i][2] = "支付订单";
                }else if (11 == businessType1){
                    values[i][2] = "佣金提现";
                }else if (12 == businessType1){
                    values[i][2] = "余额提现";
                }
                values[i][3] = d.getDriverName();
                values[i][4] = d.getDriverPhone();
                Integer payType1 = d.getPayType();
                if(1 == payType1){
                    values[i][5] = "微信支付";
                }else if (2 == payType1){
                    values[i][5] = "余额支付";
                }else if (3 == payType1){
                    values[i][5] = "线下收款";
                }
                values[i][6] = String.valueOf(Objects.isNull(d.getAmount())? BigDecimal.ZERO :d.getAmount());
                values[i][7] = String.valueOf(Objects.isNull(d.getCommissionAmount())? BigDecimal.ZERO :d.getCommissionAmount());
                values[i][8] = String.valueOf(Objects.isNull(d.getDiscountedPrice())? BigDecimal.ZERO :d.getDiscountedPrice());
                values[i][9] = String.valueOf(Objects.isNull(d.getAccountBalance())? BigDecimal.ZERO :d.getAccountBalance());
                Integer state = d.getState();
                if(2 == state){
                    values[i][10] = "完成";
                }else if(108 == state){
                    values[i][10] = "完成";
                }else if(109 == state){
                    values[i][10] = "完成";
                }
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
            ExcelUtil.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
    /**
     * 同意提现
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/agreeWithdraw")
    public Object agreeWithdraw(Integer id){
        TCashWithdrawal tCashWithdrawal = cashWithdrawalService.selectById(id);
        tCashWithdrawal.setState(2);
        cashWithdrawalService.updateById(tCashWithdrawal);
        return SUCCESS;
    }
}