|
|
@@ -57,6 +57,9 @@ import com.sqx.modules.goods.entity.Goods;
|
|
|
import com.sqx.modules.goods.entity.GoodsShop;
|
|
|
import com.sqx.modules.goods.entity.GoodsShopRelevancy;
|
|
|
import com.sqx.modules.goods.entity.GoodsSku;
|
|
|
+import com.sqx.modules.integral.dao.UserIntegralDao;
|
|
|
+import com.sqx.modules.integral.dao.UserIntegralDetailsDao;
|
|
|
+import com.sqx.modules.integral.entity.UserIntegralDetails;
|
|
|
import com.sqx.modules.message.dao.MessageInfoDao;
|
|
|
import com.sqx.modules.message.entity.MessageInfo;
|
|
|
import com.sqx.modules.order.dao.AppOrderDao;
|
|
|
@@ -181,6 +184,10 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
private AliPayController aliPayController;
|
|
|
@Autowired
|
|
|
private PlatformTransactionManager transactionManager;
|
|
|
+ @Autowired
|
|
|
+ private UserIntegralDao userIntegralDao;
|
|
|
+ @Autowired
|
|
|
+ private UserIntegralDetailsDao userIntegralDetailsDao;
|
|
|
|
|
|
@Resource
|
|
|
private RedissonClient redissonClient;
|
|
|
@@ -624,11 +631,8 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
// 开启编程式事务
|
|
|
status = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
|
|
|
|
|
- // 计算订单顺序号
|
|
|
- order.setOrderSequence(String.format("%04d", selectCurrentOrderSequenceByShopId(order, order.getShopId())));
|
|
|
-
|
|
|
- // 更新订单状态
|
|
|
- updateById(order);
|
|
|
+ // 更新订单状态及订单序号
|
|
|
+ updateOrderStatusAndSequence(order);
|
|
|
|
|
|
// 扣减库存
|
|
|
this.subStock(order);
|
|
|
@@ -639,6 +643,21 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
// 如果是支付宝或者微信支付,用户钱包新增消费记录
|
|
|
addConsumeRecordInUserMoneyDetail(order);
|
|
|
|
|
|
+ // 已接单状态的订单生成跑腿订单
|
|
|
+ if (order.getStatus() == 6) {
|
|
|
+ // 如果是外卖订单,则生成一个跑腿的订单
|
|
|
+ tbIndentService.insertIndent(order);
|
|
|
+
|
|
|
+ // 发送商家接单通知
|
|
|
+ MyGlobalThreadPool.execute(() -> {
|
|
|
+ try {
|
|
|
+ sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单:{},商家接单通知发送失败,失败原因:{}", order.getOrderId(), e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 在锁中提交事务
|
|
|
transactionManager.commit(status);
|
|
|
} catch (Exception e) {
|
|
|
@@ -660,22 +679,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 已接单状态的订单生成跑腿订单
|
|
|
- if (order.getStatus() == 6) {
|
|
|
- // 如果是外卖订单,则生成一个跑腿的订单
|
|
|
- tbIndentService.insertIndent(order);
|
|
|
-
|
|
|
- // 发送商家接单通知
|
|
|
- MyGlobalThreadPool.execute(() -> {
|
|
|
- try {
|
|
|
- sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("订单:{},商家接单通知发送失败,失败原因:{}", order.getOrderId(), e);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
// 订单已接单或者当前订单为预约订单时打印小票
|
|
|
if (order.getStatus() == 6 || reservationFlag) {
|
|
|
// 打印小票
|
|
|
@@ -2070,6 +2073,53 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
} else if (shopIds != -1) {
|
|
|
contentBuffer.append("(本单为商家优惠券,商家补贴)");
|
|
|
}
|
|
|
+ //计算积分
|
|
|
+ String flag=commonInfoService.findOne(436).getValue();
|
|
|
+ if("1".equals(flag)){
|
|
|
+ try {
|
|
|
+ UserIntegralDetails userIntegralDetails = new UserIntegralDetails();
|
|
|
+ String rules=commonInfoService.findOne(437).getValue();
|
|
|
+ //积分过期规则 -1永不过期
|
|
|
+// String overdue= commonInfoService.findOne(438).getValue();
|
|
|
+ String maxIntegral= commonInfoService.findOne(439).getValue();
|
|
|
+ String[] split = rules.split(",",5);
|
|
|
+ int am1= Integer.parseInt(split[0]);
|
|
|
+ int av1 = Integer.parseInt(split[1]);
|
|
|
+ int mx= Integer.parseInt(split[2]);
|
|
|
+ int am2 = Integer.parseInt(split[3]);
|
|
|
+ int av2= Integer.parseInt(split[4]);
|
|
|
+ double amount= tbOrder.getPayMoney().doubleValue();
|
|
|
+ int intergral=0;
|
|
|
+ if (amount>am1){
|
|
|
+ if(amount<mx){
|
|
|
+ intergral=intergral+(int)(amount/am1)*av1;
|
|
|
+ } else if (amount>=mx+am2){
|
|
|
+ int count= (int) ((amount-mx)/am2);
|
|
|
+ intergral=intergral+(mx/am1)*av1+count*av2;
|
|
|
+ }else{
|
|
|
+ intergral=intergral+(mx/am1)*av1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int max =Math.min(Integer.parseInt(maxIntegral), intergral);
|
|
|
+ userIntegralDetails.setContent("完成订单获得积分");
|
|
|
+ userIntegralDetails.setClassify(4);
|
|
|
+ userIntegralDetails.setType(1);
|
|
|
+ userIntegralDetails.setNum(max);
|
|
|
+ userIntegralDetails.setOrderNumber(tbOrder.getOrderNumber());
|
|
|
+// if(!"-1".equals(overdue)){
|
|
|
+// Date expdata=DateUtils.addDateDays(new Date(), Integer.parseInt(overdue));
|
|
|
+// userIntegralDetails.setExpTime(new SimpleDateFormat("yyyy-MM-dd").format(expdata));
|
|
|
+// }
|
|
|
+
|
|
|
+ userIntegralDetails.setCreateTime(format);
|
|
|
+ userIntegralDetails.setUserId(tbOrder.getUserId());
|
|
|
+ userIntegralDetailsDao.insert(userIntegralDetails);
|
|
|
+ //添加积分
|
|
|
+ userIntegralDao.addUserIntegral(max, tbOrder.getUserId());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.error("订单{}====积分入账异常{}",orderId, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
userMoneyDetails1.setContent(contentBuffer.toString());
|
|
|
|
|
|
@@ -2648,18 +2698,18 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取当前店铺当前订单在已支付订单中的序号
|
|
|
+ * 更新订单状态和支付顺序
|
|
|
* @param order 订单信息
|
|
|
- * @param shopId 店铺id
|
|
|
- * @return 支付顺序
|
|
|
*/
|
|
|
- private int selectCurrentOrderSequenceByShopId(TbOrder order, Long shopId) {
|
|
|
+ private void updateOrderStatusAndSequence(TbOrder order) {
|
|
|
+ Long shopId = order.getShopId();
|
|
|
RLock lock = redissonClient.getLock(String.format(RedisKey.ORDER_SEQUENCE_LOCK, shopId));
|
|
|
lock.lock();
|
|
|
try {
|
|
|
int count = appOrderDao.countCurDayPayByShopId(shopId, order.getPayTime());
|
|
|
+ order.setOrderSequence(String.format("%04d", count + 1));
|
|
|
|
|
|
- return count + 1;
|
|
|
+ updateById(order);
|
|
|
} finally {
|
|
|
lock.unlock();
|
|
|
}
|