yanghb
2024-04-15 6bc25b33e90d45904d1843e927fa709dfeb51d7f
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package cn.stylefeng.guns.modular.business.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.stylefeng.guns.config.RefundConfig;
import cn.stylefeng.guns.modular.business.dto.CounsellingOrderResponseDTO;
import cn.stylefeng.guns.modular.business.dto.request.CounsellingOrderRequest;
import cn.stylefeng.guns.modular.business.dto.request.CreateCounsellingOrderRequest;
import cn.stylefeng.guns.modular.business.dto.request.CreateOrderConsultOneRequest;
import cn.stylefeng.guns.modular.business.entity.*;
import cn.stylefeng.guns.modular.business.service.*;
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 咨询订单信息管理类
 * @author guo
 */
@Slf4j
@RestController
@Api(tags = "咨询订单信息管理类")
@ApiResource(name = "咨询订单信息管理类", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping("/business")
public class CounsellingOrderController  {
 
    @Resource
    private ICounsellingOrderService counsellingOrderService;
 
    @Resource
    private CustomerService customerService;
 
    @Resource
    private ICounsellingInfoService counsellingInfoService;
 
    @Resource
    private ICounsellingSetMealService counsellingSetMealService;
 
    @Resource
    private RefundConfig refundConfig;
 
    @Resource
    private ICounsellingUserService counsellingUserService;
 
    @Resource
    private ICounsellingOrderReservationService counsellingOrderReservationService;
 
 
    /**
     * 添加咨询订单信息
     */
    @ApiOperation("添加咨询订单信息")
    @PostResource(name = "添加咨询订单信息", path = "/counsellingOrder/add")
    public ResponseData<CounsellingOrder> add(@RequestBody CreateCounsellingOrderRequest counsellingOrderRequest) {
        //判断是否有续费课时
        if (counsellingOrderRequest.getOrderType().intValue() == 3){
            long count = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getCounsellingInfoId,counsellingOrderRequest.getCounsellingInfoId())
                    .eq(CounsellingOrder::getUserId,counsellingOrderRequest.getUserId()).eq(CounsellingOrder::getStatusFlag,2).eq(CounsellingOrder::getIsDelete,0));
            if (count == 0l){
                return new ErrorResponseData<>("疗程未完成,不能续费");
            }
        }
        CounsellingOrder counsellingOrder =  this.counsellingOrderService.createCounsellingOrder(counsellingOrderRequest);
        return new SuccessResponseData<>(counsellingOrder);
    }
 
    /**
     * 删除咨询订单信息
     */
    @ApiOperation("删除咨询订单信息")
    @PostResource(name = "删除咨询订单信息", path = "/counsellingOrder/delete")
    @BusinessLog
    public ResponseData<?> delete(@RequestParam String ids) {
        if (StrUtil.isBlank(ids)){
            return new ErrorResponseData<>("500","id不能为空");
        }
        LambdaUpdateWrapper<CounsellingOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getIsDelete,true);
        lambdaUpdateWrapper.in(CounsellingOrder::getId, ListUtil.toList(ids.split(",")));
        this.counsellingOrderService.update(lambdaUpdateWrapper);
        return new SuccessResponseData<>();
    }
 
    /**
     * 修改咨询订单信息
     */
    @ApiOperation("修改咨询订单信息")
    @PostResource(name = "修改咨询订单信息", path = "/counsellingOrder/edit")
    @BusinessLog
    public ResponseData<?> edit(@RequestBody CounsellingOrder counsellingOrder) {
        this.counsellingOrderService.updateById(counsellingOrder);
        return new SuccessResponseData<>();
    }
 
    /**
     * 修改咨询订单信息状态
     */
    @ApiOperation("修改咨询订单信息状态")
    @ApiImplicitParams({@ApiImplicitParam(name = "status",value = "状态:0待支付,1已支付,2已完成,9取消,10退款")})
    @PostResource(name = "修改咨询订单信息状态", path = "/counsellingOrder/updateStatus")
    @BusinessLog
    public ResponseData<?> updateStatus(Long id, Integer status) {
        if (id == null){
            return new ErrorResponseData<>("500","id不能为空");
        }
        CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(id);
//        //是否调用退款
//        if (StrUtil.isNotBlank(counsellingOrder.getTransactionNo()) && status.intValue() == 10){
//            if (counsellingOrder.getPayType().equals("1")){
//                Map<String,Object> map = new HashMap<>();
//                map.put("transactionId",counsellingOrder.getTransactionNo());
//                map.put("outTradeNo",counsellingOrder.getOrderNo());
//                HttpRequest httpRequest = HttpUtil.createGet(refundConfig.getWxpayUrl()).form(map);
//                String result = httpRequest.execute().body();
//                log.info("咨询订单退款信息:"+result);
//            }else if (counsellingOrder.getPayType().equals("2")){
//                Map<String,Object> map = new HashMap<>();
//                map.put("outTradeNo",counsellingOrder.getOrderNo());
//                map.put("tradeNo",counsellingOrder.getTransactionNo());
//                HttpRequest httpRequest = HttpUtil.createGet(refundConfig.getAlipayUrl()).form(map);
//                String result = httpRequest.execute().body();
//                log.info("咨询订单退款信息:"+result);
//            }
//        }else{
 
            //如果出现退费需要退费咨询师下面所有未完成的订单
            if (status.intValue() == 10){
                LambdaUpdateWrapper<CounsellingOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getStatusFlag,status).set(CounsellingOrder::getRefundTime,new Date())
                        .set(CounsellingOrder::getRefundAmount,counsellingOrder.getPayAmount())
                        .set(CounsellingOrder::getClassHours,0)
                        .set(CounsellingOrder::getResidueClassHours,0);
                lambdaUpdateWrapper.eq(CounsellingOrder::getCounsellingInfoId, counsellingOrder.getCounsellingInfoId()).eq(CounsellingOrder::getUserId,counsellingOrder.getUserId())
                        .eq(CounsellingOrder::getStatusFlag,1);
                this.counsellingOrderService.update(lambdaUpdateWrapper);
                LambdaUpdateWrapper<CounsellingUser> counsellingUserLambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingUser>().set(CounsellingUser::getStatusFlag,status)
                        .set(CounsellingUser::getClassHours,0).set(CounsellingUser::getResidueClassHours,0)
                        .eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId()).eq(CounsellingUser::getUserId,counsellingOrder.getUserId());
                if (counsellingOrder.getOrderType().intValue() ==1){
                    counsellingUserLambdaUpdateWrapper.set(CounsellingUser::getIsFirstAppointment,1);
                }
                //更新咨询师用户信息
                this.counsellingUserService.update(counsellingUserLambdaUpdateWrapper);
                //取消对应的咨询预约
                this.counsellingOrderReservationService.update(new LambdaUpdateWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingOrderId,id)
                        .in(CounsellingOrderReservation::getStauts,1,2,3).set(CounsellingOrderReservation::getStauts,5).set(CounsellingOrderReservation::getRemark,"订单取消"));
 
 
            }else{
                LambdaUpdateWrapper<CounsellingOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getStatusFlag,status);
                lambdaUpdateWrapper.eq(CounsellingOrder::getId,id);
                this.counsellingOrderService.update(lambdaUpdateWrapper);
            }
