Пример #1
0
        internal static SpTroneCountInfo LoadFromDbase(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, bool isMonth)
        {
            var cmd = dBase.Command();
            var sql = "select count(0),sum(trone.price)*100 from daily_log.tbl_mr_{0:yyyyMM} mr"
                      + " left join daily_config.tbl_trone trone on trone.id=mr.trone_id where mr.sp_trone_id={1}";

            if (!isMonth)
            {
                sql += " and mr_date='{0:yyyy-MM-dd}'";
            }

            cmd.CommandText = string.Format(sql, DateTime.Today, spTroneId);
            using (cmd)
            {
                using (var rd = dBase.ExecuteReader(cmd))
                {
                    var info = new SpTroneCountInfo();
                    info.SpTroneId = spTroneId;
                    if (!rd.Read())
                    {
                        info.Count = int.Parse(rd.GetValue(0).ToString());
                        info.Sum   = int.Parse(rd.GetValue(1).ToString());
                    }
                    return(info);
                }
            }
        }
Пример #2
0
        static IEnumerable <CustomFeeModel> LoadFromDBase(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, string customId)
        {
            var trones = LightDataModel.tbl_troneItem.GetTroneIdsBySptroneId(dBase, spTroneId);

            if (trones.Count() == 0)
            {
                return new CustomFeeModel[] { }
            }
            ;
            string sql;

            if (string.IsNullOrEmpty(customId))
            {//整个通道信息
                sql = string.Format("SELECT trone_id,fee_date= current_Date() isToday , sum(count)  FROM daily_log.tbl_custom_fee_count "
                                    + " where trone_id in({0}) "
                                    + " group by trone_id,isToday",
                                    string.Join(",", trones.Select(e => e.id)), DateTime.Today);
            }
            else
            {//用户计费信息
                sql = string.Format("SELECT trone_id,fee_date= current_Date() isToday , sum(count)  FROM daily_log.tbl_custom_fee_count "
                                    + " where trone_id in({0}) and custom_id='{1}'"
                                    + " group by trone_id,isToday",
                                    string.Join(",", trones.Select(e => e.id)), dBase.SqlEncode(customId));
            }


            var cmd = dBase.Command();

            cmd.CommandText = sql;
            System.Data.IDataReader dr  = null;
            List <CustomFeeModel>   rlt = new List <CustomFeeModel>();

            try
            {
                dr = dBase.ExecuteReader(cmd);
                while (dr.Read())
                {
                    var m = new CustomFeeModel();
                    m.CustomId = customId;
                    m.SpToneId = spTroneId;
                    m.TroneId  = dr.GetInt32(0);
                    m.Date     = dr.GetBoolean(1) ? DateTime.Today : DateTime.Today.AddDays(-1);
                    m.Count    = dr.GetInt32(2);
                    m.Fee      = decimal.ToInt32(100 * trones.First(e => e.id == m.TroneId).price);
                    rlt.Add(m);
                    cache.InsertItem(m);
                }
            }
            finally
            {
                if (dr != null)
                {
                    dr.Dispose();
                }
                cmd.Dispose();
            }
            if (rlt.Count == 0)
            {//表示该用户,日月限缓存已经建立
                var trone = trones.First();
                var m     = new CustomFeeModel();
                m.CustomId = customId;
                m.SpToneId = spTroneId;
                m.TroneId  = trone.id;
                m.Date     = DateTime.Today;
                m.Count    = 0;
                m.Fee      = decimal.ToInt32(100 * trone.price);
                rlt.Add(m);
                cache.InsertItem(m);
            }
            return(rlt);
        }