private void HandleIncome (long id, ConfigSettings settings)
        { 
            using(var db = DbContextFactory.CreateDbContext())
            {
                var storage = db.InviteStorages.Include(a=>a.Xiake).Include(a=>a.Xiake.Credits).FirstOrDefault(a => a.Id == id);
                if(storage == null)
                    return;
                var dis = (int)((long)storage.Credits * (long)settings.InviteSet.Award / 100d); 
                storage.Credits = 0;  
                var charge = new Charge()
                {
                    ChargeMode = ChargeMode.BySystem,
                    PayType = PayType.ByInviteAward,
                    Value = dis ,
                    TargetXiake = storage.Xiake,
                    Handler= storage.Xiake 
                };
                db.Charges.Add(charge);
                storage.Xiake.Credits.FreeCredits += dis;

                try
                {
                    db.SaveChanges();
                } catch(DbUpdateConcurrencyException e)
                {
                    HandleIncome(id, settings);
                    return;
                } catch(Exception e)
                {
                    
                }
                mMasterServiceProxy.PushCreditsChangeMessage(storage.Xiake.Id, storage.Xiake.Credits.FreeCredits, storage.Xiake.Credits.FreezeCredits);
                
            }
        }
Exemple #2
0
        private ChargeMapData DoCharge (long xiakeId, int value, PayType payType, string comments )
        {
            
            using(var db = DbContextFactory.CreateDbContext())
            {
                var mz = db.Xiakes.FirstOrDefault(a => a.XiakeName == Thread.CurrentPrincipal.Identity.Name); 
                var xk = db.Xiakes.Where(a => a.Id == xiakeId).Include(a=>a.Credits).FirstOrDefault();
                var credits = xk.Credits;
                var ci = new Charge()
                {
                    Handler = mz,
                    ChargeMode = ChargeMode.ByXiaoer, 
                    Comments = comments,
                    PayType = payType,
                    TargetXiake = xk,
                    Value = value
                };
                credits.FreeCredits += value;
                db.Charges.Add(ci);

                try
                {
                    db.SaveChanges();
                } catch(DbUpdateConcurrencyException)
                {
                    Thread.Sleep(100);
                    return DoCharge(xiakeId, value, payType, comments);
                } catch(Exception e)
                {
                    
                }

                mMasterServiceProxy.PushCreditsChangeMessage(xk.Id, xk.Credits.FreeCredits, xk.Credits.FreezeCredits);
                 
                return new ChargeMapData()
                {
                    XiakeId = xk.Id,
                    Credits = xk.Credits.FreeCredits
                };

                   
            }
            
        }
Exemple #3
0
 public JsonResult DoChargeByMengzhu(DoChargeByMengzhuPostModel model)
 {
     var result = new DoChargeByMengzhuPostResult();
     using (var db = DbContextFactory.CreateDbContext())
     {
         Xiake xiake;
         TokenXCodeValidation.Validate(model, db, out xiake);
         var ids = model.XiakeIds.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries).Select(a=> Convert.ToInt64(a));
         var xiakes = db.Xiakes.Where(a => ids.Contains(a.Id));
         foreach(var xk in xiakes)
         {
             var ci = new Charge()
             { 
                 Handler = xiake.XiakeName,
                 ChargeMode = ChargeMode.ByXiaoer, 
                 Comments = model.Comments,
                 PayType = model.PayType,
                 TargetXiake = xk,
                 Value = model.Value
             };
             xk.Credits += model.Value;
             db.Charges.Add(ci);
             
             result.ChargeMaps.Add(new DoChargeByMengzhuPostResult.ChargeMap()
             {
                 XiakeId = xk.Id, Credits = xk.Credits
             });
         }
         db.SaveChanges();
     }
     return new JsonResult() { Data = result };
 }
