|
@@ -1,17 +1,28 @@
|
|
|
package cn.newfeifan.mall.module.product.service.spuapply;
|
|
|
|
|
|
import cn.newfeifan.mall.module.product.controller.admin.skuapply.vo.SkuApplySaveReqVO;
|
|
|
-import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSkuSaveReqVO;
|
|
|
+import cn.newfeifan.mall.module.product.controller.admin.spu.vo.ProductSpuSaveReqVO;
|
|
|
+import cn.newfeifan.mall.module.product.convert.spuapply.SpuApplyConvert;
|
|
|
+import cn.newfeifan.mall.module.product.dal.dataobject.skuapply.SkuApplyDO;
|
|
|
+import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
import cn.newfeifan.mall.module.product.enums.spu.ProductSpuStatusEnum;
|
|
|
-import cn.newfeifan.mall.module.product.service.sku.ProductSkuService;
|
|
|
+import cn.newfeifan.mall.module.product.enums.spu.SpuApplyCheckStatusEnum;
|
|
|
+import cn.newfeifan.mall.module.product.service.category.ProductCategoryService;
|
|
|
import cn.newfeifan.mall.module.product.service.skuapply.SkuApplyService;
|
|
|
+import cn.newfeifan.mall.module.product.service.spu.ProductSpuService;
|
|
|
+import cn.newfeifan.mall.module.system.api.sms.SmsCodeApi;
|
|
|
+import cn.newfeifan.mall.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
|
|
import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserShopDetailsVO;
|
|
|
+import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
+import cn.newfeifan.mall.module.system.enums.sms.SmsSceneEnum;
|
|
|
+import cn.newfeifan.mall.module.system.service.permission.PermissionService;
|
|
|
+import cn.newfeifan.mall.module.system.service.permission.RoleService;
|
|
|
import cn.newfeifan.mall.module.system.service.user.AdminUserService;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -24,8 +35,10 @@ import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
|
import cn.newfeifan.mall.module.product.dal.mysql.spuapply.SpuApplyMapper;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.getMinValue;
|
|
|
-import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.getSumValue;
|
|
|
+import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*;
|
|
|
+import static cn.newfeifan.mall.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
|
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
+import static cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
|
|
|
import static cn.newfeifan.mall.module.product.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
/**
|
|
@@ -42,24 +55,59 @@ public class SpuApplyServiceImpl implements SpuApplyService {
|
|
|
@Resource
|
|
|
private SkuApplyService skuApplyService;
|
|
|
@Resource
|
|
|
- @Lazy // 循环依赖,避免报错
|
|
|
- private ProductSkuService productSkuService;
|
|
|
- @Resource
|
|
|
private AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
+ private ProductCategoryService categoryService;
|
|
|
+ @Resource
|
|
|
+ private AdminUserService userService;
|
|
|
+ @Resource
|
|
|
+ private ProductSpuService spuService;
|
|
|
+ @Resource
|
|
|
+ private RoleService roleService;
|
|
|
+ @Resource
|
|
|
+ private PermissionService permissionService;
|
|
|
+ @Resource
|
|
|
+ private SmsCodeApi smsCodeApi;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Long createSpuApply(SpuApplySaveReqVO createReqVO) {
|
|
|
+// 校验分类、品牌
|
|
|
+ validateCategory(createReqVO.getCategoryId());
|
|
|
+// brandService.validateProductBrand(createReqVO.getBrandId());
|
|
|
+
|
|
|
+ // 根据商户ID查询对应的店铺ID
|
|
|
+ // todo 后续如果存在多店铺的情况
|
|
|
+
|
|
|
+
|
|
|
// 校验 SKU
|
|
|
List<SkuApplySaveReqVO> skuSaveReqList = createReqVO.getSkus();
|
|
|
- productSkuService.validateSkuList(BeanUtils.toBean(skuSaveReqList, ProductSkuSaveReqVO.class), createReqVO.getSpecType(), createReqVO.getHighPrecision());
|
|
|
+ skuApplyService.validateSkuList(skuSaveReqList, createReqVO.getSpecType(), createReqVO.getHighPrecision());
|
|
|
|
|
|
SpuApplyDO spuApply = BeanUtils.toBean(createReqVO, SpuApplyDO.class);
|
|
|
// 初始化 SPU 中 SKU 相关属性
|
|
|
initSpuFromSkus(spuApply, skuSaveReqList);
|
|
|
+
|
|
|
+ //加入商户、店铺信息
|
|
|
+ UserShopDetailsVO userShopDetails = userService.getUserShopDetails();
|
|
|
+
|
|
|
+ spuApply.setShopId(userShopDetails.getShopId());
|
|
|
+ spuApply.setMerchantId(userShopDetails.getMerId());
|
|
|
+
|
|
|
+ for (SkuApplySaveReqVO productSkuSaveReqVO : skuSaveReqList) {
|
|
|
+ productSkuSaveReqVO.setShopId(userShopDetails.getShopId());
|
|
|
+ productSkuSaveReqVO.setMerchantId(userShopDetails.getMerId());
|
|
|
+ }
|
|
|
+
|
|
|
+ spuApply.setApplyMemberUserId(getLoginUserId());
|
|
|
// 插入 SPU
|
|
|
spuApplyMapper.insert(spuApply);
|
|
|
// 插入 SKU
|
|
|
skuApplyService.createSkuList(spuApply.getId(), skuSaveReqList);
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ sendSms(createReqVO.getName());
|
|
|
+
|
|
|
// 返回
|
|
|
return spuApply.getId();
|
|
|
}
|
|
@@ -96,12 +144,129 @@ public class SpuApplyServiceImpl implements SpuApplyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void updateSpuApply(SpuApplySaveReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateSpuApplyExists(updateReqVO.getId());
|
|
|
- // 更新
|
|
|
+
|
|
|
+ // 校验分类、品牌
|
|
|
+ validateCategory(updateReqVO.getCategoryId());
|
|
|
+
|
|
|
+ // 获取原来的SPU对比
|
|
|
+ SpuApplyRespVO spuApplyDetail = getSpuApplyDetail(updateReqVO.getId());
|
|
|
+
|
|
|
+
|
|
|
+// brandService.validateProductBrand(updateReqVO.getBrandId());
|
|
|
+ // 校验SKU
|
|
|
+ List<SkuApplySaveReqVO> skuSaveReqList = updateReqVO.getSkus();
|
|
|
+ skuApplyService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType(), updateReqVO.getHighPrecision());
|
|
|
+
|
|
|
+ // 更新 SPU
|
|
|
SpuApplyDO updateObj = BeanUtils.toBean(updateReqVO, SpuApplyDO.class);
|
|
|
+ initSpuFromSkus(updateObj, skuSaveReqList);
|
|
|
+
|
|
|
+ //最大推广费, 单位: 分 add by Ben
|
|
|
+ Integer maxPromotionFee = 0;
|
|
|
+
|
|
|
+ for (SkuApplySaveReqVO productSkuSaveReqVO : skuSaveReqList) {
|
|
|
+ productSkuSaveReqVO.setShopId(updateReqVO.getShopId());
|
|
|
+ productSkuSaveReqVO.setMerchantId(updateReqVO.getMerchantId());
|
|
|
+
|
|
|
+ Integer skuPromotionFee = productSkuSaveReqVO.getPromotionFee();
|
|
|
+ if (skuPromotionFee > maxPromotionFee)
|
|
|
+ maxPromotionFee = skuPromotionFee;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateObj.setPromotionFee(maxPromotionFee);
|
|
|
+ updateObj.setCheckStatus(SpuApplyCheckStatusEnum.WAIT_CHECK.getStatus());
|
|
|
+
|
|
|
+ // 有部分字段更新了才需要审核,否则不需要审核
|
|
|
+ if (spuApplyDetail.getName().equals(updateReqVO.getName()) &&
|
|
|
+ spuApplyDetail.getProducerArea().equals(updateReqVO.getProducerArea()) &&
|
|
|
+ spuApplyDetail.getKeyword().equals(updateReqVO.getKeyword()) &&
|
|
|
+ spuApplyDetail.getIntroduction().equals(updateReqVO.getIntroduction()) &&
|
|
|
+ spuApplyDetail.getSliderPicUrls().equals(updateReqVO.getSliderPicUrls()) &&
|
|
|
+ spuApplyDetail.getDescription().equals(updateReqVO.getDescription()) &&
|
|
|
+ spuApplyDetail.getHighPrecision().equals(updateReqVO.getHighPrecision()) &&
|
|
|
+ spuApplyDetail.getSkus().size() == updateReqVO.getSkus().size()
|
|
|
+ ) {
|
|
|
+ boolean flag = isFlag(updateReqVO, spuApplyDetail);
|
|
|
+
|
|
|
+ // 如果关键消息没有变动那就不用审核,直接更新到商品中,并且不用发送审核短信
|
|
|
+ if (flag) {
|
|
|
+ updateObj.setCheckStatus(SpuApplyCheckStatusEnum.CHECK_PASS.getStatus());
|
|
|
+
|
|
|
+ // 更新商品
|
|
|
+ ProductSpuSaveReqVO bean = BeanUtils.toBean(updateReqVO, ProductSpuSaveReqVO.class);
|
|
|
+
|
|
|
+ ProductSpuDO spu = spuService.getSpuByApplyId(updateReqVO.getId());
|
|
|
+ bean.setId(spu.getId());
|
|
|
+ spuService.updateSpu(bean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
spuApplyMapper.updateById(updateObj);
|
|
|
+ // 批量更新 SKU
|
|
|
+ skuApplyService.updateSkuList(updateObj.getId(), updateReqVO.getSkus());
|
|
|
+
|
|
|
+ // 发送审核短信
|
|
|
+ if (updateObj.getCheckStatus().equals(SpuApplyCheckStatusEnum.WAIT_CHECK.getStatus())) {
|
|
|
+ // 发送短信
|
|
|
+ sendSms(updateReqVO.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送商品申请短信
|
|
|
+ *
|
|
|
+ * @param spuName 商品名称
|
|
|
+ */
|
|
|
+ private void sendSms(String spuName) {
|
|
|
+ // 商品审核角色编号
|
|
|
+ Long ptSpuCheck = roleService.getPtSpuCheck();
|
|
|
+ // 系统用户ids
|
|
|
+ List<Long> userIds = permissionService.getPtSpuCheckUserIds(ptSpuCheck);
|
|
|
+ // 系统用户s
|
|
|
+ List<AdminUserDO> users = adminUserService.getUserList(userIds);
|
|
|
+
|
|
|
+ for (AdminUserDO user : users) {
|
|
|
+ SmsCodeSendReqDTO smsCodeSendReqDTO = SmsCodeSendReqDTO.builder()
|
|
|
+ .mobile(user.getMobile())
|
|
|
+ .scene(SmsSceneEnum.SPU_APPLY_INFORM.getScene())
|
|
|
+ .createIp(getClientIP())
|
|
|
+ .name(spuName)
|
|
|
+ .build();
|
|
|
+ smsCodeApi.sendSmsCode(smsCodeSendReqDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否需要审核
|
|
|
+ *
|
|
|
+ * @param updateReqVO 原数据
|
|
|
+ * @param spuApplyDetail 新数据
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ private static boolean isFlag(SpuApplySaveReqVO updateReqVO, SpuApplyRespVO spuApplyDetail) {
|
|
|
+ boolean flag = true;
|
|
|
+ for (int i = 0; i < spuApplyDetail.getSkus().size(); i++) {
|
|
|
+ // 如果是高精度商品
|
|
|
+ if (updateReqVO.getHighPrecision()) {
|
|
|
+ if (!spuApplyDetail.getSkus().get(i).getHighPrecisionPrice().equals(updateReqVO.getSkus().get(i).getHighPrecisionPrice()) ||
|
|
|
+ !spuApplyDetail.getSkus().get(i).getHighPrecisionSettlementPrice().equals(updateReqVO.getSkus().get(i).getHighPrecisionSettlementPrice())
|
|
|
+ ) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!spuApplyDetail.getSkus().get(i).getSettlementPrice().equals(updateReqVO.getSkus().get(i).getSettlementPrice()) ||
|
|
|
+ !spuApplyDetail.getSkus().get(i).getCostPrice().equals(updateReqVO.getSkus().get(i).getCostPrice())
|
|
|
+ ) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -118,6 +283,14 @@ public class SpuApplyServiceImpl implements SpuApplyService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void validateCategory(Long id) {
|
|
|
+ categoryService.validateCategory(id);
|
|
|
+ // 校验层级
|
|
|
+ if (categoryService.getCategoryLevel(id) < CATEGORY_LEVEL) {
|
|
|
+ throw exception(SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public SpuApplyDO getSpuApply(Long id) {
|
|
|
return spuApplyMapper.selectById(id);
|
|
@@ -137,4 +310,21 @@ public class SpuApplyServiceImpl implements SpuApplyService {
|
|
|
return spuApplyMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public SpuApplyRespVO getSpuApplyDetail(Long id) {
|
|
|
+ // 获得商品 SPU 申请
|
|
|
+ SpuApplyDO spu = getSpu(id);
|
|
|
+ if (spu == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 查询商品 SKU
|
|
|
+ List<SkuApplyDO> skus = skuApplyService.getSkuListBySpuId(spu.getId());
|
|
|
+
|
|
|
+ String shopName = spuApplyMapper.selectShopNameById(spu.getShopId());
|
|
|
+
|
|
|
+ SpuApplyRespVO convert = SpuApplyConvert.INSTANCE.convert(spu, skus);
|
|
|
+ convert.setShopName(shopName);
|
|
|
+ return convert;
|
|
|
+ }
|
|
|
+
|
|
|
}
|