UserProfile.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 玩家付费模式数据画像
  5. */
  6. class UserPaymentProfile extends Object_ext
  7. {
  8. /**
  9. * @var int 付费总额
  10. */
  11. public $payAmount = 0;
  12. /**
  13. * @var int 付费次数
  14. */
  15. public $payTimes = 0;
  16. /**
  17. * @var ts 上次付费时间戳
  18. */
  19. public $lastPayTs = 0;
  20. /**
  21. * 获得当前付费数据的分类
  22. * 0:none(免费),1:fish(小R),2: Dolphin(海豚), 3: while(鲸鱼)
  23. * @return int
  24. */
  25. public function GetClass()
  26. {
  27. if ($this->payAmount <= 0) { # 免费用户
  28. return 0;
  29. } else if ($this->payAmount < 100) { # 100以下,小R
  30. return 1;
  31. } else if ($this->payAmount < 1000) { # 1000以下,中产
  32. return 2;
  33. } else { # 大于1k的都算大R了
  34. return 3;
  35. }
  36. }
  37. }
  38. /**
  39. * 用户画像
  40. * @version
  41. * 1.0.0 Created at 2017-9-23. by --gwang
  42. * @author gwang (mail@wanggangzero.cn)
  43. * @copyright ? 2017-9-23, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  44. */
  45. class UserProfile extends Object_ext
  46. {
  47. //put your code here
  48. /**
  49. * 付费画像
  50. * @var UserPaymentProfile
  51. */
  52. public $payment;
  53. public function OnPay($args = null)
  54. {
  55. // 提取参数 extract or 直接按照名字提取
  56. // 更新付费总额, 次数, 最后一次付费
  57. if (null === $args || !is_array($args)) {
  58. return false;
  59. }
  60. $amt = $args['amt'];
  61. if ($amt) { # 参数不为空
  62. $this->payment->lastPayTs = now();
  63. $this->payment->payAmount += $amt;
  64. $this->payment->payTimes++;
  65. return true;
  66. }
  67. return false;
  68. }
  69. public function __construct($arg = null)
  70. {
  71. parent::__construct($arg);
  72. $this->payment = new UserPaymentProfile($this->payment);
  73. }
  74. }