提交 788ec253 authored 作者: 吴德鹏's avatar 吴德鹏

活动

上级 62642346
......@@ -45,10 +45,11 @@ public class OrderController extends Controller {
private final TbCfItemCommentRepository commentRepository;
private final TbCfExpressTemplateRepository templateRepository;
private final TbCfExchangeRepository exchangeRepository;
private final ActivityRepository activityRepository;
private final AuthenticationUser user;
private static Logger logger = LoggerFactory.getLogger(OrderController.class);
public OrderController(TbCfToicouponRepository couponRepository, TbCfOrderRepository repository, TbCfCartRecordRRepository cartRepository, TbCfAddressRepository addressRepository, TbCfToicouponRepository toicouponRepository, TbCfStationItemRepository itemRepository, TbCfItemSkuRepository itemSkuRepository, TbCfItemCommentRepository commentRepository, TbCfExpressTemplateRepository templateRepository, @Qualifier("tbCfExchangeRepository") TbCfExchangeRepository exchangeRepository, AuthenticationUser user) {
public OrderController(TbCfToicouponRepository couponRepository, TbCfOrderRepository repository, TbCfCartRecordRRepository cartRepository, TbCfAddressRepository addressRepository, TbCfToicouponRepository toicouponRepository, TbCfStationItemRepository itemRepository, TbCfItemSkuRepository itemSkuRepository, TbCfItemCommentRepository commentRepository, TbCfExpressTemplateRepository templateRepository, @Qualifier("tbCfExchangeRepository") TbCfExchangeRepository exchangeRepository, ActivityRepository activityRepository, AuthenticationUser user) {
this.couponRepository = couponRepository;
this.repository = repository;
this.cartRepository = cartRepository;
......@@ -59,6 +60,7 @@ public class OrderController extends Controller {
this.commentRepository = commentRepository;
this.templateRepository = templateRepository;
this.exchangeRepository = exchangeRepository;
this.activityRepository = activityRepository;
this.user = user;
}
......@@ -140,7 +142,7 @@ public class OrderController extends Controller {
}
order.setCouponMap(map);
order.getItemOrderListFromCartList(list, itemRepository);
order.getItemOrderListFromCartList(list, itemRepository,activityRepository);
return new Result<>(order);
}
......@@ -179,7 +181,7 @@ public class OrderController extends Controller {
}
order.getItemOrderListFromCartList(allByUserId, itemRepository);
order.getItemOrderListFromCartList(allByUserId, itemRepository,activityRepository);
return new Result<>(order);
......@@ -321,7 +323,7 @@ public class OrderController extends Controller {
}
order.getItemOrderListFromCartList(allByUserId, itemRepository);
order.getItemOrderListFromCartList(allByUserId, itemRepository,activityRepository);
TbCfOrder save = repository.save(order);
......
package com.example.afrishop_v3.models;
import com.alibaba.fastjson.JSONObject;
import com.example.afrishop_v3.base.StateConstant;
import com.example.afrishop_v3.enums.OrderStatusEnum;
import com.example.afrishop_v3.repository.ActivityRepository;
import com.example.afrishop_v3.repository.TbCfStationItemRepository;
import com.example.afrishop_v3.util.IdUtil;
import com.example.afrishop_v3.vo.Condition;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import net.sf.json.JSONArray;
import org.hibernate.annotations.Where;
import org.springframework.data.relational.core.sql.In;
import javax.persistence.*;
import java.math.BigDecimal;
......@@ -156,7 +161,10 @@ public class TbCfOrder {
private String remarkInfo;
@Transient
private Map<String,Object> couponMap;
private BigDecimal reduceAmount;
@Transient
private Map<String, Object> couponMap;
public Map<String, Object> getCouponMap() {
return couponMap;
......@@ -193,7 +201,7 @@ public class TbCfOrder {
this.commentCount = commentCount;
}
@OneToMany(mappedBy = "orderId", cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@OneToMany(mappedBy = "orderId", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<TbCfItemOrderR> itemOrderList = new ArrayList<>();
......@@ -235,9 +243,9 @@ public class TbCfOrder {
return itemOrderList;
}
public void getItemOrderListFromCartList(List<TbCfCartRecordR> cartList, TbCfStationItemRepository itemRepository) {
public void getItemOrderListFromCartList(List<TbCfCartRecordR> cartList, TbCfStationItemRepository itemRepository, ActivityRepository activityRepository) {
itemOrderList = cartList.stream().map(f -> f.getOrderItem(orderId)).collect(Collectors.toList());
doSomeCalculations(itemRepository);
doSomeCalculations(itemRepository, activityRepository);
setOrderTime(new Date());
setDealTime(new Date());
setOrderNo(String.valueOf(IdUtil.createLongIdByDate()));
......@@ -248,26 +256,27 @@ public class TbCfOrder {
this.defaultTemplate = defaultTemplate;
}
private void doSomeCalculations(TbCfStationItemRepository itemRepository) {
private void doSomeCalculations(TbCfStationItemRepository itemRepository, ActivityRepository activityRepository) {
itemsPrice = itemsPrice == null ? new BigDecimal(0.0) : itemsPrice;
expressCost = expressCost == null ? new BigDecimal(0.0) : expressCost;
fee = fee == null ? new BigDecimal(0.0) : fee;
tax = tax == null ? new BigDecimal(0.0) : tax;
reduceAmount = reduceAmount == null ? new BigDecimal(0.0) : reduceAmount;
List<TemplateVo> templateList = new ArrayList<>();
itemOrderList.forEach(item -> {
BigDecimal itemPrice = item.getItemPriceTotal();
TbCfExpressTemplate template = item.getTemplate();
if( template != null){
if (template != null) {
System.out.println(template.getHandlingFee());
System.out.println(template.getTariff());
}
Optional<TbCfStationItem> optionalTbCfStationItem = itemRepository.findById(item.getItemId());
if( optionalTbCfStationItem.isPresent() ){
if (optionalTbCfStationItem.isPresent()) {
TbCfStationItem stationItem = optionalTbCfStationItem.get();
if( stationItem.getExpress() != null ){
if (stationItem.getExpress() != null) {
template = stationItem.getExpress();
}
}
......@@ -318,13 +327,89 @@ public class TbCfOrder {
expressCost = expressCost.add(express.getExpressFee().add(express.getContinuationFee().multiply(new BigDecimal(extralNum))));
}
}
/**
* 活动模块:活动类型 1:满减 2:满折 3:满件打折(type)
* 使用类型 1:全场 2:分类商品 3:特定商品(use_type)
*/
boolean act1 = activityRepository.existsByUseType(1);
if (act1) {
Optional<Activity> allAct = activityRepository.findFirstByUseType(1);
if (allAct.isPresent()) {
Activity activity = allAct.get();
String type = String.valueOf(activity.getType());
if ("1".equals(type)) {
// reduceAmount = caculateFullReduction(activity, itemsPrice);
caculateActFee(false, false, activity, itemsPrice, null);
} else if ("2".equals(type)) {
// BigDecimal discount = caculateFullReduction(activity, itemsPrice);
// BigDecimal rate = new BigDecimal(1).subtract(discount.divide(new BigDecimal(100)));
BigDecimal rate = caculateActFee(false, true, activity, itemsPrice, null);
itemsPrice = rate.multiply(itemsPrice);
} else if ("3".equals(type)) {
// BigDecimal discount = caculateFullCount(activity, itemOrderList.size());
// BigDecimal rate = new BigDecimal(1).subtract(discount.divide(new BigDecimal(100)));
BigDecimal rate = caculateActFee(true, true, activity, itemsPrice, itemOrderList.size());
itemsPrice = rate.multiply(itemsPrice);
}
}
}
totalPrice = itemsPrice.add(fee).add(tax).add(expressCost);
totalPrice = itemsPrice.add(fee).add(tax).add(expressCost).subtract(reduceAmount);
countRealityPay();
}
public BigDecimal caculateActFee(Boolean isCount, Boolean discount, Activity activity, BigDecimal itemsPrice, Integer itemCount) {
List<Condition> conList = JSONObject.parseArray(activity.getCondition(), Condition.class);
Collections.sort(conList, Comparator.comparing(Condition::getKey));
BigDecimal result = new BigDecimal("0.0");
for (int i = 0; i < conList.size(); i++) {
if (isCount) {
if (itemCount >= Integer.parseInt(conList.get(i).getKey())) {
result = new BigDecimal(conList.get(i).getValue());
}
} else {
if (itemsPrice.compareTo(new BigDecimal(conList.get(i).getKey())) >= 0) {
result = new BigDecimal(conList.get(i).getValue());
}
}
}
if (discount) {
result = new BigDecimal(1).subtract(result.divide(new BigDecimal(100)));
}
return result;
}
// //计算活动减免费用
// public BigDecimal caculateFullReduction(Activity activity, BigDecimal itemsPrice) {
//
// List<Condition> conList = JSONObject.parseArray(activity.getCondition(), Condition.class);
// Collections.sort(conList, Comparator.comparing(Condition::getKey));
// BigDecimal result = new BigDecimal("0.0");
// for (Condition con : conList) {
// if (itemsPrice.compareTo(new BigDecimal(con.getKey())) >= 0) {
// result = new BigDecimal(con.getValue());
// }
// }
//
// return result;
// }
//
// public BigDecimal caculateFullCount(Activity activity, Integer itemCount) {
// List<Condition> conList = JSONObject.parseArray(activity.getCondition(), Condition.class);
// Collections.sort(conList, Comparator.comparing(Condition::getKey));
// BigDecimal result = new BigDecimal("0.0");
//
// for (int i = 0; i < conList.size(); i++) {
// if (itemCount >= Integer.parseInt(conList.get(i).getKey())) {
// result = new BigDecimal(conList.get(i).getValue());
// }
// }
// return result;
// }
@Transient
private TbCfCoupon coupon;
......@@ -336,7 +421,7 @@ public class TbCfOrder {
private void countRealityPay() {
if (coupon != null) {
setCouponPrice(coupon.getDeductAmount());
// setCouponId(coupon.getCouponId());
// setCouponId(coupon.getCouponId());
}
BigDecimal couponPrice = this.getCouponPrice();
//实际需要支付款项
......@@ -747,7 +832,7 @@ public class TbCfOrder {
* 获取:手续费
*/
public BigDecimal getFee() {
return fee == null ? BigDecimal.ZERO : fee.setScale(2, BigDecimal.ROUND_HALF_UP);
return fee == null ? BigDecimal.ZERO : fee.setScale(2, BigDecimal.ROUND_HALF_UP);
}
/**
......
......@@ -5,8 +5,10 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.relational.core.sql.In;
import java.util.List;
import java.util.Optional;
/**
* @Auther: wudepeng
......@@ -17,4 +19,8 @@ public interface ActivityRepository extends JpaRepository<Activity,String> {
@Query(value = "select a from Activity a where CURRENT_TIMESTAMP between startTime and endTime and status=1 order by a.createTime desc")
Page<Activity> getAllActivity(Pageable pageable);
boolean existsByUseType(Integer useType);
Optional<Activity> findFirstByUseType(Integer useType);
}
package com.example.afrishop_v3.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.math.BigDecimal;
/**
* @Auther: wudepeng
* @Date: 2020/12/09
* @Description:活动条件
*/
@Data
@AllArgsConstructor
public class Condition {
private String key;
private String value;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论