Ejemplo n.º 1
0
        public List <ProfitDetailOM> FiiipayDetail(UserAccount account, int pageIndex)
        {
            var iDAC = new InviteRecordDAC();
            int offset, nextCount = 0;

            if (pageIndex == 1)
            {
                offset    = 0;
                nextCount = 20;
            }
            else
            {
                offset    = (pageIndex - 2) * 10 + 20;
                nextCount = 10;
            }
            var collection = iDAC.GetFiiiPayProfitDetails(account.Id, new Tuple <int, int>(offset, nextCount));
            List <ProfitDetailOM> result = new List <ProfitDetailOM>();

            collection.ForEach(item => result.Add(new ProfitDetailOM()
            {
                AccountId        = item.AccountId,
                CellPhone        = item.CellPhone,
                CryptoAmount     = item.CryptoAmount,
                Id               = item.Id,
                InvitationId     = item.InvitationId,
                InvitedAccountId = item.InvitedAccountId,
                PhoneCode        = item.PhoneCode,
                Timestamp        = item.Timestamp,
                Type             = item.Type
            }));
            return(result);
        }
Ejemplo n.º 2
0
        public PreFiiiPosProfitOM PreFiiiPosProfit(UserAccount account)
        {
            var     iDAC       = new InviteRecordDAC();
            var     collection = iDAC.GetFiiiPosProfitDetails(account.Id, (int)SystemPlatform.FiiiPOS);
            var     count      = collection.GroupBy(item => item.MerchantId).Count();
            decimal rate       = 0;

            if (count >= 3 && count < 10)
            {
                rate = 0.04m;
            }
            else if (count >= 10 && count < 30)
            {
                rate = 0.06m;
            }
            else if (count >= 30)
            {
                rate = 0.08m;
            }
            //todo
            decimal totalAmount = decimal.Zero;

            foreach (var item in collection)
            {
                totalAmount += item.CryptoAmount;
            }
            return(new PreFiiiPosProfitOM()
            {
                CryptoAmount = totalAmount.ToString(8), InviteCount = count, ProfitRate = rate
            });
        }
Ejemplo n.º 3
0
        public List <FiiiposBonusRecordOM> FiiiposDetail(UserAccount account)
        {
            var iDAC = new InviteRecordDAC();

            return(iDAC.GetFiiiPosProfitDetailList(account.Id, (int)SystemPlatform.FiiiPOS).Select(item => new FiiiposBonusRecordOM()
            {
                MerchantId = item.MerchantId, MerchantName = item.MerchantName, TotalCryptoAmount = item.TotalCryptoAmount.ToString(8)
            }).ToList());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取分红的详细信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public FiiiposProfitDetailRecordOM FiiiposMoreDetail(FiiiposBonusRecordIM im, UserAccount account)
        {
            var iDAC  = new InviteRecordDAC();
            var pfDAC = new ProfitDetailDAC();
            var data  = iDAC.GetDetailByAccountId(im.MerchantId);

            return(new FiiiposProfitDetailRecordOM()
            {
                Data = pfDAC.GetFiiiposBonusRecords(data.Id, account).Select(item => new FiiiposProfitDetailRecordOM.BonusDetail()
                {
                    CryptoAmount = item.CryptoAmount.ToString(8),
                    Timestamp = item.Timestamp.ToUnixTime().ToString()
                }).ToList(),
                MerchantName = im.MerchantName,
                TotalAmount = im.TotalCryptoAmount.ToString(8)
            });
        }
        public void UnbindingAccount(Guid merchantAccountId)
        {
            SecurityVerify.Verify <UnBindAccountVerify>(new CustomVerifier("UnBindAccount"), SystemPlatform.FiiiPOS, merchantAccountId.ToString(), (model) =>
            {
                return(model.PinVerified && model.CombinedVerified);
            });

            var accountDAC = new MerchantAccountDAC();
            var account    = accountDAC.GetById(merchantAccountId);

            var posDAC    = new POSDAC();
            var pos       = posDAC.GetById(account.POSId.Value);
            var recordId  = new POSMerchantBindRecordDAC().GetByMerchantId(merchantAccountId).Id;
            var invitorId = new InviteRecordDAC().GetInvitorIdBySn(pos.Sn);

            account.POSId = null;
            bool bindingGoogleAuth = !string.IsNullOrEmpty(account.AuthSecretKey);
            bool openedGoogleAuth  =
                ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator);

            if (bindingGoogleAuth && !openedGoogleAuth)
            {
                account.ValidationFlag =
                    ValidationFlagComponent.AddValidationFlag(account.ValidationFlag, ValidationFlag.GooogleAuthenticator);
            }

            using (var scope = new TransactionScope())
            {
                accountDAC.UnbindingAccount(account);
                new POSDAC().InactivePOS(pos);
                new POSMerchantBindRecordDAC().UnbindRecord(account.Id, pos.Id);
                if (!string.IsNullOrEmpty(account.InvitationCode))
                {
                    UnBindInviter(pos.Sn);
                }

                scope.Complete();
            }
            //Task.Run(() => RemoveRegInfoByUserId(merchantAccountId));
            if (!string.IsNullOrEmpty(account.InvitationCode))
            {
                RabbitMQSender.SendMessage("UnBindingAccount", new Tuple <Guid, long>(invitorId, recordId));
            }

            RemoveRegInfoByUserId(merchantAccountId);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 修改邀请码
        /// </summary>
        /// <param name="merchantId"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public void UpdateInviterCode(Guid merchantId, string inviterCode)
        {
            UserAccountDAC uaDac = new UserAccountDAC();

            if (!string.IsNullOrEmpty(inviterCode) && !uaDac.ExistInviterCode(inviterCode))
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.INVITERCODE_NOT_EXISTS, "邀请码不存在");
            }
            var             user  = uaDac.GetUserAccountByInviteCode(inviterCode);
            InviteRecordDAC irDac = new InviteRecordDAC();
            InviteRecord    model = new InviteRecord();

            model.AccountId        = merchantId;
            model.InviterCode      = inviterCode;
            model.Type             = InviteType.Fiiipos;
            model.Timestamp        = DateTime.UtcNow;
            model.InviterAccountId = user.Id;
            irDac.Insert(model);;
        }