Exemple #4
0
        public LoginXiakeData XiakeJoin(string xiakeName, string password, string qq, string mail, string tel, XiakeType xiakeType,string inviteCode)
        {
            var result = new LoginXiakeData();
            using (WebDbContext db = DbContextFactory.CreateDbContext())
            { 
                var settins = ConfigSettings.GetConfigSettings(  db.Settingses.FirstOrDefault().ConfigData);

                if(settins != null && settins.SystemStatusSet.IsDisableRegister)
                {
                    throw new FaultException(settins.SystemStatusSet.DisableRegisterReason);
                }
                if(settins != null && settins.SystemStatusSet.IsDisableSystem)
                {
                    throw new FaultException(settins.SystemStatusSet.DisableSystemReason);
                }

                if(settins.InviteSet.IsEnableInvite && settins.InviteSet.IsRejectNoInviteRegister &&
                   string.IsNullOrEmpty(inviteCode))
                {
                    throw new FaultException("Sorry, 没有邀请码不可注册!");
                }

                if (db.Xiakes.Any(a => a.XiakeName.Equals(xiakeName)))
                {
                    throw new FaultException("用户名已被使用中,请更换");
                }

                if(db.Xiakes.Any(a => a.Mail.Equals(mail)))
                {
                    throw new FaultException("邮箱已被使用中,请更换");
                }

                if (db.Xiakes.Any(a => a.Tel.Equals(tel)))
                {
                    throw new FaultException("手机已被使用中,请更换");
                }

                if (db.Xiakes.Any(a => a.QQ.Equals(qq)))
                {
                    throw new FaultException("QQ已被使用中,请更换");
                }

                var ip = WcfHelper.GetClientIp();
                
                var xiake = new Xiake
                {
                    XiakeName = xiakeName,
                    Password = password,
                    QQ = qq,
                    Mail = mail,
                    Tel = tel, 
                    RegisterIp = ip,
                    Credits =  new XiakeCredits()
                    {
                        FreeCredits=0,
                        FreezeCredits = 0
                    },
                    InviteStorage = new InviteStorage(),
                    IsAuthorized = true,
                    IsFrozen = false, 
                    LoginCount = 1,
                    LastLoginTime = DateTime.Now,
                    LastLoginIp = ip,
                    UserType = xiakeType,
                    Level = XiakeLevel.Guest,
                    Status = XiakeStatus.Enabled,
                    LastReadGonggaoId = 0
                };
                db.Xiakes.Add(xiake);

                var gift = 
                        xiakeType == XiakeType.Biaoju
                            ? settins.CreditsPolicySet.GifrForBiaoju
                            : settins.CreditsPolicySet.GiftForZhanggui;
                if(gift > 0)
                {
                    var charge = new Charge()
                    {
                        ChargeMode = ChargeMode.ByOwner,
                        Comments="新会员赠送",
                        Handler= xiake,
                        PayType= PayType.ByPresent,
                        TargetXiake= xiake,
                        Value = gift
                    };
                
                    xiake.Credits.FreeCredits = charge.Value;
                    db.Charges.Add(charge); 
                }

                if(!string.IsNullOrEmpty(inviteCode))
                {
                    var masterId = InviteCodeHelper.GetXiakeIdWithInviteCode(inviteCode);
                    var master = db.Xiakes.FirstOrDefault(a => a.Id == masterId);
                    if(master == null)
                    {
                        throw new FaultException("Sorry, 邀请码错误!");
                    }
                    var invite = new Invite() {Slave = xiake , Master = master};
                    db.Invites.Add(invite);
                    
                   
                }
                //if(settins.InviteSet.IsEnableInvite)
                //{
                //    var inviteStorage = new InviteStorage() {Credits = 0, Xiake = xiake};
                //    db.InviteStorages.Add(inviteStorage);
                //}
                
                
                db.SaveChanges(); 
                result.ID  = xiake.Id;
                result.Name  = xiake.XiakeName;
                result.XiakeType  = xiake.UserType;
                result.XiakeLevel  = xiake.Level;
                result.Token = Guid.NewGuid().ToString();
                
            }
            return result;
        }