예제 #1
0
        /// <summary>
        /// 发送微信模板消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="openId"></param>
        public void GetSuccessSendWXMessage(BonusReceiveInfo data, string openId)
        {
            var member = DbFactory.Default.Get <MemberInfo>().Where(p => p.Id == data.UserId).FirstOrDefault();

            #region 发送模板消息
            //TODO:DZY[150914]此处功能需要整理,暂时只是实现功能
            var msgdata = new WX_MsgTemplateSendDataModel();
            var bouns   = Get(data.BonusId);
            msgdata.first.value    = "恭喜红包领取成功!";
            msgdata.first.color    = "#000000";
            msgdata.keyword1.value = data.Price.ToString() + "元红包";// user != null ? user.Nick : "微信会员";
            msgdata.keyword1.color = "#000000";
            msgdata.keyword2.value = data.ReceiveTime.Value.ToString("yyyy-MM-dd HH:mm");
            msgdata.keyword2.color = "#FF0000";
            msgdata.keyword3.value = bouns.EndTime.ToString("yyyy-MM-dd HH:mm");
            msgdata.keyword3.color = "#FF0000";
            msgdata.remark.value   = "红包已成功领取,请在规定时间内使用,过期作废哦!";
            msgdata.remark.color   = "#000000";

            //处理url
            //var _iwxtser = Mall.ServiceProvider.Instance<IWXMsgTemplateService>.Create;
            //string url = _iwxtser.GetMessageTemplateShowUrl(Mall.Core.Plugins.Message.MessageTypeEnum.ReceiveBonus);
            //var wxmsgtmpl = _iwxtser.GetWeiXinMsgTemplate(Mall.Core.Plugins.Message.MessageTypeEnum.ReceiveBonus);

            //var siteSetting = SiteSettingApplication.SiteSettings;
            //if (wxmsgtmpl != null)
            //{
            //    if (!string.IsNullOrWhiteSpace(wxmsgtmpl.TemplateId) && wxmsgtmpl.IsOpen)
            //    {
            //        _iwxtser.SendMessageByTemplate(Core.Plugins.Message.MessageTypeEnum.ReceiveBonus, data.UserId.HasValue ? data.UserId.Value : 0, msgdata, url, openId);
            //        //Mall.ServiceProvider.Instance<IWXApiService>.Create.SendMessageByTemplate(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret, openId, wxmsgtmpl.TemplateId, "#000000", url, msgdata);
            //    }
            //}
            #endregion
        }
예제 #2
0
        private void DepositToMember(string openId, decimal price)
        {
            Entities         entity           = new Entities();
            MemberOpenIdInfo memberOpenIdInfo = (
                from p in entity.MemberOpenIdInfo
                where p.OpenId == openId
                select p).FirstOrDefault();

            if (memberOpenIdInfo != null)
            {
                BonusReceiveInfo bonusReceiveInfo = (
                    from p in entity.BonusReceiveInfo
                    where (p.OpenId == openId) && !p.IsTransformedDeposit
                    select p).FirstOrDefault();
                bonusReceiveInfo.IsTransformedDeposit = true;
                bonusReceiveInfo.ChemCloud_Members    = entity.UserMemberInfo.FirstOrDefault((UserMemberInfo p) => p.Id == memberOpenIdInfo.UserId);
                entity.SaveChanges();
                IMemberCapitalService create             = Instance <IMemberCapitalService> .Create;
                CapitalDetailModel    capitalDetailModel = new CapitalDetailModel()
                {
                    UserId = memberOpenIdInfo.UserId,
                    //SourceType = CapitalDetailInfo.CapitalDetailType.RedPacket,
                    Amount     = price,
                    CreateTime = bonusReceiveInfo.ReceiveTime.Value.ToString("yyyy-MM-dd HH:mm:ss")
                };
                create.AddCapital(capitalDetailModel);
            }
            entity.Dispose();
        }
