Example #1
0
        public void SubmitWithdrawal(CreateWithdrawModel model)
        {
            if (model.AccountType == AccountTypeEnum.Merchant)
            {
                var withdrawalDAC = new MerchantWithdrawalDAC();
                var withdrawal    = withdrawalDAC.GetById(model.WithdrawalId);
                if (withdrawal == null || withdrawal.Status != Entities.Enums.TransactionStatus.UnSubmit)
                {
                    LogHelper.Info("Invalid withdrawal id or invalid withdrawal status");
                    return;
                }

                var agent = new FiiiFinanceAgent();

                try
                {
                    var requestInfo = agent.CreateWithdraw(model);

                    if (requestInfo.Code == 0)
                    {
                        withdrawalDAC.WithdrawalSubmited(model.WithdrawalId, requestInfo.RequestID,
                                                         requestInfo.TransactionId);
                    }
                    else if (requestInfo.Code == 20002 || requestInfo.Code == 300001)
                    {
                        var merchantWalletDac = new MerchantWalletDAC();
                        var merchantWallet    = merchantWalletDac.GetById(withdrawal.MerchantWalletId);
                        using (var scope = new TransactionScope())
                        {
                            try
                            {
                                withdrawalDAC.RejectById(withdrawal.Id, "Invalid address");
                                merchantWalletDac.Unfreeze(merchantWallet.Id, withdrawal.Amount);
                                new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                                {
                                    WalletId  = merchantWallet.Id,
                                    Action    = UserWalletStatementAction.Withdrawal,
                                    Amount    = withdrawal.Amount,
                                    Balance   = merchantWallet.Balance + withdrawal.Amount,
                                    Timestamp = DateTime.UtcNow
                                });
                                scope.Complete();
                            }
                            catch (Exception exception)
                            {
                                _log.Error(exception);
                            }
                        }
                    }
                    else
                    {
                        RabbitMQSender.SendMessage("WithdrawSubmit_Delay", model);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error($"UpdateTransactionId erorr, message:{JsonConvert.SerializeObject(model)}", ex);

                    RabbitMQSender.SendMessage("WithdrawSubmit_Delay", model);
                }
            }
            else if (model.AccountType == AccountTypeEnum.User)
            {
                var withdrawalDAC = new UserWithdrawalDAC();
                var withdrawal    = withdrawalDAC.GetById(model.WithdrawalId);
                if (withdrawal == null || withdrawal.Status != Entities.Enums.TransactionStatus.UnSubmit)
                {
                    LogHelper.Info("Invalid withdrawal id or invalid withdrawal status");
                    return;
                }

                var agent = new FiiiFinanceAgent();

                try
                {
                    var requestInfo = agent.CreateWithdraw(model);

                    if (requestInfo.Code == 0)
                    {
                        withdrawalDAC.WithdrawalSubmited(model.WithdrawalId, requestInfo.RequestID, requestInfo.TransactionId);
                    }
                    else if (requestInfo.Code == 20002 || requestInfo.Code == 300001)
                    {
                        var userWalletDac = new UserWalletDAC();
                        var userWallet    = userWalletDac.GetById(withdrawal.UserWalletId);
                        using (TransactionScope scope = new TransactionScope())
                        {
                            try
                            {
                                withdrawalDAC.RejectById(withdrawal.Id, "Invalid address");
                                userWalletDac.Unfreeze(withdrawal.UserWalletId, withdrawal.Amount);

                                new UserWalletStatementDAC().Insert(new Entities.UserWalletStatement
                                {
                                    WalletId      = userWallet.Id,
                                    Action        = Entities.UserWalletStatementAction.Withdrawal,
                                    Amount        = withdrawal.Amount,
                                    Balance       = userWallet.Balance + withdrawal.Amount,
                                    FrozenAmount  = -withdrawal.Amount,
                                    FrozenBalance = userWallet.FrozenBalance - withdrawal.Amount,
                                    Timestamp     = DateTime.UtcNow
                                });

                                scope.Complete();
                            }
                            catch (Exception exception)
                            {
                                _log.Error(exception);
                            }
                        }
                    }
                    else
                    {
                        RabbitMQSender.SendMessage("WithdrawSubmit_Delay", model);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error($"UpdateTransactionId erorr, message:{JsonConvert.SerializeObject(model)}", ex);
                    RabbitMQSender.SendMessage("WithdrawSubmit_Delay", model);
                }
            }
            else
            {
                LogHelper.Info("Invalid AccountType");
            }
        }
Example #2
0
        public SaveResult SaveProfileVerify(int AdminId, string AdminName, UserProfile profile)
        {
            var oldProfile  = GetUserProfile(profile.UserAccountId.Value);
            var userAccount = FiiiPayDB.UserAccountDb.GetById(profile.UserAccountId);

            userAccount.L1VerifyStatus = profile.L1VerifyStatus.Value;
            if (oldProfile == null)
            {
                return(new SaveResult(false, "Data error"));
            }

            var profileSDK = new UserProfileAgent();
            int count      = profileSDK.GetCountByIdentityDocNo(profile.UserAccountId.Value, oldProfile.IdentityDocNo);

            if (profile.L1VerifyStatus == VerifyStatus.Certified && count > 6)
            {
                return(new SaveResult(false, "This identty document has been used for 7 accounts, cannot be verified "));
            }
            long profitId   = 0; //被邀请人奖励ID
            long exProfitId = 0; //邀请人额外奖励ID

            bool result = profileSDK.UpdateL1Status(profile.UserAccountId.Value, profile.L1VerifyStatus.Value, profile.L1Remark);

            if (result)
            {
                FiiiPayDB.UserAccountDb.Update(userAccount);
            }
            else
            {
                profileSDK.UpdateL1Status(profile.UserAccountId.Value, oldProfile.L1VerifyStatus.Value, oldProfile.L1Remark);
            }

            if (result && profile.L1VerifyStatus == VerifyStatus.Certified)
            {
                var invite = FiiiPayDB.DB.Queryable <InviteRecords>().Where(t => t.AccountId == profile.UserAccountId.Value).First();
                if (invite != null)
                {
                    var inviteProfit = FiiiPayDB.DB.Queryable <ProfitDetails>().Where(t => t.AccountId == invite.InviterAccountId && t.InvitationId == invite.Id && t.Type == ProfitType.InvitePiiiPay).First();
                    var rewardProfit = FiiiPayDB.DB.Queryable <ProfitDetails>().Where(t => t.AccountId == invite.InviterAccountId && t.Status == InviteStatusType.IssuedFrozen && t.Type == ProfitType.Reward).OrderBy(t => t.Timestamp).First();

                    profitId = inviteProfit.Id;
                    var uwComponent = new UserWalletBLL();
                    var uwsDAC      = new UserWalletStatementDAC();
                    var uwDAC       = new UserWalletDAC();
                    var pfDAC       = new ProfitDetailDAC();
                    var utDAC       = new UserTransactionDAC();

                    int invitedCount = pfDAC.GetInvitedAndActiveCount(invite.InviterAccountId);

                    var cryptoId     = new CryptocurrencyDAC().GetByCode("FIII").Id;
                    var inviteWallet = uwComponent.GetUserWallet(invite.InviterAccountId, cryptoId);
                    if (inviteWallet == null)
                    {
                        inviteWallet = uwComponent.GenerateWallet(invite.InviterAccountId, cryptoId);
                    }

                    var inviteMoney = inviteProfit.CryptoAmount;

                    var adoResult = FiiiPayDB.DB.Ado.UseTran(() =>
                    {
                        try
                        {
                            //解冻奖励
                            uwDAC.Unfreeze(inviteWallet.Id, inviteMoney);
                            //插入奖励流水
                            uwsDAC.Insert(new UserWalletStatement
                            {
                                WalletId  = inviteWallet.Id,
                                Action    = UserWalletStatementAction.Invite,
                                Amount    = inviteMoney,
                                Balance   = inviteWallet.Balance + inviteMoney,
                                Timestamp = DateTime.UtcNow
                            });
                            //修改奖励状态为已激活
                            pfDAC.UpdateStatus(inviteProfit.Id, InviteStatusType.IssuedActive);
                            utDAC.UpdateStatus(UserTransactionType.Profit, inviteProfit.Id.ToString(), invite.InviterAccountId, (byte)InviteStatusType.IssuedActive);

                            // 每当满50人时则可以奖励 采用了插入操作 所以只要满足为49个就可以了
                            if ((invitedCount + 1) % 50 == 0)
                            {
                                exProfitId      = rewardProfit.Id;
                                var rewardMoney = rewardProfit.CryptoAmount;
                                //解冻满50人的额外奖励
                                uwDAC.Unfreeze(inviteWallet.Id, rewardMoney);
                                //插入满50人的额外奖励流水
                                uwsDAC.Insert(new UserWalletStatement
                                {
                                    WalletId  = inviteWallet.Id,
                                    Action    = UserWalletStatementAction.Reward,
                                    Amount    = rewardMoney,
                                    Balance   = inviteWallet.Balance + rewardMoney,
                                    Timestamp = DateTime.UtcNow
                                });
                                //修改奖励状态为已激活
                                pfDAC.UpdateStatus(rewardProfit.Id, InviteStatusType.IssuedActive);
                                utDAC.UpdateStatus(UserTransactionType.Profit, rewardProfit.Id.ToString(), invite.InviterAccountId, (byte)InviteStatusType.IssuedActive);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Info(profile.UserAccountId + "    --------- " + e.ToString());
                        }
                    });
                    result = adoResult.Data;
                }
            }

            if (result && (profile.L1VerifyStatus == VerifyStatus.Certified || profile.L1VerifyStatus == VerifyStatus.Disapproval))
            {
                var recordId = FiiiPayDB.VerifyRecordDb.InsertReturnIdentity(new VerifyRecords()
                {
                    AccountId  = profile.UserAccountId.Value,
                    Username   = userAccount.Cellphone,
                    Body       = profile.L1Remark,
                    Type       = profile.L1VerifyStatus == VerifyStatus.Certified ? VerifyRecordType.UserLv1Verified : VerifyRecordType.UserLv1Reject,
                    CreateTime = DateTime.UtcNow
                });
                if (profile.L1VerifyStatus == VerifyStatus.Certified)
                {
                    RabbitMQSender.SendMessage("UserKYC_LV1_VERIFIED", recordId);
                }
                else if (profile.L1VerifyStatus == VerifyStatus.Disapproval)
                {
                    RabbitMQSender.SendMessage("UserKYC_LV1_REJECT", recordId);
                }
            }

            if (result && profitId > 0)
            {
                RabbitMQSender.SendMessage("UserInviteSuccessed", profitId);
            }
            if (result && exProfitId > 0)
            {
                RabbitMQSender.SendMessage("UserInviteSuccessed", profitId);
            }
            ActionLog actionLog = new ActionLog();

            actionLog.IPAddress  = GetClientIPAddress();
            actionLog.AccountId  = AdminId;
            actionLog.CreateTime = DateTime.UtcNow;
            actionLog.ModuleCode = typeof(UserProfileBLL).FullName + ".SaveProfileVerify";
            actionLog.Username   = AdminName;
            actionLog.LogContent = string.Format("verify user profile.accountId:{0},verifystatus:{1}", profile.UserAccountId, profile.L1VerifyStatus.ToString());
            new ActionLogBLL().Create(actionLog);

            return(new SaveResult(result));
        }