|
@@ -24,13 +24,11 @@ import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
-import com.fs.company.domain.Company;
|
|
|
-import com.fs.company.domain.CompanyDept;
|
|
|
-import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
-import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.CompanyDeptMapper;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
+import com.fs.company.mapper.CompanyUserUserMapper;
|
|
|
import com.fs.company.service.ICompanyDeptService;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
@@ -135,7 +133,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
private IFsStoreOrderStatusScrmService orderStatusService;
|
|
|
@Autowired
|
|
|
private FsStoreCartScrmMapper cartMapper;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserUserMapper companyUserUserMapper;
|
|
|
@Autowired
|
|
|
private FsUserAddressScrmMapper userAddressMapper;
|
|
|
|
|
@@ -463,7 +462,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
FsUserAddressScrm address= userAddressMapper.selectFsUserAddressByDefaultAddress(uid);
|
|
|
List<FsStoreCartQueryVO> carts=cartMapper.selectFsStoreCartListByIds(cartParam.getCartIds());
|
|
|
for (FsStoreCartQueryVO cart : carts) {
|
|
|
- if (cart.getChangePrice() != null && BigDecimal.ZERO.compareTo(cart.getChangePrice())<0){
|
|
|
+ if (cart.getChangePrice() != null && BigDecimal.ZERO.compareTo(cart.getChangePrice())<=0){
|
|
|
cart.setPrice(cart.getChangePrice());
|
|
|
//删除改价
|
|
|
FsStoreCartScrm fsStoreCart = new FsStoreCartScrm();
|
|
@@ -475,7 +474,25 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
String uuid = IdUtil.randomUUID();
|
|
|
redisCache.setCacheObject("orderKey:"+uuid, cartParam.getCartIds(), 300, TimeUnit.SECONDS);
|
|
|
redisCache.setCacheObject("orderCarts:"+uuid, carts, 300, TimeUnit.SECONDS);
|
|
|
- return R.ok().put("orderKey",uuid).put("address",address).put("carts",carts);
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(cartParam.getGiftCartIds())){
|
|
|
+ giftCarts=cartMapper.selectFsStoreCartListByIds(cartParam.getGiftCartIds());
|
|
|
+ if (giftCarts != null){
|
|
|
+ for (FsStoreCartQueryVO cart : giftCarts) {
|
|
|
+ if (cart.getChangePrice() != null && BigDecimal.ZERO.compareTo(cart.getChangePrice())<=0){
|
|
|
+ cart.setPrice(cart.getChangePrice());
|
|
|
+ //删除改价
|
|
|
+ FsStoreCartScrm fsStoreCart = new FsStoreCartScrm();
|
|
|
+ fsStoreCart.setId(cart.getId());
|
|
|
+ fsStoreCart.setChangePrice(BigDecimal.ZERO);
|
|
|
+ cartMapper.updateFsStoreCart(fsStoreCart);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redisCache.setCacheObject("orderGiftCarts:"+uuid, giftCarts, 300, TimeUnit.SECONDS);
|
|
|
+ redisCache.setCacheObject("orderGiftKey:"+uuid, cartParam.getGiftCartIds(), 300, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok().put("orderKey",uuid).put("address",address).put("carts",carts).put("giftCarts",giftCarts);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -486,6 +503,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
throw new CustomException("订单已过期",501);
|
|
|
}
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = redisCache.getCacheObject("orderGiftCarts:" + param.getOrderKey());
|
|
|
+ if (giftCarts != null) {
|
|
|
+ carts.addAll(giftCarts);
|
|
|
+ }
|
|
|
BigDecimal payPrice=getOrderSumPrice(carts,"truePrice");
|
|
|
if(StringUtils.isNotEmpty(param.getCreateOrderKey()))
|
|
|
{
|
|
@@ -586,6 +607,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
if(cartIds!=null){
|
|
|
//获取购物车列表
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = redisCache.getCacheObject("orderGiftCarts:" + param.getOrderKey());
|
|
|
+ if (giftCarts != null){
|
|
|
+ carts.addAll(giftCarts);
|
|
|
+ }
|
|
|
//获取地址
|
|
|
FsUserAddressScrm address=userAddressMapper.selectFsUserAddressById(param.getAddressId());
|
|
|
//生成分布式唯一值
|
|
@@ -597,22 +622,42 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
storeOrder.setStoreHouseCode("CK01");
|
|
|
storeOrder.setCompanyId(param.getCompanyId());
|
|
|
storeOrder.setCompanyUserId(param.getCompanyUserId());
|
|
|
+
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config= JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+
|
|
|
//绑定销售
|
|
|
FsUserScrm fsuser= userService.selectFsUserById(userId);
|
|
|
- if(param.getCompanyUserId()!=null){
|
|
|
- if (ObjectUtil.isNotEmpty(fsuser.getCompanyUserId())&& !Objects.equals(fsuser.getCompanyUserId(), param.getCompanyUserId())){
|
|
|
- CompanyUser companyUser=companyUserService.selectCompanyUserById(fsuser.getCompanyUserId());
|
|
|
- return R.error(String.format("请联系%s销售进行购买商品!",companyUser.getNickName()));
|
|
|
- }else {
|
|
|
- fsuser.setCompanyUserId(param.getCompanyUserId());
|
|
|
- userService.updateFsUser(fsuser);
|
|
|
- }
|
|
|
- CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
- if(companyUser!=null){
|
|
|
- storeOrder.setDeptId(companyUser.getDeptId());
|
|
|
+ if(ObjectUtil.isNotEmpty(config.getOrderAttribution())
|
|
|
+ &&config.getOrderAttribution().equals(1)){
|
|
|
+ CompanyUserUser map=new CompanyUserUser();
|
|
|
+ map.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ map.setUserId(userId);
|
|
|
+ List<CompanyUserUser> list= companyUserUserMapper.selectCompanyUserUserList(map);
|
|
|
+ if(list==null||list.size()==0){
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if(companyUser!=null&&companyUser.getStatus().equals("0")){
|
|
|
+ map.setCompanyId(companyUser.getCompanyId());
|
|
|
+ companyUserUserMapper.insertCompanyUserUser(map);
|
|
|
+ }
|
|
|
}
|
|
|
}else {
|
|
|
- storeOrder.setCompanyUserId(fsuser.getCompanyUserId());
|
|
|
+ if(param.getCompanyUserId()!=null){
|
|
|
+ if (ObjectUtil.isNotEmpty(fsuser.getCompanyUserId())&& !Objects.equals(fsuser.getCompanyUserId(), param.getCompanyUserId())){
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(fsuser.getCompanyUserId());
|
|
|
+ return R.error(String.format("请联系%s销售进行购买商品!",companyUser.getNickName()));
|
|
|
+ }else {
|
|
|
+ fsuser.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ userService.updateFsUser(fsuser);
|
|
|
+ }
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if(companyUser!=null){
|
|
|
+ storeOrder.setDeptId(companyUser.getDeptId());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ storeOrder.setCompanyUserId(fsuser.getCompanyUserId());
|
|
|
+ }
|
|
|
}
|
|
|
storeOrder.setUserId(userId);
|
|
|
storeOrder.setOrderCode(orderSn);
|
|
@@ -668,8 +713,6 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
storeOrder.setShippingType(1);
|
|
|
storeOrder.setCreateTime(new Date());
|
|
|
|
|
|
- String json=configService.selectConfigByKey("store.config");
|
|
|
- StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
|
|
|
if(config.getServiceFee()!=null){
|
|
|
storeOrder.setServiceFee(config.getServiceFee());
|
|
|
}
|
|
@@ -727,7 +770,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
if (storeOrder.getCustomerId() == null){
|
|
|
storeOrder.setCustomerId(param.getCustomerId());//6.13 添加客户id
|
|
|
}
|
|
|
- FsStoreOrderScrm tempOrder = redisCache.getCacheObject("orderInfo:" + param.getCreateOrderKey());
|
|
|
+ FsStoreOrder tempOrder = redisCache.getCacheObject("orderInfo:" + param.getCreateOrderKey());
|
|
|
if (tempOrder != null){
|
|
|
storeOrder.setOrderType(tempOrder.getOrderType());
|
|
|
storeOrder.setOrderMedium(tempOrder.getOrderMedium());
|
|
@@ -797,7 +840,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
|
|
|
//删除缓存
|
|
|
redisCache.deleteObject("orderKey:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("orderGiftKey:" + param.getOrderKey());
|
|
|
redisCache.deleteObject("orderCarts:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("orderGiftCarts:" + param.getOrderKey());
|
|
|
|
|
|
//添加记录
|
|
|
orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(),
|
|
@@ -827,6 +872,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
if(StringUtils.isNotEmpty(createOrderKey)){
|
|
|
redisCache.deleteObject("createOrderKey:"+ createOrderKey);
|
|
|
redisCache.deleteObject("orderCarts:" + createOrderKey);
|
|
|
+ redisCache.deleteObject("orderGiftCarts:" + createOrderKey);
|
|
|
redisCache.deleteObject("createOrderMoney:" + createOrderKey);
|
|
|
//货到付款自定义金额 key改为id存储
|
|
|
BigDecimal amount=redisCache.getCacheObject("createOrderAmount:"+createOrderKey);
|
|
@@ -2218,15 +2264,23 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R createSalesOrder(CompanyUser companyUser, String cateIds,Integer orderType,Integer orderMedium) {
|
|
|
+ public R createSalesOrder(CompanyUser companyUser, String cateIds,String giftCateIds,Integer orderType,Integer orderMedium) {
|
|
|
List<FsStoreCartQueryVO> carts=cartMapper.selectFsStoreCartListByIds(cateIds);
|
|
|
+
|
|
|
+
|
|
|
String uuid = IdUtil.randomUUID();
|
|
|
redisCache.setCacheObject("createOrderKey:"+uuid, companyUser.getCompanyId()+"-"+companyUser.getUserId(), 24, TimeUnit.HOURS);
|
|
|
redisCache.setCacheObject("orderCarts:"+uuid, carts, 24, TimeUnit.HOURS);
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = new ArrayList<>();
|
|
|
+ //赠品
|
|
|
+ if (giftCateIds != null){
|
|
|
+ giftCarts=cartMapper.selectFsStoreCartListByIds(giftCateIds);
|
|
|
+ redisCache.setCacheObject("orderGiftCarts:"+uuid, giftCarts, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
|
|
|
//2025.7.23 倍力优需求 制单添加订单类型,媒体来源(非必填)
|
|
|
if (orderType != null || orderMedium != null) {
|
|
|
- FsStoreOrderScrm fsStoreOrder = new FsStoreOrderScrm();
|
|
|
+ FsStoreOrder fsStoreOrder = new FsStoreOrder();
|
|
|
fsStoreOrder.setOrderMedium(orderMedium);
|
|
|
fsStoreOrder.setOrderType(orderType);
|
|
|
redisCache.setCacheObject("orderInfo:"+uuid, fsStoreOrder, 24, TimeUnit.HOURS);
|
|
@@ -2237,19 +2291,38 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
|
|
|
for(FsStoreCartQueryVO vo:carts){
|
|
|
totalMoney=totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
}
|
|
|
+ if (giftCateIds != null){
|
|
|
+ for(FsStoreCartQueryVO vo:giftCarts){
|
|
|
+ totalMoney=totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
redisCache.setCacheObject("createOrderMoney:"+uuid, totalMoney, 24, TimeUnit.HOURS);
|
|
|
- return R.ok().put("orderKey",uuid).put("carts",carts);
|
|
|
+ return R.ok().put("orderKey",uuid).put("carts",carts).put("giftCarts",giftCarts);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R getSalesOrder(String createOrderKey) {
|
|
|
+ public R getSalesOrder(String createOrderKey,Long userId) {
|
|
|
String key=redisCache.getCacheObject("createOrderKey:"+createOrderKey);
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
+ List<FsStoreCartQueryVO> giftCarts = redisCache.getCacheObject("orderGiftCarts:" + createOrderKey);
|
|
|
BigDecimal money=redisCache.getCacheObject("createOrderMoney:"+createOrderKey);
|
|
|
if (StringUtils.isEmpty(key)) {
|
|
|
throw new CustomException("订单已过期",501);
|
|
|
}
|
|
|
- return R.ok().put("carts",carts).put("totalMoney",money);
|
|
|
+ if(giftCarts == null){
|
|
|
+ giftCarts=cartMapper.selectFsStoreGiftCartList(userId);
|
|
|
+ if (giftCarts != null && !giftCarts.isEmpty()){
|
|
|
+ //计算总价
|
|
|
+ for(FsStoreCartQueryVO vo:giftCarts){
|
|
|
+ money=money.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
+ }
|
|
|
+// redisCache.setCacheObject("orderGiftCarts:"+createOrderKey, giftCarts, 24, TimeUnit.HOURS);
|
|
|
+// redisCache.setCacheObject("createOrderMoney:"+createOrderKey, money, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("carts",carts).put("totalMoney",money).put("giftCarts",giftCarts);
|
|
|
}
|
|
|
|
|
|
@Override
|