예제 #3
0
        /// <summary>
        /// 发送微信模板消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="openId"></param>
        public void GetSuccessSendWXMessage(BonusReceiveInfo data, string openId)
        {
            var user = data.Himall_Members;

            #region 发送模板消息
            //TODO:DZY[150914]此处功能需要整理,暂时只是实现功能
            var msgdata = new WX_MSGGetCouponModel();
            msgdata.first.value  = "您好,您已成功领取现金红包。!";
            msgdata.first.color  = "#000000";
            msgdata.toName.value = user != null ? user.Nick : "微信会员";
            msgdata.toName.color = "#000000";
            msgdata.gift.value   = "现金" + data.Price.ToString() + "元";
            msgdata.gift.color   = "#FF0000";
            msgdata.time.value   = data.ReceiveTime.Value.ToString("yyyy-MM-dd HH:mm");
            msgdata.time.color   = "#FF0000";
            msgdata.remark.value = "红包领取成功会直接计入预存款,可消费与提现。";
            msgdata.remark.color = "#000000";

            //处理url
            var    _iwxtser  = Himall.ServiceProvider.Instance <IWXMsgTemplateService> .Create;
            string url       = _iwxtser.GetMessageTemplateShowUrl(Himall.Core.Plugins.Message.MessageTypeEnum.ReceiveBonus);
            var    wxmsgtmpl = _iwxtser.GetWeiXinMsgTemplate(Himall.Core.Plugins.Message.MessageTypeEnum.ReceiveBonus);

            var siteSetting = Himall.ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings();

            if (wxmsgtmpl != null)
            {
                if (!string.IsNullOrWhiteSpace(wxmsgtmpl.TemplateId) && wxmsgtmpl.IsOpen)
                {
                    Himall.ServiceProvider.Instance <IWXApiService> .Create.SendMessageByTemplate(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret, openId, wxmsgtmpl.TemplateId, "#000000", url, msgdata);
                }
            }
            #endregion
        }
예제 #4
0
        /*
         * 算法逻辑:
         * 1 产生随机金额后添加一个红包详情,总金额递减
         * 2 如果当前总金额 <= 随机金额+设定的最大随机金额,证明后续生成的红包不会超过2个
         *    2.1 如果随机金额 <= 设定的最大随机金额,证明已是最后一次生成随机红包
         *    2.2 如果随机金额 >= 设定的起始金额,进行平均分配,作为最后两个红包的金额
         */
        //public void Generate( long bounsId , decimal totalPrice )
        //{
        //    try
        //    {
        //        List<BonusReceiveInfo> list = new List<BonusReceiveInfo>();
        //        while( totalPrice != 0 )
        //        {
        //            decimal randomAmount = GenerateRandomAmountPrice();

        //            if( totalPrice <= randomAmount + this._randomAmountEnd )
        //            {
        //                if( totalPrice <= this._randomAmountEnd )  //剩余金额不够
        //                {
        //                    randomAmount = totalPrice;
        //                }
        //                else if( randomAmount >= this._randomAmountStart )
        //                {
        //                    randomAmount = totalPrice / 2;
        //                }

        //            }

        //            totalPrice -= randomAmount;

        //            BonusReceiveInfo detail = new BonusReceiveInfo
        //            {
        //                BonusId = bounsId ,
        //                Price = randomAmount ,
        //                IsShare = false ,
        //                OpenId = null
        //            };

        //            list.Add( detail );
        //            if( list.Count >= 500 )  //500个一次批量提交
        //            {
        //                this._context.BonusReceiveInfo.AddRange( list );
        //                this._context.SaveChanges();
        //                list.Clear();
        //            }
        //        }
        //        this._context.BonusReceiveInfo.AddRange( list );
        //        this._context.SaveChanges();
        //    }
        //    catch
        //    {
        //        this._context.BonusReceiveInfo.Remove( p => p.BonusId == bounsId );
        //        this._context.BonusInfo.Remove( p => p.Id == bounsId );
        //        this._context.SaveChanges();
        //    }
        //    finally
        //    {
        //        this._context.Dispose();
        //    }
        //}

        public void Generate(long bounsId, decimal totalPrice)
        {
            try
            {
                DbFactory.Default
                .InTransaction(() =>
                {
                    var flag = true;
                    List <BonusReceiveInfo> list = new List <BonusReceiveInfo>();
                    while (totalPrice != 0)
                    {
                        decimal randomAmount = 0;
                        if (totalPrice <= this._randomAmountEnd && this._randomAmountEnd > this._randomAmountStart)
                        {
                            this._randomAmountEnd = totalPrice;
                        }

                        randomAmount = GenerateRandomAmountPrice();

                        if (totalPrice - randomAmount < this._randomAmountStart)
                        {
                            randomAmount = totalPrice;
                        }

                        totalPrice -= randomAmount;

                        BonusReceiveInfo detail = new BonusReceiveInfo
                        {
                            BonusId = bounsId,
                            Price   = randomAmount,
                            IsShare = false,
                            OpenId  = null
                        };

                        list.Add(detail);
                        if (list.Count >= 500)      //500个一次批量提交
                        {
                            flag = DbFactory.Default.Add <BonusReceiveInfo>(list);
                            list.Clear();
                            if (!flag)
                            {
                                return(false);
                            }
                        }
                    }
                    flag = DbFactory.Default.Add <BonusReceiveInfo>(list);
                    return(flag);
                });
            }
            catch (Exception ex)
            {
                Core.Log.Error(ex.Message, ex);
            }
        }
