|
|
@@ -29,6 +29,8 @@ import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.config.FSSysConfig;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
@@ -63,6 +65,7 @@ import com.fs.his.enums.FsStoreOrderLogEnum;
|
|
|
import com.fs.his.mapper.FsHfpayConfigMapper;
|
|
|
import com.fs.his.mapper.FsStoreProductAttrValueMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.mapper.FsUserWxMapper;
|
|
|
import com.fs.his.service.IFsExpressService;
|
|
|
import com.fs.his.service.IFsStoreProductService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
@@ -136,6 +139,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
private final RedisCache redisCache;
|
|
|
@Autowired
|
|
|
private LiveOrderMapper baseMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsUserWxMapper fsUserWxMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2364,82 +2369,86 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
private BigDecimal handleDeliveryMoney(Long cityId, FsStoreProductScrm fsStoreProduct, String totalNumSize) {
|
|
|
BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
-// List<Long> citys = new ArrayList<>();
|
|
|
-// citys.add(cityId);
|
|
|
-// citys.add(0l);
|
|
|
-// String ids = String.valueOf(fsStoreProduct.getTempId());
|
|
|
-// List<FsShippingTemplates> shippingTemplatesList = shippingTemplatesService.selectFsShippingTemplatesByIds(ids);
|
|
|
-// String cityIds = String.join(",", citys.stream()
|
|
|
-// .map(String::valueOf).collect(Collectors.toList()));
|
|
|
-// List<FsShippingTemplatesRegion> shippingTemplatesRegionList = shippingTemplatesRegionService.selectFsShippingTemplatesRegionListByTempIdsAndCityIds(ids,cityIds);
|
|
|
-// 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));
|
|
|
-// Long tempId = Long.valueOf(fsStoreProduct.getTempId());
|
|
|
-// double num = 0d;
|
|
|
-// Integer templateType = shippingTemplatesMap.get(tempId);
|
|
|
-// List<FsStoreProductAttrValue> productAttrValues = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId());
|
|
|
-// if(productAttrValues == null || productAttrValues.isEmpty()) {
|
|
|
-// return storePostage;
|
|
|
-// }
|
|
|
-// FsStoreProductAttrValue productAttrValue = productAttrValues.get(0);
|
|
|
-// Integer totalNum = Integer.valueOf(totalNumSize);
|
|
|
-// // TYPE_1: 按件数计算
|
|
|
-// if (ShippingTempEnum.TYPE_1.getValue().equals(templateType)) {
|
|
|
-// num = totalNum.doubleValue();
|
|
|
-// }
|
|
|
-// // TYPE_2: 按重量计算(数量 × 重量)
|
|
|
-// else if (ShippingTempEnum.TYPE_2.getValue().equals(templateType)) {
|
|
|
-// num = NumberUtil.mul(totalNum, productAttrValue.getWeight()).doubleValue();
|
|
|
-// }
|
|
|
-// // TYPE_3: 按体积计算(数量 × 体积)
|
|
|
-// else if (ShippingTempEnum.TYPE_3.getValue().equals(templateType)) {
|
|
|
-// num = NumberUtil.mul(totalNum, productAttrValue.getVolume()).doubleValue();
|
|
|
-// }
|
|
|
-// FsShippingTemplatesRegion shippingTemplatesRegion = shippingTemplatesRegionMap.get(tempId);
|
|
|
-// if (shippingTemplatesRegion == null) {
|
|
|
-// log.error("没有找到运费模板");
|
|
|
-// return storePostage;
|
|
|
-// }
|
|
|
-// BigDecimal price = NumberUtil.round(NumberUtil.mul(totalNum, fsStoreProduct.getPrice()), 2);
|
|
|
-//
|
|
|
-// TemplateDTO templateDTO = TemplateDTO.builder()
|
|
|
-// .number(num) // 累计数量(件数/重量/体积)
|
|
|
-// .price(price) // 累计金额
|
|
|
-// .first(shippingTemplatesRegion.getFirst().doubleValue()) // 首件数量
|
|
|
-// .firstPrice(shippingTemplatesRegion.getFirstPrice()) // 首件运费
|
|
|
-// .continues(shippingTemplatesRegion.getContinues().doubleValue()) // 续件数量
|
|
|
-// .continuePrice(shippingTemplatesRegion.getContinuePrice()) // 续件运费
|
|
|
-// .tempId(tempId) // 模板ID
|
|
|
-// .cityId(cityId) // 城市ID
|
|
|
-// .build();
|
|
|
-// //只满足首件
|
|
|
-// 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()));
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
+ List<Long> citys = new ArrayList<>();
|
|
|
+ citys.add(cityId);
|
|
|
+ citys.add(0l);
|
|
|
+ String ids = String.valueOf(fsStoreProduct.getTempId());
|
|
|
+ //如果没有配置运费 直接返回
|
|
|
+ if(StringUtils.isBlank(ids)){
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+ List<FsShippingTemplatesScrm> shippingTemplatesList = shippingTemplatesService.selectFsShippingTemplatesByIds(ids);
|
|
|
+ String cityIds = String.join(",", citys.stream()
|
|
|
+ .map(String::valueOf).collect(Collectors.toList()));
|
|
|
+ List<FsShippingTemplatesRegionScrm> shippingTemplatesRegionList = shippingTemplatesRegionService.selectFsShippingTemplatesRegionListByTempIdsAndCityIds(ids,cityIds);
|
|
|
+ Map<Long, Integer> shippingTemplatesMap = shippingTemplatesList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplatesScrm::getId,
|
|
|
+ FsShippingTemplatesScrm::getType));
|
|
|
+ //提取运费模板有相同值覆盖
|
|
|
+ Map<Long, FsShippingTemplatesRegionScrm> shippingTemplatesRegionMap =
|
|
|
+ shippingTemplatesRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplatesRegionScrm::getTempId,
|
|
|
+ YxShippingTemplatesRegion -> YxShippingTemplatesRegion,
|
|
|
+ (key1, key2) -> key2));
|
|
|
+ Long tempId = Long.valueOf(fsStoreProduct.getTempId());
|
|
|
+ double num = 0d;
|
|
|
+ Integer templateType = shippingTemplatesMap.get(tempId);
|
|
|
+ List<FsStoreProductAttrValueScrm> productAttrValues = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId());
|
|
|
+ if(productAttrValues == null || productAttrValues.isEmpty()) {
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+ FsStoreProductAttrValueScrm productAttrValue = productAttrValues.get(0);
|
|
|
+ Integer totalNum = Integer.valueOf(totalNumSize);
|
|
|
+ // TYPE_1: 按件数计算
|
|
|
+ if (ShippingTempEnum.TYPE_1.getValue().equals(templateType)) {
|
|
|
+ num = totalNum.doubleValue();
|
|
|
+ }
|
|
|
+ // TYPE_2: 按重量计算(数量 × 重量)
|
|
|
+ else if (ShippingTempEnum.TYPE_2.getValue().equals(templateType)) {
|
|
|
+ num = NumberUtil.mul(totalNum, productAttrValue.getWeight()).doubleValue();
|
|
|
+ }
|
|
|
+ // TYPE_3: 按体积计算(数量 × 体积)
|
|
|
+ else if (ShippingTempEnum.TYPE_3.getValue().equals(templateType)) {
|
|
|
+ num = NumberUtil.mul(totalNum, productAttrValue.getVolume()).doubleValue();
|
|
|
+ }
|
|
|
+ FsShippingTemplatesRegionScrm shippingTemplatesRegion = shippingTemplatesRegionMap.get(tempId);
|
|
|
+ if (shippingTemplatesRegion == null) {
|
|
|
+ log.error("没有找到运费模板");
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+ BigDecimal price = NumberUtil.round(NumberUtil.mul(totalNum, fsStoreProduct.getPrice()), 2);
|
|
|
+
|
|
|
+ TemplateDTO templateDTO = TemplateDTO.builder()
|
|
|
+ .number(num) // 累计数量(件数/重量/体积)
|
|
|
+ .price(price) // 累计金额
|
|
|
+ .first(shippingTemplatesRegion.getFirst().doubleValue()) // 首件数量
|
|
|
+ .firstPrice(shippingTemplatesRegion.getFirstPrice()) // 首件运费
|
|
|
+ .continues(shippingTemplatesRegion.getContinues().doubleValue()) // 续件数量
|
|
|
+ .continuePrice(shippingTemplatesRegion.getContinuePrice()) // 续件运费
|
|
|
+ .tempId(tempId) // 模板ID
|
|
|
+ .cityId(cityId.toString()) // 城市ID
|
|
|
+ .build();
|
|
|
+ //只满足首件
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return storePostage;
|
|
|
}
|
|
|
@@ -2847,9 +2856,25 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if(StringUtils.isNotEmpty(orderId)&&order.getOrderId().toString().equals(orderId)){
|
|
|
return R.error("正在支付中...");
|
|
|
}
|
|
|
-
|
|
|
FsUserScrm user=userMapper.selectFsUserById(Long.valueOf(order.getUserId()));
|
|
|
- if(user!=null&& StringUtils.isNotEmpty(user.getMaOpenId())){
|
|
|
+ if(user == null){
|
|
|
+ return R.error("未找到用户信息,请联系管理员!");
|
|
|
+ }
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
+ FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
+ String openId;
|
|
|
+ if(StringUtils.isNotEmpty(user.getMaOpenId())){
|
|
|
+ log.info("用户信息有openid:{}", user.getMaOpenId());
|
|
|
+ openId = user.getMaOpenId();
|
|
|
+ }else{
|
|
|
+ Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
|
|
|
+ .eq(FsUserWx::getFsUserId, order.getUserId())
|
|
|
+ .eq(FsUserWx::getAppId, fsPayConfig.getAppId());
|
|
|
+ FsUserWx fsUserWx = fsUserWxMapper.selectOne(queryWrapper);
|
|
|
+ log.info("查到的openId信息:{}", fsUserWx);
|
|
|
+ openId = fsUserWx.getOpenId();
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(openId)){
|
|
|
//已改价处理
|
|
|
if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){
|
|
|
//改过价不做处理
|
|
|
@@ -2888,8 +2913,6 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// order.setOrderCode(orderCode);
|
|
|
// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
- String json = configService.selectConfigByKey("his.pay");
|
|
|
- FsPayConfigScrm fsPayConfig = JSON.parseObject(json, FsPayConfigScrm.class);
|
|
|
LiveOrderPayment storePayment=new LiveOrderPayment();
|
|
|
storePayment.setCompanyId(order.getCompanyId());
|
|
|
storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
@@ -2899,9 +2922,9 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
storePayment.setPayMoney(order.getPayMoney());
|
|
|
storePayment.setCreateTime(new Date());
|
|
|
storePayment.setPayTypeCode("weixin");
|
|
|
- storePayment.setBusinessType(2);
|
|
|
+ storePayment.setBusinessType(5);
|
|
|
storePayment.setRemark("直播订单支付");
|
|
|
- storePayment.setOpenId(user.getRealName());
|
|
|
+ storePayment.setOpenId(openId);
|
|
|
storePayment.setUserId(user.getUserId());
|
|
|
storePayment.setBusinessId(String.valueOf(order.getOrderId()));
|
|
|
storePayment.setAppId(fsPayConfig.getAppId() == null ? "" : fsPayConfig.getAppId());
|
|
|
@@ -2910,11 +2933,11 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if (fsPayConfig.getType().equals("hf")){
|
|
|
HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
o.setTradeType("T_MINIAPP");
|
|
|
- o.setOpenid(user.getMaOpenId());
|
|
|
+ o.setOpenid(storePayment.getOpenId());
|
|
|
o.setReqSeqId("live-"+storePayment.getPayCode());
|
|
|
o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
o.setGoodsDesc("直播订单支付");
|
|
|
- if (param != null && StringUtils.isNotBlank(param.getAppId())) {
|
|
|
+ if (StringUtils.isNotBlank(param.getAppId())) {
|
|
|
o.setAppId(param.getAppId());
|
|
|
}
|
|
|
HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
@@ -2926,6 +2949,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
mt.setBusinessCode(order.getOrderCode());
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
redisCache.setCacheObject("isPaying:"+order.getOrderId(),order.getOrderId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ log.info("汇付支付");
|
|
|
Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
String s = (String) resultMap.get("package");
|
|
|
resultMap.put("packageValue",s);
|
|
|
@@ -2945,7 +2969,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
payConfig.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
wxPayService.setConfig(payConfig);
|
|
|
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
- orderRequest.setOpenid(user.getMaOpenId());//公众号支付提供用户openid
|
|
|
+ orderRequest.setOpenid(storePayment.getOpenId());
|
|
|
orderRequest.setBody("直播订单支付");
|
|
|
orderRequest.setOutTradeNo("live-" + storePayment.getPayCode());
|
|
|
orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));//测试
|
|
|
@@ -3270,9 +3294,11 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
// 更改店铺库存
|
|
|
fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
+ fsStoreProduct.setSales(fsStoreProduct.getSales()+Long.parseLong(liveOrder.getTotalNum()));
|
|
|
fsStoreProductService.updateFsStoreProduct(fsStoreProduct);
|
|
|
// 更新直播间库存
|
|
|
goods.setStock(goods.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
+ goods.setSales(goods.getSales()+Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
liveGoodsMapper.updateLiveGoods(goods);
|
|
|
|
|
|
//判断是否是三种特定产品
|