gpt4 book ai didi

mysql - 循环记录并更新付费状态

转载 作者:行者123 更新时间:2023-11-30 23:19:12 25 4
gpt4 key购买 nike

我有三个表:

accounts:           `account_id`, `donations_req`, `payments_in, balance` 
donations_required: `donation_id`, `charity_id`, `account_id`, `amount`, `status`, `date`
payments: `payment_id`, `account_id`, `amount`, `date`

我已经设法计算每个捐赠者的所有 donations_req 并覆盖 donations_req 字段以及 payments_in 字段的付款和然后是余额(payments_in - donations_req)。

但是我需要的是;使用 payments_in 总数,遍历 donations_required 列表(按 date 排序)并将 status 更改为1 为已支付的。

例如:如果我有 3 笔捐款,每笔 50 美元,我存入 120 美元。余额为 -30 美元,前两笔捐款应标记为已支付。

考虑到在 donations_required 表中有不同的帐户,我该如何标记这样的状态。

我什至需要存储过程吗?

最佳答案

您可以使用存储过程来处理这个,但是您不需要循环所有的表,您只需要检查这个人是否有足够的余额。如果不是,您也可以更新付款 ID 和用户 ID 中的状态。

希望对你有帮助:) GBU

假设此人已捐赠了三笔慈善基金,可以是今天或第二天。

第一种情况,这个人同时捐了3笔捐款,所以可以通过存储过程来检查这个人是否有足够的余额或者在这种情况下你允许这个人捐赠超过它的余额

DROP PROCEDURE IF EXISTS `checkfunds`;
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `checkfunds`(IN `payment_id` VARCHAR(50), IN `account_id` VARCHAR(50), IN `amount` INT)
COMMENT 'This procedure check the Balance'
BEGIN
DECLARE balance INT;

SELECT BALANCE INTO balance from accounts where account_id = `account_id`
IF balance > 0 AND balance > 'amount' THEN
'allow'
ELSEIF balance < 0 AND balance < 'amount' THEN
'Not allow' <-- since you are here then update the status payment and your amount within your own calculation
END IF;
END//
DELIMITER ;

希望对你有帮助

关于mysql - 循环记录并更新付费状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16291965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com