예제 #5
0
        public void SetShare(long id, string openId)
        {
            BonusReceiveInfo nullable = (
                from p in context.BonusReceiveInfo
                where p.BonusId == id && (p.OpenId == openId)
                select p).FirstOrDefault();

            nullable.IsShare = new bool?(true);
            context.Configuration.ValidateOnSaveEnabled = false;
            context.SaveChanges();
            context.Configuration.ValidateOnSaveEnabled = true;
        }
예제 #6
0
        /*
         * 算法逻辑:
         * 1 产生随机金额后添加一个红包详情,总金额递减
         * 2 如果当前总金额 <= 随机金额+设定的最大随机金额,证明后续生成的红包不会超过2个
         *    2.1 如果随机金额 <= 设定的最大随机金额,证明已是最后一次生成随机红包
         *    2.2 如果随机金额 >= 设定的起始金额,进行平均分配,作为最后两个红包的金额
         */
        //public void Generate( long bounsId , decimal totalPrice )
        //{
        //    try
        //    {
        //        List<BonusReceiveInfo> list = new List<BonusReceiveInfo>();
        //        while( totalPrice != 0 )
        //        {
        //            decimal randomAmount = GenerateRandomAmountPrice();

        //            if( totalPrice <= randomAmount + this._randomAmountEnd )
        //            {
        //                if( totalPrice <= this._randomAmountEnd )  //剩余金额不够
        //                {
        //                    randomAmount = totalPrice;
        //                }
        //                else if( randomAmount >= this._randomAmountStart )
        //                {
        //                    randomAmount = totalPrice / 2;
        //                }

        //            }

        //            totalPrice -= randomAmount;

        //            BonusReceiveInfo detail = new BonusReceiveInfo
        //            {
        //                BonusId = bounsId ,
        //                Price = randomAmount ,
        //                IsShare = false ,
        //                OpenId = null
        //            };

        //            list.Add( detail );
        //            if( list.Count >= 500 )  //500个一次批量提交
        //            {
        //                this._context.BonusReceiveInfo.AddRange( list );
        //                this._context.SaveChanges();
        //                list.Clear();
        //            }
        //        }
        //        this._context.BonusReceiveInfo.AddRange( list );
        //        this._context.SaveChanges();
        //    }
        //    catch
        //    {
        //        this._context.BonusReceiveInfo.Remove( p => p.BonusId == bounsId );
        //        this._context.BonusInfo.Remove( p => p.Id == bounsId );
        //        this._context.SaveChanges();
        //    }
        //    finally
        //    {
        //        this._context.Dispose();
        //    }
        //}

        public void Generate(long bounsId, decimal totalPrice)
        {
            try
            {
                List <BonusReceiveInfo> list = new List <BonusReceiveInfo>();
                while (totalPrice != 0)
                {
                    decimal randomAmount = 0;
                    if (totalPrice <= this._randomAmountEnd && this._randomAmountEnd > this._randomAmountStart)
                    {
                        this._randomAmountEnd = totalPrice;
                    }

                    randomAmount = GenerateRandomAmountPrice();

                    if (totalPrice - randomAmount < this._randomAmountStart)
                    {
                        randomAmount = totalPrice;
                    }

                    totalPrice -= randomAmount;

                    BonusReceiveInfo detail = new BonusReceiveInfo
                    {
                        BonusId = bounsId,
                        Price   = randomAmount,
                        IsShare = false,
                        OpenId  = null
                    };

                    list.Add(detail);
                    if (list.Count >= 500)   //500个一次批量提交
                    {
                        this._context.BonusReceiveInfo.AddRange(list);
                        this._context.SaveChanges();
                        list.Clear();
                    }
                }
                this._context.BonusReceiveInfo.AddRange(list);
                this._context.SaveChanges();
            }
            catch
            {
                this._context.BonusReceiveInfo.Remove(p => p.BonusId == bounsId);
                this._context.BonusInfo.Remove(p => p.Id == bounsId);
                this._context.SaveChanges();
            }
            finally
            {
                this._context.Dispose();
            }
        }
