|
@@ -1,12 +1,16 @@
|
|
|
package com.caimei.modules.weisha.service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.caimei.modules.product.entity.CmSku;
|
|
|
import com.caimei.modules.product.entity.Product;
|
|
|
+import com.caimei.modules.product.entity.Sku;
|
|
|
import com.caimei.modules.weisha.dao.CmOrganizePromotionDao;
|
|
|
-import com.caimei.modules.weisha.entity.OrganizeProductLadderPrice;
|
|
|
+import com.caimei.modules.weisha.entity.*;
|
|
|
import com.caimei.utils.AppUtils;
|
|
|
import com.caimei.utils.StringUtils;
|
|
|
import com.thinkgem.jeesite.common.config.Global;
|
|
@@ -15,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
-import com.caimei.modules.weisha.entity.CmOrganizeProduct;
|
|
|
import com.caimei.modules.weisha.dao.CmOrganizeProductDao;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -36,11 +39,11 @@ public class CmOrganizeProductService extends CrudService<CmOrganizeProductDao,
|
|
|
public CmOrganizeProduct get(String id) {
|
|
|
return super.get(id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public List<CmOrganizeProduct> findList(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
return super.findList(cmOrganizeProduct);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public Page<CmOrganizeProduct> findPage(Page<CmOrganizeProduct> page, CmOrganizeProduct cmOrganizeProduct) {
|
|
|
cmOrganizeProduct.setPage(page);
|
|
|
List<CmOrganizeProduct> productList = cmOrganizeProductDao.findList(cmOrganizeProduct);
|
|
@@ -64,42 +67,85 @@ public class CmOrganizeProductService extends CrudService<CmOrganizeProductDao,
|
|
|
page.setList(productList);
|
|
|
return page;
|
|
|
}
|
|
|
-
|
|
|
- @Transactional(readOnly = false)
|
|
|
- public void save(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
- super.save(cmOrganizeProduct);
|
|
|
- //保存阶梯价格列表
|
|
|
- List<OrganizeProductLadderPrice> ladderPriceList = cmOrganizeProduct.getLadderPriceList();
|
|
|
- if (1 == cmOrganizeProduct.getLadderPriceFlag()) {
|
|
|
- for (int i = 0; i < ladderPriceList.size(); i++) {
|
|
|
- Integer buyNum = ladderPriceList.get(i).getBuyNum();
|
|
|
- Double buyPrice = ladderPriceList.get(i).getBuyPrice();
|
|
|
- String ladderId = ladderPriceList.get(i).getId();
|
|
|
- String delFlag = ladderPriceList.get(i).getDelFlag();
|
|
|
- if ("0".equals(delFlag) && null != buyNum && null != buyPrice && !"".equals(buyPrice)) {
|
|
|
- ladderPriceList.get(i).setProductId(Integer.parseInt(cmOrganizeProduct.getId()));
|
|
|
- ladderPriceList.get(i).setLadderNum(i + 1);
|
|
|
- if (StringUtils.isNotBlank(ladderId)) {
|
|
|
- cmOrganizeProductDao.updateLadderPrice(ladderPriceList.get(i));
|
|
|
- } else {
|
|
|
- cmOrganizeProductDao.insertLadderPrice(ladderPriceList.get(i));
|
|
|
+ public Page<CmOrganizeProduct> organizeProductList(Page<CmOrganizeProduct> page, CmOrganizeProduct cmOrganizeProduct) {
|
|
|
+ cmOrganizeProduct.setPage(page);
|
|
|
+ // 商品信息
|
|
|
+ List<CmOrganizeProduct> productList = cmOrganizeProductDao.getOrganizeProductList(cmOrganizeProduct);
|
|
|
+ // sku
|
|
|
+ List<Integer> productIds = null;
|
|
|
+ if (null != productList) {
|
|
|
+ productIds = productList.stream().map(p -> p.getProductId()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<CmOrganizeSku> organizeSku = cmOrganizeProductDao.getOrganizeSku(productIds);
|
|
|
+ String wwwServer = Global.getConfig("wwwServer");
|
|
|
+ // 设置商品规sku
|
|
|
+ productList.forEach(product->{
|
|
|
+ product.setProductImage(AppUtils.getImageURL("product", product.getProductImage(), 0, wwwServer));
|
|
|
+ if (null != organizeSku) {
|
|
|
+ product.setSku(organizeSku.stream().filter(s -> s.getProductId().equals(product.getProductId())).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ /*for (CmOrganizeSku sku : organizeSku) {
|
|
|
+ if (sku.getProductId() == product.getProductId()) {
|
|
|
+ if (null != sku.getUnit()) {
|
|
|
+ product.setUnit(sku.getUnit());
|
|
|
}
|
|
|
- } else {
|
|
|
- if (StringUtils.isNotBlank(ladderId)) {
|
|
|
- cmOrganizeProductDao.deleteLadderPriceById(ladderId);
|
|
|
- } else {
|
|
|
- break;
|
|
|
+ if (null != sku.getPrice()) {
|
|
|
+ product.setPrice(sku.getPrice());
|
|
|
+ }
|
|
|
+ if (null != sku.getMinBuyNumber()) {
|
|
|
+ product.setMinBuyNumber(sku.getMinBuyNumber());
|
|
|
}
|
|
|
}
|
|
|
+ }*/
|
|
|
+ });
|
|
|
+ page.setList(productList);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void updateproduct(Integer validFlag, Integer id) {
|
|
|
+ cmOrganizeProductDao.updateproduct(validFlag, id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void saveProduct(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
+
|
|
|
+ // 保存商品信息
|
|
|
+ List<CmSku> skuInfo = cmOrganizeProductDao.getSkuInfo(cmOrganizeProduct.getProductId().toString());
|
|
|
+ // 解析sku
|
|
|
+ try {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(cmOrganizeProduct.getSkus());
|
|
|
+ List<CmOrganizeSku> cmOrganizeSkus = jsonArray.toJavaList(CmOrganizeSku.class);
|
|
|
+
|
|
|
+ // 获取最小值
|
|
|
+ List<Double> priceList = cmOrganizeSkus.stream().map(s -> s.getPrice()).collect(Collectors.toList());
|
|
|
+ List<Integer> numberList = cmOrganizeSkus.stream().map(s -> s.getMinBuyNumber()).collect(Collectors.toList());
|
|
|
+ Double minPrice = Collections.min(priceList);
|
|
|
+ Integer minNumber = Collections.min(numberList);
|
|
|
+ // 若是阶梯价商品,则起订量重置为1
|
|
|
+ List<CmSku> collect = skuInfo.stream().filter(s -> 1 == s.getLadderPriceFlag()).collect(Collectors.toList());
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ cmOrganizeProduct.setMinBuyNumber(1);
|
|
|
+ } else {
|
|
|
+ cmOrganizeProduct.setMinBuyNumber(skuInfo.get(0).getMinBuyNumber());
|
|
|
+ }
|
|
|
+ // 设置起订量,价格
|
|
|
+ cmOrganizeProduct.setPrice(minPrice);
|
|
|
+ cmOrganizeProduct.setMinBuyNumber(minNumber);
|
|
|
+ cmOrganizeProductDao.updateMallProduct(cmOrganizeProduct);
|
|
|
+ // 保存商品sku
|
|
|
+ for (CmOrganizeSku sku : cmOrganizeSkus) {
|
|
|
+ cmOrganizeProductDao.updateMallProductSku(sku);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Transactional(readOnly = false)
|
|
|
- public void delete(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
+ public void deleteProduct(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
//删除商品对应的促销活动
|
|
|
- cmOrganizePromotionDao.deletePromotionByProductId(cmOrganizeProduct.getId());
|
|
|
- super.delete(cmOrganizeProduct);
|
|
|
+ cmOrganizeProductDao.deleteProduct(cmOrganizeProduct.getId());
|
|
|
}
|
|
|
|
|
|
public Page findProductPage(Page<Product> productPage, Product product) {
|
|
@@ -115,16 +161,62 @@ public class CmOrganizeProductService extends CrudService<CmOrganizeProductDao,
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
public void addProducts(Integer organizeId, String productIds) {
|
|
|
+ // 商品Id集合
|
|
|
String[] productIdArr = productIds.split(",");
|
|
|
+ // 获取商品、供应商信息
|
|
|
+ List<CmOrganizeProduct> shopInfo = cmOrganizeProductDao.getShopInfo(Arrays.asList(productIdArr));
|
|
|
+ // 获取组织信息
|
|
|
+ CmMallOrganize organizeInfo = cmOrganizeProductDao.getOrganizeInfo(organizeId);
|
|
|
for (String productId : productIdArr) {
|
|
|
if (StringUtils.isNotBlank(productId)) {
|
|
|
- CmOrganizeProduct cmOrganizeProduct = cmOrganizeProductDao.findProductByProductId(productId);
|
|
|
+ List<CmSku> skuInfo = cmOrganizeProductDao.getSkuInfo(productId);
|
|
|
+ CmOrganizeProduct cmOrganizeProduct = new CmOrganizeProduct();
|
|
|
+ CmOrganizeSku skuEntity = new CmOrganizeSku();
|
|
|
cmOrganizeProduct.setProductId(Integer.parseInt(productId));
|
|
|
cmOrganizeProduct.setOrganizeId(organizeId);
|
|
|
+ cmOrganizeProduct.setNormalPrice(skuInfo.get(0).getNormalPrice());
|
|
|
+ cmOrganizeProduct.setCostPrice(skuInfo.get(0).getCostPrice());
|
|
|
+ cmOrganizeProduct.setLadderPriceFlag(1);
|
|
|
+ cmOrganizeProduct.setRetailPrice(skuInfo.get(0).getPrice());
|
|
|
+ // 若是阶梯价商品,则起订量重置为1
|
|
|
+ List<CmSku> collect = skuInfo.stream().filter(s -> 1 == s.getLadderPriceFlag()).collect(Collectors.toList());
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ cmOrganizeProduct.setMinBuyNumber(1);
|
|
|
+ } else {
|
|
|
+ cmOrganizeProduct.setMinBuyNumber(skuInfo.get(0).getMinBuyNumber());
|
|
|
+ }
|
|
|
+ cmOrganizeProduct.setStatus(1);
|
|
|
cmOrganizeProduct.setAddTime(new Date());
|
|
|
+ cmOrganizeProduct.setUpdateDate(new Date());
|
|
|
+ cmOrganizeProduct.setDelFlag("0");
|
|
|
//保存组织商品
|
|
|
- cmOrganizeProductDao.insert(cmOrganizeProduct);
|
|
|
- if (cmOrganizeProduct.getLadderPriceFlag() == 1) {
|
|
|
+ cmOrganizeProductDao.insertMallProduct(cmOrganizeProduct);
|
|
|
+ // 组织sku数据保存
|
|
|
+ for (CmSku sku : skuInfo) {
|
|
|
+ skuEntity.setSkuId(sku.getSkuId());
|
|
|
+ skuEntity.setProductId(sku.getProductId());
|
|
|
+ skuEntity.setMallProductId(Integer.parseInt(cmOrganizeProduct.getId()));
|
|
|
+ skuEntity.setMinBuyNumber(sku.getMinBuyNumber());
|
|
|
+ skuEntity.setPrice(sku.getPrice());
|
|
|
+ // 设置默认分帐比例
|
|
|
+ // 联合丽格商品 采美佣金 2% 付组织 98%
|
|
|
+ // 其他供应商商品 采美佣金 3% 联合丽格 17% 供应商 80%
|
|
|
+ for (CmOrganizeProduct organizeProduct : shopInfo) {
|
|
|
+ if (organizeProduct.getProductId().equals(sku.getProductId())) {
|
|
|
+ if (organizeInfo.getId().equals(organizeId.toString())) {
|
|
|
+ skuEntity.setCmPercent(2.00);
|
|
|
+ skuEntity.setOrganizePercent(98.00);
|
|
|
+ skuEntity.setShopPercent(0.00);
|
|
|
+ } else {
|
|
|
+ skuEntity.setCmPercent(3.00);
|
|
|
+ skuEntity.setOrganizePercent(17.00);
|
|
|
+ skuEntity.setShopPercent(80.00);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cmOrganizeProductDao.insertMallSku(skuEntity);
|
|
|
+ }
|
|
|
+ /*if (cmOrganizeProduct.getLadderPriceFlag() == 1) {
|
|
|
//查询对应采美商品的阶梯价格列表
|
|
|
List<OrganizeProductLadderPrice> ladderPriceList = cmOrganizeProductDao.findFormerLadderPriceList(productId);
|
|
|
if (ladderPriceList != null && ladderPriceList.size() > 0) {
|
|
@@ -135,7 +227,7 @@ public class CmOrganizeProductService extends CrudService<CmOrganizeProductDao,
|
|
|
}else {
|
|
|
cmOrganizeProductDao.updateLadderPriceFlag(cmOrganizeProduct.getId(), 0);
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -146,13 +238,33 @@ public class CmOrganizeProductService extends CrudService<CmOrganizeProductDao,
|
|
|
cmOrganizeProductDao.updateStatus(id, status);
|
|
|
}
|
|
|
|
|
|
- public List<OrganizeProductLadderPrice> findLadderPrice(String id) {
|
|
|
- List<OrganizeProductLadderPrice> ladderPriceList = cmOrganizeProductDao.findLadderPrice(id);
|
|
|
- if (ladderPriceList != null) {
|
|
|
- ladderPriceList.forEach(ladderPrice->{
|
|
|
- ladderPrice.setDelFlag("0");
|
|
|
- });
|
|
|
+ /**
|
|
|
+ * 组织商品编辑回显
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CmOrganizeProduct findLadderPrice(String id) {
|
|
|
+ // 商品数据详情
|
|
|
+ CmOrganizeProduct productInfo = cmOrganizeProductDao.getProductInfo(id);
|
|
|
+ // 商品sku
|
|
|
+ List<Integer> productIds = new ArrayList<>();
|
|
|
+ String wwwServer = Global.getConfig("wwwServer");
|
|
|
+ if (productInfo != null) {
|
|
|
+ productInfo.setProductImage(AppUtils.getImageURL("product", productInfo.getProductImage(),0, wwwServer));
|
|
|
+
|
|
|
+ productIds.add(productInfo.getProductId());
|
|
|
+ List<CmOrganizeSku> organizeSku = cmOrganizeProductDao.getOrganizeSku(productIds);
|
|
|
+ productInfo.setSku(organizeSku);
|
|
|
}
|
|
|
- return ladderPriceList;
|
|
|
+ return productInfo;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存组织商品信息
|
|
|
+ * @param cmOrganizeProduct
|
|
|
+ */
|
|
|
+ public void saveOrganizeProduct(CmOrganizeProduct cmOrganizeProduct) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|