Search in sources :

Example 1 with Order

use of cn.lili.modules.order.order.entity.dos.Order in project lilishop by lilishop.

the class MemberEvaluationServiceImpl method addMemberEvaluation.

@Override
@Transactional(rollbackFor = Exception.class)
public MemberEvaluationDTO addMemberEvaluation(MemberEvaluationDTO memberEvaluationDTO, Boolean isSelf) {
    // 获取子订单信息
    OrderItem orderItem = orderItemService.getBySn(memberEvaluationDTO.getOrderItemSn());
    // 获取订单信息
    Order order = orderService.getBySn(orderItem.getOrderSn());
    // 检测是否可以添加会员评价
    Member member;
    checkMemberEvaluation(orderItem, order);
    if (Boolean.TRUE.equals(isSelf)) {
        // 自我评价商品时,获取当前登录用户信息
        member = memberService.getUserInfo();
    } else {
        // 获取用户信息 非自己评价时,读取数据库
        member = memberService.getById(order.getMemberId());
    }
    // 获取商品信息
    GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(memberEvaluationDTO.getSkuId());
    // 新增用户评价
    MemberEvaluation memberEvaluation = new MemberEvaluation(memberEvaluationDTO, goodsSku, member, order);
    // 过滤商品咨询敏感词
    memberEvaluation.setContent(SensitiveWordsFilter.filter(memberEvaluation.getContent()));
    // 添加评价
    this.save(memberEvaluation);
    // 修改订单货物评价状态为已评价
    orderItemService.updateCommentStatus(orderItem.getSn(), CommentStatusEnum.FINISHED);
    // 发送商品评价消息
    String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_COMMENT_COMPLETE.name();
    rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(memberEvaluation), RocketmqSendCallbackBuilder.commonCallback());
    return memberEvaluationDTO;
}
Also used : Order(cn.lili.modules.order.order.entity.dos.Order) GoodsSku(cn.lili.modules.goods.entity.dos.GoodsSku) MemberEvaluation(cn.lili.modules.member.entity.dos.MemberEvaluation) OrderItem(cn.lili.modules.order.order.entity.dos.OrderItem) Member(cn.lili.modules.member.entity.dos.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Order

use of cn.lili.modules.order.order.entity.dos.Order in project lilishop by lilishop.

the class WechatMessageUtil method wechatMpMessage.

/**
 * 发送微信消息
 *
 * @param sn
 */
public void wechatMpMessage(String sn) {
    log.info("发送消息订阅");
    Order order = orderService.getBySn(sn);
    if (order == null) {
        throw new ServiceException("订单" + sn + "不存在,发送订阅消息错误");
    }
    // 获取微信消息
    LambdaQueryWrapper<WechatMPMessage> wechatMPMessageQueryWrapper = new LambdaQueryWrapper();
    wechatMPMessageQueryWrapper.eq(WechatMPMessage::getOrderStatus, order.getOrderStatus());
    WechatMPMessage wechatMPMessage = wechatMPMessageService.getOne(wechatMPMessageQueryWrapper);
    if (wechatMPMessage == null) {
        log.info("未配置微信消息订阅");
        return;
    }
    Connect connect = connectService.queryConnect(ConnectQueryDTO.builder().userId(order.getMemberId()).unionType(ConnectEnum.WECHAT_MP_OPEN_ID.name()).build());
    if (connect == null) {
        return;
    }
    log.info("微信消息订阅消息发送:{}", order.getMemberId() + "-" + sn);
    // 获取token
    String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
    // 发送url
    String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + token;
    Map<String, Object> map = new HashMap<>(4);
    // 用户id
    map.put("touser", connect.getUnionId());
    // 模版id
    map.put("template_id", wechatMPMessage.getCode());
    // 模版中所需数据
    Map<String, Map<String, String>> postParams = createData(order, wechatMPMessage);
    map.put("data", postParams);
    map.put("page", "pages/order/orderDetail?sn=" + order.getSn());
    log.info("参数内容:" + JSONUtil.toJsonStr(map));
    String content = null;
    try {
        content = HttpUtil.post(url, JSONUtil.toJsonStr(map));
    } catch (Exception e) {
        log.error("微信消息发送错误", e);
    }
    JSONObject json = new JSONObject(content);
    log.info("微信消息发送结果:" + content);
    String errorMessage = json.getStr("errmsg");
    String errcode = json.getStr("errcode");
    // 发送失败
    if (!"0".equals(errcode)) {
        log.error("消息发送失败:" + errorMessage);
        log.error("消息发送请求token:" + token);
        log.error("消息发送请求:" + postParams);
    }
}
Also used : Order(cn.lili.modules.order.order.entity.dos.Order) Connect(cn.lili.modules.connect.entity.Connect) ServiceException(cn.lili.common.exception.ServiceException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) WechatMPMessage(cn.lili.modules.wechat.entity.dos.WechatMPMessage) ServiceException(cn.lili.common.exception.ServiceException) JSONObject(cn.hutool.json.JSONObject) JSONObject(cn.hutool.json.JSONObject)

Example 3 with Order

use of cn.lili.modules.order.order.entity.dos.Order in project lilishop by lilishop.

the class WechatMessageUtil method wechatMessage.

/**
 * 发送微信消息
 *
 * @param sn
 */
public void wechatMessage(String sn) {
    Order order = orderService.getBySn(sn);
    if (order == null) {
        throw new ServiceException("订单" + sn + "不存在,发送微信公众号消息错误");
    }
    // 获取微信消息
    LambdaQueryWrapper<WechatMessage> wechatMessageQueryWrapper = new LambdaQueryWrapper();
    wechatMessageQueryWrapper.eq(WechatMessage::getOrderStatus, order.getOrderStatus());
    WechatMessage wechatMessage = wechatMessageService.getOne(wechatMessageQueryWrapper);
    if (wechatMessage == null) {
        return;
    }
    Connect connect = connectService.queryConnect(ConnectQueryDTO.builder().userId(order.getMemberId()).unionType(ConnectEnum.WECHAT.name()).build());
    if (connect == null) {
        return;
    }
    log.info("微信消息发送消息:{}", order.getMemberId() + "-" + sn);
    // 获取token
    String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.H5);
    // 发送url
    String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
    Map<String, String> map = new HashMap<>(4);
    // 用户id
    map.put("touser", connect.getUnionId());
    // 模版id
    map.put("template_id", wechatMessage.getCode());
    // 模版中所需数据
    String postParams = createData(order, wechatMessage);
    map.put("data", postParams);
    log.info("参数内容:" + JSONUtil.toJsonStr(map));
    String content = HttpUtils.doPostWithJson(url, map);
    JSONObject json = new JSONObject(content);
    log.info("微信消息发送结果:" + content);
    String errorMessage = json.getStr("errmsg");
    String errcode = json.getStr("errcode");
    // 发送失败
    if (!"0".equals(errcode)) {
        log.error("消息发送失败:" + errorMessage);
        log.error("消息发送请求token:" + token);
        log.error("消息发送请求:" + postParams);
    }
}
Also used : Order(cn.lili.modules.order.order.entity.dos.Order) ServiceException(cn.lili.common.exception.ServiceException) JSONObject(cn.hutool.json.JSONObject) Connect(cn.lili.modules.connect.entity.Connect) WechatMessage(cn.lili.modules.wechat.entity.dos.WechatMessage) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 4 with Order