예제 #7
0
 public void Generate(long bounsId, decimal totalPrice)
 {
     try
     {
         try
         {
             List <BonusReceiveInfo> bonusReceiveInfos = new List <BonusReceiveInfo>();
             while (totalPrice != new decimal(0))
             {
                 decimal num = new decimal(0);
                 if (totalPrice <= _randomAmountEnd && _randomAmountEnd > _randomAmountStart)
                 {
                     _randomAmountEnd = totalPrice;
                 }
                 num = GenerateRandomAmountPrice();
                 if ((totalPrice - num) < _randomAmountStart)
                 {
                     num = totalPrice;
                 }
                 totalPrice = totalPrice - num;
                 BonusReceiveInfo bonusReceiveInfo = new BonusReceiveInfo()
                 {
                     BonusId = bounsId,
                     Price   = num,
                     IsShare = new bool?(false),
                     OpenId  = null
                 };
                 bonusReceiveInfos.Add(bonusReceiveInfo);
                 if (bonusReceiveInfos.Count < 500)
                 {
                     continue;
                 }
                 _context.BonusReceiveInfo.AddRange(bonusReceiveInfos);
                 _context.SaveChanges();
                 bonusReceiveInfos.Clear();
             }
             _context.BonusReceiveInfo.AddRange(bonusReceiveInfos);
             _context.SaveChanges();
         }
         catch
         {
             _context.BonusReceiveInfo.Remove((BonusReceiveInfo p) => p.BonusId == bounsId);
             _context.BonusInfo.Remove((BonusInfo p) => p.Id == bounsId);
             _context.SaveChanges();
         }
     }
     finally
     {
         _context.Dispose();
     }
 }
예제 #8
0
        public void GetSuccessSendWXMessage(BonusReceiveInfo data, string openId, string url)
        {
            WX_MSGGetCouponModel wXMSGGetCouponModel = new WX_MSGGetCouponModel();

            wXMSGGetCouponModel.first.@value    = "领取红包成功!";
            wXMSGGetCouponModel.first.color     = "#000000";
            wXMSGGetCouponModel.keyword1.@value = "现金红包(1个)";
            wXMSGGetCouponModel.keyword1.color  = "#000000";
            WX_MSGItemBaseModel wXMSGItemBaseModel = wXMSGGetCouponModel.keyword2;
            decimal             price = data.Price;

            wXMSGItemBaseModel.@value          = string.Concat(price.ToString(), "元");
            wXMSGGetCouponModel.keyword2.color = "#FF0000";
            wXMSGGetCouponModel.remark.@value  = "红包领取成功会直接计入预存款,可消费与提现。";
            wXMSGGetCouponModel.remark.color   = "#000000";
            SiteSettingsInfo siteSettings = Instance <ISiteSettingService> .Create.GetSiteSettings();

            Instance <IWXApiService> .Create.SendMessageByTemplate(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret, openId, siteSettings.WX_MSGGetCouponTemplateId, "#000000", url, wXMSGGetCouponModel);
        }
