| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_user_team_statistics".
- *
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $user_team_total 团队会员总数(不包括本人)
- * @property int $user_direct_total 直推会员总数(jxmall_user_children.level=1)
- * @property int $user_indirect_total 间推会员总数(jxmall_user_children.level=2)
- * @property int $active_user_team_total 团队活跃会员总数(不包括本人)
- * @property int $active_user_direct_total 直推活跃会员总数(jxmall_user_children.level=1)
- * @property int $active_user_indirect_total 间推活跃会员总数(jxmall_user_children.level=2)
- * @property int $loss_user_team_total 团队流失会员总数(不包括本人)
- * @property int $loss_user_direct_total 直推流失会员总数(jxmall_user_children.level=1)
- * @property int $loss_user_indirect_total 间推流失会员总数(jxmall_user_children.level=2)
- * @property int $user_team_order_total 团队会员订单总数(不包括本人)
- * @property int $user_direct_order_total 直推会员订单总数(jxmall_user_children.level=1)
- * @property int $user_indirect_order_total 间推会员订单总数(jxmall_user_children.level=2)
- * @property int $user_team_order_price_total 团队会员订单总额(不包括本人)
- * @property int $user_direct_order_price_total 直推会员订单总额(jxmall_user_children.level=1)
- * @property int $user_indirect_order_price_total 间推会员订单总额(jxmall_user_children.level=2)
- * @property int $new_user_direct_total 近七天新增会员总数(jxmall_user_children.level=1)
- * @property int $created_at 创建时间
- * @property int $updated_at 上次更新数据时间
- */
- class UserTeamStatistics extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_team_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['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', 'user_team_order_total', 'user_direct_order_total', 'new_user_direct_total', 'created_at', 'updated_at'], 'integer'],
- [['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'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'user_team_total' => '团队会员总数(不包括本人)',
- 'user_direct_total' => '直推会员总数(jxmall_user_children.level=1)',
- 'user_indirect_total' => '间推会员总数(jxmall_user_children.level=2)',
- 'active_user_team_total' => '团队活跃会员总数(不包括本人)',
- 'active_user_direct_total' => '直推活跃会员总数(jxmall_user_children.level=1)',
- 'active_user_indirect_total' => '间推活跃会员总数(jxmall_user_children.level=2)',
- 'loss_user_team_total' => '团队流失会员总数(不包括本人)',
- 'loss_user_direct_total' => '直推流失会员总数(jxmall_user_children.level=1)',
- 'loss_user_indirect_total' => '间推流失会员总数(jxmall_user_children.level=2)',
- 'user_team_order_total' => '团队会员订单总数(不包括本人)',
- 'user_direct_order_total' => '直推会员订单总数(jxmall_user_children.level=1)',
- 'user_indirect_order_total' => '间推会员订单总数(jxmall_user_children.level=2)',
- 'user_team_order_price_total' => '团队会员订单总额(不包括本人)',
- 'user_direct_order_price_total' => '直推会员订单总额(jxmall_user_children.level=1)',
- 'user_indirect_order_price_total' => '间推会员订单总额(jxmall_user_children.level=2)',
- 'new_user_direct_total' => '近七天新增会员总数(jxmall_user_children.level=1)',
- 'created_at' => '创建时间',
- 'updated_at' => '上次更新数据时间',
- ];
- }
- /**
- * 保存数据
- * @param array $params
- * @return bool|UserTeamStatistics
- */
- public static function setData(array $params){
- try{
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id, nickname, avatar_url, mobile');
- }
- /**
- * 团队会员订单总额
- *
- * @param integer $user_id
- * @return float
- */
- public static function getTeamFinishOrderPriceTotal(int $user_id)
- {
- return static::find()
- ->select('team_finish_order_price_total')
- ->where(['user_id' => $user_id])
- ->scalar();
- }
- }
|