| | |
| | | import com.doumee.dao.business.model.PricingRule; |
| | | import com.doumee.dao.business.model.ShopInfo; |
| | | import com.doumee.dao.dto.*; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.dao.vo.ShopDetailVO; |
| | |
| | | if (pageWrap.getModel().getOpenid() != null) { |
| | | queryWrapper.lambda().like(ShopInfo::getOpenid, pageWrap.getModel().getOpenid()); |
| | | } |
| | | for (PageWrap.SortData sortData : pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | queryWrapper.lambda().orderByDesc(ShopInfo::getId); |
| | | return PageData.from(shopInfoMapper.selectPage(page, queryWrapper)); |
| | | } |
| | | |
| | |
| | | Integer shopId; |
| | | if (existing != null) { |
| | | // 校验状态:只有待审批(0)和被驳回(2)可修改 |
| | | if (!Constants.equalsInteger(existing.getAuditStatus(), Constants.ZERO) |
| | | && !Constants.equalsInteger(existing.getAuditStatus(), Constants.TWO)) { |
| | | if (!Constants.equalsInteger(existing.getAuditStatus(), Constants.TWO)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前门店状态不允许修改"); |
| | | } |
| | | // 校验openid匹配:当前登录会员的openid必须与门店的openid一致 |
| | |
| | | shopInfo.setSalt(salt); |
| | | shopInfo.setAliAccount(request.getAliAccount()); |
| | | shopInfo.setAliName(request.getAliName()); |
| | | shopInfo.setAuditStatus(Constants.ZERO); |
| | | shopInfo.setStatus(Constants.ZERO); |
| | | shopInfo.setDeleted(Constants.ZERO); |
| | | shopInfo.setCreateTime(now); |
| | |
| | | shopInfo.setRegionMemberId(member.getId()); |
| | | // 读取押金金额 |
| | | setDepositAmountFromPricingRule(shopInfo); |
| | | // 设置默认配送范围 |
| | | setDefaultDeliveryRange(shopInfo); |
| | | shopInfoMapper.insert(shopInfo); |
| | | shopId = shopInfo.getId(); |
| | | } |
| | |
| | | if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) { |
| | | // 审核通过 → 通知缴纳押金 |
| | | String depositMoney = shopInfo.getDepositAmount() != null |
| | | ? String.valueOf(shopInfo.getDepositAmount() / 100.0) : "0"; |
| | | ? new java.math.BigDecimal(shopInfo.getDepositAmount()) |
| | | .divide(new java.math.BigDecimal(100), 2, java.math.RoundingMode.HALF_UP).toPlainString() : "0"; |
| | | sendSmsNotify(shopInfo.getTelephone(), |
| | | Constants.SmsNotify.SHOP_AUTH_APPROVED_DEPOSIT, |
| | | "storeName", shopInfo.getName(), |
| | |
| | | |
| | | // 门店名称模糊查询 |
| | | if (StringUtils.isNotBlank(dto.getName())) { |
| | | qw.lambda().like(ShopInfo::getName, dto.getName()); |
| | | qw.lambda().and(q -> q.like(ShopInfo::getName, dto.getName()).or() |
| | | .like(ShopInfo::getAddress, dto.getName())); |
| | | } |
| | | |
| | | // 城市筛选(areaId是区县,需匹配其parentId等于城市ID) |
| | |
| | | // 取件门店 |
| | | List<Orders> takeSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getType,Constants.ONE) |
| | | .ge(Orders::getCreateTime, startTime) |
| | | .lt(Orders::getCreateTime, endTime) |
| | | .eq(Orders::getTakeShopId, shopId)); |
| | |
| | | vo.setSettlementProfit(depositFee + takeFee); |
| | | |
| | | // 3. 在库订单数 |
| | | // 3.1 存件门店=本门店,status in (2已寄存, 5待取件) |
| | | Long depositStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | // 3.1 就地订单:存件门店=本门店,type=0,status in (2已寄存, 5待取件) |
| | | Long localStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getDepositShopId, shopId) |
| | | .eq(Orders::getType, Constants.ZERO) |
| | | .in(Orders::getStatus, |
| | | Constants.OrderStatus.deposited.getStatus(), |
| | | Constants.OrderStatus.arrived.getStatus())); |
| | | // 3.2 取件门店=本门店,status = 5待取件 |
| | | // 3.2 异地订单:存件门店=本门店,type=1,status=2已寄存 |
| | | Long remoteStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getDepositShopId, shopId) |
| | | .eq(Orders::getType, Constants.ONE) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.deposited.getStatus())); |
| | | // 3.3 取件门店=本门店,异地订单,status = 5待取件 |
| | | Long takeStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda() |
| | | .eq(Orders::getDeleted, Constants.ZERO) |
| | | .eq(Orders::getType,Constants.ONE) |
| | | .eq(Orders::getTakeShopId, shopId) |
| | | .eq(Orders::getStatus, Constants.OrderStatus.arrived.getStatus())); |
| | | vo.setStorageCount(depositStorageCount.intValue() + takeStorageCount.intValue()); |
| | | vo.setStorageCount(localStorageCount.intValue() + remoteStorageCount.intValue() + takeStorageCount.intValue()); |
| | | |
| | | return vo; |
| | | } |
| | |
| | | public ShopLoginVO shopPasswordLogin(ShopLoginDTO dto){ |
| | | if(StringUtils.isBlank(dto.getTelephone()) |
| | | || StringUtils.isBlank(dto.getPassword()) |
| | | || StringUtils.isBlank(dto.getOpenid()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户名或密码不能为空"); |
| | | } |
| | |
| | | ); |
| | | if(shop==null){ |
| | | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); |
| | | } |
| | | if(!Constants.equalsInteger(shop.getAuditStatus(),Constants.THREE)){ |
| | | if(Constants.equalsInteger(shop.getAuditStatus(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请完成审批流程 - 支付押金"); |
| | | } |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"门店审批流程未完成,请完成审批流程"); |
| | | } |
| | | //加密密码 |
| | | String pwd = Utils.Secure.encryptPassword( dto.getPassword(), shop.getSalt()); |
| | |
| | | |
| | | // 创建token(generateTokenForRedis 已自动清除该用户旧token,保证唯一有效) |
| | | String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate); |
| | | |
| | | // 构建响应 |
| | | ShopLoginVO vo = new ShopLoginVO(); |
| | | vo.setToken(token); |
| | |
| | | if (shopInfo.getCompanyType() == null) { |
| | | return; |
| | | } |
| | | Areas areas = areasService.findById(shopInfo.getAreaId()); |
| | | PricingRule pricingRule = pricingRuleMapper.selectOne(new QueryWrapper<PricingRule>().lambda() |
| | | .eq(PricingRule::getDeleted, Constants.ZERO) |
| | | .eq(PricingRule::getType, Constants.THREE) |
| | | .eq(PricingRule::getFieldA, String.valueOf(shopInfo.getCompanyType())) |
| | | .eq(PricingRule::getFieldA, String.valueOf(Constants.equalsInteger(shopInfo.getCompanyType(),Constants.ZERO)?Constants.ONE:Constants.ZERO)) |
| | | .eq(PricingRule::getCityId, areas.getParentId()) |
| | | .last("limit 1")); |
| | | if (pricingRule != null && StringUtils.isNotBlank(pricingRule.getFieldB())) { |
| | | shopInfo.setDepositAmount(Long.parseLong(pricingRule.getFieldB())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 从运营配置读取默认配送范围并赋值到门店记录 |
| | | */ |
| | | private void setDefaultDeliveryRange(ShopInfo shopInfo) { |
| | | SystemDictData data = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, Constants.OP_DEFAULT_DELIVERY_RANGE); |
| | | if (data != null && StringUtils.isNotBlank(data.getCode())) { |
| | | shopInfo.setDeliveryArea(new java.math.BigDecimal(data.getCode())); |
| | | } |
| | | } |
| | | |
| | |
| | | for (int i = 0; i < paramPairs.length - 1; i += 2) { |
| | | templateParam.put(paramPairs[i], paramPairs[i + 1]); |
| | | } |
| | | boolean result = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(), |
| | | String error = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(), |
| | | templateParam.toJSONString()); |
| | | if (result) { |
| | | log.info("短信发送成功: phone={}, template={}", phone, smsNotify.name()); |
| | | } else { |
| | | log.warn("短信发送失败: phone={}, template={}", phone, smsNotify.name()); |
| | | } |
| | | // 存储短信记录 |
| | | Smsrecord smsRecord = new Smsrecord(); |
| | | smsRecord.setPhone(phone); |
| | | smsRecord.setContent(content); |
| | | smsRecord.setType(Constants.ONE); |
| | | smsRecord.setStatus(result ? Constants.ONE : Constants.ZERO); |
| | | smsRecord.setStatus(error == null ? Constants.ONE : Constants.ZERO); |
| | | if (error != null) { |
| | | smsRecord.setRemark(error); |
| | | } |
| | | smsRecord.setCreateTime(new Date()); |
| | | smsRecord.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(smsRecord); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void changePassword(Integer shopId, String newPassword, String token) { |
| | | if (StringUtils.isBlank(newPassword)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "密码不能为空"); |
| | | public void changePassword(Integer shopId, String oldPassword, String newPassword, String token) { |
| | | if (StringUtils.isBlank(oldPassword)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "旧密码不能为空"); |
| | | } |
| | | // 校验密码必须同时包含字母和数字 |
| | | if (StringUtils.isBlank(newPassword)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "新密码不能为空"); |
| | | } |
| | | // 校验新密码必须同时包含字母和数字 |
| | | boolean hasLetter = newPassword.chars().anyMatch(Character::isLetter); |
| | | boolean hasDigit = newPassword.chars().anyMatch(Character::isDigit); |
| | | if (!hasLetter || !hasDigit) { |
| | |
| | | if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | // 校验旧密码 |
| | | String oldEncryptPwd = Utils.Secure.encryptPassword(oldPassword, shopInfo.getSalt()); |
| | | if (!oldEncryptPwd.equals(shopInfo.getPassword())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "旧密码错误"); |
| | | } |
| | | // 重新生成salt,加密新密码并更新 |
| | | String salt = RandomStringUtils.randomAlphabetic(6); |
| | | shopInfo.setPassword(Utils.Secure.encryptPassword(newPassword, salt)); |
| | |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private com.doumee.core.utils.xpyun.XpyunPrintService xpyunPrintService; |
| | | |
| | | @Override |
| | | public void bindPrinter(com.doumee.dao.dto.PrinterBindDTO dto) { |
| | | ShopInfo shop = shopInfoMapper.selectById(dto.getShopId()); |
| | | if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | // 调用芯烨云注册打印机 |
| | | com.doumee.core.utils.xpyun.XpyunResponse resp = xpyunPrintService.addPrinter( |
| | | dto.getPrinterSn(), shop.getName()); |
| | | if (resp.getCode() != null && resp.getCode() == 0) { |
| | | log.info("芯烨云打印机注册成功: sn={}", dto.getPrinterSn()); |
| | | } else { |
| | | log.warn("芯烨云打印机注册返回非0: sn={}, code={}, msg={}", |
| | | dto.getPrinterSn(), resp.getCode(), resp.getMsg()); |
| | | } |
| | | // 无论云端是否成功,都绑定到门店(可后续重试云端注册) |
| | | ShopInfo update = new ShopInfo(); |
| | | update.setId(dto.getShopId()); |
| | | update.setPrinterSn(dto.getPrinterSn()); |
| | | shopInfoMapper.updateById(update); |
| | | } |
| | | |
| | | @Override |
| | | public void unbindPrinter(Integer shopId) { |
| | | ShopInfo shop = shopInfoMapper.selectById(shopId); |
| | | if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if (StringUtils.isNotBlank(shop.getPrinterSn())) { |
| | | xpyunPrintService.deletePrinter(shop.getPrinterSn()); |
| | | } |
| | | ShopInfo update = new ShopInfo(); |
| | | update.setId(shopId); |
| | | update.setPrinterSn(null); |
| | | shopInfoMapper.updateById(update); |
| | | } |
| | | |
| | | @Override |
| | | public Object queryPrinterStatus(Integer shopId) { |
| | | ShopInfo shop = shopInfoMapper.selectById(shopId); |
| | | if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if (StringUtils.isBlank(shop.getPrinterSn())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "该门店未绑定打印机"); |
| | | } |
| | | return xpyunPrintService.queryPrinterStatus(shop.getPrinterSn()); |
| | | } |
| | | |
| | | } |