Browse Source

配送规则映射到结算中

hulh 8 years ago
parent
commit
2a14c5393a

+ 8 - 0
src/main/java/com/uas/platform/b2c/logistics/dao/DistributionRuleDao.java

@@ -41,6 +41,14 @@ public interface DistributionRuleDao extends JpaSpecificationExecutor<Distributi
 	@Query(value = "select d from DistributionRule d where d.enuu = :enuu order by d.num asc")
 	List<DistributionRule> findAllByEnuu(@Param("enuu") Long enuu);
 
+	/**
+	 * 根据enuu获取所有生效的配送规则
+	 * @param enuu
+	 * @param active
+	 * @return
+	 */
+	List<DistributionRule> findByEnuuAndActiveOrderByNumAsc(Long enuu, Short active);
+
 	/**
 	 * 根据enuu获取所有的配送规则名称
 	 * @param enuu

+ 75 - 0
src/main/java/com/uas/platform/b2c/logistics/model/UsableRuleInfo.java

@@ -0,0 +1,75 @@
+package com.uas.platform.b2c.logistics.model;
+
+/**
+ * Created by hulh on 2017/9/13.
+ * 适用的配送规则简要信息
+ */
+public class UsableRuleInfo {
+	/**
+	 * 配送规则名称
+	 */
+	private String ruleName;
+	/**
+	 * 实际所需价格
+	 */
+//	private Double actualFare;
+	/**
+	 * 配送方式
+	 */
+	private Integer method;
+	/**
+	 * 卖家enuu
+	 */
+	private Long enuu;
+	/**
+	 * 配送规则币别
+	 */
+	private String currencyName;
+
+	public UsableRuleInfo(DistributionRule rule){
+		this.ruleName = rule.getRuleName();
+		this.method = rule.getShippingMethod();
+		this.currencyName = rule.getCurrencyName();
+		this.enuu = rule.getEnuu();
+	}
+
+	public String getRuleName() {
+		return ruleName;
+	}
+
+	public void setRuleName(String ruleName) {
+		this.ruleName = ruleName;
+	}
+
+//	public Double getActualFare() {
+//		return actualFare;
+//	}
+//
+//	public void setActualFare(Double actualFare) {
+//		this.actualFare = actualFare;
+//	}
+
+	public Integer getMethod() {
+		return method;
+	}
+
+	public void setMethod(Integer method) {
+		this.method = method;
+	}
+
+	public Long getEnuu() {
+		return enuu;
+	}
+
+	public void setEnuu(Long enuu) {
+		this.enuu = enuu;
+	}
+
+	public String getCurrencyName() {
+		return currencyName;
+	}
+
+	public void setCurrencyName(String currencyName) {
+		this.currencyName = currencyName;
+	}
+}

+ 27 - 9
src/main/java/com/uas/platform/b2c/logistics/service/impl/DistributionRuleServiceImpl.java

@@ -8,6 +8,7 @@ import com.uas.platform.b2c.logistics.dao.DistributionRuleDao;
 import com.uas.platform.b2c.logistics.model.DistributionRule;
 import com.uas.platform.b2c.logistics.model.RuleQtyArea;
 import com.uas.platform.b2c.logistics.model.RuleQtyFare;
+import com.uas.platform.b2c.logistics.model.UsableRuleInfo;
 import com.uas.platform.b2c.logistics.service.DistributionRuleService;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
@@ -263,39 +264,56 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 		return distributionRuleDao.findShippingMethodByEnuuAndActive(enuu, ShortConstant.YES_SHORT);
 	}
 
-	public Map<String, Map<String, Object>> findRuleMatchArea(List<String> uuidArray, String area){
+	/**
+	 * 返回所有店铺适用的配送规则
+	 * @param uuidArray
+	 * @param area
+	 * @return
+	 */
+	public Map<String, List<UsableRuleInfo>> findRuleMatchArea(List<String> uuidArray, String area){
 		if (area == null){
 			throw new IllegalOperatorException("地址信息缺失,请重新确认收货地址");
 		}
+		Map<String, List<UsableRuleInfo>> resultMap = new HashMap<>();
 		for (String uuid : uuidArray){
-			findRuleMatchArea(uuid, area);
+			List<UsableRuleInfo> list = findRuleInStore(uuid, area);
+			resultMap.put(uuid, list);
 		}
-		return null;
+		return resultMap;
 	}
 
-	public Map<String, Object> findRuleMatchArea(String uuid, String area){
+	/**
+	 * 返回该店铺适用的配送规则
+	 * @param uuid
+	 * @param area
+	 * @return
+	 */
+	public List<UsableRuleInfo> findRuleInStore(String uuid, String area){
 		StoreIn store = storeInDao.findByUuid(uuid);
 		if (store == null){
-			throw new IllegalOperatorException("店铺信息,请刷新后重试");
+			throw new IllegalOperatorException("店铺信息缺失,请刷新后重试");
 		}
-		List<DistributionRule> allRuleList = distributionRuleDao.findAllByEnuu(store.getEnUU());
-		List<DistributionRule> ruleList = new ArrayList<>();
+		List<DistributionRule> allRuleList = distributionRuleDao.findByEnuuAndActiveOrderByNumAsc(store.getEnUU(), ShortConstant.YES_SHORT);
+		List<UsableRuleInfo> ruleInfoList = new ArrayList<>();
 		List<Integer> methodList = new ArrayList<>();
 		for (DistributionRule rule : allRuleList){
 			if (!methodList.contains(rule.getShippingMethod())){
 				List<RuleQtyArea> qtyArea = rule.getAreas();
+				//转化分段地区信息
 				Map<String, Map<String, List<String>>> resultMap = convertArea(qtyArea);
+				//是否包含改地区信息
 				boolean isContains = containsArea(resultMap, area);
 				if (isContains){
 					methodList.add(rule.getShippingMethod());
+					UsableRuleInfo info = new UsableRuleInfo(rule);
+					ruleInfoList.add(info);
 				}
 			}
-
 			if (methodList.size() == 3){
 				break;
 			}
 		}
-		return null;
+		return ruleInfoList;
 	}
 
 	/**

+ 4 - 0
src/main/webapp/resources/js/common/query/logisticsPort.js

@@ -112,6 +112,10 @@ define([ 'ngResource' ], function() {
 				url: 'trade/distributionRule/rule/matchArea',
 				method: 'GET',
 				isArray : true
+			},
+			findUsableRule : {
+				url: 'trade/distributionRule/rule/matchArea',
+				method: 'GET'
 			}
 		})
 	}]);

+ 4 - 6
src/main/webapp/resources/js/usercenter/controllers/forstore/order_pay_ctrl.js

@@ -145,11 +145,9 @@ define(['app/app'], function(app) {
 		$scope.loadShippingAddress = function () {
 			return ShippingAddress.get({send : false}, function(data) {
 				$scope.sendAddress = data;
-				angular.forEach($scope.sendAddress, function (shippingAddress) {
-					if (shippingAddress.num == 1) {
-						$scope.selectAdd(shippingAddress);
-					}
-				})
+				if ($scope.sendAddress.length != 0){
+					$scope.selectAdd($scope.sendAddress[0]);
+				}
 			}, function(response) {
 				toaster.pop("error", "获取收货地址信息失败 "  + response.data);
 			});
@@ -493,7 +491,7 @@ define(['app/app'], function(app) {
 						$scope.sendAddress.push(address);
 					}
 				}
-				$scope.payment.address = address;
+				$scope.selectAdd(address);
 			}, function(){
 				toaster.pop('info', '提示 ' + '您已取消收货地址的编辑');
 			});