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, ]); } } }