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);
|
}
|
|
}
|