public async Task<IActionResult> AccountSubtractWallet(AccountType type = AccountType.All, int payoutid = 0) { AccountType[] _accounttype; if (type == AccountType.All) { _accounttype = new AccountType[4]; _accounttype[0] = AccountType.Regular; _accounttype[1] = AccountType.HotFacebooker; _accounttype[2] = AccountType.HotMom; _accounttype[3] = AccountType.HotTeen; //_accounttype[4] = AccountType.Kols; } else { _accounttype = new AccountType[1]; _accounttype[0] = type; } int count_fail = 0; var PayoutExport = await _IPayoutExportService.GetPayoutExport(payoutid); var _listTransaction = await _ITransactionBussiness.GetTotalPayoutTransactions(TransactionType.CampaignAccountPayback, TransactionStatus.Completed, _accounttype.ToList(), PayoutExport.StartDateExport.Date, PayoutExport.EndDateExport.Date); if (_listTransaction.Transactions.Count > 0) { foreach(var item in _listTransaction.Transactions) { if (item.Wallet.Balance == 0 || item.Wallet.Balance < item.TotalCashOut) continue; int senderid = item.Wallet.Id; int receiverid = 1; //walletid of system long money_number = item.TotalCashOut; int campaignid = 0; int accountid = item.Account.Id; string txt_note = string.Format("Hệ thống thực hiện trừ tiền {0} đ trên ví walletid = {1},{2}, " + "vì hệ thống đã chuyển {3} đ đến tài khoản ngân hàng của thành viên {4} thuộc walletid={5}. Và cộng {6} đ vào ví walletid={7}", money_number, senderid, item.Account.Name, money_number, item.Account.Name, senderid, money_number, receiverid); int transactionid = await _ITransactionRepository.CreateTransaction(senderid, receiverid, money_number, TransactionType.ExcecutedPaymentToAccountBanking, txt_note, string.Format("Campaign ID = {0}", campaignid), HttpContext.User.Identity.Name, campaignid); if (transactionid > 0) // nếu tạo transaction thành công { int retResult = await _ITransactionBussiness.CalculateBalance(transactionid, money_number, senderid, receiverid, "[Chuyển tiền đến tài khoản ngân hàng của thành viên][ExcecutedPaymentToAccountBanking]", HttpContext.User.Identity.Name); /* * 09: success * 10: wallet do not exist * 11: wallet balance sender or receiver less then zero or amount could be abstract * */ try { switch (retResult) { case 9: //int retValue = _ITransactionBussiness.UpdateCashOut(item.Id); await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Completed, "Success", HttpContext.User.Identity.Name);// //await _ITransactionRepository.UpdateTransactionStatus(item.Id, TransactionStatus.Completed, "Success", HttpContext.User.Identity.Name);// delete transaction if case error NotificationType notificationType = NotificationType.ExcecutedPaymentToAccountBanking; string msg = string.Format("Hệ thống đã chuyển tiền {0} đ tới tài khoản ngân hàng của bạn và tự động trừ tiền trong ví tương ứng với số tiền {1}, " + "từ chiến dịch bạn đã hoàn thành.", money_number, money_number); await _INotificationBusiness.CreateNotificationExcecutedPaymentToAccountBanking(campaignid, accountid, notificationType, msg, ""); try { var payoutexportEntity = _IPayoutExportRepository.GetById(payoutid); payoutexportEntity.IsUpdateWallet = true; payoutexportEntity.PayoutPayDate = DateTime.Now; _IPayoutExportRepository.Update(payoutexportEntity); } catch {} break; case 10: await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "Wallet do not exist", HttpContext.User.Identity.Name);// delete transaction if case error //await _ITransactionRepository.UpdateTransactionStatus(item.Id, TransactionStatus.Completed, "Wallet do not exist", HttpContext.User.Identity.Name);// delete transaction if case error count_fail++; break; case 11: await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "Wallet balance sender or receiver less then zero or amount could be abstract", HttpContext.User.Identity.Name);// delete transaction if case error //await _ITransactionRepository.UpdateTransactionStatus(item.Id, TransactionStatus.Completed, "Wallet balance sender or receiver less then zero or amount could be abstract", HttpContext.User.Identity.Name);// delete transaction if case error count_fail++; break; case 12: await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "Wallet balance sender do not enought balance", HttpContext.User.Identity.Name);// delete transaction if case error //await _ITransactionRepository.UpdateTransactionStatus(item.Id, TransactionStatus.Completed, "Wallet balance sender do not enought balance", HttpContext.User.Identity.Name);// delete transaction if case error count_fail++; break; } } catch (Exception ex) { TempData["MessageError"] = ex.Message; } } } } return RedirectToAction("AccountPayback", "Transaction", new { type = type , payoutid = payoutid }); }
public async Task <IActionResult> MicroKolSubstractMoney(long money_number, string txt_note, int caid) { var filter = new CampaignAccountByIdSpecification(caid); var campaignaccount = _ICampaignAccountRepository.GetSingleBySpec(filter); //caid = campaignaccount id if (campaignaccount != null) { try { int senderid = await _IWalletRepository.GetWalletId(EntityType.Account, campaignaccount.AccountId); int recieverid = await _IWalletRepository.GetWalletId(EntityType.Agency, campaignaccount.Campaign.AgencyId); int campaignid = campaignaccount.Campaign.Id; //check xem đã trừ tiền chưa? if (_ITransactionBusiness.CheckExist(senderid, recieverid, TransactionType.CampaignAccountRefundAgency, campaignid)) { TempData["MessageError"] = "You was Refund money!"; } else { int transactionid = await _ITransactionRepository.CreateTransaction(senderid, recieverid, money_number, TransactionType.CampaignAccountRefundAgency, txt_note, string.Format("Campaign ID = {0}", campaignid), HttpContext.User.Identity.Name, campaignid); if (transactionid > 0) { int retValue = await _ITransactionBusiness.CalculateBalance(transactionid, money_number, senderid, recieverid, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency]", HttpContext.User.Identity.Name); /* * 09: success * 10: wallet do not exist * 11: wallet balance sender or receiver less then zero or amount could be abstract * */ try { switch (retValue) { case 9: TempData["MessageSuccess"] = "Success Refund Money"; campaignaccount.IsRefundToAgency = true; await _ICampaignAccountRepository.UpdateAsync(campaignaccount); await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Completed, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Success", HttpContext.User.Identity.Name); // delete transaction if case error //############# send notification to agency ############################################ string message = string.Format("Tiền \"{0}\" trả cho Influencer \"{1}\" từ chiến dịch \"{2}\" đã được thu hồi về ví của bạn, do không thực hiện thành công.", money_number.ToPriceText(), campaignaccount.Account.Name, campaignaccount.Campaign.Title); await _INotificationService.CreateNotification(campaignaccount.CampaignId, EntityType.Agency, campaignaccount.Campaign.AgencyId, NotificationType.TransactionAccountRefundToAgency, message, ""); //###################################################################################### break; case 10: TempData["MessageError"] = "Wallet do not exist"; await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet do not exist", HttpContext.User.Identity.Name); // delete transaction if case error break; case 11: TempData["MessageError"] = "Wallet balance sender or receiver less then zero or amount could be abstract"; await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet balance sender or receiver less then zero or amount could be abstract", HttpContext.User.Identity.Name); // delete transaction if case error break; case 12: TempData["MessageError"] = "Wallet balance sender do not enought balance"; await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet balance sender do not enought balance", HttpContext.User.Identity.Name); // delete transaction if case error break; } } catch (Exception ex) { TempData["MessageError"] = ex.Message; } } else { TempData["MessageError"] = "Can't created transaction!"; } } } catch (Exception ex) { TempData["MessageError"] = ex.Message; } } else { TempData["MessageError"] = "Campaign Account NULL!"; } return(RedirectToAction("MicroKolSubstractMoney", "MicroKol", new { caid = caid })); }