Search in sources :

Example 1 with YxStoreOrderStatus

use of co.yixiang.modules.shop.domain.YxStoreOrderStatus in project yshopmall by guchengwuyue.

the class StoreOrderController method editOrder.

@NoRepeatSubmit
@Log("修改订单")
@ApiOperation(value = "修改订单")
@PostMapping(value = "/yxStoreOrder/edit")
@PreAuthorize("hasAnyRole('admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT')")
public ResponseEntity editOrder(@RequestBody YxStoreOrder resources) {
    if (ObjectUtil.isNull(resources.getPayPrice())) {
        throw new BadRequestException("请输入支付金额");
    }
    if (resources.getPayPrice().doubleValue() < 0) {
        throw new BadRequestException("金额不能低于0");
    }
    YxStoreOrderDto storeOrder = generator.convert(yxStoreOrderService.getById(resources.getId()), YxStoreOrderDto.class);
    // 判断金额是否有变动,生成一个额外订单号去支付
    int res = NumberUtil.compare(storeOrder.getPayPrice().doubleValue(), resources.getPayPrice().doubleValue());
    if (res != 0) {
        String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
        resources.setExtendOrderId(orderSn);
    }
    yxStoreOrderService.saveOrUpdate(resources);
    YxStoreOrderStatus storeOrderStatus = new YxStoreOrderStatus();
    storeOrderStatus.setOid(resources.getId());
    storeOrderStatus.setChangeType(OrderLogEnum.ORDER_EDIT.getValue());
    storeOrderStatus.setChangeMessage("修改订单价格为:" + resources.getPayPrice());
    storeOrderStatus.setChangeTime(new Date());
    yxStoreOrderStatusService.save(storeOrderStatus);
    return new ResponseEntity(HttpStatus.OK);
}
Also used : YxStoreOrderDto(co.yixiang.modules.shop.service.dto.YxStoreOrderDto) ResponseEntity(org.springframework.http.ResponseEntity) YxStoreOrderStatus(co.yixiang.modules.shop.domain.YxStoreOrderStatus) BadRequestException(co.yixiang.exception.BadRequestException) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(co.yixiang.modules.logging.aop.log.Log) NoRepeatSubmit(co.yixiang.modules.aop.NoRepeatSubmit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with YxStoreOrderStatus

use of co.yixiang.modules.shop.domain.YxStoreOrderStatus in project yshopmall by guchengwuyue.

the class StoreOrderController method update.

@NoRepeatSubmit
@ApiOperation(value = "发货")
@PutMapping(value = "/yxStoreOrder")
@PreAuthorize("hasAnyRole('admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT')")
public ResponseEntity update(@Validated @RequestBody YxStoreOrder resources) {
    if (StrUtil.isBlank(resources.getDeliveryName())) {
        throw new BadRequestException("请选择快递公司");
    }
    if (StrUtil.isBlank(resources.getDeliveryId())) {
        throw new BadRequestException("快递单号不能为空");
    }
    YxExpressDto expressDTO = generator.convert(yxExpressService.getById(Integer.valueOf(resources.getDeliveryName())), YxExpressDto.class);
    if (ObjectUtil.isNull(expressDTO)) {
        throw new BadRequestException("请先添加快递公司");
    }
    resources.setStatus(1);
    resources.setDeliveryType("express");
    resources.setDeliveryName(expressDTO.getName());
    resources.setDeliverySn(expressDTO.getCode());
    yxStoreOrderService.update(resources);
    YxStoreOrderStatus storeOrderStatus = new YxStoreOrderStatus();
    storeOrderStatus.setOid(resources.getId());
    storeOrderStatus.setChangeType("delivery_goods");
    storeOrderStatus.setChangeMessage("已发货 快递公司:" + resources.getDeliveryName() + " 快递单号:" + resources.getDeliveryId());
    storeOrderStatus.setChangeTime(new Date());
    yxStoreOrderStatusService.save(storeOrderStatus);
    // 模板消息通知
    try {
        String openid = this.getUserOpenid(resources.getUid());
        if (StrUtil.isNotBlank(openid)) {
            templateService.deliverySuccessNotice(resources.getOrderId(), expressDTO.getName(), resources.getDeliveryId(), openid);
        }
    } catch (Exception e) {
        log.info("当前用户不是微信用户不能发送模板消息哦!");
    }
    // 加入redis,7天后自动确认收货
    String redisKey = String.valueOf(StrUtil.format("{}{}", ShopConstants.REDIS_ORDER_OUTTIME_UNCONFIRM, resources.getId()));
    redisTemplate.opsForValue().set(redisKey, resources.getOrderId(), ShopConstants.ORDER_OUTTIME_UNCONFIRM, TimeUnit.DAYS);
    return new ResponseEntity(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) YxStoreOrderStatus(co.yixiang.modules.shop.domain.YxStoreOrderStatus) BadRequestException(co.yixiang.exception.BadRequestException) YxExpressDto(co.yixiang.modules.shop.service.dto.YxExpressDto) Date(java.util.Date) BadRequestException(co.yixiang.exception.BadRequestException) ParseException(java.text.ParseException) IOException(java.io.IOException) NoRepeatSubmit(co.yixiang.modules.aop.NoRepeatSubmit) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

BadRequestException (co.yixiang.exception.BadRequestException)2 NoRepeatSubmit (co.yixiang.modules.aop.NoRepeatSubmit)2 YxStoreOrderStatus (co.yixiang.modules.shop.domain.YxStoreOrderStatus)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Date (java.util.Date)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 Log (co.yixiang.modules.logging.aop.log.Log)1 YxExpressDto (co.yixiang.modules.shop.service.dto.YxExpressDto)1 YxStoreOrderDto (co.yixiang.modules.shop.service.dto.YxStoreOrderDto)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1