Ejemplo n.º 7
0
        public PreFiiiPayProfitOM PreFiiiPayProfit(UserAccount account)
        {
            var     iDAC            = new InviteRecordDAC();
            var     collection      = iDAC.GetFiiiPayProfitDetails(account.Id);
            int     inviteUserCount = 0;
            decimal totalAmount     = decimal.Zero;

            foreach (var item in collection)
            {
                if (item.Type == ProfitType.InvitePiiiPay)
                {
                    inviteUserCount++;
                }
                totalAmount += item.CryptoAmount;
            }
            return(new PreFiiiPayProfitOM()
            {
                TotalProfitAmount = totalAmount, InvitationCount = inviteUserCount
            });
        }
        /// <summary>
        /// POS机指定邀请人
        /// </summary>
        /// <param name="SN"></param>
        /// <param name="merchantId"></param>
        /// <param name="userId"></param>
        /// <param name="invitationCode"></param>
        private int BindInviter(string SN, Guid merchantId, Guid userId, string invitationCode)
        {
            var irDAC       = new InviteRecordDAC();
            var existRecord = irDAC.GetBySN(SN);

            if (existRecord == null)
            {
                return(irDAC.Insert(new InviteRecord
                {
                    SN = SN,
                    Type = InviteType.Fiiipos,
                    AccountId = merchantId,
                    Timestamp = DateTime.UtcNow,
                    InviterCode = invitationCode,
                    InviterAccountId = userId
                }));
            }
            new InviteRecordDAC().UpdateAccountInfo(userId, merchantId, invitationCode, SN);

            return(existRecord.Id);
        }