//        }
 
        return new SuccessResponseData<>();
    }
 
    /**
     * 获取咨询订单信息详情
     */
    @ApiOperation("获取咨询订单信息详情")
    @GetResource(name = "获取咨询订单信息详情", path = "/counsellingOrder/detail/{id}", requiredPermission = false)
    public ResponseData<CounsellingOrderResponseDTO> detail(@PathVariable("id") Long id) {
        CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(id);
        CounsellingOrderResponseDTO counsellingOrderResponseDTO = BeanUtil.copyProperties(counsellingOrder,CounsellingOrderResponseDTO.class);
        if (counsellingOrder.getUserId() != null){
            Customer customer = this.customerService.getById(counsellingOrder.getUserId());
            counsellingOrderResponseDTO.setUserName(customer.getNickName());
        }
        if (counsellingOrder.getCompanionUserId() != null){
            Customer customer = this.customerService.getById(counsellingOrder.getCompanionUserId());
            counsellingOrderResponseDTO.setCompanionUserName(customer.getNickName());
        }
        if (counsellingOrder.getConsultantUserId() != null){
            Customer customer = this.customerService.getById(counsellingOrder.getConsultantUserId());
            counsellingOrderResponseDTO.setConsultantUserName(customer.getNickName());
        }
        if (counsellingOrder.getCounsellingInfoId() != null){
            CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
            Customer customer = this.customerService.getById(counsellingInfo.getUserId());
            counsellingOrderResponseDTO.setCounsellingName(customer.getNickName());
        }
 
        return new SuccessResponseData<>(counsellingOrderResponseDTO);
    }
 
    /**
     * 获取咨询订单信息列表
     *
     */
    @ApiOperation("获取咨询订单信息列表")
    @GetResource(name = "获取咨询订单信息列表", path = "/counsellingOrder/list", requiredPermission = false)
    public ResponseData<List<CounsellingOrder>> counsellingOrderList(CounsellingOrder counsellingOrder) {
          LambdaQueryWrapper<CounsellingOrder> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getIsDelete,false)
                        .orderByDesc(CounsellingOrder::getId);
        return new SuccessResponseData<>(counsellingOrderService.list(lambdaQueryWrapper));
    }
 
    /**
     * 获取咨询订单信息列表(分页)
     */
    @ApiOperation("获取咨询订单信息列表(分页)")
    @GetResource(name = "获取咨询订单信息列表(分页)", path = "/counsellingOrder/page", requiredPermission = false)
    public ResponseData<PageResult<CounsellingOrderResponseDTO>> page(CounsellingOrderRequest counsellingOrderRequest) {
 
        Page<CounsellingOrderResponseDTO> page = this.counsellingOrderService.findCounsellingOrderPage(PageFactory.defaultPage(), counsellingOrderRequest);
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
 
    @ApiOperation("获取当前咨询师咨询套餐信息列表")
    @GetResource(name = "获取当前咨询师咨询套餐信息列表", path = "/counsellingOrder/setMealList", requiredPermission = false)
    public ResponseData<List<CounsellingSetMeal>> counsellingOrderSetMealList(CounsellingSetMeal counsellingSetMeal) {
        LambdaQueryWrapper<CounsellingSetMeal> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingSetMeal>()
                .orderByDesc(CounsellingSetMeal::getId).eq(CounsellingSetMeal::getIsDelete,false);
        lambdaQueryWrapper.eq(counsellingSetMeal.getCounsellingInfoId() != null,CounsellingSetMeal::getCounsellingInfoId,counsellingSetMeal.getCounsellingInfoId());
        lambdaQueryWrapper.eq(counsellingSetMeal.getSetMealType() != null,CounsellingSetMeal::getSetMealType,counsellingSetMeal.getSetMealType());
        return new SuccessResponseData<>(counsellingSetMealService.list(lambdaQueryWrapper));
    }
 
    @ApiOperation("判断当前用户是否首次咨询 true-是,false-否")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id",name = "customerId",required = true),
            @ApiImplicitParam(value = "咨询师id",name = "counsellingInfoId",required = true)
    })
    @GetResource(name = "判断当前用户是否首次咨询", path = "/counsellingOrder/isFirstCounselling", requiredPermission = false)
    public ResponseData<Boolean> isFirstCounselling(Long customerId,Long counsellingInfoId) {
        LambdaQueryWrapper<CounsellingOrder> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingOrder>()
                .eq(CounsellingOrder::getUserId,customerId).in(CounsellingOrder::getStatusFlag,1,2).eq(CounsellingOrder::getCounsellingInfoId,counsellingInfoId)
                .eq(CounsellingOrder::getOrderType,1);
        long count = this.counsellingOrderService.count(lambdaQueryWrapper);
        if (count >0){
            return new SuccessResponseData<>(false);
        }
        return new SuccessResponseData<>(true);
    }
 
}