Trade.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\CoinRate;
  4. use think\Model;
  5. /**
  6. * 交易
  7. */
  8. class Trade Extends Model
  9. {
  10. // 表名
  11. protected $name = 'trade';
  12. // 开启自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. // 定义时间戳字段名
  15. protected $createTime = 'createtime';
  16. protected $updateTime = false;
  17. // 追加属性
  18. protected $append = [
  19. ];
  20. /**
  21. * 奖金池
  22. * @return array
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. */
  27. public static function getAwardTotal()
  28. {
  29. $total = Trade::where(['status'=> 4,'on_resale'=>2])->sum('endnums');
  30. $config = Config::getConfigByGroup('trade');
  31. $awardBase = isset($config['award_base'])? floatval($config['award_base']['value']) : 0;
  32. $award = round($total + $awardBase, 2);
  33. $counts = [
  34. 'total'=> CoinRate::transfer($award),
  35. 'total_usdt'=> $award,
  36. 'award'=> $total,
  37. 'award_base'=> $awardBase,
  38. ];
  39. return $counts;
  40. }
  41. /**
  42. * 释放统计
  43. * @return array
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @throws \think\exception\DbException
  47. */
  48. public static function getReleaseTotal($userId)
  49. {
  50. $total = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('endnums');
  51. $releaseTotal = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('release_usdt');
  52. $counts = [
  53. 'total'=> $total,
  54. 'release_usdt'=> $releaseTotal,
  55. 'surplus_usdt'=> $total-$releaseTotal,
  56. ];
  57. return $counts;
  58. }
  59. /**
  60. * 获取用户释放加速值
  61. * @param $userId
  62. * @return array|false
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @throws \think\exception\DbException
  66. */
  67. public static function getSpeedTotalByUser($userId)
  68. {
  69. $uids = User::getLowerIds($userId);
  70. if(empty($uids)){
  71. return false;
  72. }
  73. // 下线销售额,包括自己
  74. $total = Trade::where(['status'=> 4,'on_resale'=>2])->whereIn('userid', $uids)->sum('endnums');
  75. // 加速参数
  76. $config = Config::getConfigByGroup('trade');
  77. $speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
  78. $speedUsdt = round($total * $speedRate/100, 2);
  79. $counts = [
  80. 'total'=> $total,
  81. 'speed_rate'=> $speedRate,
  82. 'speed_usdt'=> $speedUsdt,
  83. 'speed_total'=> CoinRate::transfer($speedUsdt),
  84. 'rate'=> $speedRate,
  85. ];
  86. return $counts;
  87. }
  88. }