|
@@ -11,12 +11,14 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
|
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
-import com.ym.mec.biz.service.MusicGroupCalenderRefundPeriodService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.api.CommonResult;
|
|
|
import com.ym.mec.common.dto.OrderCreate;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
+import com.ym.mec.common.entity.OrderSkuSync;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import com.ym.mec.mall.MallFeignService;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
@@ -35,9 +37,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.dto.PageInfoOrder;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
|
-import com.ym.mec.biz.service.GoodsService;
|
|
|
-import com.ym.mec.biz.service.SellOrderService;
|
|
|
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
@@ -56,7 +55,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
@Autowired
|
|
|
private SysUserCashAccountDao sysUserCashAccountDao;
|
|
|
@Autowired
|
|
|
- private StudentPaymentOrderDao studentPaymentOrderDao;
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
private IdGeneratorService idGeneratorService;
|
|
|
@Autowired
|
|
@@ -64,8 +63,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
@Autowired
|
|
|
private GoodsDao goodsDao;
|
|
|
@Autowired
|
|
|
- private GoodsService goodsService;
|
|
|
- @Autowired
|
|
|
private SellOrderService sellOrderService;
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
@@ -79,6 +76,14 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
private MusicGroupCalenderRefundPeriodService musicGroupCalenderRefundPeriodService;
|
|
|
@Autowired
|
|
|
private MallFeignService mallFeignService;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupPaymentCalenderGoodsService musicGroupPaymentCalenderGoodsService;
|
|
|
+ @Autowired
|
|
|
+ private SysPaymentConfigService sysPaymentConfigService;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
|
|
@@ -200,12 +205,28 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
studentPaymentRouteOrder.setAuditComment(memo);
|
|
|
studentPaymentRouteOrder.setAuditStatus(auditStatus);
|
|
|
+ MusicGroupPaymentCalender musicGroupPaymentCalender = null;
|
|
|
+ MusicGroupPaymentCalenderAddress address = null;
|
|
|
+ MusicGroup musicGroup = null;
|
|
|
+ //是否同步过商城的发货数据
|
|
|
+ Boolean syncFlag = true;
|
|
|
if (auditStatus == AuditStatusEnum.PASS) {
|
|
|
+ if (studentPaymentRouteOrder.getCalenderId() != null) {
|
|
|
+ musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
|
|
|
+ musicGroup = musicGroupDao.get(musicGroupPaymentCalender.getMusicGroupId());
|
|
|
+ if(musicGroupPaymentCalender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
|
|
|
+ address = musicGroupPaymentCalenderAddressService.lambdaQuery().
|
|
|
+ eq(MusicGroupPaymentCalenderAddress::getCalenderId, studentPaymentRouteOrder.getCalenderId()).one();
|
|
|
+ StudentPaymentOrder addressOrder = studentPaymentOrderService.findOrderByOrderNo(address.getAddress());
|
|
|
+ syncFlag = Objects.isNull(addressOrder);
|
|
|
+ if (!syncFlag){
|
|
|
+ orderNo = address.getOrderNo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|
|
|
}
|
|
|
-
|
|
|
studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
|
|
|
-
|
|
|
if (auditStatus == AuditStatusEnum.PASS) {
|
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
studentPaymentOrder.setActualAmount(studentPaymentRouteOrder.getRouteAmount());
|
|
@@ -236,7 +257,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
|
|
|
|
|
|
if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
|
|
|
- BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
|
|
|
List<Integer> goodsIdList = new ArrayList<>();
|
|
@@ -250,70 +270,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
goodsIdList.add(goodsId);
|
|
|
}
|
|
|
}
|
|
|
-// List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
|
|
|
- List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, null, goodsIdList, null, false);
|
|
|
+ List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, musicGroup==null?null:musicGroup.getId(), goodsIdList, null, false);
|
|
|
sellOrderService.batchInsert(sellOrders);
|
|
|
- /*int i = 1;
|
|
|
- for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
|
|
|
- Integer goodsId = Integer.parseInt(goodsMap.getKey());
|
|
|
- Integer nums = Integer.parseInt(goodsMap.getValue().toString());
|
|
|
- Goods goods = goodsDao.get(goodsId);
|
|
|
-
|
|
|
- BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
- if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- actualAmount = studentPaymentRouteOrder.getSaleAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
- }
|
|
|
- if (i == jsonObj.entrySet().size()) {
|
|
|
- actualAmount = studentPaymentRouteOrder.getSaleAmount().subtract(hasRouteAmount);
|
|
|
- }
|
|
|
- hasRouteAmount = hasRouteAmount.add(actualAmount);
|
|
|
- i++;
|
|
|
-
|
|
|
- int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
|
|
|
- int goodsNum = nums * complementNum;
|
|
|
- BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(nums));
|
|
|
- Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
|
|
|
- complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
|
|
|
- if (goods.getComplementGoodsIdList() != null) {
|
|
|
- List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
- complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
- complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(nums));
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- for (SellOrder sellOrder : sellOrderList) {
|
|
|
- if (!Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getParentGoodsId()) && !Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getGoodsId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
- }
|
|
|
- goodsNum = goodsNum - sellOrder.getNum();
|
|
|
- if (goodsNum <= 0) {
|
|
|
- sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
|
|
|
- }
|
|
|
- hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
|
|
|
-
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrder.getPayTime());
|
|
|
- sellOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
|
|
|
- sellOrder.setCooperationOrganId(studentPaymentRouteOrder.getSchoolId());
|
|
|
- sellOrder.setTransNo(studentPaymentRouteOrder.getTransNo());
|
|
|
- sellOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
- sellOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
|
|
|
- sellOrder.setActualAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
- sellOrder.setExpectAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setUserId(studentPaymentRouteOrder.getUserId());
|
|
|
- sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
- sellOrder.setMerNo(studentPaymentRouteOrder.getMerNo());
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrder.getCreateTime());
|
|
|
- sellOrder.setCreateIme(nowDate);
|
|
|
- sellOrder.setUpdateTime(nowDate);
|
|
|
- sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
|
|
|
- }
|
|
|
- }
|
|
|
- sellOrderDao.batchInsert(sellOrderList);*/
|
|
|
if(calender == null || calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
|
|
|
OrderCreate mallOrder = new OrderCreate();
|
|
|
mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
|
|
@@ -352,6 +310,74 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
if (studentPaymentRouteOrder.getCalenderId() == null) {
|
|
|
return true;
|
|
|
}
|
|
|
+ //同步商城的发货数据
|
|
|
+ if(!syncFlag){
|
|
|
+ AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(studentPaymentOrder.getPaymentChannel()), studentPaymentOrder.getMerNos(), studentPaymentOrder.getTenantId());
|
|
|
+ List<MusicGroupPaymentCalenderGoods> calenderGoods = musicGroupPaymentCalenderGoodsService.lambdaQuery()
|
|
|
+ .eq(MusicGroupPaymentCalenderGoods::getCalenderId, studentPaymentRouteOrder.getCalenderId()).list();
|
|
|
+ List<SellOrder> sellOrderList = new ArrayList<>();
|
|
|
+ for (MusicGroupPaymentCalenderGoods calenderGood : calenderGoods) {
|
|
|
+ //待分配金额
|
|
|
+ for (Integer i = 0; i < calenderGood.getNum(); i++) {
|
|
|
+ List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(calenderGood.getChildGoodsJson(), ComplementGoodsDto.class);
|
|
|
+ //获取总成本
|
|
|
+ BigDecimal totalCostPrice = goodsDtoList.stream().map(e->e.getOrganCostPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //待分配金额
|
|
|
+ BigDecimal totalAmount = calenderGood.getSinglePrice();
|
|
|
+ BigDecimal waitAmount = totalAmount;
|
|
|
+ for (int j = 0; j < goodsDtoList.size(); j++) {
|
|
|
+ ComplementGoodsDto goodsDto = goodsDtoList.get(j);
|
|
|
+ //获取比例
|
|
|
+ BigDecimal proportion = BigDecimal.ZERO;
|
|
|
+ if (totalCostPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ proportion = goodsDto.getOrganCostPrice().divide(totalCostPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
+ sellOrder.setGoodsSkuId(goodsDto.getSkuStockId());
|
|
|
+ sellOrder.setOrganSellCost(goodsDto.getOrganCostPrice());
|
|
|
+ sellOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
+ sellOrder.setType(StringUtils.endsWithIgnoreCase("INSTRUMENT", calenderGood.getGoodsType()) ? SellTypeEnum.INSTRUMENT
|
|
|
+ : StringUtils.endsWithIgnoreCase("ACCESSORIES", calenderGood.getGoodsType()) ? SellTypeEnum.ACCESSORIES
|
|
|
+ : StringUtils.endsWithIgnoreCase("TEACHING", calenderGood.getGoodsType()) ? SellTypeEnum.TEACHING
|
|
|
+ : StringUtils.endsWithIgnoreCase("STAFF", calenderGood.getGoodsType()) ? SellTypeEnum.STAFF
|
|
|
+ : SellTypeEnum.OTHER);
|
|
|
+ sellOrder.setOrderNo(orderNo);
|
|
|
+ if (j == goodsDtoList.size() - 1) {
|
|
|
+ sellOrder.setOrderAmount(waitAmount);
|
|
|
+ } else {
|
|
|
+ BigDecimal amount = totalAmount.multiply(proportion);
|
|
|
+ waitAmount = waitAmount.subtract(amount);
|
|
|
+ sellOrder.setOrderAmount(amount);
|
|
|
+ }
|
|
|
+ sellOrder.setActualAmount(sellOrder.getOrderAmount());
|
|
|
+ sellOrder.setExpectAmount(sellOrder.getOrderAmount());
|
|
|
+ sellOrder.setCouponRemitAmount(BigDecimal.ZERO);
|
|
|
+ sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
+ sellOrder.setParentGoodsId(calenderGood.getGoodsId());
|
|
|
+ sellOrder.setNum(1);
|
|
|
+ sellOrder.setGoodsName(calenderGood.getGoodsName());
|
|
|
+ sellOrder.setAccountType(accountType);
|
|
|
+ sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
|
|
|
+ sellOrder.setEduTeacherId(musicGroup.getEducationalTeacherId());
|
|
|
+ sellOrder.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
+ sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(studentPaymentOrder.getMerNos());
|
|
|
+ sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
|
|
|
+ sellOrder.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
+ sellOrderList.add(sellOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellOrderService.batchInsert(sellOrderList);
|
|
|
+ if(address.getDeliveryFlag()){
|
|
|
+ OrderSkuSync orderSkuSync = new OrderSkuSync();
|
|
|
+ orderSkuSync.setOrderNo(orderNo);
|
|
|
+ orderSkuSync.setSkuSyncList(JSONArray.parseArray(address.getAddress(), OrderSkuSync.SkuSync.class));
|
|
|
+ List<OrderSkuSync> orderSkuSyncs = new ArrayList<>();
|
|
|
+ orderSkuSyncs.add(orderSkuSync);
|
|
|
+ studentPaymentOrderService.updateShippedStatus(orderSkuSyncs);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//根据学校缴费项id,确定缴费状态
|
|
|
// BigDecimal amount = studentPaymentRouteOrderDao.sumAmountByCalenderId(studentPaymentRouteOrder.getCalenderId());
|
|
@@ -361,8 +387,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
//是否已完成回款
|
|
|
if(aBoolean){
|
|
|
List<MusicGroupPaymentCalenderDetail> calenderDetails = musicGroupPaymentCalenderDetailDao.getCalenderDetailWithCalender(studentPaymentRouteOrder.getCalenderId());
|
|
|
- MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
|
|
|
-
|
|
|
if (studentPaymentRouteOrder.getRouteAmount().compareTo(musicGroupPaymentCalender.getCurrentTotalAmount()) >= 0) {
|
|
|
musicGroupPaymentCalender.setActualNum(musicGroupPaymentCalender.getExpectNum());
|
|
|
musicGroupPaymentCalender.setStatus(MusicGroupPaymentCalender.PaymentCalenderStatusEnum.PAID);
|
|
@@ -398,11 +422,11 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean deleteRouteOrder(Long orderId) {
|
|
|
- StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(orderId);
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.get(orderId);
|
|
|
if (studentPaymentOrder == null) {
|
|
|
throw new BizException("订单不存在,请核查");
|
|
|
}
|
|
|
- studentPaymentOrderDao.delete(orderId);
|
|
|
+ studentPaymentOrderService.delete(orderId);
|
|
|
studentPaymentRouteOrderDao.deleteByOrderNo(studentPaymentOrder.getOrderNo());
|
|
|
//归还库存
|
|
|
List<SellOrder> sellOrders = sellOrderService.getSellOrderByParentGoodsId(orderId, null);
|