|
|
@@ -1,8 +1,24 @@
|
|
|
package com.uas.platform.b2c.fa.payment.service.impl;
|
|
|
|
|
|
+import com.uas.platform.b2c.core.constant.Status;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.fa.payment.dao.InstallmentDao;
|
|
|
+import com.uas.platform.b2c.fa.payment.dao.InstallmentStoreDao;
|
|
|
+import com.uas.platform.b2c.fa.payment.model.Installment;
|
|
|
+import com.uas.platform.b2c.fa.payment.model.InstallmentDetail;
|
|
|
+import com.uas.platform.b2c.fa.payment.model.InstallmentStore;
|
|
|
import com.uas.platform.b2c.fa.payment.service.InstallmentService;
|
|
|
+import com.uas.platform.b2c.trade.order.dao.OrderDao;
|
|
|
+import com.uas.platform.b2c.trade.order.dao.PurchaseDao;
|
|
|
+import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
+import com.uas.platform.b2c.trade.order.model.Purchase;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 分期支付service实现类
|
|
|
* @author wangyc
|
|
|
@@ -11,4 +27,123 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class InstallmentServiceImpl implements InstallmentService{
|
|
|
+
|
|
|
+ private final InstallmentStoreDao installmentStoreDao;
|
|
|
+
|
|
|
+ private final PurchaseDao purchaseDao;
|
|
|
+
|
|
|
+ private final OrderDao orderDao;
|
|
|
+
|
|
|
+ private final InstallmentDao installmentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public InstallmentServiceImpl(InstallmentStoreDao installmentStoreDao, PurchaseDao purchaseDao, OrderDao orderDao, InstallmentDao installmentDao) {
|
|
|
+ this.installmentStoreDao = installmentStoreDao;
|
|
|
+ this.purchaseDao = purchaseDao;
|
|
|
+ this.orderDao = orderDao;
|
|
|
+ this.installmentDao = installmentDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Installment createInstallment(Installment installment, Long purchaseId) {
|
|
|
+ Purchase purchase = purchaseDao.findOne(purchaseId);
|
|
|
+ // 基础验证
|
|
|
+ if (purchase == null)
|
|
|
+ throw new IllegalOperatorException("此订单不存在,请重新确认信息");
|
|
|
+ if (!SystemSession.getUser().getEnterprise().getUu().equals(purchase.getSellerenuu()))
|
|
|
+ throw new IllegalOperatorException("此订单不属于当前企业,请重新确认信息");
|
|
|
+ if (Status.TOBECONFIRMED.value() != purchase.getStatus().intValue())
|
|
|
+ throw new IllegalOperatorException("此订单状态不为待付款,不可设置分期");
|
|
|
+
|
|
|
+ InstallmentStore installmentStore = installmentStoreDao.findByEnuuAndEnable(SystemSession.getUser().getEnterprise().getUu(), (short) 1);
|
|
|
+ if (installmentStore == null)
|
|
|
+ throw new IllegalOperatorException("当前企业没有设置分期功能权限,如有需要请联系客服");
|
|
|
+
|
|
|
+ List<InstallmentDetail> installmentDetails = installment.getInstallmentDetails();
|
|
|
+ if (CollectionUtils.isEmpty(installmentDetails))
|
|
|
+ throw new IllegalOperatorException("分期详情为空,请您设置分期详情");
|
|
|
+
|
|
|
+ for(InstallmentDetail installmentDetail : installmentDetails) {
|
|
|
+ installmentDetail.setStatus(Status.TOBEPAID.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置分期基本信息
|
|
|
+ installment.setSellerenuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ installment.setStatus(Status.TOBEPAID.value());
|
|
|
+ installment.setCount(installmentDetails.size());
|
|
|
+ installment.setCurrentNo((short) 1);
|
|
|
+ installment.setOrderNum(purchase.getOrderid());
|
|
|
+ installment.setPurchaseId(purchaseId);
|
|
|
+
|
|
|
+ Order order = orderDao.findOrderByOrderid(purchase.getOrderid());
|
|
|
+ if (order == null)
|
|
|
+ throw new IllegalOperatorException("此订单不存在,请重新确认信息");
|
|
|
+
|
|
|
+ installment.setOrderId(order.getId());
|
|
|
+ installment.setPrice(purchase.getPrice());
|
|
|
+ installment.setInstallmentDetails(installmentDetails);
|
|
|
+
|
|
|
+ // 保存分期信息
|
|
|
+ installment = installmentDao.save(installment);
|
|
|
+
|
|
|
+ // 订单、采购单保存分期id
|
|
|
+ purchase.setInstallmentId(installment.getId());
|
|
|
+ order.setInstallmentId(installment.getId());
|
|
|
+
|
|
|
+ return installment;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Installment updateInstallment(Installment installment, Long purchaseId) {
|
|
|
+ Purchase purchase = purchaseDao.findOne(purchaseId);
|
|
|
+ // 基础验证
|
|
|
+ if (purchase == null)
|
|
|
+ throw new IllegalOperatorException("此订单不存在,请重新确认信息");
|
|
|
+ if (!SystemSession.getUser().getEnterprise().getUu().equals(purchase.getSellerenuu()))
|
|
|
+ throw new IllegalOperatorException("此订单不属于当前企业,请重新确认信息");
|
|
|
+ if (Status.TOBECONFIRMED.value() != purchase.getStatus().intValue())
|
|
|
+ throw new IllegalOperatorException("此订单状态不为待付款,不可修改分期信息");
|
|
|
+
|
|
|
+ InstallmentStore installmentStore = installmentStoreDao.findByEnuuAndEnable(SystemSession.getUser().getEnterprise().getUu(), (short) 1);
|
|
|
+ if (installmentStore == null)
|
|
|
+ throw new IllegalOperatorException("当前企业没有设置分期功能权限,如有需要请联系客服");
|
|
|
+
|
|
|
+ List<InstallmentDetail> installmentDetails = installment.getInstallmentDetails();
|
|
|
+ if (CollectionUtils.isEmpty(installmentDetails))
|
|
|
+ throw new IllegalOperatorException("分期详情为空,请您设置分期详情");
|
|
|
+
|
|
|
+ Installment oldInstallment = installmentDao.findByPurchaseId(purchaseId);
|
|
|
+ if (oldInstallment == null)
|
|
|
+ throw new IllegalOperatorException("此订单分期信息不存在,请重新确认信息");
|
|
|
+ installmentDao.delete(oldInstallment.getId());
|
|
|
+
|
|
|
+ for(InstallmentDetail installmentDetail : installmentDetails) {
|
|
|
+ installmentDetail.setStatus(Status.TOBEPAID.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置分期基本信息
|
|
|
+ installment.setSellerenuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ installment.setStatus(Status.TOBEPAID.value());
|
|
|
+ installment.setCount(installmentDetails.size());
|
|
|
+ installment.setCurrentNo((short) 1);
|
|
|
+ installment.setOrderNum(purchase.getOrderid());
|
|
|
+ installment.setPurchaseId(purchaseId);
|
|
|
+
|
|
|
+ Order order = orderDao.findOrderByOrderid(purchase.getOrderid());
|
|
|
+ if (order == null)
|
|
|
+ throw new IllegalOperatorException("此订单不存在,请重新确认信息");
|
|
|
+
|
|
|
+ installment.setOrderId(order.getId());
|
|
|
+ installment.setPrice(purchase.getPrice());
|
|
|
+ installment.setInstallmentDetails(installmentDetails);
|
|
|
+
|
|
|
+ // 保存分期信息
|
|
|
+ installment = installmentDao.save(installment);
|
|
|
+
|
|
|
+ // 订单、采购单保存分期id
|
|
|
+ purchase.setInstallmentId(installment.getId());
|
|
|
+ order.setInstallmentId(installment.getId());
|
|
|
+
|
|
|
+ return installment;
|
|
|
+ }
|
|
|
}
|