配送工单

分红列表
可退款金额
This commit is contained in:
邱贞招 2024-10-11 18:13:15 +08:00
parent a86345c520
commit 2c221178d5
26 changed files with 654 additions and 142 deletions

View File

@ -27,6 +27,7 @@ import com.ruoyi.system.domain.store.StoreVo;
import com.ruoyi.system.service.*;
import com.ruoyi.system.service.store.RlStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -73,6 +74,12 @@ public class AppVerifyController extends BaseController
@Autowired
private IRlModelAccessoryService modelAccessoryService;
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private IRlOrderOperService orderOperService;
/**
* 实名认证
*/
@ -537,19 +544,37 @@ public class AppVerifyController extends BaseController
}
String outTradeNo = etOrder1.getOutTradeNo();
ChannelVO channelVO = channelService.selectSmChannelByChannelId(etOrder1.getPayChannel());
if(StrUtil.isNotBlank(outTradeNo)){
// 如果有outtradeno则关闭订单
wxPayService.closeOrder(outTradeNo,channelVO);
logger.info("【订单改价】订单【{}】,有outTradeNo = 【{}】,查询订单未支付,关闭订单:{}", etOrder1.getOrderNo(),outTradeNo);
}
BigDecimal payFee = BigDecimal.ZERO;
if(ObjectUtil.isNotNull(order.getPayFee())){
payFee = payFee.add(order.getPayFee());
}
order.setPayFee(payFee);
return toAjax(orderService.updateRlOrderByOrderNo(order));
Boolean execute = transactionTemplate.execute(e -> {
if(StrUtil.isNotBlank(outTradeNo)){
/** 关闭未支付订单 */
if(wxPayService.closeOrder(outTradeNo,channelVO)){
throw new ServiceException("关闭未支付订单失败");
}
logger.info("【订单改价】订单【{}】,有outTradeNo = 【{}】,查询订单未支付,关闭订单:{}", etOrder1.getOrderNo(),outTradeNo);
BigDecimal payFee = BigDecimal.ZERO;
if(ObjectUtil.isNotNull(order.getPayFee())){
payFee = payFee.add(order.getPayFee());
}
order.setPayFee(payFee);
/** 更新订单信息 */
int i = orderService.updateRlOrderByOrderNo(order);
if(i == 0){
throw new ServiceException("【改价】更新订单信息失败");
}
/** 记录订单履历 */
if(orderOperService.recordOrderHistory(order.getOrderNo(),ServiceConstants.ORDER_OPERATION_CHANGE_PRICE,
etOrder1.getStatus(),order.getStatus(),etOrder1.getPayFee(),order.getPayFee(),etOrder1.getUserId(),etOrder1.getPhone(),
"订单改价,修改前价格:"+etOrder1.getPayFee()+",修改后价格:"+order.getPayFee())){
throw new ServiceException("【改价】更新订单信息失败");
}
}
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("【改价】失败");
return toAjax(1);
}
/**
* 根据sn查询正在进行中的订单
*/

View File

@ -0,0 +1,239 @@
package com.ruoyi.web.controller.appAgent;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.RlUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.domain.accessory.RlAccessory;
import com.ruoyi.system.domain.device.RlDeviceQuery;
import com.ruoyi.system.domain.device.RlDeviceVO;
import com.ruoyi.system.domain.model.RlModel;
import com.ruoyi.system.domain.model.RlModelQuery;
import com.ruoyi.system.domain.order.RlOrderQuery;
import com.ruoyi.system.domain.order.RlOrderVO;
import com.ruoyi.system.domain.rule.RlFeeRule;
import com.ruoyi.system.domain.userExt.RlUserExt;
import com.ruoyi.system.service.*;
import com.ruoyi.system.service.store.RlStoreService;
import com.ruoyi.system.service.store.StoreAssembler;
import com.ruoyi.system.service.store.StoreValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* app接口需要登录校验的
* 校验
* @author ruoyi
*/
@Slf4j
@RestController
@RequestMapping("/appAgent")
public class AppAgentController extends BaseController
{
@Resource
private IRlUserService rlUserService;
@Autowired
private SysLoginService loginService;
@Resource
private IRlOrderService orderService;
@Autowired
private IRlDeviceService deviceService;
@Autowired
private IRlUserExtService rlUserExtService;
@Autowired
private IRlModelService modelService;
@Autowired
private RlStoreService storeService;
@Autowired
private StoreValidator storeValidator;
@Autowired
private StoreAssembler storeAssembler;
@Autowired
private IRlFeeRuleService feeRuleService;
@Autowired
private IRlDeliveryOrderService deliveryOrderService;
@Resource
private IRlAgentService rlAgentService;
@Autowired
private IRlAccessoryService rlAccessoryService;
/**
* 车辆列表
*/
@GetMapping(value = "/vehicleList")
public AjaxResult allVehicleInfo(RlDeviceQuery query)
{
logger.info("【车辆列表】请求参数query={}", JSON.toJSONString(query));
authorityVerify();
List<RlDeviceVO> devices = deviceService.selectDeviceList(query);
return success(devices);
}
/**
* 订单列表
*/
@GetMapping("/orderList")
public AjaxResult orderList(RlOrderQuery order)
{
order.setMerchantId(getUserId());
logger.info("订单列表请求order=【"+JSON.toJSONString(order)+"");
authorityVerify();
List<RlOrderVO> rlOrderVOS = orderService.selectRlOrderList(order);
return success(rlOrderVOS);
}
/**
* 订单信息
*/
@GetMapping("/orderInfo")
public AjaxResult orderInfo(String orderNo)
{
logger.info("订单列表请求order=【"+JSON.toJSON(orderNo)+"");
RlOrderVO rlOrder = orderService.getOrderInfoByOrderNo(orderNo);
return success(rlOrder);
}
/**
* 新增车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.INSERT)
@PostMapping(value = "/model/save")
public AjaxResult add(@RequestBody RlModelQuery model)
{
authorityVerify();
return toAjax(modelService.insertEModel(model));
}
/**
* 修改车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.UPDATE)
@PutMapping(value = "/model/edit")
public AjaxResult edit(@RequestBody RlModelQuery model)
{
authorityVerify();
return toAjax(modelService.updateEModel(model));
}
/**
* 删除车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.DELETE)
@DeleteMapping("/model/{modelIds}")
public AjaxResult remove(@PathVariable Long[] modelIds)
{
authorityVerify();
for (Long modelId:modelIds) {
RlModel model = new RlModel();
model.setModelId(modelId);
model.setDelFlag("2");
modelService.updateEModel(model);
}
return toAjax(1);
}
/**
* 新增收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.INSERT)
@PostMapping("/rule/save")
public AjaxResult addModel(@RequestBody RlFeeRule rlFeeRule)
{
authorityVerify();
return toAjax(feeRuleService.insertRlFeeRule(rlFeeRule));
}
/**
* 修改收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.UPDATE)
@PutMapping("/rule/edit")
public AjaxResult editModel(@RequestBody RlFeeRule rlFeeRule)
{
authorityVerify();
return toAjax(feeRuleService.updateRlFeeRule(rlFeeRule));
}
/**
* 删除收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.DELETE)
@DeleteMapping("/rule/{ruleIds}")
public AjaxResult removeModel(@PathVariable Long[] ruleIds)
{
authorityVerify();
for (Long ruleId:ruleIds) {
RlFeeRule rule = new RlFeeRule();
rule.setRuleId(ruleId);
rule.setDelFlag("2");
feeRuleService.updateRlFeeRule(rule);
}
return toAjax(1);
}
private void authorityVerify() {
RlUser rlUser = rlUserService.selectUserById(getUserId());
if(!rlUser.getUserType().equals(ServiceConstants.USER_TYPE_AGENT)){
throw new ServiceException("您没有数据的权限,请联系管理员添加权限");
}
}
/**
* 根据userId获取车型列表代理商
*/
@GetMapping("/getModelListByUserId")
public AjaxResult getModelListByUserId()
{
authorityVerify();
logger.info("根据userId获取车型列表代理商【userId="+getUserId()+"");
RlUserExt rlUserExt = rlUserExtService.selectRlUserExtByUserId(getUserId());
return success(modelService.selectEModelListByAgentId(rlUserExt.getAgentId()));
}
/**
* 根据token获取店铺列表代理商
*/
@GetMapping("/getStoreListByToken")
public AjaxResult getStoreListByToken()
{
authorityVerify();
logger.info("根据token获取店铺列表代理商【userId="+getUserId()+"");
RlUserExt rlUserExt = rlUserExtService.selectRlUserExtByUserId(getUserId());
return success(storeService.selectSmStoreListByAgentId(rlUserExt.getAgentId()));
}
/**
* 查询配件列表代理商
*/
@GetMapping("/getAccessorylist")
public AjaxResult getAccessorylist()
{
RlAccessory rlAccessory = new RlAccessory();
List<RlAccessory> list = rlAccessoryService.selectRlAccessoryList(rlAccessory);
return success(list);
}
}

View File

@ -9,22 +9,21 @@ import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.domain.entity.RlUser;
import com.ruoyi.common.core.domain.entity.RlUserVO;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.domain.agent.RlAgentVO;
import com.ruoyi.system.domain.changeBalance.RlChangeBalance;
import com.ruoyi.system.domain.changeBalance.RlChangeBalanceQuery;
import com.ruoyi.system.domain.deliveryOrder.RlDeliveryOrderVO;
import com.ruoyi.system.domain.device.RlDeviceQuery;
import com.ruoyi.system.domain.device.RlDeviceVO;
import com.ruoyi.system.domain.model.RlModel;
import com.ruoyi.system.domain.model.RlModelQuery;
import com.ruoyi.system.domain.order.RlOrderQuery;
import com.ruoyi.system.domain.order.RlOrderVO;
import com.ruoyi.system.domain.rule.RlFeeRule;
import com.ruoyi.system.domain.store.StoreBO;
import com.ruoyi.system.domain.store.StoreQuery;
import com.ruoyi.system.domain.store.StoreVo;
@ -88,6 +87,9 @@ public class AppAdminController extends BaseController
@Autowired
private IRlDeliveryOrderService deliveryOrderService;
@Resource
private IRlAgentService rlAgentService;
/**
* 首页统计
*/
@ -161,6 +163,7 @@ public class AppAdminController extends BaseController
@GetMapping(value = "/vehicleList")
public AjaxResult allVehicleInfo(RlDeviceQuery query)
{
authorityVerify();
logger.info("【车辆列表】请求参数query={}", JSON.toJSONString(query));
List<RlDeviceVO> devices = deviceService.selectDeviceList(query);
return success(devices);
@ -193,7 +196,6 @@ public class AppAdminController extends BaseController
}
/**
* 车辆上线
*/
@ -219,12 +221,12 @@ public class AppAdminController extends BaseController
}
/**
*
* 根据商户id[merchantId]获取车型列表
*/
@GetMapping("/getModelListByMerchantId")
public AjaxResult getModelListByMerchantId()
{
authorityVerify();
logger.info("根据userid获取车型列表【userId="+getUserId()+"");
return success(modelService.getModelListByMerchantId(getUserId()));
}
@ -235,26 +237,13 @@ public class AppAdminController extends BaseController
@GetMapping("/orderList")
public AjaxResult orderList(RlOrderQuery order)
{
authorityVerify();
order.setMerchantId(getUserId());
logger.info("订单列表请求order=【"+JSON.toJSONString(order)+"");
List<RlOrderVO> rlOrderVOS = orderService.selectRlOrderList(order);
return success(rlOrderVOS);
}
/**
* 查询配送工单列表 送达时间
*/
@GetMapping("/deliveryOrderList")
public AjaxResult list(RlDeliveryOrderVO rlDeliveryOrder)
{
if(ObjectUtil.isNull(rlDeliveryOrder.getStatusList()) || rlDeliveryOrder.getStatusList().length == 0){
rlDeliveryOrder.setStatusList(null);
}
log.info("【查询配送工单列表】请求参数rlDeliveryOrder="+JSON.toJSONString(rlDeliveryOrder));
List<RlDeliveryOrderVO> list = deliveryOrderService.selectRlDeliveryOrderList(rlDeliveryOrder);
return success(list);
}
/**
* 订单信息
*/
@ -310,7 +299,17 @@ public class AppAdminController extends BaseController
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) StoreBO store)
{
int result;
store.setMerchantId(getUserId());
Long userId = getUserId();
store.setMerchantId(userId);
RlUserExt rlUserExt = rlUserExtService.selectRlUserExtByUserId(userId);
if(ObjectUtil.isNotNull(rlUserExt)){
RlAgentVO rlAgentVO = rlAgentService.selectRlAgentByAgentId(rlUserExt.getAgentId());
if(ObjectUtil.isNull(rlAgentVO)) throw new ServiceException("代理商【"+rlUserExt.getAgentId()+"】不存在");
store.setAgentId(rlAgentVO.getAgentId());
store.setServerPhone(rlAgentVO.getServicePhone());
}else{
throw new ServiceException("用户【"+userId+"】没有扩展信息");
}
if(ObjectUtil.isNull(store.getStoreId())){
store = store.filterCreate();
ServiceUtil.assertion(storeValidator.preCreate(store));
@ -323,79 +322,6 @@ public class AppAdminController extends BaseController
return toAjax(result);
}
/**
* 新增车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.INSERT)
@PostMapping(value = "/model/save")
public AjaxResult add(@RequestBody RlModelQuery model)
{
return toAjax(modelService.insertEModel(model));
}
/**
* 修改车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.UPDATE)
@PutMapping(value = "/model/edit")
public AjaxResult edit(@RequestBody RlModelQuery model)
{
return toAjax(modelService.updateEModel(model));
}
/**
* 删除车辆型号
*/
@Log(title = "车辆型号", businessType = BusinessType.DELETE)
@DeleteMapping("/model/{modelIds}")
public AjaxResult remove(@PathVariable Long[] modelIds)
{
for (Long modelId:modelIds) {
RlModel model = new RlModel();
model.setModelId(modelId);
model.setDelFlag("2");
modelService.updateEModel(model);
}
return toAjax(1);
}
/**
* 新增收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.INSERT)
@PostMapping("/rule/save")
public AjaxResult addModel(@RequestBody RlFeeRule rlFeeRule)
{
return toAjax(feeRuleService.insertRlFeeRule(rlFeeRule));
}
/**
* 修改收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.UPDATE)
@PutMapping("/rule/edit")
public AjaxResult editModel(@RequestBody RlFeeRule rlFeeRule)
{
return toAjax(feeRuleService.updateRlFeeRule(rlFeeRule));
}
/**
* 删除收费模板
*/
@Log(title = "收费模板", businessType = BusinessType.DELETE)
@DeleteMapping("/rule/{ruleIds}")
public AjaxResult removeModel(@PathVariable Long[] ruleIds)
{
for (Long ruleId:ruleIds) {
RlFeeRule rule = new RlFeeRule();
rule.setRuleId(ruleId);
rule.setDelFlag("2");
feeRuleService.updateRlFeeRule(rule);
}
return toAjax(1);
}
/**
* 根据token获取店铺列表
*/
@ -408,6 +334,29 @@ public class AppAdminController extends BaseController
return success(storeService.selectSmStoreList(storeQuery));
}
/**
* 查询配送工单列表 送达时间
*/
@GetMapping("/deliveryOrderList")
public AjaxResult list(RlDeliveryOrderVO rlDeliveryOrder)
{
if(ObjectUtil.isNull(rlDeliveryOrder.getStatusList()) || rlDeliveryOrder.getStatusList().length == 0){
rlDeliveryOrder.setStatusList(null);
}
log.info("【查询配送工单列表】请求参数rlDeliveryOrder="+JSON.toJSONString(rlDeliveryOrder));
List<RlDeliveryOrderVO> list = deliveryOrderService.selectRlDeliveryOrderList(rlDeliveryOrder);
return success(list);
}
/**
* 获取配送工单详细信息
*/
@GetMapping(value = "/deliveryOrderinfo/{deliveryId}")
public AjaxResult deliveryOrderinfo(@PathVariable("deliveryId") Long deliveryId)
{
return success(deliveryOrderService.selectRlDeliveryOrderByDeliveryId(deliveryId));
}
/**
* 立即接单
*/
@ -464,4 +413,11 @@ public class AppAdminController extends BaseController
return success(deliveryOrderService.cancelDelivery(orderNo,userId));
}
private void authorityVerify() {
RlUser rlUser = rlUserService.selectUserById(getUserId());
if(!rlUser.getUserType().equals(ServiceConstants.USER_TYPE_MERCHANT)){
throw new ServiceException("您没有数据的权限,请联系管理员添加权限");
}
}
}

