1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Console\Commands\User;
- use App\Models\PraiseModel;
- use App\Models\User\MockThumbModel;
- use App\Models\User\UserModel;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class MockThumbPhone extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'mockthumb:phone';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '手机号用户模拟点赞';
- public const BOY = [1001, 1003, 1005, 1007, 1009, 1011];
- public const GIRL = [1002, 1004, 1006, 1008, 1010, 1012];
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $users = DB::table('user_groups')->where('group_id', 6)->get();
- foreach ($users as $user) {
- $this->mock($user->uid);
- dump($user->uid);
- }
- }
- public function mock(int $uid)
- {
- /** @var UserModel $user */
- $user = UserModel::findOrFail($uid);
- if (0 == $user->partner_id) {
- $whereuids = self::GIRL;
- 2 == $user->sex && $whereuids = self::BOY;
- $mockedUids = MockThumbModel::where('thumb_user', $user->uid)
- ->whereIn('uid', $whereuids)->get(['uid'])->pluck('uid')->toArray();
- $uid = self::GIRL[rand(0, count(array_diff(self::GIRL, $mockedUids)) - 1)];
- 2 == $user->sex && $uid = self::BOY[rand(0, count(array_diff(self::BOY, $mockedUids)) - 1)];
- MockThumbModel::create([
- 'uid' => $uid,
- 'thumb_user' => $user->uid,
- 'is_timing' => 3,
- ]);
- } else {
- $whereuids = self::GIRL;
- 2 == $user->sex && $whereuids = self::BOY;
- $mockedUids = PraiseModel::where('partner_id', $user->partner_id)
- ->whereIn('uid', $whereuids)->get(['uid'])->pluck('uid')->toArray();
- $uid = self::GIRL[rand(0, count(array_diff(self::GIRL, $mockedUids)) - 1)];
- 2 == $user->sex && $uid = self::BOY[rand(0, count(array_diff(self::BOY, $mockedUids)) - 1)];
- PraiseModel::updateOrCreate(['uid' => $uid, 'partner_id' => $user->partner_id], [
- 'uid' => $uid,
- 'partner_id' => $user->partner_id,
- 'create_at' => time(),
- 'created_at' => time(),
- 'updated_at' => time(),
- 'type' => 1,
- ]);
- }
- }
- }
|