diff --git a/pluss-service-bundle/src/main/java/cn/pluss/platform/device/impl/MercOrderDetailServiceImpl.java b/pluss-service-bundle/src/main/java/cn/pluss/platform/device/impl/MercOrderDetailServiceImpl.java index 2975b28..b33ad62 100644 --- a/pluss-service-bundle/src/main/java/cn/pluss/platform/device/impl/MercOrderDetailServiceImpl.java +++ b/pluss-service-bundle/src/main/java/cn/pluss/platform/device/impl/MercOrderDetailServiceImpl.java @@ -25,6 +25,9 @@ import cn.pluss.platform.yt.YtLogistHandler; import cn.pluss.platform.yt.YtStatusEnum; import cn.pluss.platform.yt.constant.YtConstant; import com.alibaba.fastjson.JSONObject; +import com.aliyun.dysmsapi20170525.Client; +import com.aliyun.dysmsapi20170525.models.SendSmsResponse; +import com.aliyun.teaopenapi.models.Config; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -35,6 +38,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -91,30 +95,43 @@ public class MercOrderDetailServiceImpl extends ServiceImpl list = moedMapper.getByExpressNo(detail.getExpressNo()); vo.setExpressDetailList(list); - if(!list.isEmpty()){ + if (!list.isEmpty()) { vo.setLogisticProvider(list.get(0).getLogisticProvider()); } } @@ -123,23 +140,24 @@ public class MercOrderDetailServiceImpl extends ServiceImpl getDetailByOrderNo(String orderNo,String status) { + public List getDetailByOrderNo(String orderNo, String status) { QueryWrapper queryWrapper = new QueryWrapper() - .eq("orderNo",orderNo).orderByDesc("id"); - if(StringUtil.isNotEmpty(status) && !"-1".equals(status)){ - switch (status){ + .eq("orderNo", orderNo).orderByDesc("id"); + if (StringUtil.isNotEmpty(status) && !"-1".equals(status)) { + switch (status) { case "1": - queryWrapper.eq("status",DeviceOrderStatus.COMPLETED.getStatus()); + queryWrapper.eq("status", DeviceOrderStatus.COMPLETED.getStatus()); break; case "2": - queryWrapper.eq("status",DeviceOrderStatus.RECEIV_ING.getStatus()); + queryWrapper.eq("status", DeviceOrderStatus.RECEIV_ING.getStatus()); break; case "3": - queryWrapper.in("status",DeviceOrderStatus.REFUND_ING.getStatus(),DeviceOrderStatus.REFUND_SUCC.getStatus(),DeviceOrderStatus.REFUND_FAIL.getStatus()); + queryWrapper.in("status", DeviceOrderStatus.REFUND_ING.getStatus(), DeviceOrderStatus.REFUND_SUCC.getStatus(), DeviceOrderStatus.REFUND_FAIL.getStatus()); break; } } @@ -148,40 +166,41 @@ public class MercOrderDetailServiceImpl extends ServiceImpl 0,"退款金额超出商品金额"); - if(DeviceOrderStatus.SUCC_PAY.getStatus().equals(detail.getStatus()) + MsgException.check(dto.getRefundAmt().compareTo(totalAmt) > 0, "退款金额超出商品金额"); + if (DeviceOrderStatus.SUCC_PAY.getStatus().equals(detail.getStatus()) || DeviceOrderStatus.RECEIV_ING.getStatus().equals(detail.getStatus()) || DeviceOrderStatus.REFUND_FAIL.getStatus().equals(detail.getStatus()) - || DeviceOrderStatus.COMPLETED.getStatus().equals(detail.getStatus())){ + || DeviceOrderStatus.COMPLETED.getStatus().equals(detail.getStatus())) { List list = new ArrayList<>(16); - for (String picUrl:dto.getPicList()) { - MercDeviceRefundImage image = new MercDeviceRefundImage(detail,picUrl); + for (String picUrl : dto.getPicList()) { + MercDeviceRefundImage image = new MercDeviceRefundImage(detail, picUrl); list.add(image); } mdriService.saveBatch(list); @@ -198,72 +217,78 @@ public class MercOrderDetailServiceImpl extends ServiceImpl auditRefund(MercOrderDetail orderDetail) { - MsgException.checkNull(orderDetail.getId(),"退款详情订单ID为空"); - MsgException.checkBlank(orderDetail.getStatus(),"状态不能为空"); - MsgException.checkNull(orderDetail.getRefundAmt(),"退款金额不能为空"); - if(MercOrderDetail.STATUS_REFUND_FAIL.equals(orderDetail.getStatus())){ - MsgException.checkBlank(orderDetail.getRejectRemark(),"退款驳回,驳回原因不能为空!"); + MsgException.checkNull(orderDetail.getId(), "退款详情订单ID为空"); + MsgException.checkBlank(orderDetail.getStatus(), "状态不能为空"); + MsgException.checkNull(orderDetail.getRefundAmt(), "退款金额不能为空"); + if (MercOrderDetail.STATUS_REFUND_FAIL.equals(orderDetail.getStatus())) { + MsgException.checkBlank(orderDetail.getRejectRemark(), "退款驳回,驳回原因不能为空!"); } MercOrderDetail detail = baseMapper.selectById(orderDetail.getId()); - MsgException.checkNull(detail,"退款详情ID有误!"); + MsgException.checkNull(detail, "退款详情ID有误!"); // MsgException.check(!MercOrderDetail.STATUS_REFUND_AGREE.equals(detail.getStatus()),"只能处理退货退款中的订单!"); BigDecimal useRefundAmt = baseMapper.getUseRefundAmtByOrderNo(detail.getOrderNo()); BigDecimal totalOrderAmt = detail.getPrice().multiply(BigDecimal.valueOf(detail.getNum())).add(detail.getPostage()); - if(orderDetail.getRefundAmt().add(useRefundAmt).compareTo(totalOrderAmt) > 0){ + if (orderDetail.getRefundAmt().add(useRefundAmt).compareTo(totalOrderAmt) > 0) { MsgException.throwException("退款金额超出当前订单可退款总额"); } - if(MercOrderDetail.STATUS_REFUND_SUCCESS.equals(orderDetail.getStatus())){ - phoneValidateCodeService.checkSmsVerifyCode(orderDetail.getPhone(),orderDetail.getVerifyCode()); + if (MercOrderDetail.STATUS_REFUND_SUCCESS.equals(orderDetail.getStatus())) { + phoneValidateCodeService.checkSmsVerifyCode(orderDetail.getPhone(), orderDetail.getVerifyCode()); MercOrderNew orderByNo = mercOrderNewMapper.getOrderByNo(detail.getOrderNo()); - MsgException.checkNull(orderByNo,"订单有误!"); + MsgException.checkNull(orderByNo, "订单有误!"); Integer channel = orderByNo.getChannel(); - MsgException.checkNull(channel,"通道未知,退款失败"); + MsgException.checkNull(channel, "通道未知,退款失败"); Map result = null; MerchantOrder order = new MerchantOrder(); - order.convert(orderByNo,orderDetail.getRefundAmt(), SettleTypeEnum.D1.getValue(), detail.getRefundReason()); - switch (channel){ + order.convert(orderByNo, orderDetail.getRefundAmt(), SettleTypeEnum.D1.getValue(), detail.getRefundReason()); + switch (channel) { case 1: + MerchantChannelStatus channelInfo = merchantChannelStatusMapper.getByMerchantCode(orderByNo.getMerchantCode(), 1); + MsgException.checkNull(channelInfo, "收款商户通道信息异常!"); + result = ysPayOldService.refundPay(order, channelInfo.getMerchantId()); + break; case 2: case 3: MsgException.throwException("当前订单所属通道不支持退款"); break; case 4: - //银盛退款 + /* //银盛退款 MerchantChannelStatus channelInfo = merchantChannelStatusMapper.getByMerchantCode(orderByNo.getMerchantCode(), 4); - MsgException.checkNull(channelInfo,"收款商户通道信息异常!"); + MsgException.checkNull(channelInfo, "收款商户通道信息异常!"); result = ysPayOldService.refundPay(order, channelInfo.getMerchantId()); - break; + break;*/ case 5: //原生通道退款 TODO 不支持微信支付 因为微信支付走对公账户 所以这里加一个验证 - MsgException.check(!Constant.PAY_TYPE_ALIPAY.equals(orderByNo.getPayType()),"当前订单支付方式不支持退款!"); + MsgException.check(!Constant.PAY_TYPE_ALIPAY.equals(orderByNo.getPayType()), "当前订单支付方式不支持退款!"); result = aliService.refundV2(detail); break; default: MsgException.throwException("未知通道"); break; } - int code = (int)result.get("code"); + int code = (int) result.get("code"); String msg = (String) result.get("msg"); String refundNo = (String) result.get("refundNo"); - if(code != ResultCode.SUCCESS.code()){ + if (code != ResultCode.SUCCESS.code()) { return ResultGenerator.genFailResult(msg); } detail.setRefundTime(DateUtils.currentDate()); @@ -277,74 +302,111 @@ public class MercOrderDetailServiceImpl extends ServiceImpl getVerifyCode(PhoneValidateCode phoneValidateCode) { - MsgException.checkBlank(phoneValidateCode.getPhone(),"获取失败,手机号为空"); - String checkCode = StringUtil.random(4); + MsgException.checkBlank(phoneValidateCode.getPhone(), "获取失败,手机号为空"); + String checkCode = StringUtil.random(6); phoneValidateCode.setCode(checkCode); - JSONObject result = validateCodeUtil.requestManageValidateCode(phoneValidateCode.getPhone(),checkCode); - if(result.getIntValue("code") != ResultCode.SUCCESS.code()){ + //JSONObject result = validateCodeUtil.requestManageValidateCode(phoneValidateCode.getPhone(), checkCode); + /*if (result.getIntValue("code") != ResultCode.SUCCESS.code()) { return ResultGenerator.genFailResult(result.getString("msg")); + }*/ + + Client client = null; + try { + + client = createClient(); + // 1.发送短信 + com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest() + .setSignName("超掌柜") + .setTemplateCode("SMS_244665149") + .setTemplateParam("{\"code\":" + "'" + checkCode + "'" + "}") + .setPhoneNumbers(phoneValidateCode.getPhone()); + com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); + SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime); + + if (sendSmsResponse.getStatusCode() != 200) { + return ResultGenerator.genFailResult(sendSmsResponse.getBody().getMessage()); + } + + } catch (Exception e) { + e.printStackTrace(); } + phoneValidateCode.setSendDt(DateUtils.currentDate()); phoneValidateCode.setStatus("1"); phoneValidateCodeService.savePhoneValidateCode(phoneValidateCode); - return ResultGenerator.genSuccessResult("获取成功",null); + return ResultGenerator.genSuccessResult("获取成功", null); + } + + /** + * 发送短信(阿里云) + * + * @return + * @throws Exception + */ + public Client createClient() throws Exception { + Config config = new Config(); + config.accessKeyId = ACCESSKEYID; + config.accessKeySecret = ACCESSKEYSECRET; + return new com.aliyun.dysmsapi20170525.Client(config); } /** * 推送物流信息 + * * @param ids * @return */ @Transactional(rollbackFor = Exception.class) @Override public Result printLogistInfo(List ids) { - MsgException.check(ids.isEmpty(),"未选中订单数据!"); + MsgException.check(ids.isEmpty(), "未选中订单数据!"); List list = baseMapper.selectBatchIds(ids); - MsgException.check(list.isEmpty(),"订单数据异常!"); + MsgException.check(list.isEmpty(), "订单数据异常!"); boolean flag = false; - for (MercOrderDetail detail:list) { - if(!MercOrderDetail.STATUS_PAYED.equals(detail.getStatus())){ + for (MercOrderDetail detail : list) { + if (!MercOrderDetail.STATUS_PAYED.equals(detail.getStatus())) { flag = true; break; } } - MsgException.check(flag,"只能处理已支付的订单!"); + MsgException.check(flag, "只能处理已支付的订单!"); MercOrderDetail detail = list.get(0); MercOrderNew order = mercOrderNewMapper.getOrderByNo(detail.getOrderNo()); - MsgException.checkNull(order,"订单数据异常!"); - JSONObject result = ytLogistHandler.createYtOrderV2(list,order); - if(result.getIntValue("code") != ResultCode.SUCCESS.code()){ + MsgException.checkNull(order, "订单数据异常!"); + JSONObject result = ytLogistHandler.createYtOrderV2(list, order); + if (result.getIntValue("code") != ResultCode.SUCCESS.code()) { MsgException.throwException(result.getString("message")); } JSONObject data = result.getJSONObject("data"); - UpdateWrapper updateWrapper = new UpdateWrapper().in("id",ids) - .set("logistNo",data.getString("logistNo")).set("expressNo",data.getString("expressNo")) - .set("status",MercOrderDetail.STATUS_UN_RECEIVED); + UpdateWrapper updateWrapper = new UpdateWrapper().in("id", ids) + .set("logistNo", data.getString("logistNo")).set("expressNo", data.getString("expressNo")) + .set("status", MercOrderDetail.STATUS_UN_RECEIVED); update(updateWrapper); - MercOrderExpress orderExpress = new MercOrderExpress(); + MercOrderExpress orderExpress = new MercOrderExpress(); orderExpress.setOrderNo(order.getOrderNo()); orderExpress.setLogistNo(data.getString("logistNo")); orderExpress.setExpressNo(data.getString("expressNo")); orderExpress.setType(MercOrderExpress.EXPRESS_TYPE_HAIR); orderExpress.setStatus(YtStatusEnum.ACCEPT.getValue()); mercOrderExpressService.save(orderExpress); - return ResultGenerator.genSuccessResult("处理成功",null); + return ResultGenerator.genSuccessResult("处理成功", null); } /** * 分页查询 + * * @param page * @param condition * @return */ @Override public Page pageInfo(Page page, MercOrderDetail condition) { - return baseMapper.pageInfo(page,condition); + return baseMapper.pageInfo(page, condition); } @Override @@ -364,22 +426,23 @@ public class MercOrderDetailServiceImpl extends ServiceImpl inputExpressNo(Long id, String expressNo) { - MsgException.checkNull(id,"订单ID不能为空!"); - MsgException.checkBlank(expressNo,"快递单号不能为空!"); + MsgException.checkNull(id, "订单ID不能为空!"); + MsgException.checkBlank(expressNo, "快递单号不能为空!"); MercOrderDetail detail = baseMapper.selectById(id); - MsgException.checkNull(detail,"订单数据异常!"); - MsgException.check(!MercOrderDetail.STATUS_PAYED.equals(detail.getStatus()),"只能处理已支付的订单数据"); - MsgException.check(StringUtil.isNotEmpty(detail.getExpressNo()),"当前订单已存在物流单号,请勿重复填写"); + MsgException.checkNull(detail, "订单数据异常!"); + MsgException.check(!MercOrderDetail.STATUS_PAYED.equals(detail.getStatus()), "只能处理已支付的订单数据"); + MsgException.check(StringUtil.isNotEmpty(detail.getExpressNo()), "当前订单已存在物流单号,请勿重复填写"); detail.setStatus(MercOrderDetail.STATUS_UN_RECEIVED); detail.setExpressNo(expressNo); MercOrderExpress express = mercOrderExpressService.getByExpressNo(expressNo); - if(express == null){ + if (express == null) { express = new MercOrderExpress(); express.setLogistNo(detail.getLogistNo()); express.setOrderNo(detail.getOrderNo()); @@ -389,17 +452,18 @@ public class MercOrderDetailServiceImpl extends ServiceImpl listByOrderNoAndCode(String orderNo, String code) { - return baseMapper.listByOrderNoAndCode(orderNo,code); + return baseMapper.listByOrderNoAndCode(orderNo, code); } }