View File

@ -803,5 +803,55 @@ public class ServiceConstants {
/**----------------------------用户类型end----------------------------*/
/**----------------------------订单操作类型start----------------------------*/
/**
* 1 - 下单
*/
public static final String ORDER_OPERATION_PLACE_ORDER = "1";
/**
* 2 - 改价
*/
public static final String ORDER_OPERATION_CHANGE_PRICE = "2";
/**
* 3 - 支付
*/
public static final String ORDER_OPERATION_PAY = "3";
/**
* 4 - 还车结束订单
*/
public static final String ORDER_OPERATION_RETURN_END = "4";
/**
* 5 - 押金退款
*/
public static final String ORDER_OPERATION_DEPOSIT_REFUND = "5";
/**
* 6 - 退款
*/
public static final String ORDER_OPERATION_REFUND = "6";
/**
* 7 - 用户取消
*/
public static final String ORDER_OPERATION_USER_CANCEL = "7";
/**
* 8 - 系统自动取消
*/
public static final String ORDER_OPERATION_SYSTEM_CANCEL = "8";
/**
* 9 - 车损扣款
*/
public static final String ORDER_OPERATION_DEDUCTION = "9";
/**----------------------------订单操作类型end----------------------------*/
}

View File

@ -20,4 +20,13 @@ public class RlDeliveryOrderVO extends RlDeliveryOrder{
/** 店铺地址 */
private String address;
/** 用户电话 */
private String phone;
/** 用户姓名 */
private String realName;
/** 车型 */
private String model;
}

