using System;
using System.Collections.Generic;
using System.Text;
using System.IRepositories;
using System.Model;
using System.Common;
using System.Threading.Tasks;
using SqlSugar;
using System.Data;

namespace System.Repositories
{
    public class Bus_AfterSaleRepository : BaseRepository<T_Bus_AfterSale>, IBus_AfterSaleRepository
    {
        /// <summary>
        /// 获取某月员工绩效  售后退款   售后类型 1调换货 2退货 3部分退货 4对发货 5补发货 6补差额
        /// </summary>
        /// <param name="userid">某员工</param>
        /// <param name="dtStart">时间所在月</param>
        /// <returns></returns>
        public async Task<List<decimal>> BackNumberSH(int userid, DateTime dtStart)
        {
            List<decimal> intarry = new List<decimal>() { -1, -0.00M };
            try
            {
                List<SugarParameter> sugarParameter = new List<SugarParameter>();
                sugarParameter.Add(new SugarParameter("@userid", userid));
                sugarParameter.Add(new SugarParameter("@startTime", dtStart));
                sugarParameter.Add(new SugarParameter("@endTime", dtStart.AddMonths(1)));
                DataTable dt = await GetTableSugar("SELECT COUNT(1),SUM(F_Money) FROM T_Bus_AfterSale WHERE  F_CheckUserXS= @userid AND F_Type IN(2,3,6) AND F_CheckStateSH=1  AND  F_AddTime BETWEEN @startTime AND @endTime", sugarParameter);
                if (dt != null && dt.Rows.Count > 0)
                {
                    intarry.Clear();
                    intarry.Add(dt.Rows[0][0].ObjToInt());
                    intarry.Add(dt.Rows[0][1].ObjToDecimal());
                }
                return intarry;
            }
            catch { return intarry; }
        }
    }

}
