using Mall.Model.Entity.Product;
using Mall.Model.Extend.Product;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Mall.Repository.Product
{

    /// <summary>
    /// 拼团商品关联规格价格仓储层
    /// </summary>
    public class RB_Groupbuy_Activity_SpecificationPriceRepository : BaseRepository<RB_Groupbuy_Activity_Specificationprice>
    {
        /// <summary>
        /// 获取拼团活动商品规格价格列表
        /// </summary>
        /// <param name="dmodel">查询条件</param>
        /// <returns></returns>
        public List<RB_Groupbuy_Activity_Specificationprice_Extend> GetGroupbuyActivitySpecificationpriceListRepository(RB_Groupbuy_Activity_Specificationprice_Extend dmodel)
        {
            string where = $" 1=1 and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.Status)}=0";
            if (dmodel.TenantId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.TenantId)}={dmodel.TenantId}";
            }
            if (dmodel.MallBaseId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.MallBaseId)}={dmodel.MallBaseId}";
            }
            if (dmodel.Id > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.Id)}={dmodel.Id}";
            }
            if (dmodel.GoodsId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.GoodsId)}={dmodel.GoodsId}";
            }
            if (!string.IsNullOrEmpty(dmodel.GoodsIds))
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationprice_Extend.GoodsId)} in({dmodel.GoodsIds})";
            }
            string sql = $@"select * from rb_groupbuy_activity_specificationprice where {where}  ";
            return Get<RB_Groupbuy_Activity_Specificationprice_Extend>(sql).ToList();
        }
    }

    /// <summary>
    /// 拼团活动商品关联规格值仓储层
    /// </summary>
    public class RB_Groupbuy_Activity_SpecificationValueRepository : BaseRepository<RB_Groupbuy_Activity_Specificationvalue>
    {

        /// <summary>
        /// 获取拼团活动商品关联规格值列表
        /// </summary>
        /// <param name="dmodel">查询条件</param>
        /// <returns></returns>
        public List<RB_Groupbuy_Activity_Specificationvalue_Extend> GetGroupbuyActivitySpecificationValueListRepository(RB_Groupbuy_Activity_Specificationvalue_Extend dmodel)
        {
            string where = $" 1=1 and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.Status)}=0";
            if (dmodel.TenantId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.TenantId)}={dmodel.TenantId}";
            }
            if (dmodel.MallBaseId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.MallBaseId)}={dmodel.MallBaseId}";
            }
            if (dmodel.Id > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.Id)}={dmodel.Id}";
            }
            if (dmodel.SpecificationId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.SpecificationId)}={dmodel.SpecificationId}";
            }
            if (dmodel.GoodsId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.GoodsId)}={dmodel.GoodsId}";
            }
            if (!string.IsNullOrEmpty(dmodel.GoodsIds))
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specificationvalue_Extend.GoodsId)} in({dmodel.GoodsIds})";
            }
            string sql = $@"select * from rb_groupbuy_activity_specificationvalue where {where} order by Id asc";
            return Get<RB_Groupbuy_Activity_Specificationvalue_Extend>(sql).ToList();
        }
    }

    /// <summary>
    /// 拼团商品关联规格仓储层
    /// </summary>
    public class RB_Groupbuy_Activity_SpecificationRepository : BaseRepository<RB_Groupbuy_Activity_Specification>
    {

        /// <summary>
        /// 获取拼团商品关联规格列表
        /// </summary>
        /// <param name="dmodel">查询条件</param>
        /// <returns></returns>
        public List<RB_Groupbuy_Activity_Specification_Extend> GetGroupbuyActivitySpecificationListRepository(RB_Groupbuy_Activity_Specification_Extend dmodel)
        {
            string where = $" 1=1 and {nameof(RB_Groupbuy_Activity_Specification_Extend.Status)}=0";
            if (dmodel.TenantId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specification_Extend.TenantId)}={dmodel.TenantId}";
            }
            if (dmodel.MallBaseId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specification_Extend.MallBaseId)}={dmodel.MallBaseId}";
            }
            if (dmodel.Id > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specification_Extend.Id)}={dmodel.Id}";
            }
            if (dmodel.GoodsId > 0)
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specification_Extend.GoodsId)}={dmodel.GoodsId}";
            }
            if (!string.IsNullOrEmpty(dmodel.GoodsIds))
            {
                where += $@" and {nameof(RB_Groupbuy_Activity_Specification_Extend.GoodsId)} in({dmodel.GoodsIds})";
            }

            string sql = $@"select * from rb_groupbuy_activity_specification where {where} order by Id asc";
            return Get<RB_Groupbuy_Activity_Specification_Extend>(sql).ToList();
        }
    }
}