View File

@ -56,6 +56,6 @@ public class RlDividendDetail extends BaseEntity
/** 分红比例 */
@Excel(name = "分红比例")
private Integer dividendProportion;
private BigDecimal dividendProportion;
}

View File

@ -8,6 +8,7 @@ import com.ruoyi.system.domain.orderOper.RlOrderOper;
import com.ruoyi.system.domain.rule.RlFeeRule;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
@ -50,4 +51,15 @@ public class RlOrderVO extends RlOrder{
/** 分账明细 */
private List<RlDividendDetail> rlDividendDetails;
/** 可退款金额 */
private BigDecimal refundableTotalAmount;
private BigDecimal refundableDispatchFee; // 调度费
private BigDecimal refundableDeliveryFee; // 配送费
private BigDecimal refundableLeaseFee; // 租赁费骑行费
private BigDecimal refundableDeposit; // 押金
}

View File

@ -34,13 +34,21 @@ public class RlOrderOper extends BaseEntity
@Excel(name = "详情")
private String details;
/** 订单金额 */
@Excel(name = "订单金额")
private BigDecimal amountChange;
/** 变动前金额 */
@Excel(name = "变动前金额")
private String beforeAmount;
/** 订单状态 */
@Excel(name = "订单状态")
private String statusChange;
/** 变动后金额 */
@Excel(name = "变动后金额")
private String afterAmount;
/** 变动前状态 */
@Excel(name = "变动前状态")
private String beforeStatus;
/** 变动后状态 */
@Excel(name = "变动后状态")
private String afterStatus;
/** 操作人 */
@Excel(name = "操作人")