use of cn.lili.modules.order.order.entity.dos.Order in project lilishop by lilishop.

the class VerificationOrderExecute method orderChange.

@Override
public void orderChange(OrderMessage orderMessage) {
    // 订单状态为待核验,添加订单添加核验码
    if (orderMessage.getNewStatus().equals(OrderStatusEnum.TAKE)) {
        // 获取订单信息
        Order order = orderService.getBySn(orderMessage.getOrderSn());
        // 获取随机数,判定是否存在
        String code = getCode(order.getStoreId());
        // 设置订单验证码
        orderService.update(new LambdaUpdateWrapper<Order>().set(Order::getVerificationCode, code).eq(Order::getSn, orderMessage.getOrderSn()));
        // 修改虚拟订单货物可以进行售后、投诉
        orderItemService.update(new LambdaUpdateWrapper<OrderItem>().eq(OrderItem::getOrderSn, orderMessage.getOrderSn()).set(OrderItem::getAfterSaleStatus, OrderItemAfterSaleStatusEnum.NOT_APPLIED).set(OrderItem::getCommentStatus, OrderComplaintStatusEnum.NO_APPLY));
    }
}
Also used : Order(cn.lili.modules.order.order.entity.dos.Order) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) OrderItem(cn.lili.modules.order.order.entity.dos.OrderItem)

Example 5 with Order

use of cn.lili.modules.order.order.entity.dos.Order in project lilishop by lilishop.

the class VerificationOrderExecute method getCode.

/**
 * 获取随机数
 * 判断当前店铺下是否使用验证码,如果已使用则重新获取
 *
 * @param storeId 店铺ID
 * @return
 */
private String getCode(String storeId) {
    // 获取八位验证码
    String code = Long.toString(RandomUtil.randomLong(10000000, 99999999));
    LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<Order>().eq(Order::getVerificationCode, code).eq(Order::getStoreId, storeId);
    if (orderService.getOne(lambdaQueryWrapper) == null) {
        return code;
    } else {
        return this.getCode(storeId);
    }
}
Also used : Order(cn.lili.modules.order.order.entity.dos.Order) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

Order (cn.lili.modules.order.order.entity.dos.Order)48 ServiceException (cn.lili.common.exception.ServiceException)16 Transactional (org.springframework.transaction.annotation.Transactional)15 OrderLogPoint (cn.lili.modules.order.order.aop.OrderLogPoint)11 OrderItem (cn.lili.modules.order.order.entity.dos.OrderItem)11 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)8 OrderMessage (cn.lili.modules.order.order.entity.dto.OrderMessage)6 PintuanOrderMessage (cn.lili.trigger.message.PintuanOrderMessage)6 OrderLog (cn.lili.modules.order.trade.entity.dos.OrderLog)5 Pintuan (cn.lili.modules.promotion.entity.dos.Pintuan)5 Member (cn.lili.modules.member.entity.dos.Member)4 SystemLogPoint (cn.lili.modules.system.aspect.annotation.SystemLogPoint)4 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)4 DateTime (cn.hutool.core.date.DateTime)3 JSONObject (cn.hutool.json.JSONObject)3 GoodsSku (cn.lili.modules.goods.entity.dos.GoodsSku)3 ArrayList (java.util.ArrayList)3 Connect (cn.lili.modules.connect.entity.Connect)2 DistributionOrder (cn.lili.modules.distribution.entity.dos.DistributionOrder)2 StoreFlow (cn.lili.modules.order.order.entity.dos.StoreFlow)2