package com.czg.service.order.service.impl;

import com.czg.constants.PayTypeConstants;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.service.order.mapper.OrderPaymentMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;

import java.math.BigDecimal;

/**
 * 支付详情 服务层实现。
 *
 * @author ww
 * @since 2025-02-15
 */
@DubboService
public class OrderPaymentServiceImpl extends ServiceImpl<OrderPaymentMapper, OrderPayment> implements OrderPaymentService {

    @Override
    public BigDecimal countMemberInAmount(Long shopId, Long shopUserId) {
        return getOneAs(QueryWrapper.create().select("IFNULL(sum(amount), 0) as total_amount")
                .eq(OrderPayment::getShopId, shopId)
                .eq(OrderPayment::getSourceType, PayTypeConstants.SourceType.MEMBER_IN)
                .eq(OrderPayment::getPayType, PayTypeConstants.PayType.PAY)
                .eq(OrderPayment::getSourceId, shopUserId)
                .eq(OrderPayment::getPayStatus, PayTypeConstants.PayStatus.SUCCESS), BigDecimal.class);
    }
}
