Test.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\Console\Commands;
  3. use app\common\facades\SiteSetting;
  4. use app\common\models\Member;
  5. use app\common\models\MemberShopInfo;
  6. use app\common\models\Order;
  7. use app\common\models\OrderRequest;
  8. use app\common\modules\shop\ShopConfig;
  9. use app\framework\Cron\Cron;
  10. use app\host\HostManager;
  11. use Illuminate\Console\Command;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Redis;
  14. use Yunshop\AreaDividend\models\AreaDividendAgent;
  15. use function GuzzleHttp\Psr7\build_query;
  16. use function GuzzleHttp\Psr7\parse_query;
  17. use Illuminate\Database\Schema\Blueprint;
  18. use Illuminate\Support\Facades\Schema;
  19. class Test extends Command
  20. {
  21. use \Illuminate\Foundation\Bus\DispatchesJobs;
  22. protected $signature = 'test';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '测试';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. if (!Schema::hasColumn('yz_comment', 'type')) {
  37. $table->tinyInteger('type')->default(3);
  38. } $a = Redis::ping();
  39. echo $a;
  40. }
  41. private function teamMembers($uids, $level = null)
  42. {
  43. if (isset($level)) {
  44. $level--;
  45. }
  46. if (!is_array($uids)) {
  47. $uids = [$uids];
  48. }
  49. $children = Redis::hmget('children:' . \YunShop::app()->uniacid, $uids);
  50. $result = [];
  51. foreach ($children as $child) {
  52. if (isset($child)) {
  53. $childUids = explode(',', $child);
  54. if ($childUids) {
  55. $result = array_merge($result, $childUids);
  56. }
  57. }
  58. }
  59. if ($level === 0) {
  60. return $result;
  61. }
  62. if ($result) {
  63. $result = array_merge($result, $this->teamMembers($result, $level));
  64. }
  65. return $result;
  66. }
  67. private function data()
  68. {
  69. app()->db->enableQueryLog();
  70. \YunShop::app()->uniacid = 2;
  71. $members = MemberShopInfo::getQuery()->select(DB::raw('member_id as `0`'), DB::raw('parent_id as `1`'))->where('parent_id', '!=', 0)->get();
  72. $this->parents($members);
  73. $this->children($members);
  74. }
  75. private function parents($members)
  76. {
  77. $parents = [];
  78. foreach ($members as $member) {
  79. $parents[$member[0]] = $member[1];
  80. }
  81. Redis::del('parents:' . \YunShop::app()->uniacid);
  82. Redis::hmset('parents:' . \YunShop::app()->uniacid, $parents);
  83. }
  84. private function children($members)
  85. {
  86. $childrenMap = [];
  87. foreach ($members as $member) {
  88. $childrenMap[$member[1]][] = $member[0];
  89. }
  90. foreach ($childrenMap as &$children) {
  91. $children = implode(',', $children);
  92. }
  93. Redis::del('children:' . \YunShop::app()->uniacid);
  94. Redis::hmset('children:' . \YunShop::app()->uniacid, $childrenMap);
  95. }
  96. }