Commit 54afd809 by YG8999

管理系统订单退款功能及网关设备状态查询条件

parent a1003e4c
package share.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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 share.common.annotation.Log;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.enums.BusinessType;
import share.system.domain.OrderRefundArtificial;
import share.system.service.OrderRefundArtificialService;
import share.common.utils.poi.ExcelUtil;
import share.common.core.page.TableDataInfo;
/**
* 订单人工退款记录Controller
*
* @author wuwenlong
* @date 2024-02-27
*/
@RestController
@RequestMapping("/system/artificial")
public class OrderRefundArtificialController extends BaseController
{
@Autowired
private OrderRefundArtificialService orderRefundArtificialService;
/**
* 查询订单人工退款记录列表
*/
@PreAuthorize("@ss.hasPermi('system:artificial:list')")
@GetMapping("/list")
public TableDataInfo list(OrderRefundArtificial orderRefundArtificial)
{
startPage();
List<OrderRefundArtificial> list = orderRefundArtificialService.selectOrderRefundArtificialList(orderRefundArtificial);
return getDataTable(list);
}
/**
* 导出订单人工退款记录列表
*/
@PreAuthorize("@ss.hasPermi('system:artificial:export')")
@Log(title = "订单人工退款记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, OrderRefundArtificial orderRefundArtificial)
{
List<OrderRefundArtificial> list = orderRefundArtificialService.selectOrderRefundArtificialList(orderRefundArtificial);
ExcelUtil<OrderRefundArtificial> util = new ExcelUtil<OrderRefundArtificial>(OrderRefundArtificial.class);
util.exportExcel(response, list, "订单人工退款记录数据");
}
/**
* 获取订单人工退款记录详细信息
*/
@PreAuthorize("@ss.hasPermi('system:artificial:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(orderRefundArtificialService.selectOrderRefundArtificialById(id));
}
/**
* 新增订单人工退款记录
*/
@PreAuthorize("@ss.hasPermi('system:artificial:add')")
@Log(title = "订单人工退款记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody OrderRefundArtificial orderRefundArtificial)
{
return toAjax(orderRefundArtificialService.insertOrderRefundArtificial(orderRefundArtificial));
}
/**
* 修改订单人工退款记录
*/
@PreAuthorize("@ss.hasPermi('system:artificial:edit')")
@Log(title = "订单人工退款记录", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody OrderRefundArtificial orderRefundArtificial)
{
return toAjax(orderRefundArtificialService.updateOrderRefundArtificial(orderRefundArtificial));
}
/**
* 删除订单人工退款记录
*/
@PreAuthorize("@ss.hasPermi('system:artificial:remove')")
@Log(title = "订单人工退款记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(orderRefundArtificialService.deleteOrderRefundArtificialByIds(ids));
}
}
......@@ -63,6 +63,16 @@ public class SCouponController extends BaseController
}
/**
* 查询时长劵列表
*/
@PreAuthorize("@ss.hasPermi('system:coupon:list')")
@GetMapping("/list/durationCoupon")
public AjaxResult listDurationCoupon(SCoupon sCoupon) {
return AjaxResult.success(sCouponService.listDurationCoupon(sCoupon));
}
/**
* 查询团购劵类别
*/
@PreAuthorize("@ss.hasPermi('system:coupon:list')")
......
......@@ -14,6 +14,7 @@ import share.common.utils.poi.ExcelUtil;
import share.common.vo.TableDataInfoVo;
import share.system.domain.SOrder;
import share.system.domain.vo.SOrderDto;
import share.system.request.AdminRefundRequest;
import share.system.request.OrderRefundRequest;
import share.system.service.ISOrderService;
......@@ -112,16 +113,6 @@ public class SOrderController extends BaseController
/**
* 退款
*/
@PreAuthorize("hasAuthority('system:order:refund')")
@ApiOperation(value = "退款")
@RequestMapping(value = "/refund", method = RequestMethod.GET)
public AjaxResult<Boolean> refund(@Validated OrderRefundRequest request) {
return toAjax(sOrderService.refundAudit(request));
}
/**
* 人工修改订单
*/
// @PreAuthorize("hasAuthority('system:order:modify')")
......@@ -130,4 +121,14 @@ public class SOrderController extends BaseController
return toAjax(sOrderService.modifyOrder(sOrderDto));
}
/**
* 订单退款(人工退款)
*/
@PreAuthorize("@ss.hasPermi('system:order:refund')")
@ApiOperation(value = "人工退款")
@RequestMapping(value = "/refund", method = RequestMethod.POST)
public AjaxResult<Boolean> refund(@RequestBody AdminRefundRequest request) {
return toAjax(sOrderService.refundOp(request));
}
}
package share.common.enums;
/**
* @className: share.common.enums.RechargeGiveType
* @description: 充值赠送方式
* @author: lwj
* @create: 2024-02-22 15:42
*/
public enum RechargeGiveTypeEnum {
NOT_GIVE("1", "不赠送"),
GIVE_AMOUNT("2", "送金额"),
GIVE_COUPON("3", "送优惠券"),
GIVE_AMOUNT_AND_COUPON("4", "送金额及优惠券");
private String code;
private String name;
RechargeGiveTypeEnum() {
}
RechargeGiveTypeEnum(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package share.common.enums;
/**
* @className: share.common.enums.RechargeStatusEnum
* @description: 充值记录状态
* @author: lwj
* @create: 2024-02-22 15:58
*/
public enum RechargeStatusEnum {
NOT_PAY(0, "待支付"),
FINISH_PAY(1, "已支付"),
REFUND_WAY(2, "退款中"),
REFUND_FINISH(3, "退款完成");
private Integer code;
private String name;
RechargeStatusEnum() {
}
RechargeStatusEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package share.system.domain;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import lombok.Data;
/**
* 订单人工退款记录对象 s_order_refund_artificial
*
* @author wuwenlong
* @date 2024-02-27
*/
@Data
@TableName(value = "s_order_refund_artificial")
public class OrderRefundArtificial extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 退款订单号 */
@Excel(name = "退款订单号")
private String orderNo;
/** 是否使用优惠券 */
@Excel(name = "是否使用优惠券")
private Integer isCoupon;
/** 优惠券id */
@Excel(name = "优惠券id")
private Long couponId;
/** 订单支付金额 */
@Excel(name = "订单支付金额")
private BigDecimal orderAmount;
/** 订单退款金额 */
@Excel(name = "订单退款金额")
private BigDecimal refundAmount;
/** 是否退优惠券 */
@Excel(name = "是否退优惠券")
private Integer isRefundCoupon;
/** 是否生成保洁 */
@Excel(name = "是否生成保洁")
private Integer isClean;
/** 优惠券类型(1:折扣券,2,团购券,3:满减券,4:套餐劵 */
@Excel(name = "优惠券类型(1:折扣券,2,团购券,3:满减券,4:套餐劵")
private Integer couponType;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("orderNo", getOrderNo())
.append("isCoupon", getIsCoupon())
.append("couponId", getCouponId())
.append("orderAmount", getOrderAmount())
.append("refundAmount", getRefundAmount())
.append("isRefundCoupon", getIsRefundCoupon())
.append("isClean", getIsClean())
.append("couponType", getCouponType())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}
package share.system.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import share.system.domain.OrderRefundArtificial;
/**
* 订单人工退款记录Mapper接口
*
* @author wuwenlong
* @date 2024-02-27
*/
public interface OrderRefundArtificialMapper extends BaseMapper<OrderRefundArtificial>
{
/**
* 查询订单人工退款记录
*
* @param id 订单人工退款记录主键
* @return 订单人工退款记录
*/
public OrderRefundArtificial selectOrderRefundArtificialById(Long id);
/**
* 查询订单人工退款记录列表
*
* @param orderRefundArtificial 订单人工退款记录
* @return 订单人工退款记录集合
*/
public List<OrderRefundArtificial> selectOrderRefundArtificialList(OrderRefundArtificial orderRefundArtificial);
/**
* 新增订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
public int insertOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial);
/**
* 修改订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
public int updateOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial);
/**
* 删除订单人工退款记录
*
* @param id 订单人工退款记录主键
* @return 结果
*/
public int deleteOrderRefundArtificialById(Long id);
/**
* 批量删除订单人工退款记录
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteOrderRefundArtificialByIds(Long[] ids);
}
package share.system.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @className: share.system.request.AdminRefundRequest
* @description: 订单退款(管理系统)
* @author: lwj
* @create: 2024-02-25 11:09
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="AdminRefundRequest对象", description="订单退款")
public class AdminRefundRequest implements Serializable {
@ApiModelProperty(value = "订单编号")
@NotBlank(message = "订单编号不能为空")
private String orderNo;
@ApiModelProperty(value = "退款金额")
@DecimalMin(value = "0.00", message = "退款金额不能少于0.00")
private BigDecimal amount;
@ApiModelProperty(value = "是否退优惠券 0 否 1 是")
@NotNull(message = "是否退优惠券不能为空")
private Integer refundCoupon;
@ApiModelProperty(value = "是否生成保洁 0 否 1 是")
@NotNull(message = "是否生成保洁不能为空")
private Integer isClean;
@ApiModelProperty(value = "退款说明")
private String refundReason;
}
......@@ -80,4 +80,6 @@ public interface ISCouponService extends IService<SCoupon>
List<SCoupon> selectSCouponByDealgroupId(Long dealgroupId);
List<SCoupon> querySkuPoiList();
List<SCoupon> listDurationCoupon(SCoupon sCoupon);
}
......@@ -6,6 +6,7 @@ import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder;
import share.system.domain.vo.SOrderDto;
import share.system.domain.vo.SOrderVo;
import share.system.request.AdminRefundRequest;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.request.OrderRefundRequest;
......@@ -192,4 +193,11 @@ public interface ISOrderService extends IService<SOrder>
int modifyOrder(SOrderDto sOrderDto);
TableDataInfoVo pageList(SOrder sOrder);
/**
* 订单退款(人工退款)
* @param request 请求参数
* @return
*/
int refundOp(AdminRefundRequest request);
}
package share.system.service;
import share.system.domain.Recharge;
import share.system.domain.SOrder;
import share.system.request.OrderPayRequest;
import share.system.response.OrderPayResultResponse;
import share.system.response.RechargePayResultResponse;
/**
* @Author wwl
......@@ -23,4 +24,12 @@ public interface OrderPayService {
* @return OrderPayResultResponse
*/
OrderPayResultResponse saobeiPayment(SOrder sOrder);
/**
* 充值支付(扫呗-微信支付)
* @param recharge 支付参数
* @return OrderPayResultResponse
*/
RechargePayResultResponse saobeiRechargePayment(Recharge recharge);
}
package share.system.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.OrderRefundArtificial;
/**
* 订单人工退款记录Service接口
*
* @author wuwenlong
* @date 2024-02-27
*/
public interface OrderRefundArtificialService extends IService<OrderRefundArtificial>
{
/**
* 查询订单人工退款记录
*
* @param id 订单人工退款记录主键
* @return 订单人工退款记录
*/
public OrderRefundArtificial selectOrderRefundArtificialById(Long id);
/**
* 查询订单人工退款记录列表
*
* @param orderRefundArtificial 订单人工退款记录
* @return 订单人工退款记录集合
*/
public List<OrderRefundArtificial> selectOrderRefundArtificialList(OrderRefundArtificial orderRefundArtificial);
/**
* 新增订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
public int insertOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial);
/**
* 修改订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
public int updateOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial);
/**
* 批量删除订单人工退款记录
*
* @param ids 需要删除的订单人工退款记录主键集合
* @return 结果
*/
public int deleteOrderRefundArtificialByIds(Long[] ids);
/**
* 删除订单人工退款记录信息
*
* @param id 订单人工退款记录主键
* @return 结果
*/
public int deleteOrderRefundArtificialById(Long id);
}
......@@ -2,6 +2,7 @@ package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SOrder;
import share.system.request.AdminRefundRequest;
import share.system.request.OrderRefundRequest;
......@@ -11,4 +12,6 @@ import share.system.request.OrderRefundRequest;
public interface OrderRefundService extends IService<SOrder> {
boolean refund(OrderRefundRequest request, SOrder storeOrder);
boolean refundOp(AdminRefundRequest request, SOrder sOrder);
}
......@@ -20,11 +20,12 @@ import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil;
import share.common.utils.DateUtil;
import share.common.utils.JsonConvertUtil;
import share.system.domain.Recharge;
import share.system.domain.SConsumerToken;
import share.system.domain.SOrder;
import share.system.domain.vo.*;
import share.system.request.OrderPayRequest;
import share.system.response.OrderPayResultResponse;
import share.system.response.RechargePayResultResponse;
import share.system.service.*;
import share.system.util.WxPayUtil;
......@@ -55,6 +56,9 @@ public class OrderPayServiceImpl implements OrderPayService {
@Autowired
private SaobeiService saobeiService;
@Autowired
private RechargeService rechargeService;
/**
* 获取域名
*/
......@@ -104,6 +108,34 @@ public class OrderPayServiceImpl implements OrderPayService {
return response;
}
/**
* 充值支付(扫呗-微信支付)
* @param recharge 支付参数
* @return
*/
@Override
public RechargePayResultResponse saobeiRechargePayment(Recharge recharge) {
RechargePayResultResponse response = new RechargePayResultResponse();
response.setRechargeNo(recharge.getRechargeNo());
response.setPayType(PayTypeEnum.getEnumByCode(recharge.getPayType()).getValue());
response.setStatus(YesNoEnum.no.getFlag());
// 扫呗支付
ConcurrentHashMap<String, String> unifiedorder = saobeiUnifiedRecharge(recharge);
WxPayJsResultVo vo = new WxPayJsResultVo();
vo.setAppId(unifiedorder.get("appId"));
vo.setNonceStr(unifiedorder.get("nonceStr"));
vo.setPackages(unifiedorder.get("package"));
vo.setSignType(unifiedorder.get("signType"));
vo.setTimeStamp(unifiedorder.get("timeStamp"));
vo.setPaySign(unifiedorder.get("paySign"));
// 更新商户订单号
recharge.setOutTradeNo(unifiedorder.get("outTradeNo"));
recharge.setTerminalTrace(unifiedorder.get("terminalTrace"));
rechargeService.updateById(recharge);
response.setJsConfig(vo);
return response;
}
/**
* 预下单
......@@ -227,4 +259,64 @@ public class OrderPayServiceImpl implements OrderPayService {
return vo;
}
/**
* 预下单 (扫呗-微信)
* @param recharge 充值对象
* @return 预下单返回对象
*/
private ConcurrentHashMap<String, String> saobeiUnifiedRecharge(Recharge recharge) {
// 获取用户openId
SConsumerToken userToken = consumerTokenService.getTokenByUserId(recharge.getConsumerId());
if (ObjectUtil.isNull(userToken)) {
throw new BaseException("该用户没有openId");
}
// 获取appid、mch_id
// 微信签名key
String appId = weChatConfig.getAppId();
String mchId = weChatConfig.getMchId();
String signKey = weChatConfig.getSignKey();
// 获取扫呗微信预下单对象
SaobeiMiniPayRequestVo unifiedorderVo = getSaobeiUnifiedRechargeVo(recharge, userToken.getToken(), appId, mchId, signKey);
// 预下单(统一下单)
SaobeiMiniPayResponse response = saobeiService.wechatMinipay(unifiedorderVo);
logger.info("SaobeiMiniPayResponse :", JsonConvertUtil.write2JsonStr(response));
// 组装前端预下单参数
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("appId", response.getAppId());
map.put("nonceStr", response.getNonceStr());
map.put("package", response.getPackage_str());
map.put("signType", response.getSignType());
map.put("timeStamp", response.getTimeStamp());
map.put("paySign", response.getPaySign());
map.put("prepayTime", DateUtil.nowDateTimeStr());
map.put("outTradeNo", response.getOut_trade_no());
map.put("terminalTrace", unifiedorderVo.getTerminal_trace());
return map;
}
/**
* 获取预下单对象 (扫呗-微信)
* 充值
* @return 预下单对象
*/
private SaobeiMiniPayRequestVo getSaobeiUnifiedRechargeVo(Recharge recharge, String openid, String appId, String mchId, String signKey) {
AttachVo attachVo = new AttachVo(OrderTypeEnum.RECHARGE.getValue(), recharge.getConsumerId());
SaobeiMiniPayRequestVo vo = new SaobeiMiniPayRequestVo();
vo.setSub_appid(appId);
vo.setMerchant_no(saobeiConfig.getMerchantNo());
vo.setTerminal_id(saobeiConfig.getTerminalId());
vo.setAttach(JSONObject.toJSONString(attachVo));
vo.setTerminal_trace(BaseUtil.getOrderNo("WXNO"));
vo.setTerminal_time(DateUtil.nowDate(Constants.DATE_TIME_FORMAT_NUM));
vo.setOrder_body(StrUtil.concat(true,recharge.getRechargeAmount().toString(),"元充值!"));
// 订单中使用的是BigDecimal,这里要转为Integer类型
vo.setTotal_fee(String.valueOf(recharge.getRechargeAmount().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue()));
vo.setNotify_url(apiDomain + PayConstants.SAOBEI_PAY_NOTIFY_API_URI);
vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_JS);
vo.setOpen_id(openid);
vo.setDevice_no("WEB");
return vo;
}
}
package share.system.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.system.mapper.OrderRefundArtificialMapper;
import share.system.domain.OrderRefundArtificial;
import share.system.service.OrderRefundArtificialService;
/**
* 订单人工退款记录Service业务层处理
*
* @author wuwenlong
* @date 2024-02-27
*/
@Service
public class OrderRefundArtificialServiceImpl extends ServiceImpl<OrderRefundArtificialMapper, OrderRefundArtificial> implements OrderRefundArtificialService
{
@Autowired
private OrderRefundArtificialMapper orderRefundArtificialMapper;
/**
* 查询订单人工退款记录
*
* @param id 订单人工退款记录主键
* @return 订单人工退款记录
*/
@Override
public OrderRefundArtificial selectOrderRefundArtificialById(Long id)
{
return orderRefundArtificialMapper.selectOrderRefundArtificialById(id);
}
/**
* 查询订单人工退款记录列表
*
* @param orderRefundArtificial 订单人工退款记录
* @return 订单人工退款记录
*/
@Override
public List<OrderRefundArtificial> selectOrderRefundArtificialList(OrderRefundArtificial orderRefundArtificial)
{
return orderRefundArtificialMapper.selectOrderRefundArtificialList(orderRefundArtificial);
}
/**
* 新增订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
@Override
public int insertOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial)
{
orderRefundArtificial.setCreateTime(DateUtils.getNowDate());
return orderRefundArtificialMapper.insertOrderRefundArtificial(orderRefundArtificial);
}
/**
* 修改订单人工退款记录
*
* @param orderRefundArtificial 订单人工退款记录
* @return 结果
*/
@Override
public int updateOrderRefundArtificial(OrderRefundArtificial orderRefundArtificial)
{
orderRefundArtificial.setUpdateTime(DateUtils.getNowDate());
return orderRefundArtificialMapper.updateOrderRefundArtificial(orderRefundArtificial);
}
/**
* 批量删除订单人工退款记录
*
* @param ids 需要删除的订单人工退款记录主键
* @return 结果
*/
@Override
public int deleteOrderRefundArtificialByIds(Long[] ids)
{
return orderRefundArtificialMapper.deleteOrderRefundArtificialByIds(ids);
}
/**
* 删除订单人工退款记录信息
*
* @param id 订单人工退款记录主键
* @return 结果
*/
@Override
public int deleteOrderRefundArtificialById(Long id)
{
return orderRefundArtificialMapper.deleteOrderRefundArtificialById(id);
}
}
......@@ -24,6 +24,7 @@ import share.system.domain.vo.SaobeiRefundVo;
import share.system.domain.vo.WxRefundVo;
import share.system.mapper.SOrderMapper;
import share.system.mapper.WechatPayInfoMapper;
import share.system.request.AdminRefundRequest;
import share.system.request.OrderRefundRequest;
import share.system.service.*;
import share.system.util.WxPayUtil;
......@@ -73,6 +74,17 @@ public class OrderRefundServiceImpl extends ServiceImpl<SOrderMapper, SOrder> im
}
/**
* 管理系统,人工退款
* @param request
* @param sOrder
* @return
*/
@Override
public boolean refundOp(AdminRefundRequest request, SOrder sOrder) {
return refundOpSaobei(request, sOrder);
}
/**
* 公共号退款
* @param request
* @param sOrder
......@@ -155,5 +167,51 @@ public class OrderRefundServiceImpl extends ServiceImpl<SOrderMapper, SOrder> im
}
}
/**
* 扫呗退款-微信(人工退款)
* @param request
* @param sOrder
*/
private boolean refundOpSaobei(AdminRefundRequest request, SOrder sOrder) {
WechatPayInfo wechatPayInfo = wechatPayInfoService.getByNo(sOrder.getOutTradeNo());
if (ObjectUtil.isNull(wechatPayInfo)) {
throw new BaseException("微信订单不存在!");
}
SaobeiRefundVo vo = new SaobeiRefundVo();
vo.setRefund_fee(String.valueOf(request.getAmount().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue()));
vo.setTerminal_trace(BaseUtil.getOrderNo("WXNO"));
vo.setTerminal_time(DateUtil.nowDate(Constants.DATE_TIME_FORMAT_NUM));
vo.setOut_trade_no(wechatPayInfo.getTransactionId());
SaobeiTradeRefundResponse response = saobeiService.refund(vo);
if (ObjectUtil.isNotEmpty(response)) {
// 退款成功修改订单状态
SOrder order = sOrderService.getByOrderNo(sOrder.getOrderNo());
if (ObjectUtil.isNull(order)) {
throw new BaseException("退款订单不存在");
}
order.setStatus(OrderStatusEnum.CANCEL.getCode());
order.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
order.setRefundReasonTime(cn.hutool.core.date.DateUtil.date());
order.setRefundPrice(request.getAmount());
order.setRefundReason(request.getRefundReason());
boolean update = sOrderService.updateById(order);
if (update) {
SConsumptionRecords sConsumptionRecords = new SConsumptionRecords();
sConsumptionRecords.setConsumerId(order.getConsumerId());
sConsumptionRecords.setOrderId(order.getId());
sConsumptionRecords.setName(ConsumeNameEnum.REFUND.getValue());
sConsumptionRecords.setPrice(order.getPayPrice());
sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName());
sConsumptionRecords.setSign(SignEnum.STRAINHT.getValue());
sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords);
return update;
} else {
throw new BaseException("退款失败");
}
} else {
throw new BaseException("退款失败");
}
}
}
......@@ -324,4 +324,11 @@ public class SCouponServiceImpl extends ServiceImpl<SCouponMapper, SCoupon> impl
});
return sCouponList;
}
@Override
public List<SCoupon> listDurationCoupon(SCoupon sCoupon) {
sCoupon.setCouponType(CouponTypeEnum.DURATION.getCode());
List<SCoupon> sCouponList = sCouponMapper.listDuration(sCoupon);
return sCouponList;
}
}
......@@ -37,6 +37,7 @@ import share.system.domain.vo.SOrderDto;
import share.system.domain.vo.SOrderVo;
import share.system.domain.vo.SRoomVo;
import share.system.mapper.SOrderMapper;
import share.system.request.AdminRefundRequest;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.request.OrderRefundRequest;
......@@ -111,6 +112,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired
private TiktokService tiktokService;
@Autowired
private ISCleanRecordsService isCleanRecordsService;
@Autowired
private OrderRefundArtificialService orderRefundArtificialService;
private final static Long FIVE = 5l;
......@@ -339,6 +346,85 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
/**
* 订单退款(管理系统人工退款)
* @param request 请求参数
* @return
*/
@Transactional(rollbackFor = Exception.class)
@Override
public int refundOp(AdminRefundRequest request) {
SOrder sOrder = getInfoException(request.getOrderNo());
if (sOrder == null) {
throw new BaseException("订单不存在");
}
Date date = cn.hutool.core.date.DateUtil.offsetDay(cn.hutool.core.date.DateUtil.date(), -30);
if (sOrder.getCreateTime().compareTo(date) < 0) {
throw new BaseException("下单时间超过30天,不支持退款");
}
if (!YesNoEnum.yes.getIndex().equals(sOrder.getPayStatus())) {
throw new BaseException("未支付无法退款");
}
if (request.getAmount().compareTo(sOrder.getPayPrice()) > 0) {
throw new BaseException("退款金额大于实际支付金额,请修改退款金额");
}
// if (request.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
// throw new BaseException("退款金额不能为0,请修改退款金额");
// }
OrderRefundArtificial artificial = new OrderRefundArtificial();
artificial.setIsRefundCoupon(request.getRefundCoupon());
artificial.setIsClean(request.getIsClean());
artificial.setOrderNo(sOrder.getOrderNo());
artificial.setOrderAmount(sOrder.getPayPrice());
artificial.setRefundAmount(request.getAmount());
artificial.setIsCoupon(sOrder.getCouponId() != null ? YesNoEnum.yes.getIndex() : YesNoEnum.no.getIndex());
artificial.setCreateBy(SecurityUtils.getUsername());
// 是否退优惠券
if (request.getRefundCoupon().equals(YesNoEnum.yes.getIndex()) && ObjectUtil.isNotNull(sOrder.getCouponId())) {
// 退优惠券
SConsumerCoupon couponUser = consumerCouponService.getById(sOrder.getCouponId());
if(Objects.nonNull(couponUser)) {
couponUser.setUseStatus(CouponStatusEnum.NORMAL.getValue());
consumerCouponService.updateById(couponUser);
artificial.setCouponId(couponUser.getId());
artificial.setCouponType(couponUser.getCouponType());
}
}
// 是否生成保洁
if (request.getIsClean().equals(YesNoEnum.yes.getIndex())) {
//房间添加保洁记录
boolean b = isCleanRecordsService.addSCleanRecords(sOrder.getStoreId(), sOrder.getRoomId());
}
if (sOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode())) {
// 如果订单使用中,房间修改状态为空闲
SRoom sRoom = new SRoom();
sRoom.setId(sOrder.getRoomId());
sRoom.setStatus(RoomStatusEnum.FREE.getValue());
roomService.updateById(sRoom);
}
if (request.getAmount().compareTo(BigDecimal.ZERO) > 0) {
// 退款金额大于0, 微信退款
//退款
if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode())) {
try {
orderRefundService.refundOp(request, sOrder);
} catch (Exception e) {
e.printStackTrace();
throw new BaseException("微信申请退款失败!");
}
}
} else {
sOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
sOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
sOrder.setRefundReasonTime(cn.hutool.core.date.DateUtil.date());
sOrder.setRefundPrice(request.getAmount());
sOrder.setRefundReason(request.getRefundReason());
this.updateById(sOrder);
}
// 生成退款人工退款记录
return orderRefundArtificialService.insertOrderRefundArtificial(artificial);
}
/**
* 新增订单
*
* @param sOrder 订单
......@@ -812,6 +898,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
queryWrapper.le(SOrder::getRefundReasonTime, cn.hutool.core.date.DateUtil.endOfDay(sOrder.getEndDate()));
}
}
queryWrapper.orderByDesc(SOrder::getRefundReasonTime);
return baseMapper.selectList(queryWrapper);
}
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="share.system.mapper.OrderRefundArtificialMapper">
<resultMap type="OrderRefundArtificial" id="OrderRefundArtificialResult">
<result property="id" column="id" />
<result property="orderNo" column="order_no" />
<result property="isCoupon" column="is_coupon" />
<result property="couponId" column="coupon_id" />
<result property="orderAmount" column="order_amount" />
<result property="refundAmount" column="refund_amount" />
<result property="isRefundCoupon" column="is_refund_coupon" />
<result property="isClean" column="is_clean" />
<result property="couponType" column="coupon_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectOrderRefundArtificialVo">
select id, order_no, is_coupon, coupon_id, order_amount, refund_amount, is_refund_coupon, is_clean, coupon_type,
create_by, create_time, update_by, update_time, remark
from s_order_refund_artificial
</sql>
<select id="selectOrderRefundArtificialList" parameterType="OrderRefundArtificial" resultMap="OrderRefundArtificialResult">
<include refid="selectOrderRefundArtificialVo"/>
<where>
<if test="orderNo != null and orderNo != ''"> and order_no = #{orderNo}</if>
<if test="isCoupon != null "> and is_coupon = #{isCoupon}</if>
<if test="couponId != null "> and coupon_id = #{couponId}</if>
<if test="orderAmount != null "> and order_amount = #{orderAmount}</if>
<if test="refundAmount != null "> and refund_amount = #{refundAmount}</if>
<if test="isRefundCoupon != null "> and is_refund_coupon = #{isRefundCoupon}</if>
<if test="isClean != null "> and is_clean = #{isClean}</if>
<if test="couponType != null "> and coupon_type = #{couponType}</if>
</where>
</select>
<select id="selectOrderRefundArtificialById" parameterType="Long" resultMap="OrderRefundArtificialResult">
<include refid="selectOrderRefundArtificialVo"/>
where id = #{id}
</select>
<insert id="insertOrderRefundArtificial" parameterType="OrderRefundArtificial" useGeneratedKeys="true" keyProperty="id">
insert into s_order_refund_artificial
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="isCoupon != null">is_coupon,</if>
<if test="couponId != null">coupon_id,</if>
<if test="orderAmount != null">order_amount,</if>
<if test="refundAmount != null">refund_amount,</if>
<if test="isRefundCoupon != null">is_refund_coupon,</if>
<if test="isClean != null">is_clean,</if>
<if test="couponType != null">coupon_type,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="isCoupon != null">#{isCoupon},</if>
<if test="couponId != null">#{couponId},</if>
<if test="orderAmount != null">#{orderAmount},</if>
<if test="refundAmount != null">#{refundAmount},</if>
<if test="isRefundCoupon != null">#{isRefundCoupon},</if>
<if test="isClean != null">#{isClean},</if>
<if test="couponType != null">#{couponType},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateOrderRefundArtificial" parameterType="OrderRefundArtificial">
update s_order_refund_artificial
<trim prefix="SET" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
<if test="isCoupon != null">is_coupon = #{isCoupon},</if>
<if test="couponId != null">coupon_id = #{couponId},</if>
<if test="orderAmount != null">order_amount = #{orderAmount},</if>
<if test="refundAmount != null">refund_amount = #{refundAmount},</if>
<if test="isRefundCoupon != null">is_refund_coupon = #{isRefundCoupon},</if>
<if test="isClean != null">is_clean = #{isClean},</if>
<if test="couponType != null">coupon_type = #{couponType},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteOrderRefundArtificialById" parameterType="Long">
delete from s_order_refund_artificial where id = #{id}
</delete>
<delete id="deleteOrderRefundArtificialByIds" parameterType="String">
delete from s_order_refund_artificial where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment