|
|
@@ -1,5 +1,8 @@
|
|
|
package com.sqx.modules.order.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -7,6 +10,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.sqx.common.exception.SqxException;
|
|
|
+import com.sqx.common.sms.SmsSendResult;
|
|
|
+import com.sqx.common.utils.Constant;
|
|
|
import com.sqx.common.utils.DateUtils;
|
|
|
import com.sqx.common.utils.DistanceUtil;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
@@ -26,9 +31,13 @@ import com.sqx.modules.common.entity.CommonInfo;
|
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
|
import com.sqx.modules.coupon.dao.TbCouponUserDao;
|
|
|
import com.sqx.modules.coupon.entity.TbCouponUser;
|
|
|
+import com.sqx.modules.datacentre.entity.SysUserShop;
|
|
|
import com.sqx.modules.errand.dao.TbIndentDao;
|
|
|
import com.sqx.modules.errand.entity.TbIndent;
|
|
|
+import com.sqx.modules.errand.entity.TbIndentSmsSendLog;
|
|
|
import com.sqx.modules.errand.service.TbIndentService;
|
|
|
+import com.sqx.modules.errand.service.TbIndentSmsSendLogService;
|
|
|
+import com.sqx.modules.errand.service.TbIndentSmsTemplateService;
|
|
|
import com.sqx.modules.goods.dao.GoodsDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
|
@@ -42,6 +51,7 @@ import com.sqx.modules.message.entity.MessageInfo;
|
|
|
import com.sqx.modules.order.dao.AppOrderDao;
|
|
|
import com.sqx.modules.order.dao.EvaluateDao;
|
|
|
import com.sqx.modules.order.dao.OrderGoodsDao;
|
|
|
+import com.sqx.modules.order.dto.OrderFinishByShopDTO;
|
|
|
import com.sqx.modules.order.entity.Evaluate;
|
|
|
import com.sqx.modules.order.entity.OrderGoods;
|
|
|
import com.sqx.modules.order.entity.TbOrder;
|
|
|
@@ -52,11 +62,14 @@ import com.sqx.modules.pay.entity.PayDetails;
|
|
|
import com.sqx.modules.pay.service.WxErrService;
|
|
|
import com.sqx.modules.shop.service.ShopMessageService;
|
|
|
import com.sqx.modules.sys.dao.SysUserRoleDao;
|
|
|
+import com.sqx.modules.sys.entity.SysUserEntity;
|
|
|
+import com.sqx.modules.sys.service.SysUserService;
|
|
|
import com.sqx.modules.utils.SenInfoCheckUtil;
|
|
|
import com.sqx.modules.utils.excel.ExcelData;
|
|
|
import com.sqx.modules.utils.fieYun.FeiYunUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -126,6 +139,13 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
private AddressService addressService;
|
|
|
@Autowired
|
|
|
private ShopMessageService shopMessageService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ private TbIndentSmsSendLogService smsSendLogService;
|
|
|
+ @Autowired
|
|
|
+ private TbIndentSmsTemplateService smsTemplateService;
|
|
|
+
|
|
|
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);
|
|
|
|
|
|
@Override
|
|
|
@@ -474,6 +494,69 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void finishOrderByShop(OrderFinishByShopDTO orderFinishByShopDTO) {
|
|
|
+ Long orderId = orderFinishByShopDTO.getOrderId();
|
|
|
+ TbOrder order = getById(orderId);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(order)) {
|
|
|
+ throw new SqxException("无效的订单id");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(order.getAutoSendOrder()!=null && order.getAutoSendOrder()==1){
|
|
|
+ throw new SqxException("当前订单为自动派单,不能手动完成!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (order.getStatus().equals(4)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long shopId = order.getShopId();
|
|
|
+ SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ List<SysUserShop> sysUserShops = sysUserService.selectShopId(currentUser.getUserId());
|
|
|
+ if (CollUtil.isEmpty(sysUserShops) || !sysUserShops.stream().filter(e -> e.getShopId().longValue() == shopId.longValue()).findFirst().isPresent()) {
|
|
|
+ throw new SqxException("没有操作权限,只能操作完成自己店铺订单!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Constant.YES.equals(orderFinishByShopDTO.getSendSmsFlag())) {
|
|
|
+ TbIndent indent = tbIndentService.getOne(new QueryWrapper<TbIndent>().eq("order_id", orderId));
|
|
|
+ if (ObjectUtil.isNull(indent)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是外卖订单
|
|
|
+ if (ObjectUtil.equal(indent.getIndentType(), "5")) {
|
|
|
+ Long smsTemplateId = orderFinishByShopDTO.getSmsTemplateId();
|
|
|
+ if (ObjectUtil.isNull(smsTemplateId)) {
|
|
|
+ throw new SqxException("短信模板id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收货人手机
|
|
|
+ String userPhone = indent.getUserPhone();
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(userPhone)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 店铺信息
|
|
|
+ GoodsShop goodsShop = goodsShopDao.selectById(shopId);
|
|
|
+
|
|
|
+ // 发送短信并记录短信发送记录
|
|
|
+ SmsSendResult smsSendResult = smsTemplateService.sendSms(smsTemplateId, goodsShop.getPhone(), goodsShop.getShopName(), goodsShop.getShopId(), userPhone);
|
|
|
+
|
|
|
+ // sourceType 1骑手、2商家
|
|
|
+ smsSendLogService.saveLog(indent.getIndentId(), "2", smsSendResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(orderFinishByShopDTO.getImgs())) {
|
|
|
+ order.setDeliveryImgs(orderFinishByShopDTO.getImgs());
|
|
|
+ updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ accomplishOrder(orderId);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户钱包新增消费记录
|
|
|
* @param order 订单信息
|
|
|
@@ -1566,8 +1649,8 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
return Result.success();
|
|
|
}
|
|
|
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ TbIndent indent = tbIndentService.getOne(new QueryWrapper<TbIndent>().eq("order_id", orderId));
|
|
|
if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder().equals(0)) {
|
|
|
- TbIndent indent = tbIndentService.getOne(new QueryWrapper<TbIndent>().eq("order_id", orderId));
|
|
|
if (type==1){
|
|
|
if (indent == null || !"4".equals(indent.getIndentState())) {
|
|
|
log.info("订单id【{}】,请等待骑手送达!", orderId);
|
|
|
@@ -1619,8 +1702,24 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
|
|
|
errandMoney = tbOrder.getErrandMoney();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ // 商家配送短信服务费
|
|
|
+ BigDecimal smsSendMoney = BigDecimal.ZERO;
|
|
|
+ if(tbOrder.getAutoSendOrder()!=null && tbOrder.getAutoSendOrder() == 1) {
|
|
|
+ // 查询短信发送结果
|
|
|
+ if (ObjectUtil.isNotNull(indent)) {
|
|
|
+ TbIndentSmsSendLog smsSendLog = smsSendLogService.getSendSuccessByOrderId(indent.getIndentId());
|
|
|
+ if (ObjectUtil.isNotNull(smsSendLog)) {
|
|
|
+ // 查询短信发送费用
|
|
|
+ CommonInfo commonInfo = commonInfoService.findOne(421);
|
|
|
+
|
|
|
+ smsSendMoney = new BigDecimal(commonInfo.getValue());
|
|
|
+ sumMoney = sumMoney.subtract(smsSendMoney);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
BigDecimal shopMoney = sumMoney.multiply(shopRate);
|
|
|
|
|
|
shopMoney = (shopMoney.setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
@@ -1655,28 +1754,28 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
//订单金额: 商家优惠券: 用户实付金额: 跑腿费: 平台服务费: 到账金额:(本单为商家优惠券,商家补贴)
|
|
|
if (shopIds == -1) {
|
|
|
//未使用优惠券
|
|
|
- userMoneyDetails1.setContent("订单金额:" + tbOrder.getPayMoney() + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",到账金额:" + shopMoney);
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + tbOrder.getPayMoney() + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney);
|
|
|
} else if (shopIds == 0) {
|
|
|
//使用平台优惠券
|
|
|
sumMoney = tbOrder.getPayMoney().add(couponMoney);
|
|
|
- userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",到账金额:" + shopMoney + "(本单为平台优惠券,平台补贴)");
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney + "(本单为平台优惠券,平台补贴)");
|
|
|
} else {
|
|
|
//使用商家优惠券
|
|
|
sumMoney = tbOrder.getPayMoney().add(couponMoney);
|
|
|
- userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",到账金额:" + shopMoney + "(本单为商家优惠券,商家补贴)");
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney + "(本单为商家优惠券,商家补贴)");
|
|
|
}
|
|
|
} else {
|
|
|
if (shopIds == -1) {
|
|
|
//未使用优惠券
|
|
|
- userMoneyDetails1.setContent("订单金额:" + tbOrder.getPayMoney() + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",到账金额:" + shopMoney);
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + tbOrder.getPayMoney() + ",用户实付金额:" + tbOrder.getPayMoney() + ",其中跑腿费:" + errandMoney + "(" + tbOrder.getErrandMoneyIsShop() + "),平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney);
|
|
|
} else if (shopIds == 0) {
|
|
|
//使用平台优惠券
|
|
|
sumMoney = tbOrder.getPayMoney().add(couponMoney);
|
|
|
- userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",平台服务费:" + pingRate + ",到账金额:" + shopMoney + "(本单为平台优惠券,平台补贴)");
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney + "(本单为平台优惠券,平台补贴)");
|
|
|
} else {
|
|
|
//使用商家优惠券
|
|
|
sumMoney = tbOrder.getPayMoney().add(couponMoney);
|
|
|
- userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",平台服务费:" + pingRate + ",到账金额:" + shopMoney + "(本单为商家优惠券,商家补贴)");
|
|
|
+ userMoneyDetails1.setContent("订单金额:" + sumMoney + ",优惠券金额:" + couponMoney + ",用户实付金额:" + tbOrder.getPayMoney() + ",平台服务费:" + pingRate + ",短信服务费:" + smsSendMoney + ",到账金额:" + shopMoney + "(本单为商家优惠券,商家补贴)");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1713,7 +1812,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
UserEntity userEntity = userDao.selectById(tbOrder.getUserId());
|
|
|
SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 1);
|
|
|
userService.pushToSingle("订单完成", "您的订单已完成,欢迎下次光临!", userEntity.getClientid());
|
|
|
- TbIndent indent = tbIndentService.getOne(new QueryWrapper<TbIndent>().eq("order_id", orderId));
|
|
|
String shopTemplate = commonInfoService.findOne(354).getValue();
|
|
|
List<String> msgListShop = new ArrayList<>();
|
|
|
msgListShop.add(indent.getIndentNumber());
|