|
@@ -2,6 +2,9 @@ package com.fs.his.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.net.URLDecoder;
|
|
import cn.hutool.core.net.URLDecoder;
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -63,6 +66,27 @@ import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
import com.fs.qw.service.impl.QwUserServiceImpl;
|
|
import com.fs.qw.service.impl.QwUserServiceImpl;
|
|
|
|
+import com.fs.store.config.StoreIntegralConfig;
|
|
|
|
+import com.fs.store.constants.StoreConstants;
|
|
|
|
+import com.fs.store.domain.FsShippingTemplates;
|
|
|
|
+import com.fs.store.domain.FsShippingTemplatesRegion;
|
|
|
|
+import com.fs.store.domain.FsStoreCart;
|
|
|
|
+import com.fs.store.domain.FsStoreCouponUser;
|
|
|
|
+import com.fs.store.dto.FsStoreOrderComputeDTO;
|
|
|
|
+import com.fs.store.dto.FsStoreOrderPriceDTO;
|
|
|
|
+import com.fs.store.dto.TemplateDTO;
|
|
|
|
+import com.fs.store.enums.BillDetailEnum;
|
|
|
|
+import com.fs.store.enums.OrderLogEnum;
|
|
|
|
+import com.fs.store.enums.ShippingTempEnum;
|
|
|
|
+import com.fs.store.mapper.FsStoreCartMapper;
|
|
|
|
+import com.fs.store.param.FsStoreConfirmOrderParam;
|
|
|
|
+import com.fs.store.param.FsStoreOrderComputedParam;
|
|
|
|
+import com.fs.store.param.FsStoreOrderCreateParam;
|
|
|
|
+import com.fs.store.service.IFsShippingTemplatesRegionService;
|
|
|
|
+import com.fs.store.service.IFsShippingTemplatesService;
|
|
|
|
+import com.fs.store.service.IFsStoreCouponUserService;
|
|
|
|
+import com.fs.store.service.IFsStoreOrderStatusService;
|
|
|
|
+import com.fs.store.vo.FsStoreCartQueryVO;
|
|
import com.fs.system.domain.SysConfig;
|
|
import com.fs.system.domain.SysConfig;
|
|
import com.fs.tzBankPay.doman.*;
|
|
import com.fs.tzBankPay.doman.*;
|
|
import com.fs.ybPay.domain.CreateWxOrderResult;
|
|
import com.fs.ybPay.domain.CreateWxOrderResult;
|
|
@@ -84,6 +108,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -101,6 +126,8 @@ import java.sql.Timestamp;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
|
|
|
|
@@ -241,6 +268,30 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
|
|
@Autowired
|
|
@Autowired
|
|
private IFsStoreProductGroupService storeProductGroupService;
|
|
private IFsStoreProductGroupService storeProductGroupService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsStoreCartMapper cartMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsUserAddressMapper userAddressMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsStoreCouponUserService couponUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsShippingTemplatesService shippingTemplatesService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsShippingTemplatesRegionService shippingTemplatesRegionService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsUserBillService billService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsStoreProductService productService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsStoreOrderStatusService orderStatusService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询订单
|
|
* 查询订单
|
|
*
|
|
*
|
|
@@ -459,6 +510,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
|
|
List<FsStoreOrderListUVO> list=fsStoreOrderMapper.selectFsStoreOrderListUVO(param);
|
|
List<FsStoreOrderListUVO> list=fsStoreOrderMapper.selectFsStoreOrderListUVO(param);
|
|
for(FsStoreOrderListUVO vo:list){
|
|
for(FsStoreOrderListUVO vo:list){
|
|
vo.setIsAfterSales(0);
|
|
vo.setIsAfterSales(0);
|
|
|
|
+ vo.setId(vo.getOrderId());
|
|
if(vo.getStatus().equals(FsStoreOrderStatusEnum.STATUS_4.getValue())){
|
|
if(vo.getStatus().equals(FsStoreOrderStatusEnum.STATUS_4.getValue())){
|
|
//已完成订单
|
|
//已完成订单
|
|
vo.setIsAfterSales(1);
|
|
vo.setIsAfterSales(1);
|
|
@@ -3172,5 +3224,782 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
|
|
return found;
|
|
return found;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Integer selectFsStoreOrderCount(long userId, int status) {
|
|
|
|
+ return fsStoreOrderMapper.selectFsStoreOrderCount(userId,status);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R createSalesOrder(CompanyUser companyUser, String cateIds) {
|
|
|
|
+ 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);
|
|
|
|
+ //计算总价
|
|
|
|
+ BigDecimal totalMoney= BigDecimal.ZERO;
|
|
|
|
+ for(FsStoreCartQueryVO vo:carts){
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R updateSalseOrderMoney(String createOrderKey, BigDecimal money,BigDecimal payAmount) {
|
|
|
|
+ //货到付款自定义金额
|
|
|
|
+ if (payAmount==null){
|
|
|
|
+ String configJson=configService.selectConfigByKey("store.config");
|
|
|
|
+ StoreConfig config=JSONUtil.toBean(configJson,StoreConfig.class);
|
|
|
|
+ Integer amount = config.getPayAmount();
|
|
|
|
+ if (amount!=null){
|
|
|
|
+ payAmount = new BigDecimal(amount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(money==null){
|
|
|
|
+ return R.error("请输入价格");
|
|
|
|
+ }
|
|
|
|
+ if(money.compareTo(BigDecimal.ZERO)<=0){
|
|
|
|
+ return R.error("价格应大于0");
|
|
|
|
+ }
|
|
|
|
+ String key=redisCache.getCacheObject("createOrderKey:"+createOrderKey);
|
|
|
|
+ if (StringUtils.isEmpty(key)) {
|
|
|
|
+ throw new CustomException("订单已过期",501);
|
|
|
|
+ }
|
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
|
+ BigDecimal totalMoney= BigDecimal.ZERO;
|
|
|
|
+ for(FsStoreCartQueryVO vo:carts){
|
|
|
|
+ totalMoney=totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
|
+ }
|
|
|
|
+ if(money.compareTo(totalMoney)==1){
|
|
|
|
+ throw new CustomException("价格不能大于商品总价",501);
|
|
|
|
+ }
|
|
|
|
+ String json=configService.selectConfigByKey("store.config");
|
|
|
|
+ StoreConfig config= JSONUtil.toBean(json,StoreConfig.class);
|
|
|
|
+ if(config.getCreateMoneyRate()!=null){
|
|
|
|
+ totalMoney=totalMoney.multiply(new BigDecimal(config.getCreateMoneyRate())).divide(new BigDecimal(100));
|
|
|
|
+ if(money.compareTo(totalMoney)==-1){
|
|
|
|
+ throw new CustomException("价格必须大于商品总价"+config.getCreateMoneyRate()+"%",501);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ redisCache.setCacheObject("createOrderMoney:"+createOrderKey, money, 24, TimeUnit.HOURS);
|
|
|
|
+ redisCache.setCacheObject("createOrderAmount:"+createOrderKey, payAmount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R getSalesOrder(String createOrderKey) {
|
|
|
|
+ String key=redisCache.getCacheObject("createOrderKey:"+createOrderKey);
|
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
|
+ BigDecimal money=redisCache.getCacheObject("createOrderMoney:"+createOrderKey);
|
|
|
|
+ if (StringUtils.isEmpty(key)) {
|
|
|
|
+ throw new CustomException("订单已过期",501);
|
|
|
|
+ }
|
|
|
|
+ return R.ok().put("carts",carts).put("totalMoney",money);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public R addUserCart(long userId, String createOrderKey) {
|
|
|
|
+ String key=redisCache.getCacheObject("createOrderKey:"+createOrderKey);
|
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
|
+ if (StringUtils.isEmpty(key)) {
|
|
|
|
+ throw new CustomException("订单已过期",501);
|
|
|
|
+ }
|
|
|
|
+ List<Long> ids=new ArrayList<>();
|
|
|
|
+ for(FsStoreCartQueryVO vo : carts){
|
|
|
|
+ FsStoreCart storeCart = FsStoreCart.builder()
|
|
|
|
+ .cartNum(vo.getCartNum())
|
|
|
|
+ .productAttrValueId(vo.getProductAttrValueId())
|
|
|
|
+ .productId(vo.getProductId())
|
|
|
|
+ .userId(userId)
|
|
|
|
+ .isPay(0)
|
|
|
|
+ .isDel(0)
|
|
|
|
+ .isBuy(1)
|
|
|
|
+ .build();
|
|
|
|
+ storeCart.setCreateTime(new Date());
|
|
|
|
+ cartMapper.insertFsStoreCart(storeCart);
|
|
|
|
+ ids.add(storeCart.getId());
|
|
|
|
+ }
|
|
|
|
+ //删除REDIS
|
|
|
|
+// redisCache.deleteObject("createOrderKey:"+createOrderKey);
|
|
|
|
+// redisCache.deleteObject("orderCarts:" + createOrderKey);
|
|
|
|
+ String[] idArr=key.split("-");
|
|
|
|
+ return R.ok().put("cartIds",ids).put("companyId",idArr[0]).put("companyUserId",idArr[1]);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R confirmOrder(long uid, FsStoreConfirmOrderParam cartParam) {
|
|
|
|
+ //获取地址信息和购物车信息
|
|
|
|
+ FsUserAddress address= userAddressMapper.selectFsUserAddressByDefaultAddress(uid);
|
|
|
|
+ List<FsStoreCartQueryVO> carts=cartMapper.selectFsStoreCartListByIds(cartParam.getCartIds());
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public FsStoreOrderComputeDTO computedOrder(long uid, FsStoreOrderComputedParam param) {
|
|
|
|
+ String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
|
+ if (ObjectUtil.isNull(cartIds)) {
|
|
|
|
+ throw new CustomException("订单已过期",501);
|
|
|
|
+ }
|
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
|
+ BigDecimal payPrice=getOrderSumPrice(carts,"truePrice");
|
|
|
|
+ if(StringUtils.isNotEmpty(param.getCreateOrderKey()))
|
|
|
|
+ {
|
|
|
|
+ BigDecimal money=redisCache.getCacheObject("createOrderMoney:"+param.getCreateOrderKey());
|
|
|
|
+ if(money!=null){
|
|
|
|
+ payPrice=money;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ BigDecimal serviceFee=BigDecimal.ZERO;
|
|
|
|
+ String configJson=configService.selectConfigByKey("store.config");
|
|
|
|
+ StoreConfig config=JSONUtil.toBean(configJson,StoreConfig.class);
|
|
|
|
+ if(config.getServiceFee()!=null){
|
|
|
|
+ serviceFee=config.getServiceFee();
|
|
|
|
+ }
|
|
|
|
+ payPrice = payPrice.add(serviceFee);
|
|
|
|
+ FsUserAddress userAddress = null;
|
|
|
|
+ if (param.getAddressId()!=null) {
|
|
|
|
+ userAddress = userAddressMapper.selectFsUserAddressByAddressId(param.getAddressId());
|
|
|
|
+ }
|
|
|
|
+ FsStoreOrderPriceDTO priceGroup = this.getOrderPriceGroup(carts, userAddress);
|
|
|
|
+ BigDecimal payPostage = priceGroup.getStorePostage();
|
|
|
|
+ payPrice = NumberUtil.add(payPrice, payPostage);
|
|
|
|
+
|
|
|
|
+ FsUser user=userService.selectFsUserById(uid);
|
|
|
|
+ // 积分抵扣
|
|
|
|
+ BigDecimal deductionPrice = BigDecimal.ZERO; //积分抵扣金额
|
|
|
|
+ double usedIntegral = 0; //使用了多少积分
|
|
|
|
+ if (param.getUseIntegral()!=null&¶m.getUseIntegral()==1 && user.getIntegral().intValue() > 0) {
|
|
|
|
+ //如果积分总和小于用户积分 抵扣比例 计算抵扣价格
|
|
|
|
+ //默认配置
|
|
|
|
+ Double integralMax = Double.valueOf(100);
|
|
|
|
+ BigDecimal integralFull = new BigDecimal(100);
|
|
|
|
+ Double integralRatio = Double.valueOf(1);
|
|
|
|
+ String json=configService.selectConfigByKey("store.integral");
|
|
|
|
+ if(StringUtils.isEmpty(json)) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ StoreIntegralConfig integralConfig=JSONUtil.toBean(json,StoreIntegralConfig.class);
|
|
|
|
+ integralMax = integralConfig.getIntegralMax();
|
|
|
|
+ integralFull = integralConfig.getIntegralFull();
|
|
|
|
+ integralRatio =integralConfig.getIntegralRatio();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (priceGroup.getTotalPrice().compareTo(integralFull) >= 0) {
|
|
|
|
+ Double userIntegral = user.getIntegral().doubleValue();
|
|
|
|
+ if (integralMax.intValue() > 0 && Double.compare(userIntegral, integralMax) >= 0) {
|
|
|
|
+ userIntegral = integralMax;
|
|
|
|
+ }
|
|
|
|
+ deductionPrice = BigDecimal.valueOf(NumberUtil.mul(userIntegral, integralRatio));
|
|
|
|
+ if (deductionPrice.compareTo(payPrice) < 0) {
|
|
|
|
+ payPrice = NumberUtil.sub(payPrice, deductionPrice);
|
|
|
|
+ usedIntegral = userIntegral;
|
|
|
|
+ } else {
|
|
|
|
+ deductionPrice = payPrice;
|
|
|
|
+ payPrice = BigDecimal.ZERO;
|
|
|
|
+ usedIntegral = NumberUtil.round(NumberUtil.div(deductionPrice,
|
|
|
|
+ BigDecimal.valueOf(integralRatio)), 2).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (payPrice.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
+ payPrice = BigDecimal.ZERO;
|
|
|
|
+ }
|
|
|
|
+ //优惠券
|
|
|
|
+ if(param.getCouponUserId()!=null){
|
|
|
|
+ FsStoreCouponUser couponUser=couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
|
+ if(couponUser!=null&&couponUser.getStatus()==0){
|
|
|
|
+ if(couponUser.getUseMinPrice().compareTo(priceGroup.getTotalPrice())==-1){
|
|
|
|
+ payPrice=payPrice.subtract(couponUser.getCouponPrice());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return FsStoreOrderComputeDTO.builder()
|
|
|
|
+ .totalPrice(priceGroup.getTotalPrice())
|
|
|
|
+ .payPrice(payPrice)
|
|
|
|
+ .payPostage(payPostage)
|
|
|
|
+ .deductionPrice(deductionPrice)
|
|
|
|
+ .usedIntegral(usedIntegral)
|
|
|
|
+ .payIntegral(priceGroup.getPayIntegral())
|
|
|
|
+ .serviceFee(serviceFee)
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取某字段价格
|
|
|
|
+ *
|
|
|
|
+ * @param cartInfo 购物车
|
|
|
|
+ * @param key key值
|
|
|
|
+ * @return Double
|
|
|
|
+ */
|
|
|
|
+ private BigDecimal getOrderSumPrice(List<FsStoreCartQueryVO> cartInfo, String key) {
|
|
|
|
+ BigDecimal sumPrice = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ if ("truePrice".equals(key)) {
|
|
|
|
+ for (FsStoreCartQueryVO storeCart : cartInfo) {
|
|
|
|
+ sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getPrice()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if ("costPrice".equals(key)) {
|
|
|
|
+ for (FsStoreCartQueryVO storeCart : cartInfo) {
|
|
|
|
+ sumPrice = NumberUtil.add(sumPrice,
|
|
|
|
+ NumberUtil.mul(storeCart.getCartNum(), storeCart.getCost()));
|
|
|
|
+ }
|
|
|
|
+ }else if ("payIntegral".equals(key)) {
|
|
|
|
+ for (FsStoreCartQueryVO storeCart : cartInfo) {
|
|
|
|
+ if (storeCart.getIntegral() != null) {
|
|
|
|
+ sumPrice = NumberUtil.add(sumPrice,
|
|
|
|
+ NumberUtil.mul(storeCart.getCartNum(), storeCart.getIntegral()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sumPrice;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取订单价格
|
|
|
|
+ */
|
|
|
|
+ private FsStoreOrderPriceDTO getOrderPriceGroup(List<FsStoreCartQueryVO> cartInfo, FsUserAddress userAddress) {
|
|
|
|
+ BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
|
+ //免运费设置
|
|
|
|
+ BigDecimal storeFreePostage = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ BigDecimal totalPrice = this.getOrderSumPrice(cartInfo, "truePrice");//获取订单总金额
|
|
|
|
+ BigDecimal costPrice = this.getOrderSumPrice(cartInfo, "costPrice");//获取订单成本价
|
|
|
|
+ BigDecimal payIntegral = this.getOrderSumPrice(cartInfo, "payIntegral");//获取订单需要的积分
|
|
|
|
+
|
|
|
|
+ //如果设置满包邮0 表示全局包邮,如果设置大于0表示满这价格包邮,否则走运费模板算法
|
|
|
|
+ if (storeFreePostage.compareTo(BigDecimal.ZERO) != 0 && totalPrice.compareTo(storeFreePostage) <= 0) {
|
|
|
|
+ storePostage = this.handlePostage(cartInfo, userAddress);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FsStoreOrderPriceDTO priceGroupDTO = new FsStoreOrderPriceDTO();
|
|
|
|
+ priceGroupDTO.setStorePostage(storePostage);
|
|
|
|
+// priceGroupDTO.setStoreFreePostage(storeFreePostage);
|
|
|
|
+ priceGroupDTO.setTotalPrice(totalPrice);
|
|
|
|
+ priceGroupDTO.setCostPrice(costPrice);
|
|
|
|
+ priceGroupDTO.setPayIntegral(payIntegral);
|
|
|
|
+ return priceGroupDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据运费模板算法返回邮费
|
|
|
|
+ *
|
|
|
|
+ * @param cartInfo 购物车
|
|
|
|
+ * @param userAddress 地址
|
|
|
|
+ * @return double
|
|
|
|
+ */
|
|
|
|
+ private BigDecimal handlePostage(List<FsStoreCartQueryVO> cartInfo, FsUserAddress userAddress) {
|
|
|
|
+ BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
|
+ if (userAddress != null) {
|
|
|
|
+ if (userAddress.getCity() == null) {
|
|
|
|
+ return storePostage;
|
|
|
|
+ }
|
|
|
|
+ String cityId = userAddress.getCity();
|
|
|
|
+ List<String> citys = new ArrayList<>();
|
|
|
|
+ citys.add(cityId);
|
|
|
|
+ citys.add("0");//城市包括默认
|
|
|
|
+ List<Long> tempIds = cartInfo
|
|
|
|
+ .stream()
|
|
|
|
+ .map(FsStoreCartQueryVO::getTempId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //获取商品用到的运费模板
|
|
|
|
+ List<FsShippingTemplates> shippingTemplatesList =shippingTemplatesService.selectFsShippingTemplatesByIds(StringUtils.join(tempIds,","));
|
|
|
|
+
|
|
|
|
+ //获取运费模板区域列表按照城市排序
|
|
|
|
+ List<FsShippingTemplatesRegion> shippingTemplatesRegionList = shippingTemplatesRegionService.selectFsShippingTemplatesRegionListByTempIdsAndCityIds(StringUtils.join(tempIds,","),StringUtils.join(citys,","));
|
|
|
|
+
|
|
|
|
+ //提取运费模板类型
|
|
|
|
+ Map<Long, Integer> shippingTemplatesMap = shippingTemplatesList
|
|
|
|
+ .stream()
|
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplates::getId,
|
|
|
|
+ FsShippingTemplates::getType));
|
|
|
|
+ //提取运费模板有相同值覆盖
|
|
|
|
+ Map<Long, FsShippingTemplatesRegion> shippingTemplatesRegionMap =
|
|
|
|
+ shippingTemplatesRegionList.stream()
|
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplatesRegion::getTempId,
|
|
|
|
+ YxShippingTemplatesRegion -> YxShippingTemplatesRegion,
|
|
|
|
+ (key1, key2) -> key2));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map<Long, TemplateDTO> templateDTOMap = new HashMap<>();
|
|
|
|
+ for (FsStoreCartQueryVO storeCartVO : cartInfo) {
|
|
|
|
+ Long tempId = storeCartVO.getTempId();
|
|
|
|
+ //根据模板类型获取相应的数量
|
|
|
|
+ double num = 0d;
|
|
|
|
+ if (ShippingTempEnum.TYPE_1.getValue().equals(shippingTemplatesMap.get(tempId))) {
|
|
|
|
+ num = storeCartVO.getCartNum().doubleValue();
|
|
|
|
+ } else if (ShippingTempEnum.TYPE_2.getValue().equals(shippingTemplatesMap.get(tempId))) {
|
|
|
|
+ num = NumberUtil.mul(storeCartVO.getCartNum(),
|
|
|
|
+ storeCartVO.getWeight()).doubleValue();
|
|
|
|
+ } else if (ShippingTempEnum.TYPE_3.getValue().equals(shippingTemplatesMap.get(tempId))) {
|
|
|
|
+ num = NumberUtil.mul(storeCartVO.getCartNum(),
|
|
|
|
+ storeCartVO.getVolume()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FsShippingTemplatesRegion shippingTemplatesRegion = shippingTemplatesRegionMap.get(tempId);
|
|
|
|
+ BigDecimal price = NumberUtil.round(NumberUtil.mul(storeCartVO.getCartNum(),
|
|
|
|
+ storeCartVO.getPrice()), 2);
|
|
|
|
+ if (!templateDTOMap.containsKey(tempId)) {
|
|
|
|
+ TemplateDTO templateDTO = TemplateDTO.builder()
|
|
|
|
+ .number(num)
|
|
|
|
+ .price(price)
|
|
|
|
+ .first(shippingTemplatesRegion.getFirst().doubleValue())
|
|
|
|
+ .firstPrice(shippingTemplatesRegion.getFirstPrice())
|
|
|
|
+ .continues(shippingTemplatesRegion.getContinues().doubleValue())
|
|
|
|
+ .continuePrice(shippingTemplatesRegion.getContinuePrice())
|
|
|
|
+ .tempId(tempId)
|
|
|
|
+ .cityId(cityId)
|
|
|
|
+ .build();
|
|
|
|
+ templateDTOMap.put(tempId, templateDTO);
|
|
|
|
+ } else {
|
|
|
|
+ TemplateDTO templateDTO = templateDTOMap.get(tempId);
|
|
|
|
+ templateDTO.setNumber(templateDTO.getNumber() + num);
|
|
|
|
+ templateDTO.setPrice(NumberUtil.add(templateDTO.getPrice().doubleValue(), price));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //处理区域邮费
|
|
|
|
+ boolean isFirst = true; //用来是否多个产品的标识 false表示数量大于1
|
|
|
|
+ for (TemplateDTO templateDTO : templateDTOMap.values()) {
|
|
|
|
+ if (isFirst) {//首件
|
|
|
|
+ //只满足首件
|
|
|
|
+ if (Double.compare(templateDTO.getNumber(), templateDTO.getFirst()) <= 0) {
|
|
|
|
+ storePostage = NumberUtil.round(NumberUtil.add(storePostage,
|
|
|
|
+ templateDTO.getFirstPrice()), 2);
|
|
|
|
+ } else {
|
|
|
|
+ BigDecimal firstPrice = NumberUtil.add(storePostage, templateDTO.getFirstPrice());
|
|
|
|
+
|
|
|
|
+ if (templateDTO.getContinues() <= 0) {
|
|
|
|
+ storePostage = firstPrice;
|
|
|
|
+ } else {
|
|
|
|
+ //续件平均值且向上取整数
|
|
|
|
+ double average = Math.ceil(NumberUtil.div(NumberUtil.sub(templateDTO.getNumber(),
|
|
|
|
+ templateDTO.getFirst()),
|
|
|
|
+ templateDTO.getContinues().doubleValue()));
|
|
|
|
+ //最终邮费
|
|
|
|
+ storePostage = NumberUtil.add(firstPrice, NumberUtil.mul(average,
|
|
|
|
+ templateDTO.getContinuePrice()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ isFirst = false;
|
|
|
|
+ } else {
|
|
|
|
+ //多件直接在以前的基数继续续建
|
|
|
|
+ if (templateDTO.getContinues() > 0) {
|
|
|
|
+ //续件平均值且向上取整数
|
|
|
|
+ double average = Math.ceil(
|
|
|
|
+ NumberUtil.div(
|
|
|
|
+ templateDTO.getNumber(),
|
|
|
|
+ templateDTO.getContinues()
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ //最终邮费
|
|
|
|
+ storePostage = NumberUtil.add(storePostage.doubleValue(), NumberUtil.mul(average,
|
|
|
|
+ templateDTO.getContinuePrice()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return storePostage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public R createOrder(long userId, FsStoreOrderCreateParam param) {
|
|
|
|
+ FsStoreOrderComputedParam computedParam=new FsStoreOrderComputedParam();
|
|
|
|
+ BeanUtils.copyProperties(param, computedParam);
|
|
|
|
+ //计算金额
|
|
|
|
+ FsStoreOrderComputeDTO dto=this.computedOrder(userId, computedParam);
|
|
|
|
+ String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
|
+// Integer totalNum = 0;
|
|
|
|
+ BigDecimal integral = BigDecimal.ZERO;
|
|
|
|
+ if(cartIds!=null){
|
|
|
|
+ //获取购物车列表
|
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
|
+ //获取地址
|
|
|
|
+ FsUserAddress address=userAddressMapper.selectFsUserAddressByAddressId(param.getAddressId());
|
|
|
|
+ //生成分布式唯一值
|
|
|
|
+ String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
|
+ //是否使用积分
|
|
|
|
+ Boolean isIntegral=false;
|
|
|
|
+ //组合数据
|
|
|
|
+ FsStoreOrder storeOrder = new FsStoreOrder();
|
|
|
|
+ storeOrder.setStoreHouseCode("CK01");
|
|
|
|
+ storeOrder.setCompanyId(param.getCompanyId());
|
|
|
|
+ storeOrder.setCompanyUserId(param.getCompanyUserId());
|
|
|
|
+ if(param.getCompanyUserId()!=null){
|
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
|
+ if(companyUser!=null){
|
|
|
|
+ storeOrder.setDeptId(companyUser.getDeptId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ storeOrder.setUserId(userId);
|
|
|
|
+ storeOrder.setOrderCode(orderSn);
|
|
|
|
+ storeOrder.setUserName(address.getRealName());
|
|
|
|
+ storeOrder.setUserPhone(address.getPhone());
|
|
|
|
+ storeOrder.setUserAddress(address.getProvince() + " " + address.getCity() +
|
|
|
|
+ " " + address.getDistrict() + " " + address.getDetail().trim());
|
|
|
|
+ storeOrder.setCartId(cartIds);
|
|
|
|
+ storeOrder.setTotalNum(Long.parseLong(String.valueOf(carts.size())));
|
|
|
|
+ storeOrder.setTotalPrice(dto.getTotalPrice());
|
|
|
|
+ // todo add字段 TotalPostage
|
|
|
|
+ storeOrder.setTotalPostage(dto.getPayPostage());
|
|
|
|
+
|
|
|
|
+ //优惠券处理
|
|
|
|
+ if(param.getCouponUserId()!=null){
|
|
|
|
+ FsStoreCouponUser couponUser=couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
|
+ if(couponUser!=null&&couponUser.getStatus()==0){
|
|
|
|
+ // storeOrder.setCouponId(couponUser.getId()); todo 调整couponid存储到UserCouponId
|
|
|
|
+ storeOrder.setUserCouponId(couponUser.getId());
|
|
|
|
+ storeOrder.setCouponPrice(couponUser.getCouponPrice());
|
|
|
|
+ //更新优惠券状态
|
|
|
|
+ couponUser.setStatus(1);
|
|
|
|
+ couponUser.setUseTime(new Date());
|
|
|
|
+ couponUserService.updateFsStoreCouponUser(couponUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //处理推荐人
|
|
|
|
+ FsUser user= userService.selectFsUserById(storeOrder.getUserId());
|
|
|
|
+ if(user.getSpreadUserId()!=null&&user.getSpreadUserId()>0){
|
|
|
|
+ storeOrder.setTuiUserId(user.getSpreadUserId());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(param.getTuiUserId()!=null){
|
|
|
|
+ FsUser tuiUser= userService.selectFsUserById(param.getTuiUserId());
|
|
|
|
+ if(tuiUser!=null&&tuiUser.getIsPromoter()==1){
|
|
|
|
+ storeOrder.setTuiUserId(param.getTuiUserId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ storeOrder.setPayPostage(dto.getPayPostage());
|
|
|
|
+// storeOrder.setDeductionPrice(dto.getDeductionPrice()); todo 抵扣金额存储到 DiscountMoney
|
|
|
|
+ storeOrder.setDiscountMoney(dto.getDeductionPrice());
|
|
|
|
+ storeOrder.setIsPay(0);
|
|
|
|
+ storeOrder.setPayType(param.getPayType());
|
|
|
|
+ if (isIntegral) {
|
|
|
|
+ storeOrder.setPayIntegral(integral);
|
|
|
|
+ }
|
|
|
|
+ storeOrder.setUseIntegral(BigDecimal.valueOf(dto.getUsedIntegral()));
|
|
|
|
+ storeOrder.setBackIntegral(BigDecimal.ZERO);
|
|
|
|
+ storeOrder.setGainIntegral(BigDecimal.ZERO);
|
|
|
|
+ storeOrder.setRemark(param.getMark());
|
|
|
|
+ //todo 获取成本价 调整为costPrice
|
|
|
|
+ BigDecimal costPrice = this.getOrderSumPrice(carts, "costPrice");
|
|
|
|
+ storeOrder.setCostPrice(costPrice);
|
|
|
|
+ //todo 类型转换为String
|
|
|
|
+ storeOrder.setIsChannel("1");
|
|
|
|
+ storeOrder.setShippingType(1);
|
|
|
|
+ storeOrder.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+// String json=configService.selectConfigByKey("store.config");
|
|
|
|
+ // todo 更改商城配置来源 his.store
|
|
|
|
+ String json=configService.selectConfigByKey("his.store");
|
|
|
|
+ StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
|
|
|
|
+ if(config.getServiceFee()!=null){
|
|
|
|
+ storeOrder.setServiceFee(config.getServiceFee());
|
|
|
|
+ }
|
|
|
|
+ if(param.getPayType().equals(1)){
|
|
|
|
+ //全款支付
|
|
|
|
+ storeOrder.setStatus(1);
|
|
|
|
+ }
|
|
|
|
+ else if(param.getPayType().equals(2)){
|
|
|
|
+ //货到付款
|
|
|
|
+ storeOrder.setStatus(2);
|
|
|
|
+ }
|
|
|
|
+ //后台制单处理
|
|
|
|
+ if(param.getPayPrice()!=null&¶m.getPayPrice().compareTo(BigDecimal.ZERO)>0){
|
|
|
|
+ storeOrder.setPayPrice(param.getPayPrice());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ storeOrder.setPayPrice(dto.getPayPrice());
|
|
|
|
+ }
|
|
|
|
+ storeOrder.setOrderCreateType(param.getOrderCreateType());
|
|
|
|
+ Long prescribe = carts.stream().filter(item -> item.getProductType()!=null&&item.getProductType()==2).count();
|
|
|
|
+ if(prescribe>0){
|
|
|
|
+ storeOrder.setIsPrescribe(1);
|
|
|
|
+ } else {
|
|
|
|
+ storeOrder.setIsPrescribe(0);
|
|
|
|
+ }
|
|
|
|
+ Integer flag=fsStoreOrderMapper.insertFsStoreOrder(storeOrder);
|
|
|
|
+ if (flag==0) {
|
|
|
|
+ return R.error("订单创建失败");
|
|
|
|
+ }
|
|
|
|
+ //使用了积分扣积分
|
|
|
|
+ if (dto.getUsedIntegral() > 0) {
|
|
|
|
+ this.decIntegral(userId, dto.getUsedIntegral(), dto.getDeductionPrice().doubleValue(),storeOrder.getOrderId().toString());
|
|
|
|
+ }
|
|
|
|
+ //减库存加销量
|
|
|
|
+ this.deStockIncSale(carts);
|
|
|
|
+ //保存OrderItem
|
|
|
|
+ List<FsStoreOrderItem> listOrderItem=new ArrayList<>();
|
|
|
|
+ //保存购物车商品信息
|
|
|
|
+ for(FsStoreCartQueryVO vo:carts){
|
|
|
|
+ FsStoreCartDTO fsStoreCartDTO=new FsStoreCartDTO();
|
|
|
|
+ fsStoreCartDTO.setProductId(vo.getProductId());
|
|
|
|
+ fsStoreCartDTO.setPrice(vo.getPrice());
|
|
|
|
+ fsStoreCartDTO.setSku(vo.getProductAttrName());
|
|
|
|
+ fsStoreCartDTO.setProductName(vo.getProductName());
|
|
|
|
+ fsStoreCartDTO.setNum(vo.getCartNum());
|
|
|
|
+ fsStoreCartDTO.setBarCode(vo.getBarCode());
|
|
|
|
+ fsStoreCartDTO.setGroupBarCode(vo.getGroupBarCode());
|
|
|
|
+ fsStoreCartDTO.setBrokerage(vo.getBrokerage());
|
|
|
|
+ fsStoreCartDTO.setBrokerageTwo(vo.getBrokerageTwo());
|
|
|
|
+ fsStoreCartDTO.setBrokerageThree(vo.getBrokerageThree());
|
|
|
|
+ if(StringUtils.isEmpty(vo.getProductAttrImage())){
|
|
|
|
+ fsStoreCartDTO.setImage(vo.getProductImage());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ fsStoreCartDTO.setImage(vo.getProductAttrImage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FsStoreOrderItem item=new FsStoreOrderItem();
|
|
|
|
+ item.setOrderId(storeOrder.getOrderId());
|
|
|
|
+ item.setOrderCode(orderSn);
|
|
|
|
+ item.setCartId(vo.getId());
|
|
|
|
+ item.setProductId(vo.getProductId());
|
|
|
|
+ item.setJsonInfo(JSONUtil.toJsonStr(fsStoreCartDTO));
|
|
|
|
+ //todo 类型转换Long
|
|
|
|
+ item.setNum(Long.valueOf(vo.getCartNum()));
|
|
|
|
+ item.setIsAfterSales(0);
|
|
|
|
+ //处方药
|
|
|
|
+ if(vo.getProductType().equals(2)){
|
|
|
|
+ item.setIsPrescribe(1);
|
|
|
|
+ }
|
|
|
|
+ fsStoreOrderItemMapper.insertFsStoreOrderItem(item);
|
|
|
|
+ listOrderItem.add(item);
|
|
|
|
+ }
|
|
|
|
+ if(listOrderItem.size()>0){
|
|
|
|
+ String itemJson=JSONUtil.toJsonStr(listOrderItem);
|
|
|
|
+ storeOrder.setItemJson(itemJson);
|
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
+ }
|
|
|
|
+ //购物车状态修改
|
|
|
|
+ cartMapper.updateIsPay(cartIds);
|
|
|
|
+
|
|
|
|
+ //删除缓存
|
|
|
|
+ redisCache.deleteObject("orderKey:" + param.getOrderKey());
|
|
|
|
+ redisCache.deleteObject("orderCarts:" + param.getOrderKey());
|
|
|
|
+
|
|
|
|
+ //添加记录
|
|
|
|
+ orderStatusService.create(storeOrder.getOrderId(), OrderLogEnum.CREATE_ORDER.getValue(),
|
|
|
|
+ OrderLogEnum.CREATE_ORDER.getDesc());
|
|
|
|
+
|
|
|
|
+ //加入redis,24小时自动取消
|
|
|
|
+ String redisKey = String.valueOf(StrUtil.format("{}{}",
|
|
|
|
+ StoreConstants.REDIS_ORDER_OUTTIME_UNPAY, storeOrder.getOrderId()));
|
|
|
|
|
|
|
|
+ if(config.getUnPayTime()!=null&&config.getUnPayTime()>0){
|
|
|
|
+ redisCache.setCacheObject(redisKey,storeOrder.getOrderId(),config.getUnPayTime(), TimeUnit.MINUTES);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ redisCache.setCacheObject(redisKey,storeOrder.getOrderId(),30, TimeUnit.MINUTES);
|
|
|
|
+ }
|
|
|
|
+ //添加支付到期时间
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(storeOrder.getCreateTime());
|
|
|
|
+ calendar.add(Calendar.MINUTE,config.getUnPayTime());
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String payLimitTime = format.format(calendar.getTime() );
|
|
|
|
+ //删除推荐订单KEY
|
|
|
|
+ String createOrderKey = param.getCreateOrderKey();
|
|
|
|
+ if(StringUtils.isNotEmpty(createOrderKey)){
|
|
|
|
+ redisCache.deleteObject("createOrderKey:"+ createOrderKey);
|
|
|
|
+ redisCache.deleteObject("orderCarts:" + createOrderKey);
|
|
|
|
+ redisCache.deleteObject("createOrderMoney:" + createOrderKey);
|
|
|
|
+ //货到付款自定义金额 key改为id存储
|
|
|
|
+ BigDecimal amount=redisCache.getCacheObject("createOrderAmount:"+createOrderKey);
|
|
|
|
+ redisCache.deleteObject("createOrderAmount:" + createOrderKey);
|
|
|
|
+ redisCache.setCacheObject("orderAmount:"+storeOrder.getOrderId(), amount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
|
+ }
|
|
|
|
+ //todo 前端使用的是id这个属性 尽量适配前端代码
|
|
|
|
+ if(storeOrder.getId() == null){
|
|
|
|
+ storeOrder.setId(storeOrder.getOrderId());
|
|
|
|
+ }
|
|
|
|
+ return R.ok().put("order", storeOrder).put("payLimitTime",payLimitTime);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ return R.error("订单已过期");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 积分抵扣
|
|
|
|
+ */
|
|
|
|
+ private void decIntegral(Long uid, double usedIntegral, double deductionPrice,String busId) {
|
|
|
|
+ userService.decIntegral(uid, usedIntegral);
|
|
|
|
+ FsUser user=userService.selectFsUserById(uid);
|
|
|
|
+ //积分记录
|
|
|
|
+ billService.addBill(uid, BillDetailEnum.CATEGORY_2.getValue(),0, BillDetailEnum.TYPE_1.getDesc(), usedIntegral, user.getIntegral().doubleValue(),
|
|
|
|
+ "购买商品使用" + usedIntegral + "积分抵扣" + deductionPrice + "元",busId,0L);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void deStockIncSale(List<FsStoreCartQueryVO> cartInfo) {
|
|
|
|
+ for (FsStoreCartQueryVO storeCartVO : cartInfo) {
|
|
|
|
+ productService.decProductStock(storeCartVO.getProductId(),
|
|
|
|
+ storeCartVO.getProductAttrValueId(),storeCartVO.getCartNum());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ @Synchronized
|
|
|
|
+ public R mallPay(FsStoreOrderPayParam param){
|
|
|
|
+
|
|
|
|
+ FsStoreOrder order = fsStoreOrderMapper.selectFsStoreOrderByOrderId(param.getOrderId());
|
|
|
|
+
|
|
|
|
+ if (order == null) {
|
|
|
|
+ return R.error("订单不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!order.getStatus().equals(FsStoreOrderStatusEnum.STATUS_1.getValue())) {
|
|
|
|
+ return R.error("订单状态不正确");
|
|
|
|
+ }
|
|
|
|
+ FsUser user = userService.selectFsUserByUserId(param.getUserId());
|
|
|
|
+ //获取用户
|
|
|
|
+ if (user != null && StringUtils.isNotEmpty(user.getMaOpenId())) {
|
|
|
|
+ if (order.getPayMoney().compareTo(new BigDecimal(0)) == 0 && 1==2) {
|
|
|
|
+ this.payConfirm(order.getOrderCode(), "", "", "", 2);
|
|
|
|
+ return R.ok().put("data", param.getOrderId()).put("isPay", "1");
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ //在线支付
|
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
|
+ PayConfigDTO payConfigDTO = JSONUtil.toBean(json, PayConfigDTO.class);
|
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
|
+ if (StringUtils.isEmpty(payCode)) {
|
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
|
+ }
|
|
|
|
+ FsStorePayment storePayment = new FsStorePayment();
|
|
|
|
+ storePayment.setStatus(0);
|
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
|
+ storePayment.setPayMode(payConfigDTO.getType());
|
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
|
+ storePayment.setBusinessType(2);
|
|
|
|
+ storePayment.setRemark("商城订单支付");
|
|
|
|
+ storePayment.setOpenId(user.getMaOpenId());
|
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
|
+ storePayment.setCompanyId(order.getCompanyId());
|
|
|
|
+ storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
|
+ storePayment.setStoreId(order.getStoreId());
|
|
|
|
+ storePayment.setBusinessId(order.getOrderId().toString());
|
|
|
|
+ if (storePaymentService.insertFsStorePayment(storePayment) > 0) {
|
|
|
|
+
|
|
|
|
+ if (payConfigDTO.getType().equals("wx")) {
|
|
|
|
+ //创建微信订单
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
|
+ FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
|
+ payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxMchKey());
|
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
|
+ payConfig.setNotifyUrl(wxPayProperties.getNotifyUrl());
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
|
+ orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
|
+ orderRequest.setBody("药品订单支付");
|
|
|
|
+ orderRequest.setOutTradeNo("store-" + storePayment.getPayCode());
|
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
|
+ //orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(money));//测试
|
|
|
|
+ orderRequest.setTradeType("JSAPI");
|
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
|
+ try {
|
|
|
|
+ WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
|
+ return R.ok().put("data", orderResult).put("type", "wx").put("isPay", 0);
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new CustomException("支付失败" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (payConfigDTO.getType().equals("yb")) {
|
|
|
|
+ WxJspayDTO p = new WxJspayDTO();
|
|
|
|
+ // 使用setter方法为对象赋值
|
|
|
|
+ p.setPayMoney(storePayment.getPayMoney().toString());
|
|
|
|
+ p.setLowOrderId("store-" + storePayment.getPayCode());
|
|
|
|
+ p.setBody("药品订单支付");
|
|
|
|
+ p.setIsMinipg("1");
|
|
|
|
+ p.setOpenId(user.getMaOpenId());
|
|
|
|
+ p.setAttach("");
|
|
|
|
+ p.setStoreid("0");
|
|
|
|
+ CreateWxOrderResult wxOrder = payService.createWxOrder(p);
|
|
|
|
+ if (wxOrder.getStatus().equals("100")) {
|
|
|
|
+ FsStorePayment mt = new FsStorePayment();
|
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
|
+ mt.setTradeNo(wxOrder.getUpOrderId());
|
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
|
+ return R.ok().put("isPay", 0).put("data", wxOrder).put("type", "yb");
|
|
|
|
+ } else {
|
|
|
|
+ throw new CustomException("支付失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (payConfigDTO.getType().equals("tz")) {
|
|
|
|
+ PayCreateOrder o = new PayCreateOrder();
|
|
|
|
+ o.setOrderNo("store" + storePayment.getPayCode()); // 业务系统订单号
|
|
|
|
+ o.setTrxAmt(storePayment.getPayMoney().doubleValue()); // 交易金额
|
|
|
|
+ o.setBusinessCstNo(order.getUserId().toString()); // 业务平台客户号
|
|
|
|
+ String phone = "";
|
|
|
|
+ if (user.getPhone() != null && user.getPhone().length() > 4) {
|
|
|
|
+ phone = user.getPhone().substring(user.getPhone().length() - 4);
|
|
|
|
+ if (user.getPhone().length() > 11) {
|
|
|
|
+ o.setPayerMobileNo(PhoneUtil.decryptPhone(user.getPhone()));
|
|
|
|
+ } else {
|
|
|
|
+ o.setPayerMobileNo(user.getPhone());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ o.setPayerName("微信用户" + phone);
|
|
|
|
+ o.setGoodsInfo("药品订单支付"); // 订单信息
|
|
|
|
+ o.setOpenId(user.getMaOpenId());
|
|
|
|
+ o.setOrderType(2);
|
|
|
|
+ o.setOrderId(order.getOrderId().toString());
|
|
|
|
+ TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(o);
|
|
|
|
+ FsStorePayment mt = new FsStorePayment();
|
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
|
+ mt.setTradeNo(result.getBody().getOrderFlowNo());
|
|
|
|
+ fsStorePaymentMapper.updateFsStorePayment(mt);
|
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "tz");
|
|
|
|
+ }
|
|
|
|
+ else if (payConfigDTO.getType().equals("hf")) {
|
|
|
|
+ HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
|
+ o.setTradeType("T_MINIAPP");
|
|
|
|
+ o.setOpenid(user.getMaOpenId());
|
|
|
|
+ o.setReqSeqId("store-" + storePayment.getPayCode());
|
|
|
|
+ o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
|
+ o.setGoodsDesc("药品订单支付");
|
|
|
|
+ HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
|
+ FsStorePayment mt = new FsStorePayment();
|
|
|
|
+ mt.setPaymentId(storePayment.getPaymentId());
|
|
|
|
+ mt.setTradeNo(result.getHf_seq_id());
|
|
|
|
+ storePaymentService.updateFsStorePayment(mt);
|
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ return R.error("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ return R.error();
|
|
|
|
+ }
|
|
}
|
|
}
|