Ejemplo n.º 9
0
        public List <InviteRankOM> GetInviteRankList(InviteRankIM im)
        {
            var iDAC = new InviteRecordDAC();

            if (im.Type == (int)SystemPlatform.FiiiPOS)
            {
                var result = iDAC.GetFiiiPosRankDetails(im.Count)?.Select(item => new InviteRankOM()
                {
                    AccountId    = item.AccountId,
                    CellPhone    = item.CellPhone,
                    CryptoAmount = item.CryptoAmount.ToString(2),
                    PhoneCode    = item.PhoneCode
                }).ToList() ?? new List <InviteRankOM>();
                if (result.Count < im.Count)
                {
                    result.AddRange(iDAC.GetFiiiPosRankDetails(im.Count - result.Count)?.Select(item => new InviteRankOM()
                    {
                        AccountId    = item.AccountId,
                        CellPhone    = item.CellPhone,
                        CryptoAmount = item.CryptoAmount.ToString(2),
                        PhoneCode    = item.PhoneCode
                    }).ToList() ?? new List <InviteRankOM>());
                }

                return(result);
            }
            else
            {
                return(iDAC.GetFiiiPayRankDetails(im.Count).Select(item => new InviteRankOM()
                {
                    AccountId = item.AccountId,
                    CellPhone = item.CellPhone,
                    CryptoAmount = item.CryptoAmount.ToString(2),
                    PhoneCode = item.PhoneCode
                }).ToList());
            }
        }
