Ejemplo n.º 1
0
        ///// <summary>
        ///// 获取登录用户信息
        ///// </summary>
        ///// <param name="customerId"></param>
        ///// <param name="token"></param>
        ///// <returns></returns>
        //public static LoggingSessionInfo GetLjLoggingSession(string userId, string customerId)
        //{
        //    if (userId == null || userId.Trim().Length == 0) userId = "1";
        //    LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo();
        //    //loggingSessionInfo = new CLoggingSessionService().GetLoggingSessionInfo(customerId, "7d4cda48970b4ed0aa697d8c2c2e4af3");
        //    loggingSessionInfo.CurrentUser = new BS.Entity.User.UserInfo();
        //    loggingSessionInfo.CurrentUser.User_Id = userId;
        //    loggingSessionInfo.CurrentUser.customer_id = customerId;

        //    loggingSessionInfo.UserID = loggingSessionInfo.CurrentUser.User_Id;
        //    loggingSessionInfo.ClientID = customerId;
        //    loggingSessionInfo.Conn = ConfigurationManager.AppSettings["Conn_lj"].Trim();

        //    loggingSessionInfo.CurrentLoggingManager = new LoggingManager();
        //    loggingSessionInfo.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn;
        //    loggingSessionInfo.CurrentLoggingManager.User_Id = userId;
        //    loggingSessionInfo.CurrentLoggingManager.Customer_Id = customerId;
        //    loggingSessionInfo.CurrentLoggingManager.Customer_Name = "";
        //    loggingSessionInfo.CurrentLoggingManager.User_Name = "";
        //    return loggingSessionInfo;
        //}
        //public static LoggingSessionInfo GetLjLoggingSession()
        //{
        //    return GetLjLoggingSession("", "");
        //}
        //public static LoggingSessionInfo GetLjLoggingSession(string userId)
        //{
        //    return GetLjLoggingSession(userId, "");
        //}

        /// <summary>
        /// 获取BS用户登录信息
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static LoggingSessionInfo GetBSLoggingSession(string customerId, string userId)
        {
            if (userId == null || userId == string.Empty)
            {
                userId = "1";
            }

            string        conn       = "";
            string        name       = "";
            CC_Connection connection = new RedisConnectionBLL().GetConnection(customerId);//从redis里获取商户数据库链接
            RedisXML      _RedisXML  = new RedisXML();

            //如果从缓存里获取不到信息,就从数据库读取,并种到缓存里
            if (connection == null || string.IsNullOrEmpty(connection.ConnectionStr) || string.IsNullOrEmpty(connection.Customer_Name))
            {
                //记录redis读取不成功,从数据库里读取数据的情况
                _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 2);

                conn = GetCustomerConn(customerId);
                name = GetCustomerName(customerId);
                string code = GetCustomerCode(customerId);
                new RedisConnectionBLL().SetConnection(customerId, conn, name, code);
            }
            else
            {
                //记录redis读取日志
                _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 1);
                conn = connection.ConnectionStr;
                name = connection.Customer_Name;
            }



            LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo();

            //loggingSessionInfo = new CLoggingSessionService().GetLoggingSessionInfo(customerId, "7d4cda48970b4ed0aa697d8c2c2e4af3");
            loggingSessionInfo.CurrentUser             = new BS.Entity.User.UserInfo();
            loggingSessionInfo.CurrentUser.User_Id     = userId;
            loggingSessionInfo.CurrentUser.customer_id = customerId;

            loggingSessionInfo.UserID   = loggingSessionInfo.CurrentUser.User_Id;
            loggingSessionInfo.ClientID = customerId;
            loggingSessionInfo.Conn     = conn;

            loggingSessionInfo.CurrentLoggingManager = new LoggingManager();
            loggingSessionInfo.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn;
            loggingSessionInfo.CurrentLoggingManager.User_Id           = userId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Id       = customerId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Name     = name;
            loggingSessionInfo.CurrentLoggingManager.User_Name         = "";

            loggingSessionInfo.ClientName = name;
            return(loggingSessionInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取ALD会员登陆信息
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <param name="isAToC"></param>
        /// <returns></returns>
        public static LoggingSessionInfo GetBSLoggingSession(string customerId, string userId, int isAToC)
        {
            if (userId == null || userId == string.Empty)
            {
                userId = "1";
            }
            if (isAToC == 1)
            {
                userId = GetVipIDByALDVipID(customerId, userId);//同步会员,并获取商户库VipID
            }
            string        conn       = "";
            string        name       = "";
            CC_Connection connection = new RedisConnectionBLL().GetConnection(customerId);//从redis里获取商户数据库链接

            //如果从缓存里获取不到信息,就从数据库读取,并种到缓存里
            if (connection == null || string.IsNullOrEmpty(connection.ConnectionStr) || string.IsNullOrEmpty(connection.Customer_Name))
            {
                conn = GetCustomerConn(customerId);
                name = GetCustomerName(customerId);
                string code = GetCustomerCode(customerId);
                new RedisConnectionBLL().SetConnection(customerId, conn, name, code);
            }
            else
            {
                conn = connection.ConnectionStr;
                name = connection.Customer_Name;
            }


            LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo();

            //loggingSessionInfo = new CLoggingSessionService().GetLoggingSessionInfo(customerId, "7d4cda48970b4ed0aa697d8c2c2e4af3");
            loggingSessionInfo.CurrentUser             = new BS.Entity.User.UserInfo();
            loggingSessionInfo.CurrentUser.User_Id     = userId;
            loggingSessionInfo.CurrentUser.customer_id = customerId;

            loggingSessionInfo.UserID   = loggingSessionInfo.CurrentUser.User_Id;
            loggingSessionInfo.ClientID = customerId;
            loggingSessionInfo.Conn     = conn;

            loggingSessionInfo.CurrentLoggingManager = new LoggingManager();
            loggingSessionInfo.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn;
            loggingSessionInfo.CurrentLoggingManager.User_Id           = userId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Id       = customerId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Name     = name;
            loggingSessionInfo.CurrentLoggingManager.User_Name         = "";

            loggingSessionInfo.ClientName = name;
            return(loggingSessionInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 定时全量种植
        /// </summary>
        public void TimeSetBasicSetting()
        {
            CC_Connection connection = new CC_Connection();

            LoggingSessionInfo _loggingSessionInfo   = new LoggingSessionInfo();
            LoggingManager     CurrentLoggingManager = new LoggingManager();

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                connection = new RedisConnectionBLL().GetConnection(customer.Key);

                BasicSettingBLL redisBasicSettingBll = new BasicSettingBLL();
                redisBasicSettingBll.DelBasicSetting(customer.Key);
                redisBasicSettingBll.SetBasicSetting(customer.Key);
            }
        }
        /// <summary>
        /// vip绑定coupon入队列
        /// </summary>
        /// <param name="coupon"></param>
        /// <param name="strObjectId"></param>
        /// <param name="strVipId"></param>
        /// <param name="strSource"></param>
        public void SetVipMappingCoupon(CC_Coupon coupon, string strObjectId, string strVipId, string strSource)
        {
            LoggingSessionInfo _loggingSessionInfo   = new LoggingSessionInfo();
            LoggingManager     CurrentLoggingManager = new LoggingManager();
            string             strCon = string.Empty;

            var connection = new RedisConnectionBLL().GetConnection(coupon.CustomerId);

            //如果缓存获取不到数据,从数据库读取数据库连接字符串
            if (connection.CustomerID == null)
            {
                connection.ConnectionStr = GetCustomerConn(coupon.CustomerId);
            }

            CurrentLoggingManager.Connection_String = connection.ConnectionStr;

            _loggingSessionInfo.ClientID = coupon.CustomerId;
            _loggingSessionInfo.CurrentLoggingManager = CurrentLoggingManager;

            RedisCouponBLL redisCouponBLL = new RedisCouponBLL();
            //获取优惠券数量
            var count = RedisOpenAPI.Instance.CCCoupon().GetCouponListLength(coupon);

            if (count.Code == ResponseCode.Success)
            {
                if (count.Result == 0)
                {
                    var bllCouponType = new CouponTypeBLL(_loggingSessionInfo);

                    var couponType = bllCouponType.QueryByEntity(new CouponTypeEntity()
                    {
                        CustomerId = coupon.CustomerId, CouponTypeID = new Guid(coupon.CouponTypeId), IsDelete = 0
                    }, null).SingleOrDefault();
                    if (couponType != null)
                    {
                        //计算剩余的优惠券数量
                        int intCouponLenth = Convert.ToInt32(couponType.IssuedQty) - Convert.ToInt32(couponType.IsVoucher);
                        if (intCouponLenth <= 0)
                        {
                            intCouponLenth = 1000;
                            //重置优惠券数量为1000
                            bllCouponType.UpdateCouponTypeIssuedQty(coupon.CouponTypeId, intCouponLenth);
                        }

                        //这里可能是重置 Redis 缓存中该类型优惠券数据数量
                        RedisOpenAPI.Instance.CCCoupon().SetCouponList(new CC_Coupon()
                        {
                            CustomerId     = couponType.CustomerId,
                            CouponTypeId   = couponType.CouponTypeID.ToString(),
                            CouponTypeDesc = couponType.CouponTypeDesc,
                            CouponTypeName = couponType.CouponTypeName,
                            BeginTime      = couponType.BeginTime.ToString(),
                            EndTime        = couponType.EndTime.ToString(),
                            ServiceLife    = couponType.ServiceLife ?? 0,
                            CouponLenth    = intCouponLenth,
                            CouponCategory = couponType.CouponCategory
                        });
                    }
                }
                //从 Redis 中重新获取优惠券信息
                var response = redisCouponBLL.RedisGetCoupon(coupon);
                if (response.Code == ResponseCode.Success && response.Result.CouponTypeId != null && response.Result.CouponTypeId.Length > 0)
                {
                    string strCouponCode = string.Empty;
                    //从数据库中读取优惠券编码
                    strCouponCode = GetCouponNum(_loggingSessionInfo, response.Result.CustomerId);
                    var _coupon = new CC_Coupon()
                    {
                        CustomerId     = response.Result.CustomerId,
                        CouponTypeId   = response.Result.CouponTypeId,
                        CouponTypeDesc = response.Result.CouponTypeDesc,
                        CouponTypeName = response.Result.CouponTypeName,
                        CouponCode     = strCouponCode,
                        BeginTime      = response.Result.BeginTime,
                        EndTime        = response.Result.EndTime,
                        ServiceLife    = response.Result.ServiceLife,
                        CouponCategory = response.Result.CouponCategory,
                        CouponId       = Guid.NewGuid().ToString()
                    };
                    BaseService.WriteLog("---------------------------入vip绑定优惠券队列---------------------------");
                    //将优惠券推送到 Redis 缓存中
                    RedisOpenAPI.Instance.CCVipMappingCoupon().SetVipMappingCoupon(new CC_VipMappingCoupon()
                    {
                        CustomerId = coupon.CustomerId,
                        ObjectId   = strObjectId,
                        VipId      = strVipId,
                        Source     = strSource,
                        Coupon     = _coupon
                    });
                }
            }
        }
        /// <summary>
        /// 虚拟商品发优惠券
        /// </summary>
        /// <param name="lstCoupon"></param>
        /// <param name="strObjectId"></param>
        /// <param name="strVipId"></param>
        /// <param name="strSource"></param>
        public void SetVipMappingCoupon(List <CouponTypeEntity> lstCoupon, string strObjectId, string strVipId, string strSource)
        {
            BaseService.WriteLog("---------------------------入vip绑定优惠券队列开始---------------------------");

            LoggingSessionInfo _loggingSessionInfo   = new LoggingSessionInfo();
            LoggingManager     CurrentLoggingManager = new LoggingManager();
            string             strCon = string.Empty;
            var coupon = lstCoupon.FirstOrDefault();

            try
            {
                var connection = new RedisConnectionBLL().GetConnection(coupon.CustomerId);
                //如果缓存获取不到数据,从数据库读取数据库连接字符串
                if (connection.CustomerID == null)
                {
                    connection.ConnectionStr = GetCustomerConn(coupon.CustomerId);
                }

                CurrentLoggingManager.Connection_String = connection.ConnectionStr;

                _loggingSessionInfo.ClientID = coupon.CustomerId;
                _loggingSessionInfo.CurrentLoggingManager = CurrentLoggingManager;

                RedisCouponBLL redisCouponBLL = new RedisCouponBLL();

                //从 Redis 中重新获取优惠券信息
                foreach (var itemCoupon in lstCoupon)  //按照优惠券类型进行依次发送
                {
                    //下面这段话是不是应该放在下面的for循环里面??
                    //获取Redis中当前 CouponTypeID 类型的优惠券数量
                    var count = RedisOpenAPI.Instance.CCCoupon().GetCouponListLength(new CC_Coupon()
                    {
                        CustomerId   = itemCoupon.CustomerId,
                        CouponTypeId = itemCoupon.CouponTypeID.ToString()
                    });

                    if (count.Code != ResponseCode.Success)
                    {
                        BaseService.WriteLog("请求Redist失败,请求函数 GetCouponListLength ,参数 CustomerId:" + itemCoupon.CustomerId + ", CouponTypeId:" + itemCoupon.CouponTypeID.ToString());
                        continue;
                    }

                    //如果 Redis 该类型优惠券已用完
                    if (count.Result == 0)
                    {
                        CheckRedisCouponNum(_loggingSessionInfo, itemCoupon);
                    }

                    int sendRedistCount = 0;
                    //根据虚拟商品中配置的商品数量,插入到 Redist 中
                    for (int i = 0; i < itemCoupon.Item_Count; i++)
                    {
                        //获取优惠券类型数据
                        var response = redisCouponBLL.RedisGetCoupon(new CC_Coupon()
                        {
                            CustomerId   = itemCoupon.CustomerId,
                            CouponTypeId = itemCoupon.CouponTypeID.ToString()
                        });
                        #region  发送一张优惠券
                        if (response.Code == ResponseCode.Success && response.Result.CouponTypeId != null && response.Result.CouponTypeId.Length > 0)
                        {
                            string strCouponCode = string.Empty;
                            //从数据库中读取优惠券编码
                            strCouponCode = GetCouponNum(_loggingSessionInfo, response.Result.CustomerId);
                            var _coupon = new CC_Coupon()
                            {
                                CustomerId     = response.Result.CustomerId,
                                CouponTypeId   = response.Result.CouponTypeId,
                                CouponTypeDesc = response.Result.CouponTypeDesc,
                                CouponTypeName = response.Result.CouponTypeName,
                                CouponCode     = strCouponCode, //优惠券code
                                BeginTime      = response.Result.BeginTime,
                                EndTime        = response.Result.EndTime,
                                ServiceLife    = response.Result.ServiceLife,
                                CouponCategory = response.Result.CouponCategory,
                                CouponId       = Guid.NewGuid().ToString()
                            };

                            //将优惠券推送到 Redis 缓存中
                            RedisOpenAPI.Instance.CCVipMappingCoupon().SetVipMappingCoupon(new CC_VipMappingCoupon()
                            {
                                CustomerId = itemCoupon.CustomerId,
                                ObjectId   = strObjectId,
                                VipId      = strVipId,
                                Source     = strSource,
                                Coupon     = _coupon
                            });

                            sendRedistCount++;
                        } //if数量
                        #endregion
                    }     //里面的for

                    //针对每一种类型的优惠券,发送一个通知
                    DateTime?BeginDate = null;
                    string   EndDate   = null;
                    if (itemCoupon.ServiceLife > 0)
                    {
                        BeginDate = DateTime.Now;
                        EndDate   = DateTime.Now.Date.AddDays((int)itemCoupon.ServiceLife - 1).ToShortDateString() + " 23:59:59.998";
                    }
                    else
                    {
                        BeginDate = itemCoupon.BeginTime;
                        EndDate   = itemCoupon.EndTime.ToString();
                    }
                    string strValidityData = Convert.ToDateTime(BeginDate.ToString()).ToShortDateString() + "-" + Convert.ToDateTime(EndDate.ToString()).ToShortDateString();
//写入到缓存
                    new SendCouponNoticeBLL().CouponsArrivalMessage(itemCoupon.CouponTypeName, itemCoupon.CouponTypeName, strValidityData, itemCoupon.CouponCategory == null ? "" : itemCoupon.CouponCategory, itemCoupon.WeiXinUserId, _loggingSessionInfo, itemCoupon.Item_Count.ToString());//存入到缓存j


                    BaseService.WriteLog(string.Format("---------------------------入vip绑定优惠券队列数量{0}---------------------------", sendRedistCount));
                } //foreach
            }     //try
            catch (Exception ex)
            {
                BaseService.WriteLog("向Redis发送优惠券时发生异常,异常信息:" + ex.Message);
                BaseService.WriteLog("向Redis发送优惠券时发生异常,异常堆栈信息:" + ex.StackTrace);
            }
        }
Ejemplo n.º 6
0
        public DataTable DownloadCouponNew(string strCustomerId, string strCouponTypeId, int downLoadNum)
        {
            DataTable dtCoupon = new DataTable();

            dtCoupon.Columns.Add("CouponID", typeof(string));
            dtCoupon.Columns.Add("CouponCode", typeof(string));
            dtCoupon.Columns.Add("CouponDesc", typeof(string));
            dtCoupon.Columns.Add("BeginDate", typeof(DateTime));
            dtCoupon.Columns.Add("EndDate", typeof(DateTime));
            dtCoupon.Columns.Add("CouponUrl", typeof(string));
            dtCoupon.Columns.Add("ImageUrl", typeof(string));
            dtCoupon.Columns.Add("Status", typeof(Int32));
            dtCoupon.Columns.Add("CreateTime", typeof(DateTime));
            dtCoupon.Columns.Add("CreateBy", typeof(string));
            dtCoupon.Columns.Add("LastUpdateTime", typeof(DateTime));
            dtCoupon.Columns.Add("LastUpdateBy", typeof(string));
            dtCoupon.Columns.Add("IsDelete", typeof(Int32));
            dtCoupon.Columns.Add("CouponTypeID", typeof(string));
            dtCoupon.Columns.Add("CoupnName", typeof(string));
            dtCoupon.Columns.Add("DoorID", typeof(string));
            dtCoupon.Columns.Add("CouponPwd", typeof(string));
            dtCoupon.Columns.Add("CollarCardMode", typeof(string));
            dtCoupon.Columns.Add("CustomerID", typeof(string));

            DataTable dtCouponExport = new DataTable();

            dtCouponExport.Columns.Add("CouponCode", typeof(string));

            PooledRedisClientManager pooleManager = new PooledRedisClientManager(10, 5, "182.254.151.114:6379");
            var redisClient = pooleManager.GetClient();

            redisClient.Db       = 2;
            redisClient.Password = "******";
            string strKey    = "Coupon" + strCustomerId + strCouponTypeId;
            long   ListCount = redisClient.GetListCount(strKey);

            if (ListCount > 0)
            {
                string strCon = new RedisConnectionBLL().GetConnection(strCustomerId).ConnectionStr;
                long   num    = 0;
                if (downLoadNum > ListCount)
                {
                    num = ListCount;
                }
                else
                {
                    num = downLoadNum;
                }

                for (int i = 0; i < num; i++)
                {
                    var coupon = GetRedisCouponNew(strKey);
                    if (coupon.CouponTypeId != null && coupon.CouponTypeId.Length > 0)
                    {
                        String uperStr       = StringUtil.GetRandomUperStr(4);
                        String strInt        = StringUtil.GetRandomStrInt(8);
                        string strCouponCode = uperStr + "-" + strInt;

                        DataRow dr_Coupon = dtCoupon.NewRow();
                        dr_Coupon["CouponID"]   = Guid.NewGuid().ToString();
                        dr_Coupon["CouponCode"] = strCouponCode;
                        dr_Coupon["CouponDesc"] = coupon.CouponTypeDesc;
                        if (coupon.ServiceLife > 0)
                        {
                            dr_Coupon["BeginDate"] = DateTime.Now;
                            dr_Coupon["EndDate"]   = DateTime.Now.Date.AddDays(coupon.ServiceLife - 1).ToShortDateString() + " 23:59:59.998";
                        }
                        else
                        {
                            dr_Coupon["BeginDate"] = coupon.BeginTime;
                            dr_Coupon["EndDate"]   = coupon.EndTime;
                        }
                        dr_Coupon["CouponUrl"]      = "";
                        dr_Coupon["ImageUrl"]       = "";
                        dr_Coupon["Status"]         = 0;
                        dr_Coupon["CreateTime"]     = DateTime.Now;
                        dr_Coupon["CreateBy"]       = "Redis";
                        dr_Coupon["LastUpdateTime"] = DateTime.Now;
                        dr_Coupon["LastUpdateBy"]   = "Redis";
                        dr_Coupon["IsDelete"]       = 0;
                        dr_Coupon["CouponTypeID"]   = coupon.CouponTypeId;
                        dr_Coupon["CoupnName"]      = coupon.CouponTypeName;
                        dr_Coupon["DoorID"]         = "";
                        dr_Coupon["CouponPwd"]      = "";
                        dr_Coupon["CollarCardMode"] = "";
                        dr_Coupon["CustomerID"]     = coupon.CustomerId;
                        dtCoupon.Rows.Add(dr_Coupon);

                        DataRow dr_CouponExport = dtCouponExport.NewRow();
                        dr_CouponExport["CouponCode"] = strCouponCode;
                        dtCouponExport.Rows.Add(dr_CouponExport);
                    }
                }
                if (dtCoupon != null && dtCoupon.Rows.Count > 0)
                {
                    SqlBulkCopy(strCon, dtCoupon, "Coupon");

                    LoggingSessionInfo _loggingSessionInfo   = new LoggingSessionInfo();
                    LoggingManager     CurrentLoggingManager = new LoggingManager();

                    _loggingSessionInfo.ClientID              = strCustomerId;
                    CurrentLoggingManager.Connection_String   = strCon;
                    _loggingSessionInfo.CurrentLoggingManager = CurrentLoggingManager;
                    var bllCouponType = new CouponTypeBLL(_loggingSessionInfo);
                    bllCouponType.UpdateCouponTypeIsVoucher(strCustomerId);
                }
            }
            return(dtCouponExport);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 下载二维码
        /// </summary>
        /// <param name="coupon"></param>
        /// <param name="strCon"></param>
        /// <returns></returns>
        public DataTable DownloadCoupon(CC_Coupon coupon, string strCustomerid, int downLoadNum, int intIsNotLimitQty)
        {
            var                count              = RedisOpenAPI.Instance.CCCoupon().GetCouponListLength(coupon);
            DataTable          dtCoupon           = new DataTable();
            LoggingSessionInfo loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(strCustomerid, "RedisSystem");


            dtCoupon.Columns.Add("CouponID", typeof(string));
            dtCoupon.Columns.Add("CouponCode", typeof(string));
            dtCoupon.Columns.Add("CouponDesc", typeof(string));
            dtCoupon.Columns.Add("BeginDate", typeof(DateTime));
            dtCoupon.Columns.Add("EndDate", typeof(DateTime));
            dtCoupon.Columns.Add("CouponUrl", typeof(string));
            dtCoupon.Columns.Add("ImageUrl", typeof(string));
            dtCoupon.Columns.Add("Status", typeof(Int32));
            dtCoupon.Columns.Add("CreateTime", typeof(DateTime));
            dtCoupon.Columns.Add("CreateBy", typeof(string));
            dtCoupon.Columns.Add("LastUpdateTime", typeof(DateTime));
            dtCoupon.Columns.Add("LastUpdateBy", typeof(string));
            dtCoupon.Columns.Add("IsDelete", typeof(Int32));
            dtCoupon.Columns.Add("CouponTypeID", typeof(string));
            dtCoupon.Columns.Add("CoupnName", typeof(string));
            dtCoupon.Columns.Add("DoorID", typeof(string));
            dtCoupon.Columns.Add("CouponPwd", typeof(string));
            dtCoupon.Columns.Add("CollarCardMode", typeof(string));
            dtCoupon.Columns.Add("CustomerID", typeof(string));

            DataTable dtCouponExport = new DataTable();

            dtCouponExport.Columns.Add("CouponCode", typeof(string));
            CC_Connection connection = new CC_Connection();
            string        strCon     = string.Empty;

            if (count.Code == ResponseCode.Success)
            {
                if (count.Result > 0)
                {
                    connection = new RedisConnectionBLL().GetConnection(strCustomerid);
                    if (connection.ConnectionStr == null)
                    {
                        strCon = GetCustomerConn(strCustomerid);
                    }
                    else
                    {
                        strCon = connection.ConnectionStr;
                    }

                    long num = 0;
                    if (downLoadNum > count.Result)
                    {
                        if (intIsNotLimitQty == 1)
                        {
                            var bllCouponType = new CouponTypeBLL(loggingSessionInfo);
                            bllCouponType.UpdateCouponTypeIssuedQty(coupon.CouponTypeId, downLoadNum);
                            coupon.CouponLenth = downLoadNum;
                            RedisOpenAPI.Instance.CCCoupon().SetCouponList(coupon);
                            num = downLoadNum;
                        }
                        else
                        {
                            num = count.Result;
                        }
                    }
                    else
                    {
                        num = downLoadNum;
                    }

                    for (int i = 0; i < num; i++)
                    {
                        var response = RedisGetCoupon(coupon);
                        if (response.Code == ResponseCode.Success)
                        {
                            String uperStr       = StringUtil.GetRandomUperStr(4);
                            String strInt        = StringUtil.GetRandomStrInt(8);
                            string strCouponCode = uperStr + "-" + strInt;

                            DataRow dr_Coupon = dtCoupon.NewRow();
                            dr_Coupon["CouponID"]   = Guid.NewGuid().ToString();
                            dr_Coupon["CouponCode"] = strCouponCode;
                            dr_Coupon["CouponDesc"] = response.Result.CouponTypeDesc;
                            if (response.Result.ServiceLife > 0)
                            {
                                dr_Coupon["BeginDate"] = DateTime.Now;
                                dr_Coupon["EndDate"]   = DateTime.Now.Date.AddDays(response.Result.ServiceLife - 1).ToShortDateString() + " 23:59:59.998";
                            }
                            else
                            {
                                dr_Coupon["BeginDate"] = response.Result.BeginTime;
                                dr_Coupon["EndDate"]   = response.Result.EndTime;
                            }
                            dr_Coupon["CouponUrl"]      = "";
                            dr_Coupon["ImageUrl"]       = "";
                            dr_Coupon["Status"]         = 0;
                            dr_Coupon["CreateTime"]     = DateTime.Now;
                            dr_Coupon["CreateBy"]       = "Redis";
                            dr_Coupon["LastUpdateTime"] = DateTime.Now;
                            dr_Coupon["LastUpdateBy"]   = "Redis";
                            dr_Coupon["IsDelete"]       = 0;
                            dr_Coupon["CouponTypeID"]   = response.Result.CouponTypeId;
                            dr_Coupon["CoupnName"]      = response.Result.CouponTypeName;
                            dr_Coupon["DoorID"]         = "";
                            dr_Coupon["CouponPwd"]      = "";
                            dr_Coupon["CollarCardMode"] = "";
                            dr_Coupon["CustomerID"]     = coupon.CustomerId;
                            dtCoupon.Rows.Add(dr_Coupon);

                            DataRow dr_CouponExport = dtCouponExport.NewRow();
                            dr_CouponExport["CouponCode"] = strCouponCode;
                            dtCouponExport.Rows.Add(dr_CouponExport);
                        }
                    }
                    if (dtCoupon != null && dtCoupon.Rows.Count > 0)
                    {
                        SqlBulkCopy(strCon, dtCoupon, "Coupon");
                        var bllCouponType = new CouponTypeBLL(loggingSessionInfo);
                        bllCouponType.UpdateCouponTypeIsVoucher(strCustomerid);
                    }
                }
            }
            return(dtCouponExport);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取BS用户登录信息
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static LoggingSessionInfo GetBSLoggingSession(string customerId, string userId)
        {
            if (userId == null || userId == string.Empty)
            {
                userId = "system";
            }

            string conn = "";
            string name = "";



            CC_Connection connection = new RedisConnectionBLL().GetConnection(customerId);//从redis里获取商户数据库链接
            RedisXML      _RedisXML  = new RedisXML();

            //如果从缓存里获取不到信息,就从数据库读取,并种到缓存里
            if (connection == null || string.IsNullOrEmpty(connection.ConnectionStr) || string.IsNullOrEmpty(connection.Customer_Name))
            {
                //记录redis读取不成功,从数据库里读取数据的情况
                _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 2);

                conn = GetCustomerConn(customerId);
                name = GetCustomerName(customerId);
                string code = GetCustomerCode(customerId);
                new RedisConnectionBLL().SetConnection(customerId, conn, name, code);
            }
            else
            {
                //记录redis读取日志
                _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 1);
                conn = connection.ConnectionStr;
                name = connection.Customer_Name;
            }



            LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo();

            //loggingSessionInfo = new CLoggingSessionService().GetLoggingSessionInfo(customerId, "7d4cda48970b4ed0aa697d8c2c2e4af3");
            loggingSessionInfo.CurrentUser             = new BS.Entity.User.UserInfo();
            loggingSessionInfo.CurrentUser.User_Id     = userId;
            loggingSessionInfo.CurrentUser.customer_id = customerId;

            loggingSessionInfo.UserID   = loggingSessionInfo.CurrentUser.User_Id;
            loggingSessionInfo.ClientID = customerId;
            loggingSessionInfo.Conn     = conn;

            loggingSessionInfo.CurrentLoggingManager = new LoggingManager();
            loggingSessionInfo.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn;
            loggingSessionInfo.CurrentLoggingManager.User_Id           = userId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Id       = customerId;
            loggingSessionInfo.CurrentLoggingManager.Customer_Name     = name;
            loggingSessionInfo.CurrentLoggingManager.User_Name         = "";
            if (!string.IsNullOrEmpty(conn))
            {
                //用户角色信息
                cUserService         userService   = new cUserService(loggingSessionInfo);
                string               applicationId = "649F8B8BDA9840D6A18130A5FF4CB9C8";//[T_Def_App] app
                IList <UserRoleInfo> userRoleList  = userService.GetUserRoles(loggingSessionInfo.UserID, applicationId);
                if (userRoleList != null && userRoleList.Count > 0)
                {
                    loggingSessionInfo.CurrentUserRole        = new UserRoleInfo();
                    loggingSessionInfo.CurrentUserRole.UserId = loggingSessionInfo.UserID;
                    //loggingSessionInfo.CurrentUserRole.UserName = login_user.User_Name;
                    loggingSessionInfo.CurrentUserRole.RoleId   = userRoleList[0].RoleId;
                    loggingSessionInfo.CurrentUserRole.RoleCode = userRoleList[0].RoleCode;
                    loggingSessionInfo.CurrentUserRole.RoleName = userRoleList[0].RoleName;

                    loggingSessionInfo.CurrentUserRole.UnitId = userService.GetDefaultUnitByUserIdAndRoleId(
                        loggingSessionInfo.CurrentUserRole.UserId, loggingSessionInfo.CurrentUserRole.RoleId);
                }
                loggingSessionInfo.ClientName = name;
            }
            return(loggingSessionInfo);
        }