[英]PHP+mysql : What would be the simplest way to calculate individual profits from a transaction list containing deposits, gains and withdrawals
我完全不知道正確的方法來做到這一點(更不用說最好的方法了)。
我有一組共享比特幣數量的用戶。 我們每天共同交易和分享利潤(減去一小部分歸我管理)。
我正在嘗試建立一個系統來准確計算利潤和費用,但我就是想不出辦法。
這些是我在 mysql 數據庫中創建的表:
tansactions:(此信息是從交易所 api 中提取的)
用戶:
會計:
在我的腦海中,我想我會運行一個每晚的腳本來計算每個人的利潤百分比並將其記錄到當天的會計表中。
我在想會計表在夜間腳本中可能看起來像這樣:
Date Transaction Amount Person / System
1/02/2021 Deposit 0.10000000 Person 1
2/02/2021 Profit 0.00041235 System
3/02/2021 Profit 0.00032456 System
4/02/2021 Profit 0.00021435 System
5/02/2021 Deposit 0.13234000 Person 2
6/02/2021 Profit 0.00152390 System
7/02/2021 Profit 0.00143540 System
8/02/2021 Profit 0.00325476 System
9/02/2021 Profit 0.00462534 System
10/02/2021 Deposit 0.00432100 Person 2
11/02/2021 Deposit 0.00625300 Person 3
12/02/2021 Profit 0.00876000 System
13/02/2021 Profit 0.00453720 System
14/02/2021 Profit 0.00642620 System
15/02/2021 Profit 0.00754000 System
16/02/2021 Withdraw 0.00087640 Person 1
17/02/2021 Profit 0.00245300 System
18/02/2021 Withdraw 0.00032625 Person 2
19/02/2021 Profit 0.00134432 System
20/02/2021 Deposit 0.01234500 Person 3
我想不出一個簡單的方法來計算每天的利潤......
任何指導/建議/幫助將不勝感激!
想通了。。
簡而言之,這里是循環(不是最有效的方式,但它有效)
foreach(user)
{
check initial deposit amount and date
make an array of every date since
foreach(date since)
{
check what the whole account did on that day
calculate this user's percentage on that day
if there is a withdraw / deposit, handle that too
}
}
含糊不清,但希望能解釋邏輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.