MockThumbPhone.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Console\Commands\User;
  3. use App\Models\PraiseModel;
  4. use App\Models\User\MockThumbModel;
  5. use App\Models\User\UserModel;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\DB;
  8. class MockThumbPhone extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'mockthumb:phone';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '手机号用户模拟点赞';
  22. public const BOY = [1001, 1003, 1005, 1007, 1009, 1011];
  23. public const GIRL = [1002, 1004, 1006, 1008, 1010, 1012];
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $users = DB::table('user_groups')->where('group_id', 6)->get();
  41. foreach ($users as $user) {
  42. $this->mock($user->uid);
  43. dump($user->uid);
  44. }
  45. }
  46. public function mock(int $uid)
  47. {
  48. /** @var UserModel $user */
  49. $user = UserModel::findOrFail($uid);
  50. if (0 == $user->partner_id) {
  51. $whereuids = self::GIRL;
  52. 2 == $user->sex && $whereuids = self::BOY;
  53. $mockedUids = MockThumbModel::where('thumb_user', $user->uid)
  54. ->whereIn('uid', $whereuids)->get(['uid'])->pluck('uid')->toArray();
  55. $uid = self::GIRL[rand(0, count(array_diff(self::GIRL, $mockedUids)) - 1)];
  56. 2 == $user->sex && $uid = self::BOY[rand(0, count(array_diff(self::BOY, $mockedUids)) - 1)];
  57. MockThumbModel::create([
  58. 'uid' => $uid,
  59. 'thumb_user' => $user->uid,
  60. 'is_timing' => 3,
  61. ]);
  62. } else {
  63. $whereuids = self::GIRL;
  64. 2 == $user->sex && $whereuids = self::BOY;
  65. $mockedUids = PraiseModel::where('partner_id', $user->partner_id)
  66. ->whereIn('uid', $whereuids)->get(['uid'])->pluck('uid')->toArray();
  67. $uid = self::GIRL[rand(0, count(array_diff(self::GIRL, $mockedUids)) - 1)];
  68. 2 == $user->sex && $uid = self::BOY[rand(0, count(array_diff(self::BOY, $mockedUids)) - 1)];
  69. PraiseModel::updateOrCreate(['uid' => $uid, 'partner_id' => $user->partner_id], [
  70. 'uid' => $uid,
  71. 'partner_id' => $user->partner_id,
  72. 'create_at' => time(),
  73. 'created_at' => time(),
  74. 'updated_at' => time(),
  75. 'type' => 1,
  76. ]);
  77. }
  78. }
  79. }