|
@@ -11,14 +11,18 @@ import com.ym.mec.biz.dal.dto.ReplacementPayDto;
|
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.dal.page.ReplacementInstrumentActivityQueryInfo;
|
|
|
+import com.ym.mec.biz.dal.page.ReplacementInstrumentQueryInfo;
|
|
|
import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.page.QueryInfo;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
+
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -29,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrumentActivity> implements ReplacementInstrumentActivityService {
|
|
@@ -66,6 +71,14 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
@Autowired
|
|
|
private ReplacementInstrumentCooperationDao replacementInstrumentCooperationDao;
|
|
|
@Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
+ @Autowired
|
|
|
+ private SysPaymentConfigService sysPaymentConfigService;
|
|
|
+ @Autowired
|
|
|
+ private SellOrderDao sellOrderDao;
|
|
|
+ @Autowired
|
|
|
private QuestionnaireUserResultDao questionnaireUserResultDao;
|
|
|
@Autowired
|
|
|
private QuestionnaireQuestionDao questionnaireQuestionDao;
|
|
@@ -86,6 +99,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
if (sysUser == null) {
|
|
|
throw new BizException("用户信息获取失败,请重新登陆");
|
|
|
}
|
|
|
+ replacementInstrumentActivity.setGoodsId(replacementInstrumentActivity.getInstrumentsId());
|
|
|
replacementInstrumentActivity.setUserId(sysUser.getId());
|
|
|
//如果用户是43分部,那么修改用户信息
|
|
|
if (sysUser.getOrganId() == 43) {
|
|
@@ -119,7 +133,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
}
|
|
|
//已开启缴费推送购买链接
|
|
|
if (sendPush && replacementInstrumentActivity.getOpenFlag().equals(1) && replacementInstrumentActivity.getInstrumentsId() != null) {
|
|
|
- ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
|
|
|
+ //换成商品列表中商品4.25
|
|
|
+ Goods goods = goodsDao.get(replacementInstrumentActivity.getGoodsId());
|
|
|
Map<Integer, String> userMap = new HashMap<>();
|
|
|
Map<Integer, String> userPhoneMap = new HashMap<>();
|
|
|
Integer userId = replacementInstrumentActivity.getUserId();
|
|
@@ -127,11 +142,11 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
String pushUrl = baseApiUrl + "/#/questionGoodsSale?id=";
|
|
|
userMap.put(userId, userId.toString());
|
|
|
sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
|
|
|
- userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", replacementInstrument.getBrand(), "");
|
|
|
+ userMap, null, 0, "5?" + pushUrl + replacementInstrumentActivity.getId(), "STUDENT", goods.getBrand(), "");
|
|
|
|
|
|
userPhoneMap.put(replacementInstrumentActivity.getUserId(), replacementInstrumentActivity.getMobileNo());
|
|
|
sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, MessageTypeEnum.REPLACEMENT_PAY_PUSH,
|
|
|
- userPhoneMap, null, 0, null, "STUDENT", replacementInstrument.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
|
|
|
+ userPhoneMap, null, 0, null, "STUDENT", goods.getBrand(), HttpUtil.getSortUrl(pushUrl + replacementInstrumentActivity.getId()));
|
|
|
}
|
|
|
return replacementInstrumentActivity;
|
|
|
}
|
|
@@ -213,6 +228,7 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
return replacementInstrumentActivity;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public ReplacementInstrumentActivity findByUserId(Integer cooperationOrganId, Integer userId,Integer cooperationId) {
|
|
|
return replacementInstrumentActivityDao.findByUserId(cooperationOrganId, userId,cooperationId);
|
|
@@ -253,6 +269,10 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
ReplacementInstrumentActivity replacementInstrumentActivity = replacementInstrumentActivityDao.getLock(replacementPayDto.getId());
|
|
|
Integer userId = replacementInstrumentActivity.getUserId();
|
|
|
|
|
|
+ if (replacementInstrumentActivity.getGoodsId() == null) {
|
|
|
+ throw new BizException("数据维护中,请稍后支付");
|
|
|
+ }
|
|
|
+
|
|
|
//处理关闭订单
|
|
|
if (replacementInstrumentActivity.getPayStatus().equals(1) && replacementPayDto.getRePay()) {
|
|
|
StudentPaymentOrder oldOrder = studentPaymentOrderService.getUserReplacementIngOrder(userId, replacementInstrumentActivity.getId());
|
|
@@ -263,10 +283,10 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ReplacementInstrument replacementInstrument = replacementInstrumentDao.get(replacementInstrumentActivity.getInstrumentsId());
|
|
|
- BigDecimal orderAmount = replacementInstrument.getSalePrice();
|
|
|
+ Goods goods = goodsDao.get(replacementInstrumentActivity.getInstrumentsId());
|
|
|
+ BigDecimal orderAmount = goods.getGroupPurchasePrice();
|
|
|
BigDecimal amount = replacementPayDto.getAmount(); //扣除余额之前的金额
|
|
|
- if (amount.compareTo(replacementInstrument.getSalePrice()) != 0) {
|
|
|
+ if (amount.compareTo(orderAmount) != 0) {
|
|
|
throw new BizException("商品价格不符");
|
|
|
}
|
|
|
|
|
@@ -413,6 +433,8 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
|
}
|
|
|
+ //添加sell_order
|
|
|
+ this.addSellOrder(studentPaymentOrder, replacementInstrumentActivity);
|
|
|
try {
|
|
|
contractService.transferProduceContract(userId, null);
|
|
|
} catch (Exception e) {
|
|
@@ -470,6 +492,67 @@ public class ReplacementInstrumentActivityServiceImpl extends BaseServiceImpl<In
|
|
|
return pageInfo;
|
|
|
}
|
|
|
|
|
|
+ private List<SellOrder> addSellOrder(StudentPaymentOrder order, ReplacementInstrumentActivity replacementInstrumentActivity) {
|
|
|
+ if (replacementInstrumentActivity.getGoodsId() == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Goods> goodies = new ArrayList<>();
|
|
|
+ Goods goods = goodsDao.get(replacementInstrumentActivity.getInstrumentsId());
|
|
|
+ goodies.add(goods);
|
|
|
+ if (goods.getComplementGoodsIdList() != null) {
|
|
|
+ goodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
+ }
|
|
|
+ Map<Integer, BigDecimal> groupPurchasePriceMap = goodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
+ BigDecimal goodsTotalPrice = goodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ Map<Integer, GoodsType> goodsTypeMap = goodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getType));
|
|
|
+
|
|
|
+ AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(order.getPaymentChannel()), order.getMerNos());
|
|
|
+
|
|
|
+ List<Integer> goodsIds = new ArrayList<>();
|
|
|
+ goodsIds.add(goods.getId());
|
|
|
+ List<SellOrder> sellOrders = goodsService.subtractStock(goodsIds, accountType);
|
|
|
+
|
|
|
+ BigDecimal hasRouteSellOrderExpectAmount = BigDecimal.ZERO; //已分配预计金额
|
|
|
+ BigDecimal hasRouteSellOrderBalance = BigDecimal.ZERO; //已分配余额
|
|
|
+
|
|
|
+ int i = 1;
|
|
|
+ for (SellOrder sellOrder : sellOrders) {
|
|
|
+ BigDecimal sellOrderExpectAmount = order.getExpectAmount().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : groupPurchasePriceMap.get(sellOrder.getGoodsId()).multiply(order.getExpectAmount()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
+ BigDecimal sellOrderBalance = order.getExpectAmount().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : groupPurchasePriceMap.get(sellOrder.getGoodsId()).multiply(order.getBalancePaymentAmount()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
+ if (i == sellOrders.size()) {
|
|
|
+ sellOrderExpectAmount = order.getExpectAmount().subtract(hasRouteSellOrderExpectAmount);
|
|
|
+ sellOrderBalance = order.getBalancePaymentAmount().subtract(hasRouteSellOrderBalance);
|
|
|
+ }
|
|
|
+ sellOrder.setOrganId(order.getOrganId());
|
|
|
+ sellOrder.setTransNo(order.getTransNo());
|
|
|
+ sellOrder.setOrderId(order.getId());
|
|
|
+ sellOrder.setCooperationOrganId(replacementInstrumentActivity.getCooperationOrganId());
|
|
|
+ sellOrder.setOrderNo(order.getOrderNo());
|
|
|
+ sellOrder.setActualAmount(sellOrderExpectAmount.subtract(sellOrderBalance));
|
|
|
+ sellOrder.setBalanceAmount(sellOrderBalance);
|
|
|
+ sellOrder.setExpectAmount(sellOrderExpectAmount);
|
|
|
+ sellOrder.setNum(1);
|
|
|
+ sellOrder.setUserId(order.getUserId());
|
|
|
+ sellOrder.setPaymentChannel(order.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(order.getMerNos());
|
|
|
+ sellOrder.setSellTime(order.getCreateTime());
|
|
|
+ sellOrder.setCreateIme(new Date());
|
|
|
+ sellOrder.setUpdateTime(new Date());
|
|
|
+ if (goodsTypeMap.get(sellOrder.getGoodsId()).equals(GoodsType.INSTRUMENT)) {
|
|
|
+ sellOrder.setType(SellTypeEnum.INSTRUMENT);
|
|
|
+ } else if (goodsTypeMap.get(sellOrder.getGoodsId()).equals(GoodsType.ACCESSORIES)) {
|
|
|
+ sellOrder.setType(SellTypeEnum.ACCESSORIES);
|
|
|
+ } else {
|
|
|
+ sellOrder.setType(SellTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if (sellOrders.size() > 0) {
|
|
|
+ sellOrderDao.batchInsert(sellOrders);
|
|
|
+ }
|
|
|
+ return sellOrders;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void resultSync(){
|
|
|
//获取所有问卷结果
|