using System;
using System.Collections.Generic;
using System.Text;
using Dapper;
using AutoTurnOver.Models;

namespace AutoTurnOver.DB
{
    public class AutoOrder : connectionHelper
    {

        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <param name="m">条件model</param>
        /// <param name="offset">mysql查询偏移量</param>
        /// <param name="limit">每页记录数</param>
        /// <param name="total">符合条件的记录数</param>
        /// <returns></returns>
        public static List<dc_auto_order> List(Condition_AutoOrder m,int offset, int limit, ref int total)
        {
            var sql = "select * from dc_auto_order where status!=-1 ";

            if (!string.IsNullOrWhiteSpace(m.sku))
            {
                sql += " and bailun_sku like '%" + m.sku + "%'";
            }

            if (!string.IsNullOrWhiteSpace(m.warehousecode))
            {
                sql += " and warehouse_code='"+ m.warehousecode + "'";
            }

            sql += " order by createtime desc";

            try
            {
                var obj = _connection.Page<dc_auto_order>(offset, limit, sql, ref total);

                return obj.AsList();
            }
            catch (Exception ex)
            {
                return new List<dc_auto_order>();
            }
        }
    }
}
