FixMemberRelease.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Date: 2020/10/13
  5. * Time: 9:35 PM
  6. */
  7. namespace app\console\Commands;
  8. use app\backend\modules\member\models\Member;
  9. use app\common\models\member\ChildrenOfMember;
  10. use app\common\models\member\ParentOfMember;
  11. use app\common\models\MemberShopInfo;
  12. use app\common\services\member\MemberRelation;
  13. use Illuminate\Console\Command;
  14. class FixMemberRelease extends Command
  15. {
  16. /**
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'fix:release {uniacid} {member_id}';
  22. /**
  23. * The console command description.
  24. *
  25. * @var string
  26. */
  27. protected $description = '修复指定会员关系';
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return mixed
  41. */
  42. public function handle()
  43. {
  44. $account = \app\common\models\AccountWechats::getAccountByUniacid($this->argument('uniacid'));
  45. \YunShop::app()->uniacid = $this->argument('uniacid');
  46. \YunShop::app()->weid = $this->argument('uniacid');
  47. \YunShop::app()->acid = $this->argument('uniacid');
  48. \YunShop::app()->account = $account ? $account->toArray() : '';
  49. $this->info('=========start=========');
  50. $this->process();
  51. $this->info('=========end=========');
  52. }
  53. public function t()
  54. {
  55. $bar = $this->output->createProgressBar(1000);
  56. $bar->setFormat(" %elapsed:6s%/%estimated:-6s% 内存消耗: %memory:6s%\n%current%/%max% [%bar%] %percent:3s%%");
  57. for ($i=1; $i<=1000; $i++){
  58. usleep(5000);
  59. $bar->advance();
  60. }
  61. $bar->finish();
  62. echo "\n";
  63. }
  64. public function process()
  65. {
  66. $parentMemberModle = new ParentOfMember();
  67. $childMemberModel = new ChildrenOfMember();
  68. $memberModel = new Member();
  69. $memberRelation = new MemberRelation();
  70. $memberModel->_allNodes = collect([]);
  71. $memberInfo = $memberModel->getTreeAllNodes($this->argument('uniacid'));
  72. if ($memberInfo->isEmpty()) {
  73. $this->info('----is empty-----');
  74. return;
  75. }
  76. foreach ($memberInfo as $item) {
  77. $memberModel->_allNodes->put($item->member_id, $item);
  78. }
  79. //获取指定会员所有下级
  80. $data = $memberModel->getDescendants($this->argument('uniacid'), $this->argument('member_id'));
  81. if (!$data->isEmpty()) {
  82. //导入关系链
  83. foreach ($data as $child_member_id => $val) {
  84. $attr = [];
  85. $child_attr = [];
  86. $this->info('--------foreach start------' . $child_member_id);
  87. $memberModel->filter = [];
  88. $nodeParents = $memberModel->getNodeParents($this->argument('uniacid'), $child_member_id);
  89. if (!$nodeParents->isEmpty()) {
  90. $this->info('--------insert init------');
  91. foreach ($nodeParents as $parent_member_id => $v) {
  92. $memberRelation->delMemberOfRelation($child_member_id, $parent_member_id);
  93. if ($parent_member_id != $child_member_id) {
  94. $attr[] = [
  95. 'uniacid' => $this->argument('uniacid'),
  96. 'parent_id' => $parent_member_id,
  97. 'level' => $v['depth'] + 1,
  98. 'member_id' => $child_member_id,
  99. 'created_at' => time()
  100. ];
  101. $child_attr[] = [
  102. 'uniacid' => $this->argument('uniacid'),
  103. 'child_id' => $child_member_id,
  104. 'level' => $v['depth'] + 1,
  105. 'member_id' => $parent_member_id,
  106. 'created_at' => time()
  107. ];
  108. } else {
  109. $this->info('--------fail------' . $parent_member_id);
  110. }
  111. }
  112. $parentMemberModle->createData($attr);
  113. $childMemberModel->createData($child_attr);
  114. }
  115. }
  116. }
  117. }
  118. }