| | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.*; |
| | |
| | | import com.doumee.dao.business.dao.SmsConfigMapper; |
| | | import com.doumee.dao.business.dao.SmsEmailMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.SmsEmailService; |
| | | import com.doumee.service.business.third.EmailService; |
| | | import com.doumee.service.business.third.EmayService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private EmayService emayService; |
| | | @Autowired |
| | | private SmsConfigMapper smsConfigMapper; |
| | | @Autowired |
| | | private SystemUserMapper systemUserMapper; |
| | | @Autowired |
| | | private YwCustomerMapper ywCustomerMapper; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Value("${debug_model}") |
| | | private boolean debugModel; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer sendSms(SmsEmail smsEmail) { |
| | | if(StringUtils.isBlank(smsEmail.getPhone())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | public Integer sendMerchantLoginSms(String phone) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "手机号不能为空"); |
| | | } |
| | | String nowDate = DateUtil.getFomartDate(new Date(),"yyyy-MM-dd HH:mm:ss"); |
| | | if(smsEmailMapper.selectCount(new QueryWrapper<SmsEmail>().lambda() |
| | | .eq(SmsEmail::getPhone,smsEmail.getPhone()) |
| | | .eq(SmsEmail::getType,Constants.ZERO) |
| | | .between(SmsEmail::getCreateDate, DateUtil.getFomartDate(DateUtil.afterMinutesDate(-5),"yyyy-MM-dd HH:mm:ss"),nowDate) |
| | | )>=3){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,超出发送次数,请稍后重试!"); |
| | | return doSendH5LoginSms(phone.trim(), LoginUserInfo.H5_USER_CUSTOMER); |
| | | } |
| | | |
| | | @Override |
| | | public Integer sendSms(SmsEmail smsEmail) { |
| | | if (StringUtils.isBlank(smsEmail.getPhone())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | return doSendH5LoginSms(smsEmail.getPhone().trim(), LoginUserInfo.H5_USER_OPS); |
| | | } |
| | | |
| | | private Integer doSendH5LoginSms(String phone, Integer h5UserType) { |
| | | assertH5LoginAccountExists(phone, h5UserType); |
| | | String nowDate = DateUtil.getFomartDate(new Date(), "yyyy-MM-dd HH:mm:ss"); |
| | | if (smsEmailMapper.selectCount(new QueryWrapper<SmsEmail>().lambda() |
| | | .eq(SmsEmail::getPhone, phone) |
| | | .eq(SmsEmail::getType, Constants.ZERO) |
| | | .between(SmsEmail::getCreateDate, DateUtil.getFomartDate(DateUtil.afterMinutesDate(-5), "yyyy-MM-dd HH:mm:ss"), nowDate) |
| | | ) >= 3) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,超出发送次数,请稍后重试!"); |
| | | } |
| | | String code = Constants.getRandom6Num(); |
| | | SmsConfig smsConfig = smsConfigMapper.selectOne(new QueryWrapper<SmsConfig>().lambda().eq(SmsConfig::getObjType, |
| | | SmsConstants.inventCode).last(" limit 1 ")); |
| | | //开启短信通知 |
| | | if(Objects.nonNull(smsConfig) || Constants.equalsInteger(smsConfig.getStatus(),Constants.ZERO)){ |
| | | if(StringUtils.isNotBlank(smsConfig.getContent())){ |
| | | String content = smsConfig.getContent().replace("{验证码}",code); |
| | | emayService.sendSmsByHk(smsEmail.getPhone(),content); |
| | | smsEmail.setRemark(code); |
| | | smsEmail.setIsdeleted(Constants.ZERO); |
| | | smsEmail.setCreateDate(new Date()); |
| | | smsEmail.setStatus(Constants.ZERO); |
| | | smsEmail.setType(Constants.ZERO); |
| | | smsEmail.setTitle("短信验证码"); |
| | | smsEmail.setContent(content); |
| | | smsEmail.setObjType(Constants.ZERO+""); |
| | | smsEmailMapper.insert(smsEmail); |
| | | return smsEmail.getId(); |
| | | } |
| | | SystemDictData comNameDict = systemDictDataBiz.queryByCode(Constants.SMS, Constants.SMS_COMNAME); |
| | | if (comNameDict == null || StringUtils.isBlank(comNameDict.getCode())) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "短信签名未配置,请联系管理员"); |
| | | } |
| | | return null; |
| | | String comName = comNameDict.getCode(); |
| | | if (smsConfig == null || StringUtils.isBlank(smsConfig.getContent())) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "短信服务未配置,请联系管理员"); |
| | | } |
| | | if (!Constants.equalsInteger(smsConfig.getStatus(), Constants.ZERO)) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "短信服务未开启,请联系管理员"); |
| | | } |
| | | String content = comName + smsConfig.getContent().replace("{验证码}", code); |
| | | if (!emayService.sendSingleSms(phone, content)) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "短信发送失败,请稍后重试"); |
| | | } |
| | | SmsEmail record = new SmsEmail(); |
| | | record.setPhone(phone); |
| | | record.setRemark(code); |
| | | record.setIsdeleted(Constants.ZERO); |
| | | record.setCreateDate(new Date()); |
| | | record.setStatus(Constants.ZERO); |
| | | record.setType(Constants.ZERO); |
| | | record.setTitle("短信验证码"); |
| | | record.setContent(content); |
| | | record.setObjType(Constants.ZERO + ""); |
| | | smsEmailMapper.insert(record); |
| | | return record.getId(); |
| | | } |
| | | |
| | | /** |
| | | * H5 登录发短信前校验:商户查 yw_customer,运维查 system_user |
| | | */ |
| | | private void assertH5LoginAccountExists(String phone, Integer h5UserType) { |
| | | if (Constants.equalsInteger(h5UserType, LoginUserInfo.H5_USER_CUSTOMER)) { |
| | | assertMerchantAccountExists(phone); |
| | | return; |
| | | } |
| | | if (systemUserMapper.selectCount(new QueryWrapper<SystemUser>().lambda() |
| | | .eq(SystemUser::getMobile, phone) |
| | | .eq(SystemUser::getDeleted, Boolean.FALSE)) == Constants.ZERO) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,手机号无效请检查后重试!"); |
| | | } |
| | | } |
| | | |
| | | private void assertMerchantAccountExists(String phone) { |
| | | YwCustomer customer = findMerchantByPhone(phone); |
| | | if (customer == null) { |
| | | throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(), "商户不存在或未注册"); |
| | | } |
| | | if (customer.getStatus() != null && Constants.equalsInteger(customer.getStatus(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN.getCode(), "商户账号已禁用"); |
| | | } |
| | | } |
| | | |
| | | private YwCustomer findMerchantByPhone(String phone) { |
| | | YwCustomer byCustomerPhone = ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda() |
| | | .eq(YwCustomer::getIsdeleted, Constants.ZERO) |
| | | .eq(YwCustomer::getPhone, phone) |
| | | .last(" limit 1 ")); |
| | | if (byCustomerPhone != null) { |
| | | return byCustomerPhone; |
| | | } |
| | | Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getIsdeleted, Constants.ZERO) |
| | | .eq(Member::getType, Constants.memberType.customer) |
| | | .eq(Member::getPhone, phone) |
| | | .isNotNull(Member::getCustomerId) |
| | | .orderByDesc(Member::getId) |
| | | .last(" limit 1 ")); |
| | | if (member == null || member.getCustomerId() == null) { |
| | | return null; |
| | | } |
| | | YwCustomer customer = ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda() |
| | | .eq(YwCustomer::getId, member.getCustomerId()) |
| | | .eq(YwCustomer::getIsdeleted, Constants.ZERO) |
| | | .last(" limit 1 ")); |
| | | if (customer != null) { |
| | | return customer; |
| | | } |
| | | return ywCustomerMapper.selectOne(new QueryWrapper<YwCustomer>().lambda() |
| | | .eq(YwCustomer::getIsdeleted, Constants.ZERO) |
| | | .eq(YwCustomer::getMemberId, member.getId()) |
| | | .last(" limit 1 ")); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Integer sendBillSms(String content,String mobile,Integer billId) { |
| | | boolean result = true; |
| | | if(StringUtils.isBlank(mobile)){ |
| | | result = false; |
| | | } |
| | | if(result){ |
| | | result = emayService.sendSingleSms(mobile,content); |
| | | } |
| | | SmsEmail smsEmail = new SmsEmail(); |
| | | smsEmail.setIsdeleted(Constants.ZERO); |
| | | smsEmail.setCreateDate(new Date()); |
| | | smsEmail.setStatus(result?Constants.ONE:Constants.TWO); |
| | | smsEmail.setType(Constants.ZERO); |
| | | smsEmail.setRemark(result?"短信发送成功":"短信发送失败"); |
| | | smsEmail.setTitle("账单催费"); |
| | | smsEmail.setObjId(billId); |
| | | smsEmail.setObjType(Constants.ONE+""); |
| | | smsEmail.setContent(content); |
| | | smsEmailMapper.insert(smsEmail); |
| | | return smsEmail.getId(); |
| | | } |
| | | |
| | | @Autowired |
| | | private EmailService emailService; |
| | | |
| | | @Override |
| | | public Integer sendEmail(String email,String content,Integer billId) { |
| | | boolean result = true; |
| | | if(StringUtils.isBlank(email)){ |
| | | result = false; |
| | | } |
| | | if(result){ |
| | | result= emailService.sendEmail(email,"账单催费",content,null); |
| | | } |
| | | SmsEmail smsEmail = new SmsEmail(); |
| | | smsEmail.setRemark(result?"邮件发送成功":"邮件发送失败"); |
| | | smsEmail.setIsdeleted(Constants.ZERO); |
| | | smsEmail.setTitle("账单催费"); |
| | | smsEmail.setCreateDate(new Date()); |
| | | smsEmail.setStatus(result?Constants.ONE:Constants.TWO); |
| | | smsEmail.setType(Constants.ONE); |
| | | smsEmail.setObjId(billId); |
| | | smsEmail.setObjType(Constants.TWO+""); |
| | | smsEmail.setContent(content); |
| | | smsEmailMapper.insert(smsEmail); |
| | | return smsEmail.getId(); |
| | | } |
| | | } |