예제 #9
0
 public void Generate(long bounsId, decimal totalPrice)
 {
     try
     {
         DbFactory.Default
         .InTransaction(() =>
         {
             var flag = true;
             //红包个数
             int detailCount = (int)(totalPrice / this._fixedAmount);
             List <BonusReceiveInfo> list = new List <BonusReceiveInfo>();
             //生成固定数量个红包
             for (int i = 0; i < detailCount; i++)
             {
                 BonusReceiveInfo detail = new BonusReceiveInfo
                 {
                     BonusId = bounsId,
                     Price   = this._fixedAmount,
                     IsShare = false,
                     OpenId  = null
                 };
                 list.Add(detail);
                 if (list.Count >= 500)      //500个一次批量提交
                 {
                     flag = DbFactory.Default.Add <BonusReceiveInfo>(list);
                     list.Clear();
                     if (!flag)
                     {
                         return(false);
                     }
                 }
             }
             flag = DbFactory.Default.Add <BonusReceiveInfo>(list);
             return(flag);
         });
     }
     catch (Exception ex)
     {
         Core.Log.Error(ex.Message, ex);
     }
 }
예제 #10
0
 public void Generate(long bounsId, decimal totalPrice)
 {
     try
     {
         try
         {
             int num = (int)(totalPrice / _fixedAmount);
             List <BonusReceiveInfo> bonusReceiveInfos = new List <BonusReceiveInfo>();
             for (int i = 0; i < num; i++)
             {
                 BonusReceiveInfo bonusReceiveInfo = new BonusReceiveInfo()
                 {
                     BonusId = bounsId,
                     Price   = _fixedAmount,
                     IsShare = new bool?(false),
                     OpenId  = null
                 };
                 bonusReceiveInfos.Add(bonusReceiveInfo);
                 if (bonusReceiveInfos.Count >= 500)
                 {
                     _context.BonusReceiveInfo.AddRange(bonusReceiveInfos);
                     _context.SaveChanges();
                     bonusReceiveInfos.Clear();
                 }
             }
             _context.BonusReceiveInfo.AddRange(bonusReceiveInfos);
             _context.SaveChanges();
         }
         catch
         {
             _context.BonusReceiveInfo.Remove((BonusReceiveInfo p) => p.BonusId == bounsId);
             _context.BonusInfo.Remove((BonusInfo p) => p.Id == bounsId);
             _context.SaveChanges();
         }
     }
     finally
     {
         _context.Dispose();
     }
 }
예제 #11
0
        public string Receive(string openId)
        {
            if ((
                    from p in context.OpenIdsInfo
                    where p.OpenId == openId
                    select p).Count() > 0)
            {
                return(null);
            }
            IQueryable <BonusReceiveInfo> bonusReceiveInfo =
                from p in context.BonusReceiveInfo
                where (int)p.ChemCloud_Bonus.Type == 2 && !p.ChemCloud_Bonus.IsInvalid && (p.ChemCloud_Bonus.EndTime >= DateTime.Now) && (p.ChemCloud_Bonus.StartTime <= DateTime.Now) && string.IsNullOrEmpty(p.OpenId) && !p.IsTransformedDeposit
                select p;
            BonusReceiveInfo nullable = bonusReceiveInfo.FirstOrDefault();

            if (nullable == null)
            {
                return(null);
            }
            BonusInfo himallBonus = nullable.ChemCloud_Bonus;

            himallBonus.ReceiveCount = himallBonus.ReceiveCount + 1;
            BonusInfo receivePrice = nullable.ChemCloud_Bonus;

            receivePrice.ReceivePrice     = receivePrice.ReceivePrice + nullable.Price;
            nullable.OpenId               = openId;
            nullable.ReceiveTime          = new DateTime?(DateTime.Now);
            nullable.IsTransformedDeposit = false;
            context.Configuration.ValidateOnSaveEnabled = false;
            context.SaveChanges();
            context.Configuration.ValidateOnSaveEnabled = true;
            string str = string.Concat("http://", WebHelper.GetHost(), "/userCenter");

            Task.Factory.StartNew(() => {
                DepositToMember(openId, nullable.Price);
                GetSuccessSendWXMessage(nullable, openId, str);
            });
            return("");
        }
