| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace common\models\statistics;
- use Yii;
- /**
- * This is the model class for table "{{%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 $team_finish_order_total 团队完成订单数量(不包括本人)
- * @property int $team_finish_order_price_total 团队完成订单金额(不包括本人)
- * @property int $new_user_direct_total 近七天新增会员总数(jxmall_user_children.level=1)
- * @property float $user_direct_pay_selling_price 直推已支付的订单售价总额(商品价格)
- * @property float $user_direct_finish_selling_price 直推已完成的订单售价总额(商品价格)
- * @property float $user_indirect_pay_selling_price 间推已支付的订单售价总额(商品价格)
- * @property float $user_indirect_finish_selling_price 间推已完成的订单售价总额(商品价格)
- * @property float $team_pay_selling_price 团队已支付的订单售价总额(商品价格)
- * @property float $team_finish_selling_price 团队已完成的订单售价总额(商品价格)
- * @property float $team_goods_price_total 支付金额不包含运费
- * @property int $team_order_num 团队订单数量
- * @property int $created_at 创建时间
- * @property int $updated_at 上次更新数据时间
- */
- class UserTeamStatistics extends \common\models\base\BaseActiveRecord
- {
- const COUNT_FINISH_ORDER_KEY = 'count_finish_order_key';// 统计完成订单业绩
- /**
- * {@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', 'user_indirect_order_total', 'new_user_direct_total', 'created_at', 'updated_at',
- 'team_finish_order_total'
- ], 'integer'],
- [[
- 'user_team_order_price_total', 'user_direct_order_price_total', 'user_indirect_order_price_total','team_finish_order_price_total',
- 'user_direct_pay_selling_price', 'user_direct_finish_selling_price', 'user_indirect_pay_selling_price',
- 'user_indirect_finish_selling_price', 'team_pay_selling_price', 'team_finish_selling_price'
- ], 'double'],
- ];
- }
- /**
- * {@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)',
- 'team_finish_order_total' => '团队完成订单数量(不包括本人)',
- 'team_finish_order_price_total' => '团队完成订单金额(不包括本人)',
- 'user_direct_pay_selling_price' => '直推已支付的订单售价总额(商品价格)',
- 'user_direct_finish_selling_price' => '直推已完成的订单售价总额(商品价格)',
- 'user_indirect_pay_selling_price' => '间推已支付的订单售价总额(商品价格)',
- 'user_indirect_finish_selling_price' => '间推已完成的订单售价总额(商品价格)',
- 'team_pay_selling_price' => '团队已支付的订单售价总额(商品价格)',
- 'team_finish_selling_price' => '团队已完成的订单售价总额(商品价格)',
- 'team_order_num' => '团队订单数',
- 'created_at' => '创建时间',
- 'updated_at' => '上次更新数据时间',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/11/25 0025 17:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param $user_id
- * @param $data
- * @return bool
- */
- public static function setUserTeamStatistics($mall_id, $user_id, $data) {
- try {
- $orderMdl = self::find()->where(['mall_id' => $mall_id, 'user_id' => $user_id])->one();
- if (empty($orderMdl)) {
- $orderMdl = new self();
- $orderMdl->mall_id = $mall_id;
- $orderMdl->user_id = $user_id;
- }
- // 循环赋值
- foreach ($orderMdl as $key => $value) {
- if (isset($data[$key]) && !empty($data[$key])) $orderMdl->$key += $data[$key];
- }
- if (!$orderMdl->save()) {
- self::$static_error = $orderMdl->getErrorMessage();
- return false;
- }
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|