private GetMerchantDetailOM GetFiiiPosMerchantDetail(MerchantInformation merchantDetail) { var weekArray = Enum.GetValues(typeof(Week)); var weekList = new List <int>(); foreach (var item in weekArray) { if (merchantDetail.Week.HasFlag((Enum)item)) { weekList.Add((int)Math.Log((int)item, 2) + 1); } } var currencyList = new MerchantWalletDAC().SupportReceiptList(merchantDetail.MerchantAccountId); var cryptoDict = new CryptocurrencyDAC().GetAll().ToDictionary(item => item.Code); var imageList = new MerchantOwnersFigureDAC().GetOwnersFiguresById(merchantDetail.Id); var recommendList = new MerchantRecommendDAC().GetRecommendsById(merchantDetail.Id); var result = new GetMerchantDetailOM() { AccountType = (int)Entities.Enums.AccountType.Merchant, IsAllowExpense = merchantDetail.IsAllowExpense, AvailableCryptoCodeList = currencyList.Select(item => item.CryptoCode).ToList(), AvailableCryptoIconList = currencyList.Select(item => { if (cryptoDict.ContainsKey(item.CryptoCode)) { return(cryptoDict[item.CryptoCode].IconURL.ToString()); } return(string.Empty); }).Where(item => !string.IsNullOrEmpty(item)).ToList(), Address = merchantDetail.Address, EndDate = merchantDetail.EndTime, StartDate = merchantDetail.StartTime, BussinessHour = merchantDetail.WeekTxt, ImageUrls = imageList.Select(item => item.FileId).ToList(), Location = new Location() { Longitude = merchantDetail.Lng, Latitude = merchantDetail.Lat }, Introduce = merchantDetail.Introduce, RecommendGoods = recommendList.Select(item => new Goods() { Content = item.RecommendContent, Image = new ImageWithCompressImage() { Compress = item.ThumbnailId, Origin = item.RecommendPicture } }).ToList(), Tags = merchantDetail.Tags.Split(','), Title = merchantDetail.MerchantName, Phone = merchantDetail.Phone, PhoneCode = merchantDetail.PhoneCode, Weeks = weekList }; return(result); }
/// <summary> /// 查询所有门店信息 /// </summary> /// <param name="account"></param> public MerchantInformationES SelectMerchantInformation(Guid accountId, int countryId) { var account = new MerchantAccountDAC().GetById(accountId); if (account == null) { throw new CommonException(ReasonCode.FiiiPosReasonCode.ACCOUNT_NOT_EXISTS, "商家账户未注册或不存在"); } var information = new MerchantInformationDAC().GetByMerchantAccountId(account.Id); var country = new CountryDAC().GetById(countryId); if (information == null) { throw new CommonException(ReasonCode.MERCHANT_NONE, "商家没有门店"); //return new MerchantInformationES() //{ // Countrys = new Countrys() // { // Name_CN = country.Name_CN, // Name = country.Name // } //}; } var figures = new MerchantOwnersFigureDAC().GetOwnersFiguresById(information.Id); var category = new MerchantCategoryDAC().GetByMerchantInformationId(information.Id); var recommend = new MerchantRecommendDAC().GetRecommendsById(information.Id); return(new MerchantInformationES() { MerchantName = information.MerchantName, Categorys = category.Select(item => item.Category).ToList(), Week = information.Week, StartTime = information.StartTime, EndTime = information.EndTime, Tags = information.Tags, Phone = information.Phone, Introduce = information.Introduce, Address = information.Address, Lng = information.Lng, Lat = information.Lat, VerifyStatus = information.VerifyStatus, OwnersFigures = figures.Select(item => item.FileId).ToList(), Recommends = recommend.Select(item => new Recommend() { Content = item.RecommendContent, Picture = item.RecommendPicture }).ToList(), Countrys = new Countrys() { Name_CN = country.Name_CN, Name = country.Name }, IsPublic = information.IsPublic }); }
private GetMerchantDetailOM GetFiiiPayMerchantDetail(MerchantInformation merchantDetail) { var weekArray = Enum.GetValues(typeof(Week)); var weekList = new List <int>(); foreach (var item in weekArray) { if (merchantDetail.Week.HasFlag((Enum)item)) { weekList.Add((int)Math.Log((int)item, 2) + 1); } } var supportCurrencyList = new MerchantSupportCryptoDAC().GetList(merchantDetail.Id); var supportCryptoIdList = supportCurrencyList.Select(t => t.CryptoId).ToList(); var cryptoList = new CryptocurrencyDAC().GetAll(); var imageList = new MerchantOwnersFigureDAC().GetOwnersFiguresById(merchantDetail.Id); var recommendList = new MerchantRecommendDAC().GetRecommendsById(merchantDetail.Id); var result = new GetMerchantDetailOM() { AccountType = (int)AccountType.User, IsAllowExpense = merchantDetail.IsAllowExpense, AvailableCryptoCodeList = supportCurrencyList.Select(item => item.CryptoCode).ToList(), AvailableCryptoIconList = cryptoList.Where(c => supportCryptoIdList.Contains(c.Id)).Select(t => t.IconURL.ToString()).ToList(), Address = merchantDetail.Address, BussinessHour = merchantDetail.WeekTxt, ImageUrls = imageList.Select(item => item.FileId).ToList(), Location = new Location() { Longitude = merchantDetail.Lng, Latitude = merchantDetail.Lat }, Introduce = merchantDetail.Introduce, RecommendGoods = recommendList.Select(item => new Goods() { Content = item.RecommendContent, Image = new ImageWithCompressImage() { Compress = item.ThumbnailId, Origin = item.RecommendPicture } }).ToList(), Tags = merchantDetail.Tags.Split(','), Title = merchantDetail.MerchantName, Phone = merchantDetail.Phone, PhoneCode = merchantDetail.PhoneCode }; return(result); }
/// <summary> /// 更新所有门店信息 /// </summary> /// <param name="information"></param> /// <param name="ownersFigures"></param> /// <param name="merchantRecommends"></param> /// <param name="merchantCategories"></param> /// <param name="phone"></param> public void UpdateMerchantInformation(MerchantInformation information, List <MerchantOwnersFigure> ownersFigures, List <MerchantRecommend> merchantRecommends, List <MerchantCategory> merchantCategories, string phone) { if (new MerchantAccountDAC().GetById(information.MerchantAccountId) == null) { throw new CommonException(ReasonCode.FiiiPosReasonCode.ACCOUNT_NOT_EXISTS, "商家账户未注册或不存在"); } //var Categories = merchantCategories; var owners = new MerchantOwnersFigureDAC().GetOwnersFiguresById(information.Id); //查询商家主图id var recommends = new MerchantRecommendDAC().GetRecommendsById(information.Id); //查询商家推荐图id var merchantInfo = new MerchantInformationDAC().GetByMerchantAccountId(information.MerchantAccountId); //判断 商家名称,经营内容,商家介绍,门店相册是否一样 var isSame = merchantInfo.MerchantName == information.MerchantName && merchantInfo.Tags == information.Tags && merchantInfo.Introduce == information.Introduce; isSame &= owners.Select(item => item.FileId).All(item => ownersFigures.ToDictionary(_ => _.FileId).ContainsKey(item)) && owners.Count == ownersFigures.Count; isSame &= recommends.Select(item => item.RecommendPicture).All(item => merchantRecommends.ToDictionary(_ => _.RecommendPicture).ContainsKey(item)) && recommends.Count == merchantRecommends.Count && recommends.Select(item => item.RecommendContent).All(item => merchantRecommends.ToDictionary(_ => _.RecommendContent).ContainsKey(item)); if (merchantInfo.VerifyStatus == FiiiPay.Entities.Enums.VerifyStatus.Disapproval) { Task.WhenAll(Task.Run(() => { Parallel.ForEach(owners, item => { try { if (!ownersFigures.Any(_ => _.FileId == item.FileId)) { Task.WhenAll(Task.Run(() => { new MasterImageAgent().Delete(item.FileId.ToString()); }), Task.Run(() => { new MasterImageAgent().Delete(item.ThumbnailId.ToString()); })); } } catch { } }); }), Task.Run(() => { Parallel.ForEach(recommends, item => { if (!merchantRecommends.Any(_ => _.RecommendPicture == item.RecommendPicture)) { Task.WhenAll(Task.Run(() => { new MasterImageAgent().Delete(item.RecommendPicture.ToString()); }), Task.Run(() => { new MasterImageAgent().Delete(item.ThumbnailId.ToString()); })); } }); }), Task.Run(() => { Parallel.ForEach(ownersFigures, item => { if (!owners.Any(_ => _.FileId == item.FileId)) { var tumnailId = new MasterImageAgent().UploadWithCompress(item.FileId); item.ThumbnailId = tumnailId == Guid.Empty ? item.FileId : tumnailId; } else { item.ThumbnailId = owners.FirstOrDefault(_ => _.FileId == item.FileId)?.ThumbnailId ?? item.FileId; } }); }), Task.Run(() => { Parallel.ForEach(merchantRecommends, item => { if (!recommends.Any(_ => _.RecommendPicture == item.RecommendPicture)) { var tumnailId = new MasterImageAgent().UploadWithCompress(item.RecommendPicture); item.ThumbnailId = tumnailId == Guid.Empty ? item.RecommendPicture : tumnailId; } else { item.ThumbnailId = recommends.FirstOrDefault(_ => _.RecommendPicture == item.RecommendPicture)?.ThumbnailId ?? item.RecommendPicture; } }); })).Wait(); using (var scope = new TransactionScope()) { new MerchantInformationDAC().Update(information.Id, information); new MerchantCategoryDAC().Delete(information.Id); merchantCategories.ForEach(item => new MerchantCategoryDAC().Insert(item)); new MerchantOwnersFigureDAC().Delete(information.Id); ownersFigures.ForEach(item => new MerchantOwnersFigureDAC().Insert(item)); new MerchantRecommendDAC().Delete(information.Id); merchantRecommends.ForEach(item => new MerchantRecommendDAC().Insert(item)); scope.Complete(); } } else if (merchantInfo.VerifyStatus == FiiiPay.Entities.Enums.VerifyStatus.Certified) { if (isSame) { using (var scope = new TransactionScope()) { new MerchantInformationDAC().UpdatePartialInformation(information.Id, information); new MerchantCategoryDAC().Delete(information.Id); merchantCategories.ForEach(item => new MerchantCategoryDAC().Insert(item)); scope.Complete(); } } else { Task.WhenAll(Task.Run(() => { Parallel.ForEach(owners, item => { try { if (!ownersFigures.Any(_ => _.FileId == item.FileId)) { Task.WhenAll(Task.Run(() => { new MasterImageAgent().Delete(item.FileId.ToString()); }), Task.Run(() => { new MasterImageAgent().Delete(item.ThumbnailId.ToString()); })); } } catch { } }); }), Task.Run(() => { Parallel.ForEach(recommends, item => { if (!merchantRecommends.Any(_ => _.RecommendPicture == item.RecommendPicture)) { Task.WhenAll(Task.Run(() => { new MasterImageAgent().Delete(item.RecommendPicture.ToString()); }), Task.Run(() => { new MasterImageAgent().Delete(item.ThumbnailId.ToString()); })); } }); }), Task.Run(() => { Parallel.ForEach(ownersFigures, item => { if (!owners.Any(_ => _.FileId == item.FileId)) { var tumnailId = new MasterImageAgent().UploadWithCompress(item.FileId); item.ThumbnailId = tumnailId == Guid.Empty ? item.FileId : tumnailId; } else { item.ThumbnailId = owners.FirstOrDefault(_ => _.FileId == item.FileId)?.ThumbnailId ?? item.FileId; } }); }), Task.Run(() => { Parallel.ForEach(merchantRecommends, item => { if (!recommends.Any(_ => _.RecommendPicture == item.RecommendPicture)) { var tumnailId = new MasterImageAgent().UploadWithCompress(item.RecommendPicture); item.ThumbnailId = tumnailId == Guid.Empty ? item.RecommendPicture : tumnailId; } else { item.ThumbnailId = recommends.FirstOrDefault(_ => _.RecommendPicture == item.RecommendPicture)?.ThumbnailId ?? item.RecommendPicture; } }); })).Wait(); using (var scope = new TransactionScope()) { new MerchantInformationDAC().Update(information.Id, information); new MerchantCategoryDAC().Delete(information.Id); merchantCategories.ForEach(item => new MerchantCategoryDAC().Insert(item)); new MerchantOwnersFigureDAC().Delete(information.Id); ownersFigures.ForEach(item => new MerchantOwnersFigureDAC().Insert(item)); new MerchantRecommendDAC().Delete(information.Id); merchantRecommends.ForEach(item => new MerchantRecommendDAC().Insert(item)); scope.Complete(); } } } }
public async Task <bool> FiiipayMerchantCreateAsync(UserAccount account, FiiiPayMerchantInfoCreateIM model) { var uaDAC = new UserAccountDAC(); if (account.L1VerifyStatus != VerifyStatus.Certified) { throw new CommonException(ReasonCode.NOT_VERIFY_LV1, Resources.EMNeedLV1Verfied); } var inviteAccount = uaDAC.GetByInvitationCode(model.InviteCode); bool needInviteRecord = true; if (!string.IsNullOrEmpty(model.InviteCode)) { if (inviteAccount == null) { throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, MessageResources.InvalidInvitation); } if (inviteAccount.InvitationCode == account.InvitationCode) { throw new CommonException(ReasonCode.INVALID_INVITECODE, MessageResources.InviteCodeCanotInputSelf); } var existInviteRecord = await new InviteRecordDAC().GetDetailByAccountIdAsync(account.Id, InviteType.FiiipayMerchant); if (existInviteRecord != null) { needInviteRecord = false; } } else { needInviteRecord = false; } var merchantCountry = new CountryDAC().GetById(model.CountryId); if (merchantCountry == null) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } if (!merchantCountry.IsSupportStore) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } Regions stateRegion; Regions cityRegion; if (model.StateId.HasValue) { stateRegion = await new RegionDAC().GetByIdAsync(model.StateId.Value); if (stateRegion == null) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } if (stateRegion.CountryId != model.CountryId) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } if (model.CityId.HasValue) { cityRegion = await new RegionDAC().GetByIdAsync(model.CityId.Value); if (cityRegion == null) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } if (cityRegion.CountryId != model.CountryId || cityRegion.ParentId != stateRegion.Id) { throw new CommonException(ReasonCode.RECORD_NOT_EXIST, MessageResources.InvalidParameters); } } } #region entities Guid merchantInfoId = Guid.NewGuid(); DateTime dtNow = DateTime.UtcNow; MerchantInformation merchantInfo = new MerchantInformation { Id = merchantInfoId, CreateTime = dtNow, FromType = InputFromType.UserInput, MerchantName = model.MerchantName, WeekTxt = model.WeekTxt, Tags = model.TagList == null ? "" : string.Join(",", model.TagList), Introduce = model.Introduce, CountryId = merchantCountry.Id, StateId = model.StateId, CityId = model.CityId, PhoneCode = account.PhoneCode, Address = model.Address, Lng = model.Lng, Lat = model.Lat, Status = Status.Stop, VerifyStatus = VerifyStatus.UnderApproval, MerchantAccountId = account.Id, Phone = model.Phone, IsPublic = Status.Stop, FileId = model.StorefrontImg[0], ThumbnailId = model.StorefrontImg[1], AccountType = AccountType.User, Markup = 0, FeeRate = 0, IsAllowExpense = false, Week = Week.Monday, ApplicantName = model.ApplicantName, UseFiiiDeduct = model.UseFiiiDeduction }; InviteRecord inviteRecord = new InviteRecord { AccountId = account.Id, InviterCode = model.InviteCode, Type = InviteType.FiiipayMerchant, InviterAccountId = inviteAccount?.Id ?? Guid.Empty, Timestamp = dtNow }; FiiipayMerchantVerifyRecord record = new FiiipayMerchantVerifyRecord { CreateTime = dtNow, MerchantInfoId = merchantInfoId, BusinessLicenseImage = model.BusinessLicenseImage, LicenseNo = model.LicenseNo, VerifyStatus = VerifyStatus.UnderApproval }; List <MerchantCategory> categorys = model.MerchantCategorys.Select(t => new MerchantCategory { MerchantInformationId = merchantInfoId, Category = t }).ToList(); List <MerchantOwnersFigure> figuresList = new List <MerchantOwnersFigure>(); if (model.FigureImgList != null) { for (int i = 0; i < model.FigureImgList.Length; i++) { figuresList.Add(new MerchantOwnersFigure { MerchantInformationId = merchantInfoId, FileId = model.FigureImgList[i][0], Sort = i, ThumbnailId = model.FigureImgList[i][1] }); } } var coinList = await new CryptocurrencyDAC().GetAllAsync(); List <MerchantSupportCrypto> supportCryptoList = model.SupportCoins.Select(t => { var c = coinList.Find(m => m.Id == t); if (c != null) { return(new MerchantSupportCrypto { MerchantInfoId = merchantInfoId, CryptoId = t, CryptoCode = c.Code }); } return(null); }).Where(x => x != null).ToList(); #endregion var mInfoDAC = new MerchantInformationDAC(); var fmVerfiyRecordDAC = new FiiipayMerchantVerifyRecordDAC(); var mCategoryDAC = new MerchantCategoryDAC(); var mFigureDAC = new MerchantOwnersFigureDAC(); var mSupportCryptoDAC = new MerchantSupportCryptoDAC(); var inviteDAC = new InviteRecordDAC(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30))) { mInfoDAC.Insert(merchantInfo); fmVerfiyRecordDAC.Insert(record); if (needInviteRecord) { inviteDAC.Insert(inviteRecord); } if (categorys != null && categorys.Count > 0) { foreach (var item in categorys) { mCategoryDAC.Insert(item); } } if (figuresList != null && figuresList.Count > 0) { foreach (var item in figuresList) { mFigureDAC.Insert(item); } } if (supportCryptoList != null && supportCryptoList.Count > 0) { foreach (var item in supportCryptoList) { mSupportCryptoDAC.Insert(item); } } scope.Complete(); } return(true); }