Trade.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * @param $userId
  44. * @return array|false
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @throws \think\exception\DbException
  48. */
  49. public static function getSpeedTotalByUser($userId)
  50. {
  51. $uids = User::getLowerIds($userId);
  52. if(empty($uids)){
  53. return false;
  54. }
  55. // 下线销售额,包括自己
  56. $total = Trade::where(['status'=> 4,'on_resale'=>2])->whereIn('userid', $uids)->sum('endnums');
  57. // 加速参数
  58. $config = Config::getConfigByGroup('trade');
  59. $speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
  60. $speedUsdt = round($total * $speedRate/100, 2);
  61. $counts = [
  62. 'total'=> $total,
  63. 'speed_rate'=> $speedRate,
  64. 'speed_usdt'=> $speedUsdt,
  65. 'speed_total'=> CoinRate::transfer($speedUsdt),
  66. 'rate'=> $speedRate,
  67. ];
  68. return $counts;
  69. }
  70. }