View File

@ -54,9 +54,12 @@ public class RlRefund extends BaseEntity
/** 配送费 */
private BigDecimal deliveryFee;
/** 骑行费 */
/** 租赁费 */
private BigDecimal leaseFee;
/** 押金 */
private BigDecimal deposit;
/** 退款原因 */
@Excel(name = "退款原因")
private String reason;

View File

@ -2,6 +2,19 @@ package com.ruoyi.system.domain.refund;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class RlRefundVO extends RlRefund{
private BigDecimal totalRefundAmount; // 退款金额
private BigDecimal totalDispatchFee; // 调度费
private BigDecimal totalDeliveryFee; // 配送费
private BigDecimal totalLeaseFee; // 租赁费骑行费
private BigDecimal totalDeposit; // 押金
}

View File

@ -99,6 +99,10 @@ public class StoreBO extends Store {
bo.setContactName(getContactName());
bo.setContactMobile(getContactMobile());
bo.setShow(getShow());
bo.setMerchantId(getMerchantId());
bo.setAgentId(getAgentId());
bo.setServerPhone(getServerPhone());
bo.setSimpleAddress(getSimpleAddress());
return bo;
}
}

View File

@ -7,4 +7,6 @@ import lombok.Data;
public class RlUserQuery extends RlUser {
private String[] typeList;
private Long agentId;
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.system.mapper;
import com.ruoyi.system.domain.order.RlOrder;
import com.ruoyi.system.domain.refund.RlRefund;
import com.ruoyi.system.domain.refund.RlRefundQuery;
import com.ruoyi.system.domain.refund.RlRefundVO;
import java.util.List;
@ -101,4 +102,12 @@ public interface RlRefundMapper
* @return 结果
*/
List<RlOrder> checkUserDeposit(Long userId);
/**
* 统计已退款金额
*
* @param orderNo 订单号
* @return 结果
*/
RlRefundVO getRefundedAmount(String orderNo);
}

