MallUserPartitionRelationship.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace addons\TeamData\common\models;
  3. use common\models\user\UserPartitionRelationship;
  4. /**
  5. * 商城UserPartitionRelationship
  6. * @package addons\TeamData\common\models
  7. */
  8. class MallUserPartitionRelationship extends UserPartitionRelationship
  9. {
  10. /**
  11. * 查询我的团队会员IDs
  12. *
  13. * @param integer $uid
  14. * @param string $keyword
  15. * @param string $search_type
  16. * @return array
  17. */
  18. public static function getChildIds(int $uid, string $keyword, $search_type)
  19. {
  20. $relationship = self::find()
  21. ->where(['user_id' => $uid])
  22. ->select(['tree', 'deep'])
  23. ->orderBy('part desc')
  24. ->one();
  25. if (empty($relationship)) return [];
  26. $model = self::find()->alias('upr')
  27. ->where(['like', 'upr.tree', "{$relationship->tree},%", false])
  28. ->andWhere(['<>', 'upr.user_id', $uid])
  29. ->select(['upr.user_id']);
  30. if ($keyword) {
  31. $model->join('left join', MallUser::tableName() . ' as u', 'u.id = upr.user_id');
  32. if ($search_type == 1) $model->andWhere(['=', 'u.id', $keyword]);
  33. if ($search_type == 2) $model->andWhere(['=', 'u.nickname', $keyword]);
  34. if ($search_type == 3) $model->andWhere(['=', 'u.mobile', $keyword]);
  35. }
  36. return $model->column();
  37. }
  38. }