UserTeamStatistics.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace common\models\user;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_user_team_statistics".
  7. *
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property int $user_team_total 团队会员总数(不包括本人)
  13. * @property int $user_direct_total 直推会员总数(jxmall_user_children.level=1)
  14. * @property int $user_indirect_total 间推会员总数(jxmall_user_children.level=2)
  15. * @property int $active_user_team_total 团队活跃会员总数(不包括本人)
  16. * @property int $active_user_direct_total 直推活跃会员总数(jxmall_user_children.level=1)
  17. * @property int $active_user_indirect_total 间推活跃会员总数(jxmall_user_children.level=2)
  18. * @property int $loss_user_team_total 团队流失会员总数(不包括本人)
  19. * @property int $loss_user_direct_total 直推流失会员总数(jxmall_user_children.level=1)
  20. * @property int $loss_user_indirect_total 间推流失会员总数(jxmall_user_children.level=2)
  21. * @property int $user_team_order_total 团队会员订单总数(不包括本人)
  22. * @property int $user_direct_order_total 直推会员订单总数(jxmall_user_children.level=1)
  23. * @property int $user_indirect_order_total 间推会员订单总数(jxmall_user_children.level=2)
  24. * @property int $user_team_order_price_total 团队会员订单总额(不包括本人)
  25. * @property int $user_direct_order_price_total 直推会员订单总额(jxmall_user_children.level=1)
  26. * @property int $user_indirect_order_price_total 间推会员订单总额(jxmall_user_children.level=2)
  27. * @property int $new_user_direct_total 近七天新增会员总数(jxmall_user_children.level=1)
  28. * @property int $created_at 创建时间
  29. * @property int $updated_at 上次更新数据时间
  30. */
  31. class UserTeamStatistics extends BaseActiveRecord
  32. {
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public static function tableName()
  37. {
  38. return '{{%user_team_statistics}}';
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['mall_id', 'user_id', 'user_team_total', 'user_direct_total', 'user_indirect_total', 'active_user_team_total',
  47. 'active_user_direct_total', 'active_user_indirect_total', 'loss_user_team_total', 'loss_user_direct_total',
  48. 'loss_user_indirect_total', 'user_team_order_total', 'user_direct_order_total', 'new_user_direct_total', 'created_at', 'updated_at'], 'integer'],
  49. [['user_team_order_price_total', 'user_direct_order_price_total', 'user_indirect_order_price_total','team_finish_order_total','team_finish_order_price_total'], 'number'],
  50. ];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function attributeLabels()
  56. {
  57. return [
  58. 'id' => 'ID',
  59. 'mall_id' => '商城ID',
  60. 'user_id' => '用户ID',
  61. 'user_team_total' => '团队会员总数(不包括本人)',
  62. 'user_direct_total' => '直推会员总数(jxmall_user_children.level=1)',
  63. 'user_indirect_total' => '间推会员总数(jxmall_user_children.level=2)',
  64. 'active_user_team_total' => '团队活跃会员总数(不包括本人)',
  65. 'active_user_direct_total' => '直推活跃会员总数(jxmall_user_children.level=1)',
  66. 'active_user_indirect_total' => '间推活跃会员总数(jxmall_user_children.level=2)',
  67. 'loss_user_team_total' => '团队流失会员总数(不包括本人)',
  68. 'loss_user_direct_total' => '直推流失会员总数(jxmall_user_children.level=1)',
  69. 'loss_user_indirect_total' => '间推流失会员总数(jxmall_user_children.level=2)',
  70. 'user_team_order_total' => '团队会员订单总数(不包括本人)',
  71. 'user_direct_order_total' => '直推会员订单总数(jxmall_user_children.level=1)',
  72. 'user_indirect_order_total' => '间推会员订单总数(jxmall_user_children.level=2)',
  73. 'user_team_order_price_total' => '团队会员订单总额(不包括本人)',
  74. 'user_direct_order_price_total' => '直推会员订单总额(jxmall_user_children.level=1)',
  75. 'user_indirect_order_price_total' => '间推会员订单总额(jxmall_user_children.level=2)',
  76. 'new_user_direct_total' => '近七天新增会员总数(jxmall_user_children.level=1)',
  77. 'created_at' => '创建时间',
  78. 'updated_at' => '上次更新数据时间',
  79. ];
  80. }
  81. /**
  82. * 保存数据
  83. * @param array $params
  84. * @return bool|UserTeamStatistics
  85. */
  86. public static function setData(array $params){
  87. try{
  88. $model = new self();
  89. $model->loadDefaultValues();
  90. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  91. return $model;
  92. }catch(\Exception $e){
  93. self::$static_error = $e->getMessage();
  94. return false;
  95. }
  96. }
  97. public function getUser()
  98. {
  99. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id, nickname, avatar_url, mobile');
  100. }
  101. /**
  102. * 团队会员订单总额
  103. *
  104. * @param integer $user_id
  105. * @return float
  106. */
  107. public static function getTeamFinishOrderPriceTotal(int $user_id)
  108. {
  109. return static::find()
  110. ->select('team_finish_order_price_total')
  111. ->where(['user_id' => $user_id])
  112. ->scalar();
  113. }
  114. }