public void VerifyGoogleAuthByMerchantAccount(string googleCode, string merchantAccount)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetByUsername(merchantAccount);

            SecurityVerify.Verify(new GoogleVerifier(), SystemPlatform.FiiiPOS, account.Id.ToString(), account.AuthSecretKey, googleCode);
            var model = SecurityVerify.GetModel <BindAccountVerify>(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merchantAccount);

            model.GoogleVerified = true;
            SecurityVerify.SetModel(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merchantAccount, model);
        }
        public void VerifyPINByMerchantAccount(string pin, string merchantAccount)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetByUsername(merchantAccount);

            SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiPOS, account.Id.ToString(), account.PIN, pin);
            var model = SecurityVerify.GetModel <BindAccountVerify>(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merchantAccount);

            model.PinVerified = true;
            SecurityVerify.SetModel(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merchantAccount, model);
        }
        public AccountNeedVerifyInfo VerifyMerchantAccount(int countryId, string cellphone, string code, string merchantAccount)
        {
            SecurityVerify.Verify(new BindAccountCellphoneVerifier(), SystemPlatform.FiiiPOS, merchantAccount, code);

            var accountDac = new MerchantAccountDAC();
            var account    = accountDac.GetByUsername(merchantAccount);

            if (account == null)
            {
                throw new GeneralException(Resources.AccountNotExists);
            }

            var country = new CountryComponent().GetById(countryId);

            if (country == null)
            {
                throw new CommonException(10000, Resources.国家不存在);
            }

            string fullCellphone = $"{account.PhoneCode}{account.Cellphone}";

            if (!string.Equals(fullCellphone, country.PhoneCode + cellphone, StringComparison.InvariantCulture))
            {
                throw new GeneralException(Resources.当前手机号与账号绑定的手机号不一致);
            }

            var model = new BindAccountVerify
            {
                MerchantAccount   = merchantAccount,
                CellphoneVerified = true
            };

            SecurityVerify.SetModel(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merchantAccount, model);

            return(new AccountNeedVerifyInfo
            {
                PIN = true,
                GoogleAuth = ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator)
            });
        }
예제 #4
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);
                }
            }
        }
        public SignonDTO BindingAccount(string merhcantAccount, string posSN)
        {
            var             accountDac = new MerchantAccountDAC();
            MerchantAccount account    = accountDac.GetByUsername(merhcantAccount);

            SecurityVerify.Verify <BindAccountVerify>(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merhcantAccount, (model) =>
            {
                bool result = true;
                result      = result && merhcantAccount.Equals(model.MerchantAccount);
                result      = result && model.CellphoneVerified && model.PinVerified;
                if (account == null)
                {
                    return(false);
                }
                if (ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator))
                {
                    result = result && model.GoogleVerified;
                }
                return(result);
            });

            var posDac = new POSDAC();

            if (account.Status == AccountStatus.Locked)
            {
                throw new CommonException(ReasonCode.ACCOUNT_LOCKED, Resources.帐号已锁定);
            }

            var pos = posDac.GetBySn(posSN);

            if (pos == null)
            {
                throw new GeneralException(Resources.SN码不存在);
            }

            if (account.POSId.HasValue)
            {
                if (account.POSId == pos.Id)
                {
                    throw new GeneralException(Resources.AccountHasBoundThisPOS);
                }
                else
                {
                    throw new GeneralException(Resources.AccountHasBoundOtherPOS);
                }
            }

            if (pos.Status)
            {
                throw new GeneralException(Resources.POSHasBoundOtherAccount);
            }

            UserAccount userAccount = null;

            if (!string.IsNullOrEmpty(account.InvitationCode))
            {
                userAccount = new UserAccountDAC().GetByInvitationCode(account.InvitationCode);
            }

            POSMerchantBindRecord posBindRecord = new POSMerchantBindRecord
            {
                POSId            = pos.Id,
                SN               = pos.Sn,
                MerchantId       = account.Id,
                MerchantUsername = account.Username,
                BindTime         = DateTime.UtcNow,
                BindStatus       = (byte)POSBindStatus.Binded
            };

            using (var scope = new TransactionScope())
            {
                account.POSId = pos.Id;
                accountDac.BindPos(account);
                posDac.ActivePOS(pos);
                new POSMerchantBindRecordDAC().Insert(posBindRecord);
                if (!string.IsNullOrEmpty(account.InvitationCode) && userAccount != null)
                {
                    ReBindInviter(posSN, account.Id, userAccount.Id, account.InvitationCode);
                }

                scope.Complete();
            }

            return(GetAccessToken(pos, account));
        }
예제 #6
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();
            }
        }