Ejemplo n.º 10
0
        public void DistributeRewards(FiiiPayRewardMessage message, int fiiicoinId)
        {
            MerchantAccountDAC maDAC = new MerchantAccountDAC();
            var merchant             = maDAC.GetByUsername(message.Account);

            if (merchant == null)
            {
                throw new CommonException(10000, $"无效的商家名:{message.Account}");
            }

            InviteRecord invitor = GetInvitor(merchant.Id);

            if (invitor == null)
            {
                throw new CommonException(10000, "没有邀请人");
            }

            var invitedList = new InviteRecordDAC().GetFiiiPosRecordsByInvitorId(invitor.InviterAccountId, InviteType.Fiiipos);
            var rewardRate  = GetRewardPercentage(invitedList == null ? 0 : invitedList.Count);

            if (rewardRate == 0)
            {
                throw new CommonException(10000, "没有达到奖励条件");
            }

            decimal t            = (decimal)Math.Pow(10, -8);
            long    nTotalReward = (long)Math.Floor(message.Reward * rewardRate);

            if (nTotalReward == 0)
            {
                throw new CommonException(10000, "奖励金额为0");
            }
            decimal  rewardAmount = nTotalReward * t;
            DateTime dtNow        = DateTime.UtcNow;

            if (message.CurrentDate > 0)
            {
                dtNow = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(message.CurrentDate);
            }
            var distributeRecord = new RewardDistributeRecords
            {
                UserAccountId     = invitor.InviterAccountId,
                MerchantAccountId = merchant.Id,
                SN             = message.SN,
                OriginalReward = message.Reward,
                Percentage     = rewardRate,
                ActualReward   = rewardAmount,
                Timestamp      = dtNow
            };

            long    profitId;
            decimal oldBalance    = 0;
            var     invitorWallet = uwDAC.GetByAccountId(invitor.InviterAccountId, fiiicoinId);

            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                if (invitorWallet == null)
                {
                    invitorWallet = CreateWallet(invitor.InviterAccountId, fiiicoinId, rewardAmount);
                }
                else
                {
                    oldBalance = invitorWallet.Balance;
                    uwDAC.Increase(invitorWallet.Id, rewardAmount);
                }

                var profitDetail = new ProfitDetail
                {
                    InvitationId = invitor.Id,
                    CryptoAmount = rewardAmount,
                    AccountId    = invitor.InviterAccountId,
                    Status       = InviteStatusType.IssuedActive,
                    Type         = ProfitType.InvitePiiiPos,
                    OrderNo      = CreateOrderno(),
                    Timestamp    = dtNow,
                    CryptoId     = invitorWallet.CryptoId,
                    CryptoCode   = "FIII"
                };
                profitId = pfDAC.Insert(profitDetail);

                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = invitorWallet.Id,
                    Action        = UserWalletStatementAction.Reward,
                    Amount        = rewardAmount,
                    Balance       = oldBalance + rewardAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = invitorWallet.FrozenBalance,
                    Timestamp     = dtNow
                });

                transDAC.Insert(new UserTransaction
                {
                    AccountId    = invitor.InviterAccountId,
                    Amount       = rewardAmount,
                    CryptoCode   = "FIII",
                    CryptoId     = fiiicoinId,
                    DetailId     = profitId.ToString(),
                    Id           = Guid.NewGuid(),
                    MerchantName = string.Empty,
                    OrderNo      = profitDetail.OrderNo,
                    Status       = 2,
                    Timestamp    = dtNow,
                    Type         = UserTransactionType.Profit
                });

                distributeRecord.ProfitId = profitId;
                rdrDAC.Insert(distributeRecord);

                scope.Complete();
            }

            if (profitId > 0)
            {
                try
                {
                    MessagePushService.PubUserInviteSuccessed(profitId, 0);
                }
                catch (Exception ex)
                {
                    throw new CommonException(10000, ex.Message);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 插入记录
        /// </summary>
        /// <param name="inviteCode">邀请码</param>
        /// <param name="accoundId">被邀请人id</param>
        /// /// <param name="type">1:fiiipay 2:fiiipos</param>
        public void InsertRecord(InviteRecordIM im)
        {
            //判断是fiiipos还是fiiipay

            //1 插入数据 invite profit两个表 邀请双方都支持插入数据 钱包 流水进行更新
            // 判断当前邀请人数到达五十 进行推送。。。。。。。。。。。。

            //2 插入数据 invite
            if (!(im.Type == (int)SystemPlatform.FiiiPay || im.Type == (int)SystemPlatform.FiiiPOS))
            {
                throw new ArgumentException("只支持fiiipay和fiiipos邀请");
            }
            var userAccountDAC    = new UserAccountDAC();
            var account           = userAccountDAC.GetByInvitationCode(im.InvitationCode);
            var settingCollection = new MasterSettingDAC().SelectByGroup("InviteReward");
            var cryptoCurrencty   = new CryptocurrencyDAC().GetByCode("FIII");
            var cryptoId          = cryptoCurrencty.Id;

            if (im.Type == (int)SystemPlatform.FiiiPay)
            {
                var iDAC        = new InviteRecordDAC();
                var pfDAC       = new ProfitDetailDAC();
                var uwComponent = new UserWalletComponent();

                var uwDAC  = new UserWalletDAC();
                var uwsDAC = new UserWalletStatementDAC();
                var utDAC  = new UserTransactionDAC();

                var inviteMoney  = decimal.Parse(settingCollection.Where(item => item.Name == "Invite_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var rewardMoney  = decimal.Parse(settingCollection.Where(item => item.Name == "Over_People_Count_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var maxCount     = decimal.Parse(settingCollection.Where(item => item.Name == "Max_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var orderNo1     = CreateOrderno();
                var orderNo2     = CreateOrderno();
                var inviteWallet = uwComponent.GetUserWallet(account.Id, cryptoId);
                if (inviteWallet == null)
                {
                    inviteWallet = uwComponent.GenerateWallet(account.Id, cryptoId);
                }

                var beInvitedWallet = uwComponent.GetUserWallet(im.BeInvitedAccountId, cryptoId);
                if (beInvitedWallet == null)
                {
                    beInvitedWallet = uwComponent.GenerateWallet(im.BeInvitedAccountId, cryptoId);
                }

                int     inviteId;
                long    profitId1    = 0; //邀请人奖励ID
                long    profitId2    = 0; //被邀请人奖励ID
                long    exProfitId1  = 0; //邀请人额外奖励ID
                decimal totalReward  = pfDAC.GetTotalReward(account);
                int     invitedCount = pfDAC.GetInvitedCount(account);

                using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
                {
                    //插入数据到inviterecord表中
                    inviteId = iDAC.Insert(new InviteRecord()
                    {
                        Type = (InviteType)im.Type, AccountId = im.BeInvitedAccountId, Timestamp = DateTime.UtcNow, InviterCode = im.InvitationCode, InviterAccountId = account.Id
                    });

                    if (totalReward < maxCount)
                    {
                        profitId1 = pfDAC.Insert(new ProfitDetail()
                        {
                            InvitationId = inviteId,
                            CryptoAmount = inviteMoney,
                            AccountId    = account.Id,
                            Status       = InviteStatusType.IssuedFrozen,
                            Type         = ProfitType.InvitePiiiPay,
                            OrderNo      = orderNo1,
                            Timestamp    = DateTime.UtcNow,
                            CryptoId     = cryptoId
                        });

                        utDAC.Insert(new UserTransaction
                        {
                            Id         = Guid.NewGuid(),
                            AccountId  = account.Id,
                            CryptoId   = cryptoCurrencty.Id,
                            CryptoCode = cryptoCurrencty.Code,
                            Type       = UserTransactionType.Profit,
                            DetailId   = profitId1.ToString(),
                            Status     = (byte)InviteStatusType.IssuedFrozen,
                            Timestamp  = DateTime.UtcNow,
                            Amount     = inviteMoney,
                            OrderNo    = orderNo1
                        });

                        uwDAC.IncreaseFrozen(inviteWallet.Id, inviteMoney);

                        uwsDAC.Insert(new UserWalletStatement
                        {
                            WalletId      = inviteWallet.Id,
                            Action        = UserWalletStatementAction.Invite,
                            Amount        = 0,
                            Balance       = inviteWallet.Balance,
                            FrozenAmount  = inviteMoney,
                            FrozenBalance = inviteWallet.FrozenBalance + inviteMoney,
                            Timestamp     = DateTime.UtcNow
                        });

                        // 每当满50人时则可以奖励 采用了插入操作 所以只要满足为49个就可以了
                        if ((invitedCount + 1) % 50 == 0)
                        {
                            var pd50 = new ProfitDetail()
                            {
                                InvitationId = inviteId,
                                CryptoAmount = rewardMoney,
                                AccountId    = account.Id,
                                Status       = InviteStatusType.IssuedFrozen,
                                Type         = ProfitType.Reward,
                                OrderNo      = CreateOrderno(),
                                Timestamp    = DateTime.UtcNow,
                                CryptoId     = cryptoId
                            };
                            exProfitId1 = pfDAC.Insert(pd50);

                            utDAC.Insert(new UserTransaction
                            {
                                Id         = Guid.NewGuid(),
                                AccountId  = account.Id,
                                CryptoId   = cryptoCurrencty.Id,
                                CryptoCode = cryptoCurrencty.Code,
                                Type       = UserTransactionType.Profit,
                                DetailId   = exProfitId1.ToString(),
                                Status     = (byte)InviteStatusType.IssuedFrozen,
                                Timestamp  = DateTime.UtcNow,
                                Amount     = rewardMoney,
                                OrderNo    = pd50.OrderNo
                            });

                            uwDAC.IncreaseFrozen(inviteWallet.Id, rewardMoney);

                            uwsDAC.Insert(new UserWalletStatement
                            {
                                WalletId      = inviteWallet.Id,
                                Action        = UserWalletStatementAction.Invite,
                                Amount        = 0,
                                Balance       = inviteWallet.Balance,
                                FrozenAmount  = rewardMoney,
                                FrozenBalance = inviteWallet.FrozenBalance + inviteMoney + rewardMoney,
                                Timestamp     = DateTime.UtcNow
                            });
                        }
                        profitId2 = pfDAC.Insert(new ProfitDetail()
                        {
                            InvitationId = inviteId,
                            CryptoAmount = inviteMoney,
                            AccountId    = im.BeInvitedAccountId,
                            Type         = ProfitType.BeInvited,
                            Status       = InviteStatusType.IssuedActive,
                            OrderNo      = orderNo2,
                            Timestamp    = DateTime.UtcNow,
                            CryptoId     = cryptoId
                        });
                        utDAC.Insert(new UserTransaction
                        {
                            Id         = Guid.NewGuid(),
                            AccountId  = im.BeInvitedAccountId,
                            CryptoId   = cryptoCurrencty.Id,
                            CryptoCode = cryptoCurrencty.Code,
                            Type       = UserTransactionType.Profit,
                            DetailId   = profitId2.ToString(),
                            Status     = (byte)InviteStatusType.IssuedActive,
                            Timestamp  = DateTime.UtcNow,
                            Amount     = inviteMoney,
                            OrderNo    = orderNo2
                        });
                        uwDAC.Increase(beInvitedWallet.Id, inviteMoney);
                        uwsDAC.Insert(new UserWalletStatement
                        {
                            WalletId      = beInvitedWallet.Id,
                            Action        = UserWalletStatementAction.BeInvite,
                            Amount        = inviteMoney,
                            Balance       = beInvitedWallet.Balance + inviteMoney,
                            FrozenAmount  = 0,
                            FrozenBalance = beInvitedWallet.FrozenBalance,
                            Timestamp     = DateTime.UtcNow
                        });
                    }
                    scope.Complete();
                }

                if (!(im.Type == (int)SystemPlatform.FiiiPay || im.Type == (int)SystemPlatform.FiiiPOS))
                {
                    throw new ArgumentException("只支持fiiipay和fiiipos邀请");
                }

                if (im.Type == (int)SystemPlatform.FiiiPay)
                {
                    UserMSMQ.PubUserInviteSuccessed(profitId2, 0);
                }
                //else if (im.Type == SystemPlatform.FiiiPOS)
                //    MerchantMSMQ.PubUserInviteSuccessed(profitId2, 0);
            }
            //else
            //{
            //    var iDAC = new InviteRecordDAC();
            //    iDAC.Insert(new InviteRecord() { Type = im.Type, AccountId = im.BeInvitedAccountId, Timestamp = DateTime.UtcNow, InviterCode = im.InvitationCode, InviterAccountId = account.Id });
            //}
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public void DistributeRewards(FiiiPayRewardMessage message, DateTime dt)
        {
            if (fiiicoinId == 0)
            {
                var fiiicoin = new CryptocurrencyDAC().GetByCode("FIII");
                fiiicoinId = fiiicoin.Id;
            }
            MerchantAccountDAC maDAC = new MerchantAccountDAC();
            var merchant             = maDAC.GetByUsername(message.Account);

            if (merchant == null)
            {
                throw new CommonException(10000, $"无效的商家名:{message.Account}");
            }

            InviteRecord invitor = GetInvitor(merchant.Id);

            if (invitor == null)
            {
                throw new CommonException(10000, "没有邀请人");
            }

            var invitedList = new InviteRecordDAC().GetFiiiPosRecordsByInvitorId(invitor.InviterAccountId, InviteType.Fiiipos);
            var rewardRate  = GetRewardPercentage(invitedList == null ? 0 : invitedList.Count);

            if (rewardRate == 0)
            {
                throw new CommonException(10000, "没有达到奖励条件");
            }

            decimal t            = (decimal)Math.Pow(10, -8);
            long    nTotalReward = (long)Math.Floor(message.ActualReward * rewardRate);

            if (nTotalReward == 0)
            {
                throw new CommonException(10000, "奖励金额为0");
            }
            decimal rewardAmount     = nTotalReward * t;
            var     distributeRecord = new RewardDistributeRecords
            {
                UserAccountId     = invitor.InviterAccountId,
                MerchantAccountId = merchant.Id,
                SN             = message.SN,
                OriginalReward = message.ActualReward,
                Percentage     = rewardRate,
                ActualReward   = rewardAmount,
                Timestamp      = dt
            };

            long    profitId      = 0;
            decimal oldBalance    = 0;
            var     invitorWallet = uwDAC.GetByAccountId(invitor.InviterAccountId, fiiicoinId);

            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                if (invitorWallet == null)
                {
                    invitorWallet = CreateWallet(invitor.InviterAccountId, fiiicoinId, rewardAmount);
                }
                else
                {
                    oldBalance = invitorWallet.Balance;
                    uwDAC.Increase(invitorWallet.Id, rewardAmount);
                }
                profitId = pfDAC.Insert(new ProfitDetail()
                {
                    InvitationId = invitor.Id,
                    CryptoAmount = rewardAmount,
                    AccountId    = invitor.InviterAccountId,
                    Status       = InviteStatusType.IssuedActive,
                    Type         = ProfitType.InvitePiiiPos,
                    OrderNo      = CreateOrderno(),
                    Timestamp    = dt,
                    CryptoId     = invitorWallet.CryptoId
                });
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = invitorWallet.Id,
                    Action        = UserWalletStatementAction.Reward,
                    Amount        = rewardAmount,
                    Balance       = oldBalance + rewardAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = invitorWallet.FrozenBalance,
                    Timestamp     = dt,
                    Remark        = "System"
                });

                distributeRecord.ProfitId = profitId;
                rdrDAC.Insert(distributeRecord);

                new TempDataDAC().MessageComplated(message.Id);

                scope.Complete();
            }
        }