无关风月
2024-12-30 b3502b0a24f221e2e6207072ac9741cd792f23c9
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
package com.jilongda.manage.controller;
 
 
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.manage.authority.model.SecUser;
import com.jilongda.manage.authority.service.SecUserService;
import com.jilongda.manage.dto.AccountDetailDTO;
import com.jilongda.manage.model.*;
import com.jilongda.manage.query.TLineUpQuery;
import com.jilongda.manage.query.TOrderAccountingQuery;
import com.jilongda.manage.service.*;
import com.jilongda.manage.utils.LoginInfoUtil;
import com.jilongda.manage.vo.TOrderAccountVO;
import com.jilongda.manage.vo.TOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 * 订单核算表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@RestController
@Api(tags = "订单核算")
@RequestMapping("/t-order-accounting")
public class TOrderAccountingController {
    @Autowired
    private SecUserService secUserService;
    @Autowired
    private TStoreService storeService;
    @Autowired
    private TOrderService orderService;
    @Autowired
    private TOrderAccountingService orderAccountingService;
    @Autowired
    private TAppUserService appUserService;
    @Autowired
    private TOptometryDetailService optometryDetailService;
    @Autowired
    private TOrderGoodsService orderGoodsService;
    @Autowired
    private SecFeeItemsService feeItemsService;
    @Autowired
    private LoginInfoUtil loginInfoUtil;
    @ApiOperation(value = "核算订单分页列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TOrderVO>> pageList(@RequestBody TOrderAccountingQuery query) {
        if (StringUtils.hasLength(query.getStartTime())){
            query.setStartTime(query.getStartTime()+" 00:00:00");
            query.setEndTime(query.getEndTime()+" 23:59:59");
        }
        PageInfo<TOrderVO> res = orderAccountingService.pageList(query);
        return ApiResult.success(res);
    }
    @ApiOperation(value = "核算详情页面")
    @GetMapping(value = "/detail")
    public ApiResult<TOrderAccountVO> detail(Integer id) {
        TOrderAccountVO res = new TOrderAccountVO();
        TOrder byId = orderService.getById(id);
        if (byId.getUserId()!=null){
            TAppUser byId1 = appUserService.getById(byId.getUserId());
            if(byId1!=null){
                res.setName(byId1.getName());
                res.setPhone(byId1.getPhone());
            }
        }
        res.setAge(byId.getAge());
        res.setRealName(byId.getRealName());
        res.setGender(byId.getGender());
        List<TOptometryDetail> list = optometryDetailService.lambdaQuery().eq(TOptometryDetail::getOrderId, id)
                .eq(TOptometryDetail::getType, 1).list();
        res.setOptometryDetails(list);
        List<TOrderGoods> orderGoods = orderGoodsService.lambdaQuery()
                .eq(TOrderGoods::getOrderId, id).list();
        BigDecimal goodsMoney = new BigDecimal("0");
        BigDecimal costMoney = new BigDecimal("0");
        BigDecimal constConfirm = new BigDecimal("0");
        for (TOrderGoods orderGood : orderGoods) {
            goodsMoney =goodsMoney.add(orderGood.getGoodsMoney());
            costMoney=costMoney.add(orderGood.getCost()==null?new BigDecimal("0"):orderGood.getCost());
            constConfirm=constConfirm.add(orderGood.getConstConfirm()==null?new BigDecimal("0"):orderGood.getConstConfirm());
        }
        res.setOrderGoods(orderGoods);
        TStore byId1 = storeService.getById(byId.getStoreId());
        res.setStoreName(byId1.getName());
        res.setOrderMoney(goodsMoney);
        res.setCouponMoney(byId.getCouponMoney());
        res.setPayMoney(byId.getPayMoney());
        res.setPayType(byId.getPayTypeName());
        res.setRealPayMoney(byId.getPayMoney());
        SecFeeItems one1 = feeItemsService.lambdaQuery().eq(SecFeeItems::getName, byId.getPayTypeName())
                .one();
        BigDecimal percent = one1.getPercent();
        BigDecimal bigDecimal1 = byId.getPayMoney().multiply(percent).setScale(2, BigDecimal.ROUND_DOWN);
        res.setCommission(bigDecimal1);
        if (byId.getIsAccounting()==1){
            res.setProfitMoney(byId.getPayMoney().subtract(bigDecimal1).subtract(constConfirm));
            res.setProfitRating(res.getProfitMoney().divide(byId.getPayMoney(),2, BigDecimal.ROUND_DOWN));
        }
        return ApiResult.success(res);
    }
    @ApiOperation(value = "确认核算操作")
    @GetMapping(value = "/confirm")
    public ApiResult confirm(@RequestBody AccountDetailDTO dto) {
        List<TOrderGoods> list = dto.getList();
        orderGoodsService.updateBatchById(list);
        TOrder byId = orderService.getById(dto.getId());
        byId.setPayTypeName(dto.getPayTypeName());
        byId.setPayTypeName(dto.getPayTypeName());
        byId.setPayMoney(dto.getPayMoney());
        byId.setCommissionMoney(dto.getCommission());
        byId.setIsAccounting(1);
        Long userId = loginInfoUtil.getUserId();
        SecUser byId1 = secUserService.getById(userId);
        byId.setAccountingName(byId1.getNickName());
        byId.setAccountingTime(LocalDateTime.now());
        orderService.updateById(byId);
        return ApiResult.success();
    }
}