liujie
2023-10-25 69ca3dc78191794f27a06411c479e3f16dcf39a3
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
package com.dsh.guns.modular.system.controller.code;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.feignClient.account.AppUserClient;
import com.dsh.course.feignClient.account.CityManagerClient;
import com.dsh.course.feignClient.account.model.CityManager;
import com.dsh.course.feignClient.account.model.Coach;
import com.dsh.course.feignClient.account.model.TAppUser;
import com.dsh.course.feignClient.course.*;
import com.dsh.course.feignClient.course.model.*;
import com.dsh.course.feignClient.other.BannerClient;
import com.dsh.course.feignClient.other.SiteClient;
import com.dsh.course.feignClient.other.StoreClient;
import com.dsh.course.feignClient.other.model.Banner;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.model.TCoursePackagePayment;
import com.dsh.guns.modular.system.service.ICityService;
import com.dsh.guns.modular.system.service.ICoursePackageService;
import com.dsh.guns.modular.system.service.IStoreService;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 广告管理控制器
 *
 */
@Controller
@RequestMapping("/cpPayment")
public class CoursePackagePaymentController extends BaseController {
    private String PREFIX = "/system/cpPayment/";
    @Autowired
    private BannerClient bannerClient;
    @Autowired
    private IStoreService storeService;
    @Autowired
    private ICityService cityService;
    @Autowired
    private CoursePackageTypeClient coursePackageTypeClient;
    @Autowired
    private CoursePackagePaymentClient coursePackagePaymentClient;
    @Autowired
    private AppUserClient appUserClient;
    @Autowired
    private StoreClient storeClient;
    @Autowired
    private CoursePackageDiscountClient coursePackageDiscountClient;
    @Autowired
    private CoursePackagePaymentConfigClient coursePackagePaymentConfigClient;
    @Autowired
    private CoursePackageClient coursePackageClient;
 
    /**
     * 跳转到购课记录页面
     */
    @RequestMapping("")
    public String index(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        List<TCoursePackageType> coursePackage = coursePackageTypeClient.queryAllCoursePackageType();
        model.addAttribute("coursePackage",coursePackage);
        model.addAttribute("list",list);
        Integer roleType = UserExt.getUser().getObjectType();
        model.addAttribute("roleType",roleType);
        return PREFIX + "cpPayment.html";
    }
    /**
     * 跳转到广告添加页面
     */
    @RequestMapping("/add")
    public String operator(Model model) {
        List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
        model.addAttribute("list",list);
        Integer roleType = UserExt.getUser().getObjectType();
        model.addAttribute("roleType",roleType);
        if(UserExt.getUser().getObjectType()==3){
            List<TStore> list1 = storeService.list(new LambdaQueryWrapper<TStore>().eq(TStore::getId, UserExt.getUser().getObjectId()));
            model.addAttribute("stores",list1);
        }else {
            model.addAttribute("stores",new ArrayList<>());
        }
        return PREFIX + "cpPayment_add.html";
    }
    /**
     *  添加购课记录
     */
    @ResponseBody
    @PostMapping(value = "/addCoursePackagePayment/{id}")
    public ResultUtil addCoach(@RequestBody TCoursePackagePayment tCoursePackagePayment, @PathVariable("id")Integer id) {
        Integer objectId = UserExt.getUser().getObjectId();
        Integer objectType = UserExt.getUser().getObjectType();
        String name = UserExt.getUser().getName();
        tCoursePackagePayment.setPayUserId(objectId);
        // 获取课包id
        Integer coursePackageId = tCoursePackagePayment.getCoursePackageId();
        List<TCoursePackageDiscount> list = coursePackageDiscountClient.queryByCoursePackageId(coursePackageId);
 
        // 获取当前课包价格配置
        CoursePackagePaymentConfig coursePackagePaymentConfigs = coursePackagePaymentConfigClient.getById(id);
        Integer coursePackageId1 = tCoursePackagePayment.getCoursePackageId();
        TCoursePackage tCoursePackage = coursePackageClient.queryById(coursePackageId1);
        Double cashPayment = coursePackagePaymentConfigs.getCashPayment();
        String c1 = Double.toString(cashPayment);
        BigDecimal bigDecimal = new BigDecimal(c1);
        tCoursePackagePayment.setCashPayment(bigDecimal);
        Date currentDate = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(Calendar.DAY_OF_MONTH, 20);
        Date updatedDate = calendar.getTime();
        tCoursePackagePayment.setOriginalPrice(cashPayment);
        tCoursePackagePayment.setUseTime(updatedDate);
        tCoursePackagePayment.setPlayPaiCoin(coursePackagePaymentConfigs.getPlayPaiCoin());
        coursePackagePaymentClient.addCoursePackagePayment(tCoursePackagePayment);
        return ResultUtil.success("添加成功");
    }
    /**
     * 获取列表
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public List<CoursePackagePaymentVO> listAll(CoursePackagePaymentQuery query) {
        Integer objectType = UserExt.getUser().getObjectType();
        List<Integer> ids =new ArrayList<>();
        if(objectType==3){
            // 找出当前门店的课包
            ids =  coursePackageClient.queryIdsByStore(UserExt.getUser().getObjectId());
            query.setIds(ids);
        }
        if (objectType == 2){
            Integer objectId = UserExt.getUser().getObjectId();
            List<Integer> operatorId = storeService.list(new QueryWrapper<TStore>().eq("operatorId", objectId))
                    .stream().map(TStore::getId).collect(Collectors.toList());
            query.setStoreIds(operatorId);
        }
        return coursePackagePaymentClient.listAll(query);
    }
 
    /**
     * 手动支付
     */
    @RequestMapping(value = "/pay")
    @ResponseBody
    public Object pay(@RequestBody CoursePackagePayDTO dto) {
 
        String name = UserExt.getUser().getName();
        dto.setPayUserName(name);
        dto.setUserId(UserExt.getUser().getId());
        coursePackagePaymentClient.changeState(dto);
        return ResultUtil.success();
    }
 
    /**
     * 根据用户电话 获取用户
     */
    @RequestMapping(value = "/getUserByPhone/{phone}")
    @ResponseBody
    public TAppUser getUserByPhone(@PathVariable("phone") String phone) {
        return appUserClient.getAppUserByPhone(phone);
    }
    /**
     * 根据用户id 获取用户电话
     */
    @RequestMapping(value = "/queryStudentList")
    @ResponseBody
    public List<TStudent> queryStudentList(Integer appUserId) {
        return appUserClient.queryStudentList(appUserId);
    }
 
    /**
     * 根据市获取门店
     */
    @RequestMapping(value = "/getStore")
    @ResponseBody
    public List<Store> getStore(String city) {
        return storeClient.getStore(city);
    }
 
    /**
     * 根据课包id 获取课时规格
     */
    @RequestMapping(value = "/getCoursePackageConfig")
    @ResponseBody
    public List<CoursePackagePaymentConfig> getCoursePackageConfig(Integer id) {
        return coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(id);
    }
 
}