| | |
| | | import com.doumee.dao.vo.ShopCenterVO; |
| | | import com.doumee.dao.vo.ShopLoginVO; |
| | | import com.doumee.dao.vo.ShopNearbyVO; |
| | | import com.doumee.dao.vo.ShopSalesStatsVO; |
| | | import com.doumee.dao.vo.ShopWebDetailVO; |
| | | import com.doumee.service.business.AreasService; |
| | | import com.doumee.service.business.ShopInfoService; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void applyShop(ShopApplyDTO request, Member member) { |
| | | Integer memberId = member.getId(); |
| | | public void applyShop(ShopApplyDTO request) { |
| | | Member member = memberMapper.selectById(request.getMemberId()); |
| | | |
| | | // 1. 校验门店手机号唯一性(shop_info.telephone) |
| | | checkTelephoneUnique(request.getTelephone(), null); |
| | | |
| | | // 2. 根据类型校验附件 |
| | | if (Constants.equalsInteger(request.getCompanyType(), Constants.ZERO)) { |
| | |
| | | // 3. 查询该会员是否已有门店记录 |
| | | QueryWrapper<ShopInfo> existQw = new QueryWrapper<>(); |
| | | existQw.lambda() |
| | | .eq(ShopInfo::getRegionMemberId, memberId) |
| | | .eq(ShopInfo::getRegionMemberId, member.getId()) |
| | | .eq(ShopInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1"); |
| | | ShopInfo existing = shopInfoMapper.selectOne(existQw); |
| | |
| | | existing.setPassword(encryptedPassword); |
| | | existing.setSalt(salt); |
| | | existing.setAliAccount(request.getAliAccount()); |
| | | existing.setAuditStatus(Constants.ZERO); |
| | | existing.setAliName(request.getAliName()); |
| | | existing.setUpdateTime(now); |
| | | existing.setUpdateUser(memberId); |
| | | existing.setAuditRemark(null); |
| | | existing.setAuditTime(null); |
| | | existing.setAuditUserId(null); |
| | | existing.setAuditStatus(Constants.ZERO); |
| | | shopInfoMapper.updateById(existing); |
| | | shopId = existing.getId(); |
| | | } else { |
| | | // 1. 校验门店手机号唯一性(shop_info.telephone) |
| | | checkTelephoneUnique(request.getTelephone(), null); |
| | | // 新建 |
| | | ShopInfo shopInfo = new ShopInfo(); |
| | | shopInfo.setCompanyType(request.getCompanyType()); |
| | |
| | | shopInfo.setPassword(encryptedPassword); |
| | | shopInfo.setSalt(salt); |
| | | shopInfo.setAliAccount(request.getAliAccount()); |
| | | shopInfo.setOpenid(member.getOpenid()); |
| | | shopInfo.setAuditStatus(Constants.ZERO); |
| | | shopInfo.setAliName(request.getAliName()); |
| | | shopInfo.setStatus(Constants.ZERO); |
| | | shopInfo.setDeleted(Constants.ZERO); |
| | | shopInfo.setCreateTime(now); |
| | | shopInfo.setUpdateTime(now); |
| | | shopInfo.setCreateUser(memberId); |
| | | shopInfo.setRegionMemberId(memberId); |
| | | shopInfo.setRegionMemberId(member.getId()); |
| | | shopInfoMapper.insert(shopInfo); |
| | | shopId = shopInfo.getId(); |
| | | } |
| | |
| | | shopInfo.setLegalPersonName(request.getLegalPersonName()); |
| | | shopInfo.setLegalPersonPhone(request.getLegalPersonPhone()); |
| | | shopInfo.setLegalPersonCard(request.getLegalPersonCard()); |
| | | shopInfo.setAliAccount(request.getAliAccount()); |
| | | shopInfo.setAliName(request.getAliName()); |
| | | shopInfo.setUpdateTime(now); |
| | | shopInfoMapper.updateById(shopInfo); |
| | | |
| | |
| | | vo.setPayStatus(shopInfo.getPayStatus()); |
| | | vo.setScore(shopInfo.getScore()); |
| | | vo.setCreateTime(shopInfo.getCreateTime()); |
| | | vo.setAliAccount(shopInfo.getAliAccount()); |
| | | vo.setAliName(shopInfo.getAliName()); |
| | | vo.setDepositAmount(shopInfo.getDepositAmount()); |
| | | |
| | | // 拼接图片前缀 |
| | | String imgPrefix = ""; |
| | | try { |
| | | imgPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode(); |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILES).getCode(); |
| | | } catch (Exception e) { |
| | | // 未配置时忽略 |
| | | } |
| | |
| | | String memberPrefix = ""; |
| | | try { |
| | | memberPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.MEMBER_FILES).getCode(); |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.MEMBER_FILES).getCode(); |
| | | } catch (Exception e) { |
| | | // 未配置时忽略 |
| | | } |
| | |
| | | qw.lambda().like(ShopInfo::getName, dto.getName()); |
| | | } |
| | | |
| | | // 城市筛选(areaId是区县,需匹配其parentId等于城市ID) |
| | | if (dto.getCityId() != null) { |
| | | qw.inSql("AREA_ID", |
| | | "SELECT id FROM areas WHERE parent_id = " + dto.getCityId() + " AND isdeleted = 0"); |
| | | } |
| | | |
| | | // 距离筛选(单位:米 → 转换为km比较) |
| | | if (distanceMeter != null && distanceMeter > 0) { |
| | | double maxKm = distanceMeter / 1000.0; |
| | |
| | | vo.setShopHours(shop.getShopHours()); |
| | | vo.setAddress(shop.getAddress()); |
| | | vo.setScore(shop.getScore()); |
| | | vo.setLatitude(shop.getLatitude()); |
| | | vo.setLongitude(shop.getLongitude()); |
| | | // 门头照第一张 |
| | | vo.setCoverImg(getFirstImage(shop.getId(), Constants.FileType.STORE_FRONT.getKey(), imgPrefix)); |
| | | // 距离 |
| | |
| | | vo.setName(shop.getName()); |
| | | vo.setAddress(shop.getAddress()); |
| | | vo.setContent(shop.getContent()); |
| | | vo.setDepositTypes(shop.getDepositTypes()); |
| | | vo.setFeeStandard(shop.getFeeStandard()); |
| | | vo.setLatitude(shop.getLatitude()); |
| | | vo.setLongitude(shop.getLongitude()); |
| | | |
| | | // 门头照 + 内部照 全路径集合 |
| | | String imgPrefix = getShopPrefix(); |
| | |
| | | private String getShopPrefix() { |
| | | try { |
| | | return systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode(); |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILES).getCode(); |
| | | } catch (Exception e) { |
| | | return ""; |
| | | } |
| | |
| | | vo.setCoverImg(shop.getCoverImg()); |
| | | if (StringUtils.isNotBlank(shop.getCoverImg())) { |
| | | String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SHOP_FILES).getCode(); |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.SHOP_FILES).getCode(); |
| | | vo.setFullCoverImg(path + shop.getCoverImg()); |
| | | } |
| | | vo.setHasMessage(false); |
| | |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .in(Orders::getStatus, Constants.OrderStatus.delivering.getStatus(), Constants.OrderStatus.arrived.getStatus())); |
| | | vo.setWaitReceiveCount(waitReceiveCount.intValue()); |
| | | // 支付宝提现账号 |
| | | vo.setAliAccount(shop.getAliAccount()); |
| | | vo.setAliName(shop.getAliName()); |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | | public ShopSalesStatsVO getShopSalesStats(Integer shopId, Integer period) { |
| | | // 计算时间范围 0=今日 1=本月 2=上月 |
| | | Calendar cal = Calendar.getInstance(); |
| | | Date startTime; |
| | | Date endTime; |
| | | |
| | | if (Constants.equalsInteger(period, 2)) { |
| | | // 上月:上月1号00:00:00 ~ 本月1号00:00:00 |
| | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | | cal.set(Calendar.MINUTE, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | endTime = cal.getTime(); |
| | | cal.add(Calendar.MONTH, -1); |
| | | startTime = cal.getTime(); |
| | | } else if (Constants.equalsInteger(period, 1)) { |
| | | // 本月:本月1号00:00:00 ~ 下月1号00:00:00 |
| | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | | cal.set(Calendar.MINUTE, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | startTime = cal.getTime(); |
| | | cal.add(Calendar.MONTH, 1); |
| | | endTime = cal.getTime(); |
| | | } else { |
| | | // 今日:今天00:00:00 ~ 明天00:00:00 |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | | cal.set(Calendar.MINUTE, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | startTime = cal.getTime(); |
| | | cal.add(Calendar.DAY_OF_MONTH, 1); |
| | | endTime = cal.getTime(); |
| | | } |
| | | |
| | | ShopSalesStatsVO vo = new ShopSalesStatsVO(); |
| | | |
| | | // 1. 销售额 + 订单数:按订单创建时间,存件门店或取件门店是本门店 |
| | | // 存件门店 |
| | | List<Orders> depositSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .ge(Orders::getCreateTime, startTime) |
| | | .lt(Orders::getCreateTime, endTime) |
| | | .eq(Orders::getDepositShopId, shopId)); |
| | | // 取件门店 |
| | | List<Orders> takeSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .ge(Orders::getCreateTime, startTime) |
| | | .lt(Orders::getCreateTime, endTime) |
| | | .eq(Orders::getTakeShopId, shopId)); |
| | | long salesAmount = depositSalesOrders.stream().mapToLong(o -> o.getTotalAmount() != null ? o.getTotalAmount() : 0L).sum() |
| | | + takeSalesOrders.stream().mapToLong(o -> o.getTotalAmount() != null ? o.getTotalAmount() : 0L).sum(); |
| | | vo.setSalesAmount(salesAmount); |
| | | vo.setOrderCount(depositSalesOrders.size() + takeSalesOrders.size()); |
| | | |
| | | // 2. 结算利润:按结算时间,根据门店角色取depositShopFee或takeShopFee |
| | | // 存件门店 = 本门店 的订单,取 depositShopFee |
| | | List<Orders> depositSettleOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getSettlementStatus, Constants.ONE) |
| | | .ge(Orders::getSettlementTime, startTime) |
| | | .lt(Orders::getSettlementTime, endTime) |
| | | .eq(Orders::getDepositShopId, shopId)); |
| | | // 取件门店 = 本门店 的订单,取 takeShopFee |
| | | List<Orders> takeSettleOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getSettlementStatus, Constants.ONE) |
| | | .ge(Orders::getSettlementTime, startTime) |
| | | .lt(Orders::getSettlementTime, endTime) |
| | | .eq(Orders::getTakeShopId, shopId)); |
| | | long depositFee = depositSettleOrders.stream() |
| | | .mapToLong(o -> o.getDepositShopFee() != null ? o.getDepositShopFee() : 0L).sum(); |
| | | long takeFee = takeSettleOrders.stream() |
| | | .mapToLong(o -> o.getTakeShopFee() != null ? o.getTakeShopFee() : 0L).sum(); |
| | | vo.setSettlementProfit(depositFee + takeFee); |
| | | |
| | | // 3. 在库订单数 |
| | | // 3.1 存件门店=本门店,status in (2已寄存, 5待取件) |
| | | Long depositStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getDepositShopId, shopId) |
| | | .in(Orders::getStatus, |
| | | Constants.OrderStatus.deposited.getStatus(), |
| | | Constants.OrderStatus.arrived.getStatus())); |
| | | // 3.2 取件门店=本门店,status = 5待取件 |
| | | Long takeStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getTakeShopId, shopId) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.arrived.getStatus())); |
| | | vo.setStorageCount(depositStorageCount.intValue() + takeStorageCount.intValue()); |
| | | |
| | | return vo; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ShopLoginVO shopSilentLogin(String openid) { |
| | | if (StringUtils.isBlank(openid)) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "openid不能为空"); |
| | | public ShopLoginVO shopSilentLogin(Integer memberId) { |
| | | Member member = memberMapper.selectById(memberId); |
| | | if(Objects.isNull(member)||StringUtils.isBlank(member.getOpenid())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "当前登录会员身份异常,请联系管理员!"); |
| | | } |
| | | ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda() |
| | | .eq(ShopInfo::getOpenid, openid) |
| | | .eq(ShopInfo::getOpenid, member.getOpenid()) |
| | | .eq(ShopInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (shop == null) { |
| | | return null; |
| | | } |
| | | |
| | | // 创建token(generateTokenForRedis 已自动清除该用户旧token,保证唯一有效) |
| | | String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate); |
| | | |