|
@@ -2,15 +2,21 @@ package com.caimei365.user.service.impl;
|
|
|
|
|
|
import com.caimei365.user.components.RedisService;
|
|
|
import com.caimei365.user.mapper.BaseMapper;
|
|
|
+import com.caimei365.user.mapper.PersonalCenterMapper;
|
|
|
import com.caimei365.user.mapper.ShopMapper;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
+import com.caimei365.user.model.dto.ShopBannerDto;
|
|
|
import com.caimei365.user.model.dto.ShopUpdateDto;
|
|
|
import com.caimei365.user.model.po.ShopCertPo;
|
|
|
import com.caimei365.user.model.po.UserPo;
|
|
|
import com.caimei365.user.model.vo.*;
|
|
|
import com.caimei365.user.service.ShopService;
|
|
|
+import com.caimei365.user.utils.DateUtil;
|
|
|
+import com.caimei365.user.utils.ImageUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -25,13 +31,16 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class ShopServiceImpl implements ShopService {
|
|
|
-
|
|
|
+ @Value("${caimei.wwwDomain}")
|
|
|
+ private String wwwDomain;
|
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
|
@Resource
|
|
|
private BaseMapper baseMapper;
|
|
|
@Resource
|
|
|
private ShopMapper shopMapper;
|
|
|
+ @Resource
|
|
|
+ private PersonalCenterMapper personalCenterMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -139,7 +148,7 @@ public class ShopServiceImpl implements ShopService {
|
|
|
* @return ClubUpdateDto
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson updateShopUserInfo(ShopUpdateDto shopUpdateDto, String operationLicence, String hygienicLicense, String taxLicense, String honorCertification, String productCertification) {
|
|
|
+ public ResponseJson<Void> updateShopUserInfo(ShopUpdateDto shopUpdateDto, String operationLicence, String hygienicLicense, String taxLicense, String honorCertification, String productCertification) {
|
|
|
// 参数校验
|
|
|
if (null == shopUpdateDto.getUserId()) {
|
|
|
return ResponseJson.error("参数异常:用户Id不能为空!");
|
|
@@ -212,4 +221,183 @@ public class ShopServiceImpl implements ShopService {
|
|
|
}
|
|
|
return ResponseJson.success("修改供应商资料成功", null);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商首页数据
|
|
|
+ *
|
|
|
+ * @param shopId 供应商Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<ShopHomeVo> getShopHomeData(Integer shopId) {
|
|
|
+ ShopHomeVo supplier = shopMapper.getShopHomeData(shopId);
|
|
|
+ if (supplier != null && supplier.getBusinessScope() != null) {
|
|
|
+ String[] businessScope = supplier.getBusinessScope().split("/");
|
|
|
+ supplier.setBusinessScopeArr(businessScope);
|
|
|
+ supplier.setLogo(ImageUtils.getImageURL("shopLogo", supplier.getLogo(), 0, wwwDomain));
|
|
|
+ }
|
|
|
+ //公司资质照片
|
|
|
+ List<String> productionLicence = shopMapper.getShopCertById(shopId, 2);
|
|
|
+ if (null != productionLicence && productionLicence.size() > 0) {
|
|
|
+ supplier.setMedicalPracticeLicenseImg1(productionLicence.get(0));
|
|
|
+ }
|
|
|
+ List<String> hygienicLicense = shopMapper.getShopCertById(shopId, 5);
|
|
|
+ if (null != hygienicLicense && hygienicLicense.size() > 0) {
|
|
|
+ supplier.setMedicalPracticeLicenseImg2(hygienicLicense.get(0));
|
|
|
+ }
|
|
|
+ List<String> taxLicense = shopMapper.getShopCertById(shopId, 6);
|
|
|
+ if (null != taxLicense && taxLicense.size() > 0) {
|
|
|
+ supplier.setMedicalPracticeLicenseImg3(taxLicense.get(0));
|
|
|
+ }
|
|
|
+ return ResponseJson.success(supplier);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商首页-轮播图片
|
|
|
+ *
|
|
|
+ * @param shopId 供应商Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<ShopBannerVo>> getShopHomeImages(Integer shopId) {
|
|
|
+ List<ShopBannerVo> images = shopMapper.getShopHomeImages(shopId);
|
|
|
+ return ResponseJson.success(images);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商-更新轮播图片
|
|
|
+ *
|
|
|
+ * @param shopBannerDto {
|
|
|
+ * id 图片id
|
|
|
+ * shopId 供应商Id
|
|
|
+ * image 图片
|
|
|
+ * title 名称
|
|
|
+ * link 链接
|
|
|
+ * info 描述
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Void> saveShopHomeImages(ShopBannerDto shopBannerDto) {
|
|
|
+ ShopBannerVo shopBanner = new ShopBannerVo();
|
|
|
+ BeanUtils.copyProperties(shopBannerDto, shopBanner);
|
|
|
+ if (null != shopBannerDto.getId()){
|
|
|
+ // 更新
|
|
|
+ shopBanner.setId(shopBannerDto.getId());
|
|
|
+ shopMapper.updateShopHomeImage(shopBanner);
|
|
|
+ } else {
|
|
|
+ // 新增
|
|
|
+ int count = shopMapper.getShopHomeImageCount(shopBannerDto.getShopId());
|
|
|
+ if (count >= 4) {
|
|
|
+ return ResponseJson.error("主页广告图的上限是4张图!", null);
|
|
|
+ }
|
|
|
+ shopMapper.insertShopHomeImage(shopBanner);
|
|
|
+ }
|
|
|
+ return ResponseJson.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商-删除轮播图片
|
|
|
+ *
|
|
|
+ * @param id 图片id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Void> deleteShopHomeImages(Integer id) {
|
|
|
+ shopMapper.deleteShopHomeImage(id);
|
|
|
+ return ResponseJson.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商个人中心数据
|
|
|
+ *
|
|
|
+ * @param userId 用户Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> getShopPersonalData(Integer userId) {
|
|
|
+ Map<String, Object> result = new HashMap<>(11);
|
|
|
+ // 1.用户信息
|
|
|
+ UserVo user = baseMapper.getUserByUserId(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return ResponseJson.error("用户信息不存在", null);
|
|
|
+ }
|
|
|
+ result.put("user", user);
|
|
|
+ // 2.供应商信息
|
|
|
+ ShopVo shop = shopMapper.getShopById(user.getShopId());
|
|
|
+ if (shop == null) {
|
|
|
+ return ResponseJson.error("供应商信息不存在", null);
|
|
|
+ }
|
|
|
+ shop.setLogo(ImageUtils.getImageURL("shopLogo", shop.getLogo(), 0, wwwDomain));
|
|
|
+ result.put("shop", shop);
|
|
|
+ // 3.资料完整度
|
|
|
+ List<String> productCertification = shopMapper.getShopCertById(user.getShopId(), 3);
|
|
|
+ List<String> certificateHonor = shopMapper.getShopCertById(user.getShopId(), 1);
|
|
|
+ // 4.是否有荣誉证书与产品证书
|
|
|
+ boolean b = productCertification != null && productCertification.size() > 0 && certificateHonor != null && certificateHonor.size() > 0;
|
|
|
+ if (StringUtils.isNotBlank(user.getEmail()) && StringUtils.isNotBlank(shop.getLegalPerson()) && StringUtils.isNotBlank(shop.getShopDesc())
|
|
|
+ && StringUtils.isNotBlank(shop.getLogo()) && b) {
|
|
|
+ result.put("dataIntegrity", "100%");
|
|
|
+ } else if (StringUtils.isNotBlank(shop.getLegalPerson()) && StringUtils.isNotBlank(shop.getShopDesc()) && StringUtils.isNotBlank(shop.getLogo())) {
|
|
|
+ result.put("dataIntegrity", "90%");
|
|
|
+ } else {
|
|
|
+ result.put("dataIntegrity", "70%");
|
|
|
+ }
|
|
|
+ // 5.店铺促销活动
|
|
|
+ PromotionsVo promotions = shopMapper.getShopPromotionsByShopId(user.getShopId());
|
|
|
+ if (null != promotions && 3 == promotions.getMode()) {
|
|
|
+ List<ProductItemVo> productGifts = shopMapper.getPromotionsGifts(promotions.getId());
|
|
|
+ productGifts.forEach(p -> {
|
|
|
+ p.setImage(ImageUtils.getImageURL("product", p.getImage(), 0, wwwDomain));
|
|
|
+ });
|
|
|
+ promotions.setGiftList(productGifts);
|
|
|
+ }
|
|
|
+ result.put("promotions", promotions);
|
|
|
+ // 6.未读消息数量
|
|
|
+ Integer unReadMessageCount = personalCenterMapper.getUnReadMessageCount(userId);
|
|
|
+ result.put("unReadMessageCount", unReadMessageCount);
|
|
|
+ // 7.商品数量统计,validFlag 商品状态,见ProductStatus,0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已冻结'
|
|
|
+ Integer allNum = shopMapper.getShopProductCount(user.getShopId(), null);
|
|
|
+ result.put("allNum", allNum);
|
|
|
+ // 8.已上架数量
|
|
|
+ Integer upNum = shopMapper.getShopProductCount(user.getShopId(), 2);
|
|
|
+ result.put("upNum", upNum);
|
|
|
+ // 9.已下架数量
|
|
|
+ Integer downNum = shopMapper.getShopProductCount(user.getShopId(), 3);
|
|
|
+ result.put("downNum", downNum);
|
|
|
+ // 10.单品销售排名
|
|
|
+ List<Map<String, Object>> salesRankingList = shopMapper.getSalesRankingList(user.getShopId());
|
|
|
+ if (salesRankingList != null && salesRankingList.size() > 0) {
|
|
|
+ salesRankingList.forEach(map -> {
|
|
|
+ ProductItemVo product = shopMapper.getProductShown((Integer) map.get("productId"));
|
|
|
+ if (product != null) {
|
|
|
+ map.put("name", product.getName());
|
|
|
+ map.put("image", ImageUtils.getImageURL("product", product.getImage(), 0, wwwDomain));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ result.put("salesRankingList", salesRankingList);
|
|
|
+ // 11.销售情况统计
|
|
|
+ List<Map<String, Object>> salesStatisticsList = new ArrayList<>();
|
|
|
+ Date endDayOfDay = DateUtil.getDayEnd();
|
|
|
+ // 近一个月销售情况统计
|
|
|
+ Date beginDayOfYesterday = DateUtil.addMonth(endDayOfDay, -1);
|
|
|
+ Map<String, Object> m1 = shopMapper.getSalesStatistics(user.getShopId(), DateUtil.formatDateTime(beginDayOfYesterday), DateUtil.formatDateTime(endDayOfDay));
|
|
|
+ m1.put("time", "近一月");
|
|
|
+ salesStatisticsList.add(m1);
|
|
|
+ // 近三个月销售情况统计
|
|
|
+ Date beginDayOfLastWeek = DateUtil.addMonth(endDayOfDay, -3);
|
|
|
+ Map<String, Object> m2 = shopMapper.getSalesStatistics(user.getShopId(), DateUtil.formatDateTime(beginDayOfLastWeek), DateUtil.formatDateTime(endDayOfDay));
|
|
|
+ m2.put("time", "近三月");
|
|
|
+ salesStatisticsList.add(m2);
|
|
|
+ // 近半年销售情况统计
|
|
|
+ Date beginDayOfLastMonth = DateUtil.addMonth(endDayOfDay, -6);
|
|
|
+ Map<String, Object> m3 = shopMapper.getSalesStatistics(user.getShopId(), DateUtil.formatDateTime(beginDayOfLastMonth), DateUtil.formatDateTime(endDayOfDay));
|
|
|
+ m3.put("time", "近半年");
|
|
|
+ salesStatisticsList.add(m3);
|
|
|
+ // 近一年销售情况统计
|
|
|
+ Date beginDayOfLastYear = DateUtil.addMonth(endDayOfDay, -12);
|
|
|
+ Map<String, Object> m4 = shopMapper.getSalesStatistics(user.getShopId(), DateUtil.formatDateTime(beginDayOfLastYear), DateUtil.formatDateTime(endDayOfDay));
|
|
|
+ m4.put("time", "近一年");
|
|
|
+ salesStatisticsList.add(m4);
|
|
|
+ result.put("salesStatisticsList", salesStatisticsList);
|
|
|
+
|
|
|
+ return ResponseJson.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
}
|