UserController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\commands;
  8. use yii\console\Controller;
  9. use yii\console\ExitCode;
  10. use app\models\User;
  11. class UserController extends Controller
  12. {
  13. /**
  14. * 重建用户关系
  15. * @return int Exit code
  16. */
  17. public function actionRebuild()
  18. {
  19. $stores = User::find()->select('store_id')->groupBy('store_id')->asArray()->all();
  20. foreach ($stores as $store) {
  21. $users = User::find()->where(['store_id' => $store['store_id']])->all();
  22. foreach ($users as $user) {
  23. echo 'store_id:' . $store['store_id'] . ' user_id:' . $user->id . ' => 重建中' . PHP_EOL;
  24. $user->rebuildTreePath();
  25. $user->getBehavior('oldTreePath')->rebuildTreePath();
  26. echo 'store_id:' . $store['store_id'] . ' user_id:' . $user->id . ' => 重建完成' . PHP_EOL;
  27. }
  28. }
  29. return ExitCode::OK;
  30. }
  31. }