Trade.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $config = Config::getConfigByGroup('trade');
  30. $awardBase = isset($config['award_base'])? floatval($config['award_base']['value']) : 0;
  31. // 计算增加比例
  32. $addAward = Award::getAddAward();
  33. $award = round($addAward + $awardBase, 2);
  34. $counts = [
  35. 'total_usdt'=> $award,
  36. 'award_add'=> $addAward,
  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])->column('id');
  51. $totalUsdt = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('release_total_usdt');
  52. $releaseTotal = Trade::where(['status'=> 4,'on_resale'=>1,'relevant_userid'=> $userId])->sum('release_usdt');
  53. //$totalUsdt = round(CoinRate::transfer($total), 2);
  54. $counts = [
  55. 'total_usdt'=> $totalUsdt,
  56. 'release_usdt'=> round($releaseTotal, 2),
  57. 'surplus_usdt'=> round(max(0, $totalUsdt-$releaseTotal), 2),
  58. ];
  59. return $counts;
  60. }
  61. /**
  62. * 获取用户释放加速值
  63. * @param $userId
  64. * @return array|false
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. */
  69. public static function getSpeedTotalByUser($userId)
  70. {
  71. $uids = User::getLowerIds($userId);
  72. if(empty($uids)){
  73. return false;
  74. }
  75. // 下线销售额,包括自己
  76. $total = Trade::where(['status'=> 4,'on_resale'=>2])->whereIn('userid', $uids)->sum('pre_price');
  77. // 加速参数
  78. $config = Config::getConfigByGroup('trade');
  79. $speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
  80. $speedTotal = round($total * $speedRate/100, 2);
  81. $counts = [
  82. 'total'=> $total,
  83. 'speed_rate'=> $speedRate,
  84. 'speed_usdt'=> CoinRate::transfer($speedTotal),
  85. 'speed_total'=> $speedTotal,
  86. 'rate'=> $speedRate,
  87. ];
  88. return $counts;
  89. }
  90. }