
package com.tmerclub.cloud.user.feign;

import com.tmerclub.cloud.api.user.feign.UserLevelAndScoreOrderFeignClient;
import com.tmerclub.cloud.common.order.vo.ShopCartOrderMergerVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.user.manager.UserLevelOrderManager;
import com.tmerclub.cloud.user.manager.UserScoreOrderManager;
import com.tmerclub.cloud.user.service.UserScoreLogService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 用户等级积分订单计算feign连接
 * @author tmerclub
 * @date 2021/05/10
 */
@DubboService
public class UserLevelAndScoreOrderFeignController implements UserLevelAndScoreOrderFeignClient {


    @Autowired
    private UserScoreOrderManager userScoreOrderManager;

    @Autowired
    private UserLevelOrderManager userLevelOrderManager;

    @Autowired
    private UserScoreLogService userScoreLogService;


    @Override
    public ServerResponseEntity<ShopCartOrderMergerVO> calculateLevelAndScoreDiscount(ShopCartOrderMergerVO shopCartOrderMerger) {
        // 订单预售不能参与积分等级优惠
        userLevelOrderManager.calculateLevelDiscount(shopCartOrderMerger);
        userScoreOrderManager.calculateScoreDiscount(shopCartOrderMerger);
        return ServerResponseEntity.success(shopCartOrderMerger);
    }

    @Override
    public ServerResponseEntity<Long> getScoreCount(List<Long> refundIds) {
        return ServerResponseEntity.success(userScoreLogService.getScoreCountByRefundIds(refundIds));
    }

    @Override
    public ServerResponseEntity<Boolean> getHaveFreeFeeRight(Long userId, Long shopId) {
        Boolean haveFreeFeeRight = userLevelOrderManager.getHaveFreeFeeRight(userId, shopId);
        return ServerResponseEntity.success(haveFreeFeeRight);
    }


}
