DayBaseModel.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * DayBaseModel.php UTF-8
  4. *
  5. *
  6. * @date : 5/21/2018 2:11 PM
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\data;
  13. use huo\model\common\CommonModel;
  14. class DayBaseModel extends CommonModel {
  15. /**
  16. * DayBaseModel 切换为db_hw_dw数据库
  17. *
  18. * @param array $data
  19. */
  20. public function __construct($data = []) {
  21. parent::__construct($data);
  22. $_db_dw_config = include CMF_ROOT.'data/conf/database_dw.php';
  23. $this->connect($_db_dw_config);
  24. }
  25. /**
  26. * 计算费率
  27. * @param $divisor 除数
  28. * @param $dividend 被除数
  29. * @param int $precision 保留小数
  30. *
  31. * @return float
  32. */
  33. public static function calculateRate($divisor, $dividend, $precision = 2) {
  34. $result = 0;
  35. if (empty($dividend)) {
  36. return round($result, $precision);
  37. }
  38. return round(($divisor / $dividend), $precision);
  39. }
  40. /**
  41. * 新增付费率
  42. * @param int $precision 保留小数
  43. *
  44. * @return float
  45. */
  46. public function getNewPaymentRate($precision = 2) {
  47. return static::calculateRate($this->reg_pay_cnt, $this->reg_cnt, $precision);
  48. }
  49. /**
  50. * 活跃付费率
  51. *
  52. * @param int $precision 保留小数
  53. *
  54. * @return float
  55. */
  56. public function getActivePaymentRate($precision = 2) {
  57. return static::calculateRate($this->pay_user_cnt, $this->user_cnt, $precision);
  58. }
  59. /**
  60. * 新增注册ARPU
  61. *
  62. * @param int $precision 保留小数
  63. *
  64. * @return float
  65. */
  66. public function getNewRegARPU($precision = 2) {
  67. return static::calculateRate($this->first_pay_sum_money, $this->reg_cnt, $precision);
  68. }
  69. /**
  70. * 活跃ARPU
  71. *
  72. * @param int $precision 保留小数
  73. *
  74. * @return float
  75. */
  76. public function getActiveARPU($precision = 2) {
  77. return static::calculateRate($this->sum_money, $this->user_cnt, $precision);
  78. }
  79. /**
  80. * 付费ARPU
  81. *
  82. * @param int $precision 保留小数
  83. *
  84. * @return float
  85. */
  86. public function getPaidARPU($precision = 2) {
  87. return static::calculateRate($this->sum_money, $this->pay_user_cnt, $precision);
  88. }
  89. }