예제 #12
0
 public void Generate(long bounsId, decimal totalPrice)
 {
     try
     {
         //红包个数
         int detailCount = ( int )(totalPrice / this._fixedAmount);
         List <BonusReceiveInfo> list = new List <BonusReceiveInfo>();
         //生成固定数量个红包
         for (int i = 0; i < detailCount; i++)
         {
             BonusReceiveInfo detail = new BonusReceiveInfo
             {
                 BonusId = bounsId,
                 Price   = this._fixedAmount,
                 IsShare = false,
                 OpenId  = null
             };
             list.Add(detail);
             if (list.Count >= 500)   //500个一次批量提交
             {
                 this._context.BonusReceiveInfo.AddRange(list);
                 this._context.SaveChanges();
                 list.Clear();
             }
         }
         this._context.BonusReceiveInfo.AddRange(list);
         this._context.SaveChanges();
     }
     catch
     {
         this._context.BonusReceiveInfo.Remove(p => p.BonusId == bounsId);
         this._context.BonusInfo.Remove(p => p.Id == bounsId);
         this._context.SaveChanges();
     }
     finally
     {
         this._context.Dispose();
     }
 }
예제 #13
0
        public object Receive(long id, string openId)
        {
            if (!IsAttention(openId))
            {
                ReceiveModel receiveModel = new ReceiveModel()
                {
                    State = ReceiveStatus.NotAttention,
                    Price = new decimal(0)
                };
                return(receiveModel);
            }
            IQueryable <BonusReceiveInfo> bonusReceiveInfo =
                from p in context.BonusReceiveInfo
                where (p.OpenId == openId) && p.BonusId == id
                select p;
            int  num  = bonusReceiveInfo.Count();
            bool flag = (
                from p in bonusReceiveInfo
                where p.IsShare == true
                select p).Count() != 0;

            if (num > 0 && (!flag && num == 1 || num == 2))
            {
                ReceiveModel receiveModel1 = new ReceiveModel()
                {
                    State = ReceiveStatus.Receive,
                    Price = new decimal(0)
                };
                return(receiveModel1);
            }
            IQueryable <BonusReceiveInfo> bonusReceiveInfos =
                from p in context.BonusReceiveInfo
                where p.BonusId == id && string.IsNullOrEmpty(p.OpenId)
                select p;
            BonusReceiveInfo nullable = bonusReceiveInfos.FirstOrDefault();

            if (nullable == null)
            {
                ReceiveModel receiveModel2 = new ReceiveModel()
                {
                    State = ReceiveStatus.HaveNot,
                    Price = new decimal(0)
                };
                return(receiveModel2);
            }
            if (nullable.ChemCloud_Bonus.IsInvalid)
            {
                ReceiveModel receiveModel3 = new ReceiveModel()
                {
                    State = ReceiveStatus.Invalid,
                    Price = new decimal(0)
                };
                return(receiveModel3);
            }
            BonusInfo himallBonus = nullable.ChemCloud_Bonus;

            himallBonus.ReceiveCount = himallBonus.ReceiveCount + 1;
            BonusInfo receivePrice = nullable.ChemCloud_Bonus;

            receivePrice.ReceivePrice     = receivePrice.ReceivePrice + nullable.Price;
            nullable.OpenId               = openId;
            nullable.ReceiveTime          = new DateTime?(DateTime.Now);
            nullable.IsTransformedDeposit = false;
            context.Configuration.ValidateOnSaveEnabled = false;
            context.SaveChanges();
            context.Configuration.ValidateOnSaveEnabled = true;
            string str = string.Concat("http://", WebHelper.GetHost(), "/userCenter");

            Task.Factory.StartNew(() => {
                Instance <IWXApiService> .Create.Subscribe(openId);
                DepositToMember(openId, nullable.Price);
                GetSuccessSendWXMessage(nullable, openId, str);
            });
            ReceiveModel receiveModel4 = new ReceiveModel()
            {
                State = ReceiveStatus.CanReceive,
                Price = nullable.Price
            };

            return(receiveModel4);
        }