View File

@ -2,6 +2,7 @@ package com.ruoyi.system.service;
import com.ruoyi.system.domain.orderOper.RlOrderOper;
import java.math.BigDecimal;
import java.util.List;
/**
@ -59,4 +60,22 @@ public interface IRlOrderOperService
* @return 结果
*/
public int deleteRlOrderOperByOperId(Long operId);
/**
* 记录订单操作日志
*
* @param orderNo 订单号标识唯一订单
* @param type 操作类型表示订单的操作行为如下单支付等参考订单操作类型常量
* @param beforeStatus 操作前的订单状态
* @param afterStatus 操作后的订单状态
* @param beforeAmount 操作前的金额如订单金额押金等
* @param afterAmount 操作后的金额如订单金额调整后押金退款等变化
* @param userId 操作用户的ID记录是哪个用户执行了该操作
* @param phone 操作用户的手机号用于追溯用户信息
*
* @return 返回操作是否成功的结果`true` 表示成功`false` 表示失败
*/
public boolean recordOrderHistory(String orderNo, String type, String beforeStatus, String afterStatus,
BigDecimal beforeAmount, BigDecimal afterAmount, Long userId, String phone,String detail);
}

View File

@ -2,6 +2,7 @@ package com.ruoyi.system.service;
import com.ruoyi.system.domain.order.RlOrder;
import com.ruoyi.system.domain.refund.RlRefund;
import com.ruoyi.system.domain.refund.RlRefundVO;
import java.util.List;
@ -100,4 +101,12 @@ public interface IRlRefundService
* @return 结果
*/
List<RlOrder> checkUserDeposit(Long userId);
/**
* 统计已退款金额
*
* @param orderNo 订单号
* @return 结果
*/
RlRefundVO getRefundedAmount(String orderNo);
}

View File

