/// <summary> /// 更新店铺资金信息(结算时,退款时,充值时) /// </summary> /// <param name="model"></param> public void UpdateShopAccount(ShopAccountInfo model) { //Context.ShopAccountInfo.Attach(model); //Context.Entry(model).State = System.Data.Entity.EntityState.Modified; //Context.SaveChanges(); DbFactory.Default.Update(model); }
/// <summary> /// 店铺帐户(在入驻成功后建立一个帐户) /// </summary> /// <param name="model"></param> public void AddShopAccount(ShopAccountInfo model) { if (!Context.ShopAccountInfo.Any(a => a.ShopId == model.ShopId)) { Context.ShopAccountInfo.Add(model); Context.SaveChanges(); } }
/// <summary> /// 店铺帐户(在入驻成功后建立一个帐户) /// </summary> /// <param name="model"></param> public void AddShopAccount(ShopAccountInfo model) { //if (!Context.ShopAccountInfo.Any(a => a.ShopId == model.ShopId)) if (!DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == model.ShopId).Exist()) { //Context.ShopAccountInfo.Add(model); //Context.SaveChanges(); DbFactory.Default.Add(model); } }
public object Register(StoreInfoModel model) { if (string.IsNullOrWhiteSpace(model.contactsPhone)) { return(Json(new { success = false, msg = "错误的手机号码" })); } bool result = ServiceProvider.Instance <IMemberService> .Create.CheckMobileExist(model.contactsPhone); if (result) { return(Json(new { success = false, msg = "当前手机号已注册" })); } else { result = ServiceProvider.Instance <IMemberService> .Create.CheckMemberExist(model.contactsPhone); if (result) { return(Json(new { success = false, msg = "当前手机号已注册" })); } } var member = ServiceProvider.Instance <IMemberService> .Create.Register(model.contactsPhone, model.password, model.contactsPhone); if (member != null) { var manager = ServiceProvider.Instance <IManagerService> .Create.AddSellerManager(model.contactsPhone, member.Password, member.PasswordSalt); if (manager != null) { var shop = ServiceProvider.Instance <IShopService> .Create.GetShop(manager.ShopId); shop.ShopName = model.shopName; shop.Industry = model.industry; shop.CompanyPhone = model.companyPhone; shop.Lat = model.lat; shop.Lng = model.lng; shop.CompanyAddress = model.companyAddress; shop.OpeningTime = model.openingTime; shop.BusinessLicenceNumberPhoto = model.businessLicenceNumberPhoto; shop.BranchImage = model.branchImage; if (!string.IsNullOrEmpty(model.branchImage)) { if (model.branchImage.Split(';').Length > 0) { shop.Logo = model.branchImage.Split(';')[0]; } } shop.ShopDescription = model.shopDescription; shop.WelcomeTitle = model.shopDescription; shop.ContactsName = model.contactsName; shop.ContactsPhone = model.contactsPhone; shop.ContactsPosition = model.contactsPosition; shop.BusinessType = Himall.CommonModel.ShopBusinessType.Enterprise; shop.Stage = Himall.Model.ShopInfo.ShopStage.Finish; shop.ShopStatus = Himall.Model.ShopInfo.ShopAuditStatus.WaitConfirm; //默认状态为待确认 shop.EndDate = DateTime.Now.AddYears(1); shop.GradeId = 1; //写入店铺默认套餐 //更新商家信息 ServiceProvider.Instance <IShopService> .Create.UpdateShop(shop); //添加商家结算账户 ShopAccountInfo shopAccountInfo = new ShopAccountInfo() { ShopId = shop.Id, ShopName = shop.ShopName, Balance = 0, PendingSettlement = 0, Settled = 0 }; ServiceProvider.Instance <IBillingService> .Create.AddShopAccount(shopAccountInfo); //登录 ServiceProvider.Instance <IManagerService> .Create.Login(model.contactsPhone, model.password); return(Json(new { success = true, msg = UserCookieEncryptHelper.Encrypt(manager.Id, CookieKeysCollection.USERROLE_SELLERADMIN) })); } else { return(Json(new { success = false, msg = "注册失败" })); } } else { return(Json(new { success = false, msg = "注册失败" })); } }
public void OrderMarketService(int monthCount, long shopId, MarketType type) { if (shopId <= 0) { throw new HimallException("ShopId不能识别"); } if (monthCount <= 0) { throw new HimallException("购买服务时长必须大于零"); } var shop = DbFactory.Default.Get <ShopInfo>().Where(p => p.Id == shopId).FirstOrDefault(); if (shop == null || shopId <= 0) { throw new HimallException("ShopId不能识别"); } var price = DbFactory.Default.Get <MarketSettingInfo>().Where(a => a.TypeId == type).Select(a => a.Price).FirstOrDefault <decimal>(); var StartTime = DateTime.Now; MarketServiceRecordInfo model = new MarketServiceRecordInfo(); model.StartTime = StartTime; model.Price = price * monthCount; var shopAccount = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();//店铺帐户信息 #region 它下面会取几次只,如为空会报异常,默认存入0的初始值 if (shopAccount == null) { shopAccount = new ShopAccountInfo(); shopAccount.ShopId = shopId; shopAccount.ShopName = shop.ShopName; shopAccount.Balance = 0; shopAccount.PendingSettlement = 0; shopAccount.Settled = 0; shopAccount.ReMark = string.Empty; DbFactory.Default.Add(shopAccount); } #endregion if (shopAccount.Balance < model.Price) //店铺余额不足以支付服务费用 { throw new HimallException("您的店铺余额为:" + shopAccount.Balance + "元,不足以支付此次营销服务购买费用,请先充值。"); } DbFactory.Default.InTransaction(() => { var market = DbFactory.Default.Get <ActiveMarketServiceInfo>().Where(a => a.ShopId == shopId && a.TypeId == type).FirstOrDefault(); if (market != null) { var maxTime = MarketApplication.GetServiceEndTime(market.Id); if (maxTime > DateTime.Now) //如果结束时间大于当前时间,续费从结束时间加上购买月数,否则从当前时间加上购买月数 { StartTime = maxTime; } model.StartTime = StartTime; model.BuyTime = DateTime.Now; model.EndTime = StartTime.AddMonths(monthCount); // model.MarketServiceId = market.Id; model.SettlementFlag = 1; model.MarketServiceId = market.Id; DbFactory.Default.Add(model); } else { model.StartTime = StartTime; model.EndTime = StartTime.AddMonths(monthCount); model.SettlementFlag = 1; model.BuyTime = DateTime.Now; ActiveMarketServiceInfo activeMarketServiceInfo = new ActiveMarketServiceInfo(); activeMarketServiceInfo.ShopId = shopId; activeMarketServiceInfo.ShopName = shop.ShopName; activeMarketServiceInfo.TypeId = type; DbFactory.Default.Add(activeMarketServiceInfo); model.MarketServiceId = activeMarketServiceInfo.Id; DbFactory.Default.Add(model); } var ShopAccount = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault(); ShopAccountItemInfo info = new ShopAccountItemInfo(); info.IsIncome = false; info.ShopId = shopId; info.DetailId = model.Id.ToString(); info.ShopName = shop.ShopName; info.AccountNo = shopId + info.DetailId + new Random().Next(10000); info.ReMark = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月"; info.TradeType = ShopAccountType.MarketingServices; info.CreateTime = DateTime.Now; info.Amount = price * monthCount; info.AccoutID = ShopAccount.Id; ShopAccount.Balance -= info.Amount; //总余额减钱 info.Balance = ShopAccount.Balance; //变动后当前剩余金额 DbFactory.Default.Add(info); DbFactory.Default.Update(ShopAccount); var platAccount = DbFactory.Default.Get <PlatAccountInfo>().FirstOrDefault(); var pinfo = new PlatAccountItemInfo { IsIncome = true, DetailId = model.Id.ToString(), AccountNo = info.AccountNo, ReMark = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月", TradeType = PlatAccountType.MarketingServices, CreateTime = DateTime.Now, Amount = price * monthCount, AccoutID = platAccount.Id }; platAccount.Balance += info.Amount; //总余额加钱 pinfo.Balance = platAccount.Balance; //变动后当前剩余金额 DbFactory.Default.Add(pinfo); DbFactory.Default.Update(platAccount); }); }
/// <summary> /// 更新店铺资金信息(结算时,退款时,充值时) /// </summary> /// <param name="model"></param> public void UpdateShopAccount(ShopAccountInfo model) { Context.ShopAccountInfo.Attach(model); Context.Entry(model).State = System.Data.Entity.EntityState.Modified; Context.SaveChanges(); }