package com.jwipc.sys.logic.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwipc.api.constant.RestCode;
import com.jwipc.api.dto.ApiResult;
import com.jwipc.shopping.entity.ShoppingCart;
import com.jwipc.shopping.service.IShoppingCartService;
import com.jwipc.sys.constant.ShopingCartConst;
import com.jwipc.sys.dto.ShopCartDTO;
import com.jwipc.sys.logic.ShoppingCartLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.baomidou.dynamic.datasource.support.DdConstants.SLAVE;

/**
 * 功能描述:
 *
 * @Author: zx
 * @Date: 2024/4/7 0007 10:12
 */
@Service
@RequiredArgsConstructor
public class ShoppingCartLogicImpl implements ShoppingCartLogic {

    @Autowired
    IShoppingCartService service;

    @Override
    public ApiResult updateStatus(ShopCartDTO param) {
        ShoppingCart shoppingCart = service.getOne(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getOrderId,param.getOrderCode()));
        if(shoppingCart==null){
            return ApiResult.builder().code(RestCode.SAP_ERROR.getCode()).message("没有匹配到对应的订单").build();
        }
        if(param.getCancelType().equals(ShopingCartConst.CART_ZERO)){
            //订单取消  7天未确认自动取消
            shoppingCart.setStatus(2);
        }if(param.getCancelType().equals(ShopingCartConst.CART_SEVEN)){
            //电商因为自身原因无法发货而取消
            shoppingCart.setStatus(3);
        }
        shoppingCart.setCancelReason(param.getCancelReason());
        service.updateById(shoppingCart);
        return ApiResult.builder().code(RestCode.SAP_SUCCESS.getCode()).message("成功").build();
    }
}