@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.RlUser;
import com.ruoyi.common.core.domain.entity.RlUserVO;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.wx.domain.NotifyEventType;
import com.ruoyi.common.utils.DateUtils;
@ -12,8 +14,11 @@ import com.ruoyi.system.domain.EtCallbackLog;
import com.ruoyi.system.domain.changeBalance.RlChangeBalance;
import com.ruoyi.system.domain.channel.ChannelVO;
import com.ruoyi.system.domain.deliveryOrder.RlDeliveryOrder;
import com.ruoyi.system.domain.dividendDetail.RlDividendDetail;
import com.ruoyi.system.domain.order.RlOrder;
import com.ruoyi.system.domain.refund.RlRefund;
import com.ruoyi.system.domain.userExt.RlUserExt;
import com.ruoyi.system.domain.vo.RlUserQuery;
import com.ruoyi.system.mapper.EtCallbackLogMapper;
import com.ruoyi.system.service.*;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
@ -34,7 +39,9 @@ import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -50,9 +57,6 @@ public class CallbackServiceImpl implements CallbackService {
@Resource
private IRlOrderService orderService;
@Autowired
private IRlFeeRuleService feeRuleService;
@Resource
private IRlRefundService etRefundService;
@ -77,6 +81,12 @@ public class CallbackServiceImpl implements CallbackService {
@Autowired
private IRlDeliveryOrderService deliveryOrderService;
@Resource
private IRlDividendDetailService dividendDetailService;
@Resource
private IRlUserExtService userExtService;
/**
* 微信支付回调
@ -115,37 +125,37 @@ public class CallbackServiceImpl implements CallbackService {
*/
@Override
public void businessHandle(String outTradeNo,String payType) {
// 充值成功后的业务处理
RlOrder order = orderService.selectRlOrderByOutTradeNo(outTradeNo);
// 充值成功后的业务处理 原订单
RlOrder originalOrder = orderService.selectRlOrderByOutTradeNo(outTradeNo);
RlOrder updateOrder = new RlOrder();
updateOrder.setOrderId(order.getOrderId());
logger.info("【微信支付回调】订单信息 : " + JSON.toJSONString(order));
Long payChannel = order.getPayChannel();
updateOrder.setOrderId(originalOrder.getOrderId());
logger.info("【微信支付回调】订单信息 : " + JSON.toJSONString(originalOrder));
Long payChannel = originalOrder.getPayChannel();
ChannelVO channelVO = rlChannelService.selectSmChannelByChannelId(payChannel);
logger.info("【微信支付回调】租赁订单支付");
Boolean execute = transactionTemplate.execute(e -> {
/** 生成账变记录*/
generateChanggeBalance(order);
generateChanggeBalance(originalOrder);
updateOrder.setPaid("1");
updateOrder.setPayTime(DateUtils.getNowDate());
updateOrder.setPayType(payType);
if(order.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_SELF_PICKUP)){
if(originalOrder.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_SELF_PICKUP)){
updateOrder.setStatus(ServiceConstants.ORDER_STATUS_TO_BE_TAKEN);
}else{
updateOrder.setStatus(ServiceConstants.ORDER_STATUS_TO_BE_SENT);
}
updateOrder.setCost(getCost(channelVO,order.getPayFee()));
updateOrder.setCost(getCost(channelVO,originalOrder.getPayFee()));
/** 如果是续租的订单,结束原订单*/
if(order.getType().equals(ServiceConstants.ORDER_TYPE_RELET)){
closeOriginalOrder(order, updateOrder);
if(originalOrder.getType().equals(ServiceConstants.ORDER_TYPE_RELET)){
closeOriginalOrder(originalOrder, updateOrder);
}else{
// 如果是免费送取车或收费送取车则创建新的配送工单
if(order.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_FREE_DELIVERY_CAR) || order.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_CHARGE_DELIVERY_CAR)){
if(originalOrder.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_FREE_DELIVERY_CAR) || originalOrder.getDeliveryMethod().equals(ServiceConstants.DELIVERY_METHOD_CHARGE_DELIVERY_CAR)){
/** 创建配送工单,状态为:待接单 */
createDeliveryOrder(order, updateOrder);
createDeliveryOrder(originalOrder, updateOrder);
}
}
logger.info("=================【微信支付回调】开始更新订单信息=================={}",JSON.toJSON(updateOrder));
@ -154,12 +164,49 @@ public class CallbackServiceImpl implements CallbackService {
logger.error("【微信支付回调】更新订单信息失败");
throw new ServiceException("【微信支付回调】更新订单信息失败");
}
/** 计算分成 所有合伙人的分成明细*/
calculationDividend(originalOrder);
logger.info("=================【微信支付回调】全部结束!!!!!==================");
return Boolean.TRUE;
});
if(!execute)throw new ServiceException("微信支付回调失败");
}
private void calculationDividend(RlOrder originalOrder) {
RlUserExt rlUserExt = userExtService.selectRlUserExtByUserId(originalOrder.getMerchantId());
RlUser rlUser = userService.selectUserById(rlUserExt.getUserId());
RlDividendDetail rlDividendDetail = new RlDividendDetail();
rlDividendDetail.setAgentId(originalOrder.getAgentId());
rlDividendDetail.setPartnerId(rlUserExt.getUserId());
rlDividendDetail.setOrderNo(originalOrder.getOrderNo());
rlDividendDetail.setTotalAmount(originalOrder.getPayFee());
BigDecimal needDividendAmount = originalOrder.getLeaseFee().add(originalOrder.getOverdueFee());//租赁费和逾期费进行分成
logger.info("【微信支付回调】租赁费和逾期费进行分成============"+needDividendAmount);
// 保留两位小数点
BigDecimal dividendAmount = rlUserExt.getDividendProportion().multiply(needDividendAmount)
.setScale(2, RoundingMode.HALF_UP);
logger.info("【微信支付回调】计算出来的分成金额===分成人{}========="+needDividendAmount,rlUserExt.getUserId());
rlDividendDetail.setDividendAmount(dividendAmount);
rlDividendDetail.setDividendProportion(rlUserExt.getDividendProportion());
rlDividendDetail.setCreateTime(DateUtils.getNowDate());
rlDividendDetail.setPartnerName(rlUser.getUserName());
rlDividendDetail.setPartnerPhone(rlUser.getPhonenumber());
rlDividendDetail.setPartnerType(rlUser.getUserType());
int i = dividendDetailService.insertRlDividendDetail(rlDividendDetail);
if(i>0){
logger.info("=================【微信支付回调】计算合作人分成成功==================");
}
}
// private List<RlUserVO> getPartnerList(Long merchantId) {
// RlUserQuery rlUserQuery = new RlUserQuery();
// String[] typeList = {"02","03"};
// rlUserQuery.setTypeList(typeList);
// rlUserQuery.setAgentId(agentId);
// List<RlUserVO> list = eUserService.selectUserList(rlUserQuery);
// return list;
// }
/** 创建配送工单 */
private void createDeliveryOrder(RlOrder order, RlOrder updateOrder) {
RlDeliveryOrder deliveryOrder = new RlDeliveryOrder();

View File

@ -7,6 +7,7 @@ import com.ruoyi.system.service.IRlOrderOperService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
/**
@ -93,4 +94,22 @@ public class RlOrderOperServiceImpl implements IRlOrderOperService
{
return rlOrderOperMapper.deleteRlOrderOperByOperId(operId);
}
@Override
public boolean recordOrderHistory(String orderNo, String type, String beforeStatus,String afterStatus, BigDecimal beforeAmount,BigDecimal afterAmount,Long userId,String phone,String detail) {
RlOrderOper rlOrderOper = new RlOrderOper();
rlOrderOper.setOrderNo(orderNo);
rlOrderOper.setOperType(type);
rlOrderOper.setBeforeAmount(beforeAmount.toString());
rlOrderOper.setAfterAmount(afterAmount.toString());
rlOrderOper.setBeforeStatus(beforeStatus);
rlOrderOper.setAfterStatus(afterStatus);
rlOrderOper.setOperUserId(userId);
rlOrderOper.setOperPhone(phone);
rlOrderOper.setCreateTime(DateUtils.getNowDate());
rlOrderOper.setDetails(detail);
return false;
}
}

View File

@ -23,6 +23,7 @@ import com.ruoyi.system.domain.order.RlOrderQuery;
import com.ruoyi.system.domain.order.RlOrderVO;
import com.ruoyi.system.domain.orderOper.RlOrderOper;
import com.ruoyi.system.domain.refund.RlRefund;
import com.ruoyi.system.domain.refund.RlRefundVO;
import com.ruoyi.system.domain.rule.RlFeeRule;
import com.ruoyi.system.domain.store.StoreVo;
import com.ruoyi.system.domain.userExt.RlUserExt;
@ -105,6 +106,9 @@ public class RlOrderServiceImpl implements IRlOrderService
@Resource
private IRlDividendDetailService rlDividendDetailService;
@Autowired
private IRlOrderOperService orderOperService;
/**
* 查询订单
*
@ -173,14 +177,35 @@ public class RlOrderServiceImpl implements IRlOrderService
order.setRule(feeRule);
/** 操作记录*/
RlOrderOper orderOper = new RlOrderOper();
orderOper.setOrderNo(orderNo);
List<RlOrderOper> rlOrderOpers = rlOrderOperService.selectRlOrderOperList(new RlOrderOper());
order.setOrderOpers(rlOrderOpers);
/** 收益明细*/
List<RlDividendDetail> rlDividendDetails = rlDividendDetailService.selectRlDividendDetailList(new RlDividendDetail());
RlDividendDetail rlDividendDetail = new RlDividendDetail();
rlDividendDetail.setOrderNo(orderNo);
List<RlDividendDetail> rlDividendDetails = rlDividendDetailService.selectRlDividendDetailList(rlDividendDetail);
order.setRlDividendDetails(rlDividendDetails);
/** 显示可退款金额 根据订单号查询可退款金额 refundableAmount*/
getRefundable(orderNo, order);
return order;
}
private void getRefundable(String orderNo, RlOrderVO order) {
RlRefundVO refundVO = refundService.getRefundedAmount(orderNo);
BigDecimal refundableAmount = order.getPayFee().subtract(refundVO.getTotalRefundAmount());
BigDecimal refundableDispatchFee = order.getDispatchFee().subtract(refundVO.getTotalDispatchFee());
BigDecimal refundableDeliveryFee = order.getDeliveryFee().subtract(refundVO.getTotalDeliveryFee());
BigDecimal refundableDeposit = order.getDeposit().subtract(refundVO.getTotalDeposit());
BigDecimal refundableLeaseFee = order.getLeaseFee().subtract(refundVO.getTotalLeaseFee());
order.setRefundableTotalAmount(refundableAmount);
order.setRefundableDispatchFee(refundableDispatchFee);
order.setRefundableDeliveryFee(refundableDeliveryFee);
order.setRefundableDeposit(refundableDeposit);
order.setRefundableLeaseFee(refundableLeaseFee);
}
/**
* 查询订单列表
*
@ -495,6 +520,12 @@ public class RlOrderServiceImpl implements IRlOrderService
rlOrder.setOrderNo(orderNo);
rlOrder.setDeductionAmount(money);
int i = orderMapper.updateRlOrderByOrderNo(rlOrder);
/** 记录订单履历 */
RlOrderVO orde = orderMapper.selectRlOrderByOrderNo(orderNo);
if(orderOperService.recordOrderHistory(orderNo,ServiceConstants.ORDER_OPERATION_DEDUCTION,
orde.getStatus(),orde.getStatus(),orde.getPayFee(),orde.getPayFee(),orde.getUserId(),orde.getPhone(),"车损扣款:扣款金额:"+money+",实际押金退款:"+orde.getDeposit()+"-"+money)){
throw new ServiceException("【改价】更新订单信息失败");
}
return i>0;
}

