UserTeamStatistics.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace common\models\statistics;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%user_team_statistics}}".
  6. *
  7. *
  8. * @property int $id ID
  9. * @property int $mall_id 商城ID
  10. * @property int $user_id 用户ID
  11. * @property int $user_team_total 团队会员总数(不包括本人)
  12. * @property int $user_direct_total 直推会员总数(jxmall_user_children.level=1)
  13. * @property int $user_indirect_total 间推会员总数(jxmall_user_children.level=2)
  14. * @property int $active_user_team_total 团队活跃会员总数(不包括本人)
  15. * @property int $active_user_direct_total 直推活跃会员总数(jxmall_user_children.level=1)
  16. * @property int $active_user_indirect_total 间推活跃会员总数(jxmall_user_children.level=2)
  17. * @property int $loss_user_team_total 团队流失会员总数(不包括本人)
  18. * @property int $loss_user_direct_total 直推流失会员总数(jxmall_user_children.level=1)
  19. * @property int $loss_user_indirect_total 间推流失会员总数(jxmall_user_children.level=2)
  20. * @property int $user_team_order_total 团队会员订单总数(不包括本人)
  21. * @property int $user_direct_order_total 直推会员订单总数(jxmall_user_children.level=1)
  22. * @property int $user_indirect_order_total 间推会员订单总数(jxmall_user_children.level=2)
  23. * @property int $user_team_order_price_total 团队会员订单总额(不包括本人)
  24. * @property int $user_direct_order_price_total 直推会员订单总额(jxmall_user_children.level=1)
  25. * @property int $user_indirect_order_price_total 间推会员订单总额(jxmall_user_children.level=2)
  26. * @property int $team_finish_order_total 团队完成订单数量(不包括本人)
  27. * @property int $team_finish_order_price_total 团队完成订单金额(不包括本人)
  28. * @property int $new_user_direct_total 近七天新增会员总数(jxmall_user_children.level=1)
  29. * @property float $user_direct_pay_selling_price 直推已支付的订单售价总额(商品价格)
  30. * @property float $user_direct_finish_selling_price 直推已完成的订单售价总额(商品价格)
  31. * @property float $user_indirect_pay_selling_price 间推已支付的订单售价总额(商品价格)
  32. * @property float $user_indirect_finish_selling_price 间推已完成的订单售价总额(商品价格)
  33. * @property float $team_pay_selling_price 团队已支付的订单售价总额(商品价格)
  34. * @property float $team_finish_selling_price 团队已完成的订单售价总额(商品价格)
  35. * @property float $team_goods_price_total 支付金额不包含运费
  36. * @property int $team_order_num 团队订单数量
  37. * @property int $created_at 创建时间
  38. * @property int $updated_at 上次更新数据时间
  39. */
  40. class UserTeamStatistics extends \common\models\base\BaseActiveRecord
  41. {
  42. const COUNT_FINISH_ORDER_KEY = 'count_finish_order_key';// 统计完成订单业绩
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public static function tableName()
  47. {
  48. return '{{%user_team_statistics}}';
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function rules()
  54. {
  55. return [
  56. [[
  57. 'mall_id', 'user_id', 'user_team_total', 'user_direct_total', 'user_indirect_total', 'active_user_team_total', 'active_user_direct_total', 'active_user_indirect_total', 'loss_user_team_total', 'loss_user_direct_total', 'loss_user_indirect_total',
  58. 'user_team_order_total', 'user_direct_order_total', 'user_indirect_order_total', 'new_user_direct_total', 'created_at', 'updated_at',
  59. 'team_finish_order_total'
  60. ], 'integer'],
  61. [[
  62. 'user_team_order_price_total', 'user_direct_order_price_total', 'user_indirect_order_price_total','team_finish_order_price_total',
  63. 'user_direct_pay_selling_price', 'user_direct_finish_selling_price', 'user_indirect_pay_selling_price',
  64. 'user_indirect_finish_selling_price', 'team_pay_selling_price', 'team_finish_selling_price'
  65. ], 'double'],
  66. ];
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function attributeLabels()
  72. {
  73. return [
  74. 'id' => 'ID',
  75. 'mall_id' => '商城ID',
  76. 'user_id' => '用户ID',
  77. 'user_team_total' => '团队会员总数(不包括本人)',
  78. 'user_direct_total' => '直推会员总数(jxmall_user_children.level=1)',
  79. 'user_indirect_total' => '间推会员总数(jxmall_user_children.level=2)',
  80. 'active_user_team_total' => '团队活跃会员总数(不包括本人)',
  81. 'active_user_direct_total' => '直推活跃会员总数(jxmall_user_children.level=1)',
  82. 'active_user_indirect_total' => '间推活跃会员总数(jxmall_user_children.level=2)',
  83. 'loss_user_team_total' => '团队流失会员总数(不包括本人)',
  84. 'loss_user_direct_total' => '直推流失会员总数(jxmall_user_children.level=1)',
  85. 'loss_user_indirect_total' => '间推流失会员总数(jxmall_user_children.level=2)',
  86. 'user_team_order_total' => '团队会员订单总数(不包括本人)',
  87. 'user_direct_order_total' => '直推会员订单总数(jxmall_user_children.level=1)',
  88. 'user_indirect_order_total' => '间推会员订单总数(jxmall_user_children.level=2)',
  89. 'user_team_order_price_total' => '团队会员订单总额(不包括本人)',
  90. 'user_direct_order_price_total' => '直推会员订单总额(jxmall_user_children.level=1)',
  91. 'user_indirect_order_price_total' => '间推会员订单总额(jxmall_user_children.level=2)',
  92. 'new_user_direct_total' => '近七天新增会员总数(jxmall_user_children.level=1)',
  93. 'team_finish_order_total' => '团队完成订单数量(不包括本人)',
  94. 'team_finish_order_price_total' => '团队完成订单金额(不包括本人)',
  95. 'user_direct_pay_selling_price' => '直推已支付的订单售价总额(商品价格)',
  96. 'user_direct_finish_selling_price' => '直推已完成的订单售价总额(商品价格)',
  97. 'user_indirect_pay_selling_price' => '间推已支付的订单售价总额(商品价格)',
  98. 'user_indirect_finish_selling_price' => '间推已完成的订单售价总额(商品价格)',
  99. 'team_pay_selling_price' => '团队已支付的订单售价总额(商品价格)',
  100. 'team_finish_selling_price' => '团队已完成的订单售价总额(商品价格)',
  101. 'team_order_num' => '团队订单数',
  102. 'created_at' => '创建时间',
  103. 'updated_at' => '上次更新数据时间',
  104. ];
  105. }
  106. /**
  107. * 保存数据
  108. * @Author: lun
  109. * @DateTime: 2021/11/25 0025 17:32
  110. * @Copyright: copyright (c) 2021 广东七件事集团
  111. * @param $mall_id
  112. * @param $user_id
  113. * @param $data
  114. * @return bool
  115. */
  116. public static function setUserTeamStatistics($mall_id, $user_id, $data) {
  117. try {
  118. $orderMdl = self::find()->where(['mall_id' => $mall_id, 'user_id' => $user_id])->one();
  119. if (empty($orderMdl)) {
  120. $orderMdl = new self();
  121. $orderMdl->mall_id = $mall_id;
  122. $orderMdl->user_id = $user_id;
  123. }
  124. // 循环赋值
  125. foreach ($orderMdl as $key => $value) {
  126. if (isset($data[$key]) && !empty($data[$key])) $orderMdl->$key += $data[$key];
  127. }
  128. if (!$orderMdl->save()) {
  129. self::$static_error = $orderMdl->getErrorMessage();
  130. return false;
  131. }
  132. return true;
  133. } catch (\Exception $e) {
  134. self::$static_error = $e->getMessage();
  135. return false;
  136. }
  137. }
  138. }