|
@@ -0,0 +1,91 @@
|
|
|
+package com.iamberry.wechat.service.agentInfo;
|
|
|
+
|
|
|
+import com.iamberry.wechat.core.entity.OrderUtil;
|
|
|
+import com.iamberry.wechat.core.entity.agentInfo.AgentConfig;
|
|
|
+import com.iamberry.wechat.core.entity.agentInfo.AgentOrder;
|
|
|
+import com.iamberry.wechat.core.entity.agentInfo.AgentOrderItem;
|
|
|
+import com.iamberry.wechat.core.entity.product.Product;
|
|
|
+import com.iamberry.wechat.core.entity.product.ProductColor;
|
|
|
+import com.iamberry.wechat.face.agentInfo.AgentPurchaseOrderService;
|
|
|
+import com.iamberry.wechat.service.mapper.AgentInfoMapper;
|
|
|
+import com.iamberry.wechat.service.mapper.AgentPurchaseOrderMapper;
|
|
|
+import com.iamberry.wechat.service.mapper.ProductInfoMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+ * Created by liuzhiwei on 2017/10/11.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AgentPurchaseOrderServiceImpl implements AgentPurchaseOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AgentPurchaseOrderMapper agentPurchaseOrderMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoMapper productInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AgentInfoMapper agentInfoMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String,Object> addAgentOrder(AgentOrder agentOrder, List<AgentOrderItem> agentOrderItemList) {
|
|
|
+ Map<String,Object> map = new HashMap<String,Object>();
|
|
|
+ map.put("status","400");
|
|
|
+
|
|
|
+ agentOrder.setAgentStatus(OrderUtil.ORDERSTAUTS_TOBEPAID);
|
|
|
+ int amount = 0;
|
|
|
+
|
|
|
+ for(AgentOrderItem agentOrderItem : agentOrderItemList){
|
|
|
+ ProductColor productColor = new ProductColor();
|
|
|
+ productColor.setColorId(agentOrderItem.getColorId());
|
|
|
+ productColor.setColorProductId(agentOrderItem.getProductId());
|
|
|
+ productColor = productInfoMapper.getProductColor(productColor);
|
|
|
+ Product product = productInfoMapper.getProductByProductId(agentOrderItem.getProductId(),agentOrderItem.getColorId());
|
|
|
+ if(productColor == null || product == null){
|
|
|
+ map.put("msg","查询产品出错!");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ agentOrderItem.setProductId(product.getProductId());
|
|
|
+ agentOrderItem.setItemProductName(product.getProductName());
|
|
|
+ agentOrderItem.setColorId(productColor.getColorId());
|
|
|
+ agentOrderItem.setItemColorName(productColor.getColorName());
|
|
|
+ agentOrderItem.setProductType(product.getProductType().getTypeId());
|
|
|
+ agentOrderItem.setProductRentType(product.getProductRentType());
|
|
|
+ agentOrderItem.setItemProductPrice(productColor.getColorPrice());
|
|
|
+ agentOrderItem.setItemProductPic(product.getProductIntroduceImg());
|
|
|
+
|
|
|
+
|
|
|
+ Integer discount = 0;
|
|
|
+ AgentConfig agentConfig = new AgentConfig();
|
|
|
+ agentConfig.setColorId(productColor.getColorId());
|
|
|
+ agentConfig.setAgentId(agentOrder.getAgentId());
|
|
|
+ agentConfig = agentInfoMapper.getAgentConfig(agentConfig);
|
|
|
+ if(agentConfig != null){
|
|
|
+ discount = agentConfig.getConfigAmount();
|
|
|
+ }else{
|
|
|
+ discount = productColor.getColorDiscount();
|
|
|
+ }
|
|
|
+ agentOrderItem.setItemProductDiscount(discount);
|
|
|
+
|
|
|
+ Integer itemSummary = 0;
|
|
|
+ if(agentOrderItem.getItemNum() == null || agentOrderItem.getItemNum() < 1){
|
|
|
+ map.put("msg","产品数量不能小于1!");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ itemSummary = agentOrderItem.getItemNum() * discount;
|
|
|
+ amount += itemSummary;
|
|
|
+ }
|
|
|
+
|
|
|
+ agentPurchaseOrderMapper.addAgentOrder(agentOrder);
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|