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

问题描述

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

我有一组共享比特币的用户。我们每天集体交易并分享利润(减去一小部分给我的管理费用)。

我正在尝试建立一个系统来准确计算利润和费用,但我就是不知道如何去做。

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

tansactions:(这个信息是从交易所的api中拉出来的)

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

用户:

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

会计:

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

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

我在想,使用夜间脚本时,会计表可能看起来像这样:

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
      
   }


}

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...