【问题标题】:PHP+mysql : What would be the simplest way to calculate individual profits from a transaction list containing deposits, gains and withdrawalsPHP + mysql:从包含存款,收益和取款的交易列表中计算个人利润的最简单方法是什么
【发布时间】:2021-05-21 08:26:23
【问题描述】:

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

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

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

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

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

  • id(主键)
  • transactionID(唯一)
  • transactionType(存款、盈亏、取款)
  • 金额(btc 入金、盈亏、取款金额)
  • 余额(交易后余额)
  • timestamp(交易的时间戳)

用户:

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

会计:

  • id(主键)
  • userId(来自用户表的 ID)
  • transactionType(存款、盈亏、取款)
  • 金额(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

我想不出一个简单的方法来计算每天的利润......

任何指导/建议/帮助将不胜感激!

【问题讨论】:

    标签: php mysql calculator bitcoin accounting


    【解决方案1】:

    想通了..

    简而言之,这里是循环(不是最有效的方式,但它有效)

    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
          
       }
    
    
    }
    

    含糊不清,但希望能解释其中的逻辑。

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 2021-10-11
      • 2014-10-30
      • 2011-08-24
      • 2020-10-13
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2017-10-12
      相关资源
      最近更新 更多