顺丰同城状态异步回调,增加确认收货流程
This commit is contained in:
parent
4f62b2aa2f
commit
17223ff49c
119
ShopOrderBaseServiceImpl.java
Normal file
119
ShopOrderBaseServiceImpl.java
Normal file
@ -0,0 +1,119 @@
|
||||
/**
|
||||
* 确认收货处理
|
||||
* @param order_ids 订单ID列表
|
||||
* @param order_rows 订单数据列表
|
||||
* @return 是否处理成功
|
||||
*/
|
||||
public boolean receive(List<String> order_ids, List<ShopOrderBase> order_rows) {
|
||||
// 检测数据是否合法,过滤允许修改的数据
|
||||
if (CollUtil.isEmpty(order_ids)) {
|
||||
throw new ApiException(I18nUtil._("请选择需要确认收货的订单!"));
|
||||
}
|
||||
|
||||
if (CollUtil.isEmpty(order_rows)) {
|
||||
order_rows = gets(order_ids);
|
||||
}
|
||||
|
||||
List<String> receive_id_row = new ArrayList<>();
|
||||
|
||||
for (ShopOrderBase order_row : order_rows) {
|
||||
// 判断订单是否可以确认收货
|
||||
if (ifReceive(order_row.getOrder_state_id())) {
|
||||
receive_id_row.add(order_row.getOrder_id());
|
||||
|
||||
// 增加积分和经验
|
||||
// todo 目前付款支付积分,此处为收货后发放
|
||||
Integer user_id = order_row.getBuyer_user_id();
|
||||
String order_id = order_row.getOrder_id();
|
||||
Integer store_id = order_row.getStore_id();
|
||||
|
||||
ShopOrderData order_data_row = shopOrderDataService.get(order_id);
|
||||
BigDecimal order_points_add = order_data_row.getOrder_points_add();
|
||||
|
||||
BigDecimal order_points_add_all = order_points_add.add(order_data_row.getOrder_double_points_add());
|
||||
|
||||
// 发放购物积分
|
||||
if (CheckUtil.isNotEmpty(order_points_add_all)) {
|
||||
String desc = String.format(I18nUtil._("购物获取积分 %s,订单号 %s"), order_points_add_all, order_id);
|
||||
if (!payService.points(user_id, order_points_add_all, PointsType.POINTS_TYPE_CONSUME, desc, store_id, null, order_id)) {
|
||||
throw new ApiException(I18nUtil._("积分操作失败!"));
|
||||
}
|
||||
}
|
||||
|
||||
// todo 根据送花郎插件是否开启显示是否需要分钱给不同商户
|
||||
/*
|
||||
boolean hall_enable = accountBaseConfigService.getConfig("hall_enable", false);
|
||||
if (hall_enable) {
|
||||
BigDecimal order_commission_fee = order_data_row.getOrder_commission_fee();
|
||||
sendMoneyForTransfer(order_row, order_commission_fee);
|
||||
}
|
||||
*/
|
||||
|
||||
// 分销功能处理
|
||||
String fx_settle_type = accountBaseConfigService.getConfig("fx_settle_type", "receive");
|
||||
if (StrUtil.equals(fx_settle_type, "receive")) {
|
||||
// todo settleDistributionUserOrder
|
||||
shopDistributionUserOrderService.settleDistributionUserOrder(order_id);
|
||||
}
|
||||
|
||||
// 重要:拉卡拉给平台和代理商分账
|
||||
Pair<Boolean, String> retOrderSeparateRet = lakalaApiService.innerDoOrderSeparate(order_row.getOrder_id(), Convert.toStr(order_row.getStore_id()));
|
||||
if (!retOrderSeparateRet.getFirst()) {
|
||||
throw new ApiException(I18nUtil._("平台或代理商分账失败: " + retOrderSeparateRet.getSecond()));
|
||||
}
|
||||
|
||||
// 统计总营业额
|
||||
ShopStoreAnalytics analytics_row = shopStoreAnalyticsService.get(store_id);
|
||||
BigDecimal order_payment_amount = order_row.getOrder_payment_amount();
|
||||
analytics_row.setStore_trade_amount(NumberUtil.add(analytics_row.getStore_trade_amount(), order_payment_amount));
|
||||
if (!shopStoreAnalyticsService.edit(analytics_row)) {
|
||||
throw new ApiException(ResultCode.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否有符合条件的订单
|
||||
if (CollUtil.isEmpty(receive_id_row)) {
|
||||
throw new ApiException(I18nUtil._("无符合确认收货条件的订单!"));
|
||||
}
|
||||
|
||||
// 修改订单状态, 随机去一个订单获取店铺编号
|
||||
ShopOrderBase shopOrderBase = order_rows.get(0);
|
||||
Integer store_id = shopOrderBase.getStore_id();
|
||||
editNextState(receive_id_row, store_id, StateCode.ORDER_STATE_SHIPPED, order_rows, 0);
|
||||
|
||||
// 如果是商家,且启用供应商,则商家看到供应商店铺商品 store_type = 2
|
||||
boolean ifSupplierMarket = accountBaseConfigService.ifSupplierMarket();
|
||||
UserDto user = getCurrentUser();
|
||||
store_id = user != null ? Convert.toInt(user.getStore_id(), 0) : 0;
|
||||
|
||||
// 处理供应商市场的库存增加逻辑
|
||||
if (ifSupplierMarket && CheckUtil.isNotEmpty(store_id)) {
|
||||
// 供应商商品,增加商家库存
|
||||
QueryWrapper<ShopOrderItem> itemQueryWrapper = new QueryWrapper<>();
|
||||
itemQueryWrapper.in("order_id", receive_id_row);
|
||||
List<ShopOrderItem> order_item_rows = shopOrderItemService.find(itemQueryWrapper);
|
||||
|
||||
List<Long> item_src_ids = order_item_rows.stream().map(ShopOrderItem::getItem_id).distinct().collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(item_src_ids)) {
|
||||
QueryWrapper<ShopProductItem> productItemQueryWrapper = new QueryWrapper<>();
|
||||
productItemQueryWrapper.in("item_src_id", item_src_ids).eq("store_id", store_id);
|
||||
List<ShopProductItem> product_item_rows = shopProductItemService.find(productItemQueryWrapper);
|
||||
|
||||
// 更新供应商商品库存
|
||||
for (ShopProductItem product_item_row : product_item_rows) {
|
||||
String item_src_id = product_item_row.getItem_src_id();
|
||||
Optional<ShopOrderItem> orderItemOpl = order_item_rows.stream().filter(s -> ObjectUtil.equal(s.getItem_id(), item_src_id)).findFirst();
|
||||
if (orderItemOpl.isPresent()) {
|
||||
ShopOrderItem shopOrderItem = orderItemOpl.get();
|
||||
Integer order_item_quantity = shopOrderItem.getOrder_item_quantity();
|
||||
product_item_row.setItem_quantity(product_item_row.getItem_quantity() + order_item_quantity);
|
||||
if (!shopProductItemService.edit(product_item_row)) {
|
||||
throw new ApiException(ResultCode.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -104,7 +104,6 @@ public class ShopOrderBaseController extends BaseControllerImpl {
|
||||
return shopOrderBaseService.cancel(order_id);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "确认收货", notes = "确认收货")
|
||||
@RequestMapping(value = "/receive", method = {RequestMethod.GET, RequestMethod.POST})
|
||||
public CommonResult receive(@RequestParam(name = "order_id") String order_id) {
|
||||
|
||||
@ -4793,7 +4793,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* 确认收货 (c端和管理端调用)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ -4811,6 +4811,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
throw new ApiUserException(I18nUtil._("用户信息异常!"));
|
||||
}
|
||||
|
||||
// 当前登录用户id和所有店铺
|
||||
Integer user_id = user.getId();
|
||||
Integer store_id = Convert.toInt(user.getStore_id());
|
||||
|
||||
@ -4834,6 +4835,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
List<ShopOrderBase> baseList = new ArrayList<>();
|
||||
|
||||
if (CollUtil.isNotEmpty(order_info_rows)) {
|
||||
// 过重供应商代发订单
|
||||
dist_order_id = order_info_rows.stream().map(ShopOrderInfo::getOrder_id).distinct().collect(Collectors.toList());
|
||||
baseList = shopOrderBaseService.gets(dist_order_id);
|
||||
}
|
||||
@ -4856,6 +4858,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
receive(order_ids, orderBaseList);
|
||||
|
||||
if (CollUtil.isNotEmpty(order_info_rows) && CollUtil.isNotEmpty(dist_order_id)) {
|
||||
// 供应商代发订单 确认收货
|
||||
receive(order_ids, baseList);
|
||||
}
|
||||
|
||||
@ -4918,6 +4921,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
List<String> receive_id_row = new ArrayList<>();
|
||||
|
||||
for (ShopOrderBase order_row : order_rows) {
|
||||
// 是否允许确认收货?
|
||||
if (ifReceive(order_row.getOrder_state_id())) {
|
||||
receive_id_row.add(order_row.getOrder_id());
|
||||
|
||||
@ -5016,7 +5020,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单确认收货
|
||||
* 订单确认收货(定时任务用途)
|
||||
*
|
||||
* @param order_id 订单id
|
||||
*/
|
||||
@ -8296,20 +8300,26 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
/**
|
||||
* 自动确认收货
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public void autoReceive() {
|
||||
// 2. 更新为确认收货
|
||||
List<String> order_id_receipt = shopOrderInfoService.getAutoFinishOrderId();
|
||||
if (CollUtil.isNotEmpty(order_id_receipt)) {
|
||||
if (CollUtil.isEmpty(order_id_receipt)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String order_id : order_id_receipt) {
|
||||
try {
|
||||
if (!shopOrderBaseService.receive(Collections.singletonList(order_id), null)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认出错"), order_id));
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货出错"), order_id));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认出错"), order_id), e);
|
||||
}
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货发生异常"), order_id), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,15 +181,19 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得可以取消订单id: 订单必须为待付款状态 且 未付款 且 超时, 订货等等不是必须付款的忽略。
|
||||
* 获取能自动确认收货的订单号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getAutoFinishOrderId() {
|
||||
QueryWrapper<ShopOrderInfo> queryWrapper = new QueryWrapper<>();
|
||||
// 已发货,已签收
|
||||
queryWrapper.in("order_state_id", StateCode.ORDER_STATE_SHIPPED, StateCode.ORDER_STATE_RECEIVED);
|
||||
Float order_autofinish_time = accountBaseConfigService.getConfig("order_autofinish_time", 10f);
|
||||
|
||||
// 默认7天,自动收货
|
||||
// 配置了发货或已签收的订单,1天自动收货
|
||||
Float order_autofinish_time = accountBaseConfigService.getConfig("order_autofinish_time", 7f);
|
||||
int second = NumberUtil.mul(order_autofinish_time, 24, 60, 60).intValue();
|
||||
long time = DateUtil.offsetSecond(new Date(), -second).getTime();
|
||||
queryWrapper.lt("order_deal_time", time);
|
||||
|
||||
@ -958,8 +958,11 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
// 顺丰同城状态:17-配送员妥投完单;
|
||||
pushRemark = "已完成配送";
|
||||
|
||||
// 通知微信用户确认收货
|
||||
// 通知微信用户确认收货(同城配送不能调用微信的确认收货)
|
||||
// wxOrderShippingService.notifyConfirmReceive(shopStoreSfOrder.getShop_order_id());
|
||||
// 订单确认收货
|
||||
shopOrderBaseService.receive(shopStoreSfOrder.getShop_order_id(), null);
|
||||
|
||||
}
|
||||
|
||||
success = shopOrderInfoService.changeOrderStatus(shopStoreSfOrder.getShop_order_id(), orderStatus, orderIsOutStatus, orderIsShippedStatus);
|
||||
@ -1057,14 +1060,18 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
// logger.debug("准备发送SSE消息...");
|
||||
// SseEmitterUtil.sendMessage(shopStoreSfOrder.getSf_order_id(), jsonData);
|
||||
|
||||
// 通知微信用户确认收货(同城配送不能调用该微信接口)
|
||||
// wxOrderShippingService.notifyConfirmReceive(shopStoreSfOrder.getShop_order_id());
|
||||
|
||||
// 订单确认收货
|
||||
shopOrderBaseService.receive(shopStoreSfOrder.getShop_order_id(), null);
|
||||
|
||||
// 消息推送
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("category", CommonConstant.PUSH_MSG_CATE_MCH_ORDER_DETAIL);
|
||||
payload.put("orderId", orderId);
|
||||
pushMessageService.noticeMerchantEmployeeOrderAction(null, orderId, "", "顺丰同城订单[" + orderId + "]已完成配送。", null);
|
||||
|
||||
// 通知微信用户确认收货
|
||||
// wxOrderShippingService.notifyConfirmReceive(shopStoreSfOrder.getShop_order_id());
|
||||
|
||||
return new ThirdApiRes().success("success");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user