简体   繁体   English

PHP + mysql:从包含存款,收益和取款的交易列表中计算个人利润的最简单方法是什么

[英]PHP+mysql : What would be the simplest way to calculate individual profits from a transaction list containing deposits, gains and withdrawals

I'm absolutely stumped on the right way to do this (let alone the best way).我完全不知道正确的方法来做到这一点(更不用说最好的方法了)。

I have a group of users with shared quantities of bitcoins.我有一组共享比特币数量的用户。 We collectively trade and share the profits each day (minus a small percentage which goes to me for the management).我们每天共同交易和分享利润(减去一小部分归我管理)。

I'm trying to build a system to accurately calculate profits and fees but I just can't figure out the way to do it.我正在尝试建立一个系统来准确计算利润和费用,但我就是想不出办法。

These are the tables I've created in the mysql db:这些是我在 mysql 数据库中创建的表:

tansactions: (this information is pulled from the exchange api) tansactions:(此信息是从交易所 api 中提取的)

  • id (primary key) id(主键)
  • transactionID (unique)交易ID(唯一)
  • transactionType (Deposit, Profit/Loss, Withdrawal)交易类型(存款、盈利/亏损、取款)
  • amount (btc amount of deposit, profit or loss, withdrawal)金额(btc 入金金额、盈亏、取款)
  • balance (balance after transaction)余额(交易后余额)
  • timestamp (timestamp of the transaction)时间戳(交易的时间戳)

users:用户:

  • id (primary key) id(主键)
  • nickname (person's name)昵称(人名)

accounting:会计:

  • id (primary key) id(主键)
  • userId (id from users table) userId(来自用户表的 ID)
  • transactionType (Deposit, Profit/Loss, Withdrawal)交易类型(存款、盈利/亏损、取款)
  • amount (btc amount of deposits, calculated profits, withdrawal)金额(btc 存款金额、计算利润、提款)
  • date日期

In my mind, I was thinking I would run a nightly script that would calculate the percentage of each person's profits and record it to the accounting table for that day.在我的脑海中,我想我会运行一个每晚的脚本来计算每个人的利润百分比并将其记录到当天的会计表中。

I was thinking the accounting table could look something like this with the nightly script:我在想会计表在夜间脚本中可能看起来像这样:

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

I can't think of an easy way to calculate the profit daily...我想不出一个简单的方法来计算每天的利润......

Any guidance / advice / help would be greatly appreciated!任何指导/建议/帮助将不胜感激!

Figured this out..想通了。。

In short, here are the loops (not the most efficient way but, it works)简而言之,这里是循环(不是最有效的方式,但它有效)

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
      
   }


}

vague but hopefully explains the logic.含糊不清,但希望能解释逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM