繁体   English   中英

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

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

我完全不知道正确的方法来做到这一点(更不用说最好的方法了)。

我有一组共享比特币数量的用户。 我们每天共同交易和分享利润(减去一小部分归我管理)。

我正在尝试建立一个系统来准确计算利润和费用,但我就是想不出办法。

这些是我在 mysql 数据库中创建的表:

tansactions:(此信息是从交易所 api 中提取的)

  • id(主键)
  • 交易ID(唯一)
  • 交易类型(存款、盈利/亏损、取款)
  • 金额(btc 入金金额、盈亏、取款)
  • 余额(交易后余额)
  • 时间戳(交易的时间戳)

用户:

  • id(主键)
  • 昵称(人名)

会计:

  • id(主键)
  • userId(来自用户表的 ID)
  • 交易类型(存款、盈利/亏损、取款)
  • 金额(btc 存款金额、计算利润、提款)
  • 日期

在我的脑海中,我想我会运行一个每晚的脚本来计算每个人的利润百分比并将其记录到当天的会计表中。

我在想会计表在夜间脚本中可能看起来像这样:

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.

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