@@ -57,6 +57,7 @@ import com.iformall.common.IdWorker;
import com.iformall.common.ResultData;
import com.iformall.domain.dto.OrderComposeSaveDto;
import com.iformall.domain.dto.OrderSaveDto;
import com.iformall.domain.dto.PlatPushOrderSaveDto;
import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.exception.MallinkException;
@@ -2765,6 +2766,51 @@ public class WxOrderServiceImpl implements WxOrderService {
@Autowired
@Qualifier("cUserBasicInfoRedisTemplate")
RedisTemplate<String, WxCUserBasicInfo> cUserBasicInfoRedisTemplate;
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxComposeOrder savePlatPushOrderForCoupon(TenantEntity tenantEntity,boolean allowUnPayOrder,EnumComposeOrder composeOrderType,WxCUserBasicInfo user,List<PlatPushOrderSaveDto> platPushOrderList,EnumPayWay payWay) {
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
// 防止同一用户重复下单,1秒内
String key = new StringBuilder().append("savePlatPushOrder:").append(user.getId()).toString();
boolean hasKey = cUserBasicInfoRedisTemplate.hasKey(key);
if (hasKey) {
logger.error("用户正在下单,请求异常返回,user: {} " + JSON.toJSONString(user));
throw new MallinkException(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION);
}
cUserBasicInfoRedisTemplate.opsForValue().set(key, user, 1000, TimeUnit.MILLISECONDS);
OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrderType.getCode());
//从这里开始,就需要锁住渠道的价格,不能修改
WxComposeOrder composeOrder = orderAdapterService.createDBMainOrderByPushOrder(tenantEntity,user, platPushOrderList, payWay);
Date orderDate = new Date();
WxOrder lastOrder = null;
for (int i = 0 ; i < platPushOrderList.size(); i ++) {
PlatPushOrderSaveDto orderdto = platPushOrderList.get(i);
Map<Long,WxCouponChannel> couponChannelMap = composeOrder.getCouponChannelMap();
Long couponChannelId = orderdto.getCouponChannelId();
WxCouponChannel couponChannel = couponChannelMap.get(couponChannelId);
orderdto.setWxCouponChannel(couponChannel);
//券一个数量创建一个订单
boolean isOneNumberOneOrder = orderAdapterService.isOneNumberOneOrder();
if (isOneNumberOneOrder) {
for (int j = 0; j < orderdto.getCount(); j++) {
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), 1,
orderdto.isPress(),orderdto.getOrderGroupId(),orderdto.getFormId(),orderdto.getShippingType(),orderdto.getAddress(),orderdto.getWxCouponChannel(), payWay);
}
}else {
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), orderdto.getCount(),
orderdto.isPress(),orderdto.getOrderGroupId(),orderdto.getFormId(),orderdto.getShippingType(),orderdto.getAddress(),orderdto.getWxCouponChannel(), payWay);
}
}
//如果没有orderId,则用lastOrder的信息
if (EnumComposeOrder.isSingle(composeOrderType.getCode())) {
composeOrder.setSingleOrder(lastOrder);
}
return composeOrder;
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxComposeOrder saveOrderForCoupon(TenantEntity tenantEntity,boolean allowUnPayOrder,EnumComposeOrder composeOrderType,WxCUserBasicInfo user,List<OrderComposeSaveDto> orderSave,EnumPayWay payWay) {
@@ -2795,10 +2841,14 @@ public class WxOrderServiceImpl implements WxOrderService {
boolean isOneNumberOneOrder = orderAdapterService.isOneNumberOneOrder();
if (isOneNumberOneOrder) {
for (int j = 0; j < orderdto.getCount(); j++) {
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), 1, orderdto, payWay);
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), 1,
orderdto.getSignleOrder().isPressOrder(),orderdto.getSignleOrder().getOrderGroupId(),orderdto.getSignleOrder().getFormId(),
orderdto.getShippingType(),orderdto.getAddress(),orderdto.getWxCouponChannel(), payWay);
}
}else {
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), orderdto.getCount(), orderdto, payWay);
lastOrder = proxy.handleSaveOrderForCouponSingle(orderDate,allowUnPayOrder,composeOrder, user, orderdto.getWxCoupon(), orderdto.getCount(),
orderdto.getSignleOrder().isPressOrder(),orderdto.getSignleOrder().getOrderGroupId(),orderdto.getSignleOrder().getFormId(),
orderdto.getShippingType(),orderdto.getAddress(),orderdto.getWxCouponChannel(), payWay);
}
}
//如果没有orderId,则用lastOrder的信息
@@ -2809,15 +2859,15 @@ public class WxOrderServiceImpl implements WxOrderService {
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxOrder handleSaveOrderForCouponSingle(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user,WxCoupon coupon,int perCouponNumber,OrderComposeSaveDto orderdto,EnumPayWay payWay) {
public WxOrder handleSaveOrderForCouponSingle(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user,WxCoupon coupon,int perCouponNumber,
boolean isPressOrder,Long orderGroupId,String formId,Integer shippinType,UserBasicInfoAddress address,WxCouponChannel couponChannel,EnumPayWay payWay) {
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
// 是否砍价
WxOrder order = null;
WxCouponChannel couponChannel = orderdto.getWxCouponChannel();
if (checkCouponIsFree(coupon,couponChannel,orderdto.getShippingType())) {
if (checkCouponIsFree(coupon,couponChannel,shippinType)) {
// 免费券
order = proxy.saveFreeOrderForCoupon(orderDate,allowUnPayOrder,composeOrder,user, coupon,perCouponNumber,couponChannel,
orderdto.getSignleOrder().getFormId(),null,payWay,orderdto.getShippingType(),orderdto.getAddress() );
formId,null,payWay,shippinType,address );
if (order != null) {
// 6. 下订单完成,发送内部消息
// 下订单完成,发送内部消息
@@ -2830,7 +2880,8 @@ public class WxOrderServiceImpl implements WxOrderService {
}
} else {
// 有价券
order = proxy.saveNoFreeOrderForCoupon(orderDate,allowUnPayOrder,composeOrder,user, orderdto.getWxCoupon(),perCouponNumber,couponChannel,orderdto,payWay);
order = proxy.saveNoFreeOrderForCoupon(orderDate,allowUnPayOrder,composeOrder,user, coupon,perCouponNumber,isPressOrder,
orderGroupId,formId,shippinType,address,couponChannel,payWay);
}
// couponActionLog
// try {
@@ -2936,7 +2987,8 @@ public class WxOrderServiceImpl implements WxOrderService {
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxOrder saveNoFreeOrderForCoupon(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber,WxCouponChannel couponChannel,OrderComposeSaveDto orderdto,EnumPayWay payWay) {
public WxOrder saveNoFreeOrderForCoupon(Date orderDate,boolean allowUnPayOrder,WxComposeOrder composeOrder,WxCUserBasicInfo user, WxCoupon coupon,int couponNumber,
boolean isPressOrder,Long orderGroupId,String formId,Integer shippinType,UserBasicInfoAddress address,WxCouponChannel couponChannel,EnumPayWay payWay) {
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
// 3. 减库存操作。所有的订单都跟减库存操作时的订单详情保持一致
@@ -2970,22 +3022,22 @@ public class WxOrderServiceImpl implements WxOrderService {
Long orderNumber;
// 4.1 价格 渠道/券
WxComposeChildOrderPrice price = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType())
.getChildCouponOrderPrice(orderdto,coupon,couponChannel, orderdto.getSignleOrder().isPressOrder(), orderdto.getSignleOrder().getOrderGroupId() , couponNumber);
.getChildCouponOrderPrice(shippinType,coupon,couponChannel, isPressOrder, orderGroupId , couponNumber);
Integer orderStatus = OrderHelper.getOrderStatusWxCoupon(coupon, orderdto.getSignleOrder().getOrder GroupId() );
Integer orderStatus = OrderHelper.getOrderStatusWxCoupon(coupon, orderGroupId);
// 4.2 保存订单
WxOrder record = new WxOrder();
record.setType(orderType);
record.setPayVendor(payWay.getCode());
record.setCouponChannelId(orderdto.getSignleOrder().getCouponChannel Id());
record.setOrderGroupId(orderdto.getSignleOrder().getOrder GroupId() );
record.setFormId(orderdto.getSignleOrder().getFormId() );
record.setCouponChannelId(couponChannel.get Id());
record.setOrderGroupId(orderGroupId);
record.setFormId(formId );
record.setPayment(price.getRealPayMent());
record.setShippingType(orderdto.getShippingType() );
if(EnumOrderShopingType.DISTRIBUTION.getCode().equals(orderdto.getShippingType() )){
record.setShippingType(shippinType );
if(EnumOrderShopingType.DISTRIBUTION.getCode().equals(shippinType )){
record.setFreightPrice(coupon.getFreightPrice());
record.setShippingAddress(JSON.toJSONString(orderdto.getAddress() ));
record.setShippingAddress(JSON.toJSONString(address ));
}
record.setOrderStatus(orderStatus);
@@ -2998,13 +3050,13 @@ public class WxOrderServiceImpl implements WxOrderService {
record.setCouponNumber(couponNumber);
try {
orderNumber = proxy.saveNoFreeOrder(orderDate,record, user, coupon, orderdto.getSignleOrder(). isPressOrder() );
orderNumber = proxy.saveNoFreeOrder(orderDate,record, user, coupon, isPressOrder);
} catch (Exception e) {
logger.error("保存订单:" + e.getMessage(),e);
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]订单保存错误,"+e.getMessage());
}
if (orderdto.getSignleOrder(). isPressOrder() ) {
if (isPressOrder) {
// 5. 第一次砍价
try {
proxy.firstPress(orderDate,record, user, coupon, orderNumber);
@@ -3315,7 +3367,8 @@ public class WxOrderServiceImpl implements WxOrderService {
for ( int i =0 ; i< composeOrderSaveDto.size(); i++ ) {
OrderComposeSaveDto ocsd = composeOrderSaveDto.get(i);
WxCoupon coupon = singleOrderCheck(ocsd.getSignleOrder(),ocsd.getCount(),wxCUserBasicInfo,payWay,tenantEntity,i+1,singleProduct);
WxCoupon coupon = singleOrderCheck(ocsd.getSignleOrder().getCouponChannelId(),ocsd.getSignleOrder().getOrderGroupId(),ocsd.getCount(),
wxCUserBasicInfo,payWay,tenantEntity,i+1,singleProduct);
ocsd.setWxCoupon(coupon);
}
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
@@ -3338,6 +3391,50 @@ public class WxOrderServiceImpl implements WxOrderService {
}
}
@Override
public ResultData platPushSaveOrder(boolean allowUnPayOrder,EnumComposeOrder composeOrderType,List<PlatPushOrderSaveDto> platPushOrderList,Long cUserId,EnumPayWay payWay,TenantEntity tenantEntity) {
try {
if (null == platPushOrderList || platPushOrderList.size() <= 0 ) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"无商品信息");
}
WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUserId,tenantEntity.getFinalTenantId());
if (wxCUserBasicInfo != null && wxCUserBasicInfo.getStatus().equals(EnumCUserBasicInfoStatus.LOCKED.getCode())) {
logger.info("会员权益被锁定:cUserId:" + cUserId);
return new ResultData(ErrorCode.MEMBER_IS_LOCKED);
}
boolean singleProduct = false;
if (platPushOrderList.size() == 1) {
singleProduct = true;
}
for ( int i =0 ; i< platPushOrderList.size(); i++ ) {
PlatPushOrderSaveDto ocsd = platPushOrderList.get(i);
WxCoupon coupon = singleOrderCheck(ocsd.getCouponChannelId(),ocsd.getOrderGroupId(),ocsd.getCount(),wxCUserBasicInfo,payWay,tenantEntity,i+1,singleProduct);
ocsd.setWxCoupon(coupon);
}
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
try {
WxComposeOrder order = proxy.savePlatPushOrderForCoupon(tenantEntity,allowUnPayOrder,composeOrderType,wxCUserBasicInfo, platPushOrderList, payWay);
return new ResultData(order);
} catch (MallinkException e) {
logger.error("saveOrderForCoupon error.",e);
throw new MallinkException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
logger.error("saveOrderForCoupon error.",e);
throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), e.getMessage());
}
}catch(MallinkException me) {
return new ResultData(me.getErrorCode(),me.getMessage());
}catch(Exception e) {
logger.error("composeSaveOrder error.",e);
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage());
}
}
@Override
public void sendInsideOrderPushMsg(TenantEntity tenantEntity,Long composeOrderId) {
@@ -3459,26 +3556,25 @@ public class WxOrderServiceImpl implements WxOrderService {
// }
private WxCoupon singleOrderCheck(OrderSaveDto orderSaveDto,int productCount,WxCUserBasicInfo wxCUserBasicInfo,EnumPayWay payWay,TenantEntity tenantEntity,int curindex,boolean singleProduct) {
logger.info("OrderSave: " + orderSaveDto);
private WxCoupon singleOrderCheck(Long couponChannelId,Long orderGroupId,int productCount,WxCUserBasicInfo wxCUserBasicInfo,EnumPayWay payWay,TenantEntity tenantEntity,int curindex,boolean singleProduct) {
String premsg = "";
if (singleProduct) {
premsg = "此券";
}else {
premsg = "第["+curindex+"]张券";
}
if (orderSaveDto.getCouponChannelId() == null) {
if (couponChannelId == null) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), premsg+"couponChannelId不能为空");
}
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(orderSaveDto.getCouponChannelId() ,tenantEntity.getTenantId());
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId ,tenantEntity.getTenantId());
if (wxCouponChannel == null) {
logger.error("couponChannelId find error, " + orderSaveDto.getCouponChannelId() );
logger.error("couponChannelId find error, " + couponChannelId );
throw new MallinkException(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF.getCode(),premsg+"投放渠道不存在");
}
if (!singleProduct) {
premsg = premsg+"【"+wxCouponChannel.getTitle()+"】";
}
couponChannelCheck(orderSaveDto, wxCouponChannel,premsg);
couponChannelCheck(wxCouponChannel,premsg);
WxCoupon coupon = wxCouponService.getById(wxCouponChannel.getCouponId(),wxCouponChannel.getTenantId());
if (null == coupon) {
@@ -3499,7 +3595,7 @@ public class WxOrderServiceImpl implements WxOrderService {
WxCouponCVo wxCouponCVo = null;
String key = "cc:" + orderSaveDto.getCouponChannelId() ;
String key = "cc:" + couponChannelId ;
ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue();
// 缓存
boolean hasKey = cdRedisTemplate.hasKey(key);
@@ -3508,7 +3604,7 @@ public class WxOrderServiceImpl implements WxOrderService {
wxCouponCVo = operations.get(key);
} else {
// 游戏没有入缓存,需要从数据库中读取
wxCouponCVo = wxCouponChannelService.findDetailVo(orderSaveDto.getCouponChannelId() ,wxCouponChannel.getTenantId(),false);
wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelId ,wxCouponChannel.getTenantId(),false);
if (wxCouponCVo != null) {
// 游戏优化,进缓存
cdRedisTemplate.opsForValue().set(key, wxCouponCVo, 3600, TimeUnit.SECONDS);
@@ -3565,7 +3661,7 @@ public class WxOrderServiceImpl implements WxOrderService {
couponUserCheck(wxCUserBasicInfo, wxCouponCVo,premsg);
Long couponId = orderSaveDto.getCouponId() == null ? wxCouponChannel.getCouponId() : orderSaveDto .getCouponId();
Long couponId = wxCouponChannel.getCouponId();
if (couponId == null) {
logger.error("couponChannelId或者couponId不能为空");
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), premsg+"couponChannelId或者couponId不能为空");
@@ -3582,14 +3678,14 @@ public class WxOrderServiceImpl implements WxOrderService {
if (!checkCouponIsFree(coupon,wxCouponChannel,null)) {
// 有价,拼团检查
if (isOrderGroup(orderSaveDto.getOrder GroupId() )) {
checkOrderGroup(wxCUserBasicInfo, orderSaveDto.getOrder GroupId() ,coupon,premsg);
if (isOrderGroup(orderGroupId)) {
checkOrderGroup(wxCUserBasicInfo, orderGroupId,coupon,premsg);
}
}
return coupon;
}
private void couponChannelCheck(OrderSaveDto orderSaveDto, WxCouponChannel wxCouponChannel,String premsg) {
private void couponChannelCheck(WxCouponChannel wxCouponChannel,String premsg) {
if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) {
Date now = new Date();
if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) {