|
@@ -96,7 +96,9 @@ import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.enums.*;
|
|
import com.fs.hisStore.enums.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.qw.domain.FsCompanyCustomer;
|
|
import com.fs.qw.domain.FsCompanyCustomer;
|
|
|
|
|
+import com.fs.qw.domain.FsCompanyExternalPayReceipt;
|
|
|
import com.fs.qw.mapper.FsCompanyCustomerMapper;
|
|
import com.fs.qw.mapper.FsCompanyCustomerMapper;
|
|
|
|
|
+import com.fs.qw.mapper.FsCompanyExternalPayReceiptMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
import com.fs.ybPay.domain.OrderResult;
|
|
import com.fs.ybPay.domain.OrderResult;
|
|
@@ -356,6 +358,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsCompanyCustomerMapper fsCompanyCustomerMapper;
|
|
private FsCompanyCustomerMapper fsCompanyCustomerMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsCompanyExternalPayReceiptMapper companyExternalPayReceiptMapper;
|
|
|
|
|
+
|
|
|
//ERP 类型到服务的映射
|
|
//ERP 类型到服务的映射
|
|
|
private Map<Integer, IErpOrderService> erpServiceMap;
|
|
private Map<Integer, IErpOrderService> erpServiceMap;
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
@@ -620,6 +625,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (StringUtils.isNotEmpty(cartParam.getGiftCartIds())) {
|
|
if (StringUtils.isNotEmpty(cartParam.getGiftCartIds())) {
|
|
|
List<FsStoreCartQueryVO> giftCarts = cartMapper.selectFsStoreCartListByIds(cartParam.getGiftCartIds());
|
|
List<FsStoreCartQueryVO> giftCarts = cartMapper.selectFsStoreCartListByIds(cartParam.getGiftCartIds());
|
|
|
redisCache.setCacheObject("orderGiftCarts:" + uuid, giftCarts, 300, TimeUnit.SECONDS);
|
|
redisCache.setCacheObject("orderGiftCarts:" + uuid, giftCarts, 300, TimeUnit.SECONDS);
|
|
|
|
|
+ redisCache.setCacheObject("orderGiftCartKey:" + uuid, cartParam.getGiftCartIds(), 300, TimeUnit.SECONDS);
|
|
|
}
|
|
}
|
|
|
redisCache.setCacheObject("orderKey:" + uuid, cartParam.getCartIds(), 300, TimeUnit.SECONDS);
|
|
redisCache.setCacheObject("orderKey:" + uuid, cartParam.getCartIds(), 300, TimeUnit.SECONDS);
|
|
|
redisCache.setCacheObject("orderCarts:" + uuid, carts, 300, TimeUnit.SECONDS);
|
|
redisCache.setCacheObject("orderCarts:" + uuid, carts, 300, TimeUnit.SECONDS);
|
|
@@ -744,6 +750,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
// Integer totalNum = 0;
|
|
// Integer totalNum = 0;
|
|
|
BigDecimal integral = BigDecimal.ZERO;
|
|
BigDecimal integral = BigDecimal.ZERO;
|
|
|
if (cartIds != null) {
|
|
if (cartIds != null) {
|
|
|
|
|
+ //赠品
|
|
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = redisCache.getCacheObject("orderGiftCarts:" + param.getOrderKey());
|
|
|
|
|
+ String giftCartIds = redisCache.getCacheObject("orderGiftCartKey:" + param.getOrderKey());
|
|
|
|
|
+
|
|
|
//获取购物车列表
|
|
//获取购物车列表
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
//获取地址
|
|
//获取地址
|
|
@@ -754,6 +764,19 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
Boolean isIntegral = false;
|
|
Boolean isIntegral = false;
|
|
|
//组合数据
|
|
//组合数据
|
|
|
FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ //扣减金额
|
|
|
|
|
+ if (ObjectUtil.isNotNull(param.getReceipt())) {
|
|
|
|
|
+ storeOrder.setDeductionPrice(param.getReceipt().getTotalFee());
|
|
|
|
|
+ //收款记录更新
|
|
|
|
|
+ try {
|
|
|
|
|
+ FsCompanyExternalPayReceipt receipt = new FsCompanyExternalPayReceipt();
|
|
|
|
|
+ receipt.setId(param.getReceipt().getId());
|
|
|
|
|
+ receipt.setStatus(1);
|
|
|
|
|
+ companyExternalPayReceiptMapper.updateFsCompanyExternalPayReceipt(receipt);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("收款记录更新失败:{}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
//订单类型
|
|
//订单类型
|
|
|
storeOrder.setErpType(carts.get(0).getErpType());
|
|
storeOrder.setErpType(carts.get(0).getErpType());
|
|
|
storeOrder.setStoreHouseCode("CK01");
|
|
storeOrder.setStoreHouseCode("CK01");
|
|
@@ -789,6 +812,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//storeOrder.setCompanyUserId(fsUser.getCompanyUserId());
|
|
//storeOrder.setCompanyUserId(fsUser.getCompanyUserId());
|
|
|
|
|
+ storeOrder.setCompanyCustomerId(param.getCompanyCustomerId());
|
|
|
storeOrder.setUserId(userId);
|
|
storeOrder.setUserId(userId);
|
|
|
storeOrder.setOrderCode(orderSn);
|
|
storeOrder.setOrderCode(orderSn);
|
|
|
storeOrder.setRealName(address.getRealName());
|
|
storeOrder.setRealName(address.getRealName());
|
|
@@ -862,9 +886,45 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (param.getPayType().equals("1")) {
|
|
if (param.getPayType().equals("1")) {
|
|
|
//全款支付
|
|
//全款支付
|
|
|
storeOrder.setStatus(0);
|
|
storeOrder.setStatus(0);
|
|
|
|
|
+ FsCompanyExternalPayReceipt receipt = param.getReceipt();
|
|
|
|
|
+ if (param.getCompanyCustomerId() != null && receipt != null) {
|
|
|
|
|
+ int compareTo = receipt.getTotalFee().compareTo(storeOrder.getPayPrice());
|
|
|
|
|
+ //部分抵扣 把订单总金额减去收款金额
|
|
|
|
|
+ if (compareTo < 0) {
|
|
|
|
|
+ storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
|
|
|
|
|
+ storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
|
|
|
|
|
+ storeOrder.setDeductionPrice(receipt.getTotalFee());
|
|
|
|
|
+ }
|
|
|
|
|
+ //全部抵扣需把支付金额改成订单总金额
|
|
|
|
|
+ if (compareTo >= 0) {
|
|
|
|
|
+ storeOrder.setPaid(1);
|
|
|
|
|
+ storeOrder.setStatus(1);
|
|
|
|
|
+ storeOrder.setPayPrice(new BigDecimal(0));
|
|
|
|
|
+ storeOrder.setDeductionPrice(receipt.getTotalFee());
|
|
|
|
|
+ storeOrder.setPayMoney(storeOrder.getTotalPrice());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} else if (param.getPayType().equals("2")) {
|
|
} else if (param.getPayType().equals("2")) {
|
|
|
//物流代收
|
|
//物流代收
|
|
|
storeOrder.setStatus(1);
|
|
storeOrder.setStatus(1);
|
|
|
|
|
+ FsCompanyExternalPayReceipt receipt = param.getReceipt();
|
|
|
|
|
+ if (param.getCompanyCustomerId() != null && receipt != null) {
|
|
|
|
|
+ int compareTo = receipt.getTotalFee().compareTo(storeOrder.getPayPrice());
|
|
|
|
|
+ if (compareTo < 0) {
|
|
|
|
|
+ storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
|
|
|
|
|
+ storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
|
|
|
|
|
+ storeOrder.setDeductionPrice(receipt.getTotalFee());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (compareTo >= 0) {
|
|
|
|
|
+ storeOrder.setPayMoney(storeOrder.getTotalPrice());
|
|
|
|
|
+ storeOrder.setPayPrice(new BigDecimal(0));
|
|
|
|
|
+ storeOrder.setDeductionPrice(receipt.getTotalFee());
|
|
|
|
|
+ //全部抵扣 支付类型改成全款支付
|
|
|
|
|
+ storeOrder.setPayType("1");
|
|
|
|
|
+ }
|
|
|
|
|
+ storeOrder.setPaid(1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
} else if (param.getPayType().equals("3")) {
|
|
} else if (param.getPayType().equals("3")) {
|
|
|
//货到付款
|
|
//货到付款
|
|
|
BigDecimal amount = param.getAmount(); //货到付款 自定义代收金额
|
|
BigDecimal amount = param.getAmount(); //货到付款 自定义代收金额
|
|
@@ -931,6 +991,12 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
this.deStockIncSale(carts);
|
|
this.deStockIncSale(carts);
|
|
|
//保存OrderItem
|
|
//保存OrderItem
|
|
|
List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
|
|
List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
|
|
|
|
|
+ //赠品和商品合并
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(giftCarts)) {
|
|
|
|
|
+ //减库存加销量
|
|
|
|
|
+ this.deStockIncSale(giftCarts);
|
|
|
|
|
+ carts.addAll(giftCarts);
|
|
|
|
|
+ }
|
|
|
//保存购物车商品信息
|
|
//保存购物车商品信息
|
|
|
for (FsStoreCartQueryVO vo : carts) {
|
|
for (FsStoreCartQueryVO vo : carts) {
|
|
|
FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
|
|
FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
|
|
@@ -966,6 +1032,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
listOrderItem.add(item);
|
|
listOrderItem.add(item);
|
|
|
}
|
|
}
|
|
|
if (listOrderItem.size() > 0) {
|
|
if (listOrderItem.size() > 0) {
|
|
|
|
|
+ if (StringUtils.isNotEmpty(giftCartIds)) {
|
|
|
|
|
+ cartMapper.updateIsPay(giftCartIds);
|
|
|
|
|
+ String newCartIds = storeOrder.getCartId() + "," + giftCartIds;
|
|
|
|
|
+ storeOrder.setCartId(newCartIds);
|
|
|
|
|
+ }
|
|
|
String itemJson = JSONUtil.toJsonStr(listOrderItem);
|
|
String itemJson = JSONUtil.toJsonStr(listOrderItem);
|
|
|
storeOrder.setItemJson(itemJson);
|
|
storeOrder.setItemJson(itemJson);
|
|
|
fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
@@ -1556,6 +1627,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public R createUserOrder(FsStoreOrderCreateUserParam param) {
|
|
public R createUserOrder(FsStoreOrderCreateUserParam param) {
|
|
|
|
|
+ FsCompanyExternalPayReceipt receipt = null;
|
|
|
if (param.getCompanyCustomerId() != null) {
|
|
if (param.getCompanyCustomerId() != null) {
|
|
|
FsCompanyCustomer fsCompanyCustomer = fsCompanyCustomerMapper.selectFsCompanyCustomerById(param.getCompanyCustomerId());
|
|
FsCompanyCustomer fsCompanyCustomer = fsCompanyCustomerMapper.selectFsCompanyCustomerById(param.getCompanyCustomerId());
|
|
|
if (fsCompanyCustomer == null) {
|
|
if (fsCompanyCustomer == null) {
|
|
@@ -1570,12 +1642,22 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
address.setProvince(param.getProvince());
|
|
address.setProvince(param.getProvince());
|
|
|
address.setCity(param.getCity());
|
|
address.setCity(param.getCity());
|
|
|
address.setDistrict(param.getDistrict());
|
|
address.setDistrict(param.getDistrict());
|
|
|
|
|
+ address.setCreateTime(new Date());
|
|
|
address.setUserId(1L);//目前默认给id为1的用户
|
|
address.setUserId(1L);//目前默认给id为1的用户
|
|
|
int i = userAddressMapper.insertFsUserAddress(address);
|
|
int i = userAddressMapper.insertFsUserAddress(address);
|
|
|
if (i <= 0) {
|
|
if (i <= 0) {
|
|
|
return R.error("收货地址保存失败");
|
|
return R.error("收货地址保存失败");
|
|
|
}
|
|
}
|
|
|
param.setAddressId(address.getId());
|
|
param.setAddressId(address.getId());
|
|
|
|
|
+ if (param.getReceiveMoneyId() != null) {
|
|
|
|
|
+ receipt = companyExternalPayReceiptMapper.selectFsCompanyExternalPayReceiptById(param.getReceiveMoneyId());
|
|
|
|
|
+ if (receipt == null) {
|
|
|
|
|
+ return R.error("收款信息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (receipt.getStatus() != 0) {
|
|
|
|
|
+ return R.error("收款信息已处理");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
if (param.getUserId() == null) {
|
|
if (param.getUserId() == null) {
|
|
|
return R.error("会员不能为空");
|
|
return R.error("会员不能为空");
|
|
@@ -1641,6 +1723,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
createParam.setOrderCreateType(3); //后台制单
|
|
createParam.setOrderCreateType(3); //后台制单
|
|
|
createParam.setOrderType(param.getOrderType());
|
|
createParam.setOrderType(param.getOrderType());
|
|
|
createParam.setOrderMedium(param.getOrderMedium()); //后台制单
|
|
createParam.setOrderMedium(param.getOrderMedium()); //后台制单
|
|
|
|
|
+ createParam.setReceipt(receipt);//收款信息
|
|
|
|
|
+ createParam.setCompanyCustomerId(param.getCompanyCustomerId());
|
|
|
return this.createOrder(param.getUserId(), createParam);
|
|
return this.createOrder(param.getUserId(), createParam);
|
|
|
} else {
|
|
} else {
|
|
|
throw new CustomException("创建失败");
|
|
throw new CustomException("创建失败");
|
|
@@ -4258,8 +4342,14 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ //获取用户信息
|
|
|
|
|
+ FsUserScrm user= null;
|
|
|
|
|
+ if(order.getCompanyCustomerId() != null) {
|
|
|
|
|
+ user = userService.selectFsUserById(param.getUserId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ userService.selectFsUserById(order.getUserId());
|
|
|
|
|
|
|
|
- FsUserScrm user=userService.selectFsUserById(order.getUserId());
|
|
|
|
|
|
|
+ }
|
|
|
if(user!=null){
|
|
if(user!=null){
|
|
|
//已改价处理
|
|
//已改价处理
|
|
|
if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|