View File

@ -4,11 +4,13 @@ import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.order.RlOrder;
import com.ruoyi.system.domain.refund.RlRefund;
import com.ruoyi.system.domain.refund.RlRefundVO;
import com.ruoyi.system.mapper.RlRefundMapper;
import com.ruoyi.system.service.IRlRefundService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
/**
@ -154,4 +156,15 @@ public class RlRefundServiceImpl implements IRlRefundService
public List<RlOrder> checkUserDeposit(Long userId) {
return etRefundMapper.checkUserDeposit(userId);
}
/**
* 统计已退款金额
*
* @param orderNo 订单号
* @return 结果
*/
@Override
public RlRefundVO getRefundedAmount(String orderNo) {
return etRefundMapper.getRefundedAmount(orderNo);
}
}

View File

@ -34,6 +34,14 @@ public interface RlStoreService
*/
public List<StoreVo> selectSmStoreList(StoreQuery store);
/**
* 根据代理商id查询店铺列表
*
* @param agentId 代理商id
* @return 商户集合
*/
public List<StoreVo> selectSmStoreListByAgentId(Long agentId);
/**
* 根据商户查询店铺列表列表
*

View File

@ -129,6 +129,22 @@ public class StoreServiceImpl implements RlStoreService
return storeVos;
}
/**
* 根据代理商id查询店铺列表
*
* @param agentId 店铺
* @return 店铺
*/
@Override
public List<StoreVo> selectSmStoreListByAgentId(Long agentId)
{
StoreQuery storeQuery = new StoreQuery();
storeQuery.setAgentId(agentId);
List<StoreVo> storeVos = storeMapper.selectSmStoreList(storeQuery);
return storeVos;
}
/**
* 根据商户查询店铺列表列表
*

View File

@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select do.delivery_id, do.order_no, do.agent_id, do.deliveryman_id, do.deliveryman_type,
do.deliveryman, do.deliveryman_phone, do.status, do.create_time,s.lng,s.lat,s.address,
do.store_id, do.store_name, do.delivery_address, do.delivery_lon, do.delivery_lat ,do.delivery_time,
o.order_id, o.type, o.status, o.phone, o.pay_time from rl_delivery_order do
o.order_id, o.type, o.status, o.phone, o.real_name, o.model, o.pay_time from rl_delivery_order do
left join rl_order o on o.order_no = do.order_no
left join rl_store s on s.store_id = do.store_id
</sql>

View File

@ -25,7 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select m.model_id, m.model, m.full_voltage, m.low_voltage,
m.full_endurance, m.create_by, m.create_time,
m.update_by, m.update_time, m.remark, m.intro, m.agent_id, m.deposit, m.picture, m.description from rl_model m
where m.agent_id = #{agentId}
where m.del_flag = '0' and m.agent_id = #{agentId}
</select>
<select id="selectEModelByModelId" parameterType="Long" resultMap="EModelResult">

View File

@ -7,7 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="RlOrderOper" id="RlOrderOperResult" autoMapping="true" />
<sql id="selectRlOrderOperVo">
select oper_id, order_no, oper_type, details, amount_change, status_change, oper_user_id, create_time, oper_phone from rl_order_oper
select oper_id, order_no, oper_type, details, before_amount, after_amount, before_status, after_status, oper_user_id, create_time, oper_phone from rl_order_oper
</sql>
<select id="selectRlOrderOperList" parameterType="RlOrderOper" resultMap="RlOrderOperResult">
@ -16,8 +16,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''"> and order_no = #{orderNo}</if>
<if test="operType != null and operType != ''"> and oper_type = #{operType}</if>
<if test="details != null and details != ''"> and details = #{details}</if>
<if test="amountChange != null "> and amount_change = #{amountChange}</if>
<if test="statusChange != null and statusChange != ''"> and status_change = #{statusChange}</if>
<if test="operUserId != null "> and oper_user_id = #{operUserId}</if>
<if test="operPhone != null and operPhone != ''"> and oper_phone = #{operPhone}</if>
</where>
@ -34,8 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="operType != null and operType != ''">oper_type,</if>
<if test="details != null">details,</if>
<if test="amountChange != null">amount_change,</if>
<if test="statusChange != null">status_change,</if>
<if test="beforeAmount != null">before_amount,</if>
<if test="afterAmount != null">after_amount,</if>
<if test="beforeStatus != null">before_status,</if>
<if test="afterStatus != null">after_status,</if>
<if test="operUserId != null">oper_user_id,</if>
<if test="createTime != null">create_time,</if>
<if test="operPhone != null">oper_phone,</if>
@ -44,8 +44,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="operType != null and operType != ''">#{operType},</if>
<if test="details != null">#{details},</if>
<if test="amountChange != null">#{amountChange},</if>
<if test="statusChange != null">#{statusChange},</if>
<if test="beforeAmount != null">#{beforeAmount},</if>
<if test="afterAmount != null">#{afterAmount},</if>
<if test="beforeStatus != null">#{beforeStatus},</if>
<if test="afterStatus != null">#{afterStatus},</if>
<if test="operUserId != null">#{operUserId},</if>
<if test="createTime != null">#{createTime},</if>
<if test="operPhone != null">#{operPhone},</if>
@ -58,8 +60,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
<if test="operType != null and operType != ''">oper_type = #{operType},</if>
<if test="details != null">details = #{details},</if>
<if test="amountChange != null">amount_change = #{amountChange},</if>
<if test="statusChange != null">status_change = #{statusChange},</if>
<if test="beforeAmount != null">before_amount = #{beforeAmount},</if>
<if test="afterAmount != null">after_amount = #{afterAmount},</if>
<if test="beforeStatus != null">before_status = #{beforeStatus},</if>
<if test="afterStatus != null">after_status = #{afterStatus},</if>
<if test="operUserId != null">oper_user_id = #{operUserId},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="operPhone != null">oper_phone = #{operPhone},</if>

View File

@ -4,7 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.RlRefundMapper">
<resultMap type="RlRefund" id="EtRefundResult" autoMapping="true" />
<resultMap type="RlRefundVO" id="EtRefundResult" autoMapping="true" />
<sql id="selectEtRefundVo">
select id, refund_no, order_no, user_id, amount, dispatch_fee, manage_fee, lease_fee, appointment_fee, type, reason, create_time, item_desc,refund_result from et_refund
@ -148,4 +148,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND o.type = 2 and o.user_id = #{userId}
AND ref.id IS NULL;
</select>
<select id="getRefundedAmount" resultMap="EtRefundResult">
SELECT
COALESCE(SUM(amount), 0) AS total_refund_amount,
COALESCE(SUM(dispatch_fee), 0) AS total_dispatch_fee,
COALESCE(SUM(delivery_fee), 0) AS total_delivery_fee,
COALESCE(SUM(lease_fee), 0) AS total_lease_fee,
COALESCE(SUM(deposit), 0) AS total_deposit
FROM
rl_refund
WHERE
order_no = #{orderNo};
</select>
</mapper>

View File

@ -21,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus, s.name storeName,s.store_id,
u.wxopenid from rl_user u
left join rl_user_ext ex on u.user_id = ex.user_id
left join rl_store s on s.user_id = u.user_id
left join rl_store s on s.merchant_id = u.user_id
where u.del_flag = '0'
<if test="userId != null and userId != 0">
AND u.user_id = #{userId}
@ -29,6 +29,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%')
</if>
<if test="agentId != null and agentId != 0">
AND ex.agent_id = #{agentId}
</if>
<if test="status != null and status != ''">
AND u.status = #{status}
</if>
@ -96,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="myAccountInfoByUserId" parameterType="Long" resultMap="EUserResult">
select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,
u.phonenumber, u.password, u.sex, u.status,
u.phonenumber, u.password, u.sex, u.status,u.user_type,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus
from rl_user u