package com.ltkj.web.controller.mall;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
import com.github.binarywang.wxpay.service.WxPayService;
|
import com.ltkj.common.utils.JacksonUtil;
|
import com.ltkj.framework.config.UserHoder;
|
import com.ltkj.hosp.domain.TjReservation;
|
import com.ltkj.hosp.domain.Wxuser;
|
import com.ltkj.hosp.service.ITbTransitionService;
|
import com.ltkj.hosp.service.ITjReservationService;
|
import com.ltkj.mall.domain.MallOrder;
|
import com.ltkj.mall.domain.MallTimeConfig;
|
import com.ltkj.mall.domain.OrderRefund;
|
import com.ltkj.mall.mallOrderUtils.OrderConstants;
|
import com.ltkj.mall.service.IMallOrderService;
|
import com.ltkj.mall.service.IMallTimeConfigService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import com.ltkj.common.annotation.Log;
|
import com.ltkj.common.core.controller.BaseController;
|
import com.ltkj.common.core.domain.AjaxResult;
|
import com.ltkj.common.enums.BusinessType;
|
import com.ltkj.mall.domain.MallAftersale;
|
import com.ltkj.mall.service.IMallAftersaleService;
|
import com.ltkj.common.utils.poi.ExcelUtil;
|
import com.ltkj.common.core.page.TableDataInfo;
|
|
/**
|
* 售后Controller
|
*
|
* @author ltkj_赵佳豪&李格
|
* @date 2023-07-12
|
*/
|
@RestController
|
@RequestMapping("/mall/aftersale")
|
@Api(tags = "PC端售后审批接口集")
|
public class MallAftersaleController extends BaseController {
|
@Autowired
|
private IMallAftersaleService mallAftersaleService;
|
@Autowired
|
private IMallOrderService orderService;
|
@Autowired
|
private WxPayService wxPayService;
|
@Autowired
|
private IMallTimeConfigService mallTimeConfigService;
|
@Resource
|
private ITjReservationService reservationService;
|
@Resource
|
private ITbTransitionService transitionService;
|
|
/**
|
* 查询售后列表
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:list')")
|
@GetMapping("/list")
|
@ApiOperation(value = "查询售后列表")
|
public TableDataInfo list(MallAftersale mallAftersale) {
|
startPage();
|
if(null !=mallAftersale.getEndTime()){
|
String endTime = mallAftersale.getEndTime();
|
DateTime dateTime = DateUtil.endOfDay(DateUtil.parse(endTime));
|
String format = DateUtil.format(dateTime, "yyyy-MM-dd HH:mm:ss");
|
mallAftersale.setEndTime(format);
|
}
|
List<MallAftersale> list = mallAftersaleService.selectMallAftersaleList(mallAftersale);
|
if(null !=list && list.size()>0){
|
for (MallAftersale aftersale : list) {
|
MallOrder order = orderService.selectMallOrderById(Long.valueOf(aftersale.getOrderId()));
|
if(null !=order){
|
aftersale.setMobile(order.getMobile());
|
}
|
}
|
}
|
return getDataTable(list);
|
}
|
|
/**
|
* 导出售后列表
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:export')")
|
@Log(title = "售后", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, MallAftersale mallAftersale) {
|
List<MallAftersale> list = mallAftersaleService.selectMallAftersaleList(mallAftersale);
|
ExcelUtil<MallAftersale> util = new ExcelUtil<MallAftersale>(MallAftersale.class);
|
util.exportExcel(response, list, "售后数据");
|
}
|
|
/**
|
* 获取售后详细信息
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:query')")
|
@GetMapping(value = "/{id}")
|
@ApiOperation(value = "获取售后详细信息")
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
return success(mallAftersaleService.selectMallAftersaleById(id));
|
}
|
|
/**
|
* 新增售后
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:add')")
|
@Log(title = "售后", businessType = BusinessType.INSERT)
|
@PostMapping
|
@ApiOperation(value = "新增售后")
|
public AjaxResult add(@RequestBody MallAftersale mallAftersale) {
|
return toAjax(mallAftersaleService.insertMallAftersale(mallAftersale));
|
}
|
|
/**
|
* 修改售后
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:edit')")
|
@Log(title = "售后", businessType = BusinessType.UPDATE)
|
@PutMapping
|
@ApiOperation(value = "修改售后")
|
public AjaxResult edit(@RequestBody MallAftersale mallAftersale) {
|
return toAjax(mallAftersaleService.updateMallAftersale(mallAftersale));
|
}
|
|
/**
|
* 删除售后
|
*/
|
@PreAuthorize("@ss.hasPermi('mall:aftersale:remove')")
|
@Log(title = "售后", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{ids}")
|
@ApiOperation(value = "删除售后")
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
return toAjax(mallAftersaleService.deleteMallAftersaleByIds(ids));
|
}
|
|
|
/**
|
* 订单同意退款
|
* @param orderRefund 订单信息,{ orderId:xxx }
|
* @return 订单退款操作结果
|
*/
|
@PostMapping("/agreeToRefund")
|
@ApiOperation(value = "订单同意退款")
|
@Transactional
|
public AjaxResult agreeToRefund(@RequestBody OrderRefund orderRefund) {
|
MallOrder order = orderService.getById(orderRefund.getId());
|
if(null==order){
|
return AjaxResult.error("订单数据不存在!!!");
|
}
|
if (!OrderConstants.isRefundStatus(order)&&!OrderConstants.isRefundVerify(order)) {
|
return AjaxResult.error( "退款申请状态下订单才可以审核退款");
|
}
|
BeanUtil.copyProperties(orderRefund,order);
|
Date now = new Date();
|
order.setOrderStatus(Long.valueOf(OrderConstants.STATUS_REFUND_CONFIRM));
|
order.setUpdateTime(now);
|
order.setRefundTime(now);
|
order.setCloseTime(now);
|
// 返还优惠券
|
// List<MallCouponUser> couponUsers = couponUserService.findByOid(orderId);
|
// for (MallCouponUser couponUser: couponUsers) {
|
// // 优惠券状态设置为可使用
|
// couponUser.setStatus(CouponUserConstant.STATUS_USABLE);
|
// couponUser.setUpdateTime(LocalDateTime.now());
|
// couponUserService.update(couponUser);
|
// }
|
if (1 == orderRefund.getRefundType()) {
|
//原路退回的话要调用支付商接口
|
// 微信退款
|
WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();
|
wxPayRefundRequest.setOutTradeNo(order.getOrderSn());
|
wxPayRefundRequest.setOutRefundNo("refund_" + order.getOrderSn());
|
// 元转成分
|
Integer totalFee = order.getActualPrice().multiply(new BigDecimal(100)).intValue();
|
wxPayRefundRequest.setTotalFee(totalFee);
|
wxPayRefundRequest.setRefundFee(totalFee);
|
WxPayRefundResult wxPayRefundResult;
|
try {
|
wxPayRefundResult = wxPayService.refund(wxPayRefundRequest);
|
} catch (WxPayException e) {
|
return AjaxResult.error("订单退款失败");
|
}
|
if (!"SUCCESS".equals(wxPayRefundResult.getReturnCode())) {
|
return AjaxResult.error("订单退款失败");
|
}
|
if (!"SUCCESS".equals(wxPayRefundResult.getResultCode())) {
|
return AjaxResult.error("订单退款失败");
|
}
|
}
|
//TODO 发送邮件和短信通知,这里采用异步发送
|
// 退款成功通知用户, 例如“您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。”
|
// 注意订单号只发后6位
|
/*notifyService.notifySmsTemplate(order.getMobile(), NotifyType.REFUND,
|
new String[]{order.getOrderSn().substring(8, 14)});*/
|
orderService.updateById(order);
|
MallAftersale aftersale = mallAftersaleService.getOne(new LambdaQueryWrapper<MallAftersale>().eq(MallAftersale::getOrderId, order.getId()));
|
aftersale.setStatus(3L);
|
aftersale.setHandleTime(new Date());
|
mallAftersaleService.updateById(aftersale);
|
//对应预约时间数量减1
|
final TjReservation byId = reservationService.getById(order.getReservationId());
|
final Date reservationTime = byId.getReservationTime();
|
LambdaQueryWrapper<MallTimeConfig> wq=new LambdaQueryWrapper<>();
|
wq.eq(MallTimeConfig::getTime,reservationTime);
|
final MallTimeConfig one = mallTimeConfigService.getOne(wq);
|
one.setNowNum(one.getNowNum()+1);
|
mallTimeConfigService.updateById(one);
|
// byId.setIsExpire(1);
|
reservationService.removeById(byId.getId());
|
transitionService.deletedTbTransitionByCusId(byId.getIdCard());
|
return AjaxResult.success();
|
}
|
|
|
/**
|
* 售后拒绝接口
|
*/
|
@PostMapping("/refuse")
|
@ApiOperation(value = "售后拒绝接口")
|
public AjaxResult refuse(@RequestBody String id) {
|
Long idd = JacksonUtil.parseLong(id, "id");
|
MallAftersale aftersale = mallAftersaleService.getById(idd);
|
aftersale.setStatus(4L);
|
aftersale.setHandleTime(new Date());
|
return toAjax(mallAftersaleService.updateById(aftersale));
|
}
|
}
|