xuhy
2024-12-27 feb54524cd28ef924dd14e771ca298d949b15478
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
package com.jilongda.manage.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.TOrderDTO;
import com.jilongda.manage.model.TCoupon;
import com.jilongda.manage.model.TCouponReceive;
import com.jilongda.manage.model.TOptometryDetail;
import com.jilongda.manage.model.TOrder;
import com.jilongda.manage.query.TOptometryQuery;
import com.jilongda.manage.service.*;
import com.jilongda.manage.utils.LoginInfoUtil;
import com.jilongda.manage.vo.TOptometryVO;
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.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 销售订单表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@Api(tags = "销售订单")
@RestController
@RequestMapping("/t-order")
public class TOrderController {
 
    @Autowired
    private TAppUserService tAppUserService;
    @Autowired
    private SecUserService secUserService;
    @Autowired
    private TCouponReceiveService couponReceiveService;
    @Autowired
    private TCouponService couponService;
    @Autowired
    private TOrderService orderService;
    @Autowired
    private TOptometryDetailService optometryDetailService;
 
    @ApiOperation(value = "查询用户信息")
    @GetMapping(value = "/getUserById")
    public ApiResult getUserById(@RequestParam Integer userId) {
        return ApiResult.success(tAppUserService.getById(userId));
    }
 
    @ApiOperation(value = "查询员工信息")
    @GetMapping(value = "/getStaffList")
    public ApiResult getStaffList() {
        List<SecUser> list = secUserService.list(Wrappers.lambdaQuery(SecUser.class)
                .eq(SecUser::getUserType, 3)
                .eq(SecUser::getIsDelete, 0));
        return ApiResult.success(list);
    }
 
    @ApiOperation(value = "查询优惠券")
    @GetMapping(value = "/getCouponListByUserId")
    public ApiResult<List<TCoupon>> getCouponListByUserId(@RequestParam Integer userId, @RequestParam Integer storeId) {
        List<TCouponReceive> list = couponReceiveService.list(Wrappers.lambdaQuery(TCouponReceive.class)
                .eq(TCouponReceive::getUserId, userId)
                .eq(TCouponReceive::getStatus, 1));
        List<TCouponReceive> tCouponReceives = new ArrayList<>();
        for (TCouponReceive tCouponReceive : list) {
            if (StringUtils.hasLength(tCouponReceive.getStoreId())){
                if (Arrays.asList(tCouponReceive.getStoreId().split(",")).contains(storeId+"")){
                    tCouponReceives.add(tCouponReceive);
                }
            }else{
                // 通用
                tCouponReceives.add(tCouponReceive);
            }
        }
        List<Integer> collect = list.stream().map(TCouponReceive::getCouponId).collect(Collectors.toList());
        if (collect.isEmpty()){
            collect.add(-1);
        }
        List<TCoupon> list1 = couponService.lambdaQuery().in(TCoupon::getId, collect).list();
        return ApiResult.success(list1);
    }
 
    @ApiOperation(value = "添加订单")
    @PostMapping(value = "/addOrder")
    public ApiResult addOrder(@RequestBody TOrderDTO dto) {
 
        // 查询店员
        SecUser user = secUserService.getById(dto.getSysId());
        if(Objects.nonNull(user)){
            dto.setStoreId(user.getStoreId());
        }
        orderService.save(dto);
 
        List<TOptometryDetail> optometryDetails = dto.getOptometryDetails();
        if (!CollectionUtils.isEmpty(optometryDetails)){
            for (TOptometryDetail optometryDetail : optometryDetails) {
                optometryDetail.setOrderId(dto.getId());
            }
            optometryDetailService.saveBatch(optometryDetails);
        }
 
        // TODO 周哥 补库存
 
        return ApiResult.success();
    }
 
    @ApiOperation(value = "销售订单详情")
    @GetMapping(value = "/getOrderDetailById")
    public ApiResult getOrderDetailById(@RequestParam Integer orderId) {
 
        TOrderVO orderVO = orderService.getOrderDetailById(orderId);
 
        // TODO 周哥 商品信息集合
 
        // TODO 周哥 验光处方 判断是关联或者手动
 
 
        return ApiResult.success(orderVO);
    }
 
}