where('name', $mediaName)->first(); if (!$mediaRecord) { return null; } // 查找是否存在相同的账号 $userRow = $model->where('account_id', $accountId)->first(); if ($userRow) { $userRow->access_token = $accessToken; $userRow->expires_at = $expiresAt; $userRow->name = $accountName; $userRow->save(); } else { // 创建新账号并关联父级 $data = [ 'account_id' => $accountId, 'name' => $accountName, 'access_token' => $accessToken, 'expires_at' => $expiresAt, 'parent_id' => $mediaRecord->id, 'dist_id' => getDistributorId(), 'created_at' => Carbon::now(), // 自动生成时间戳 'updated_at' => Carbon::now(), ]; $model->insert($data); } return true; } /* * 查出dist_id=0和parent_id=0的账号 */ public static function getRootAccounts() { $model = new Model(); $accounts = $model->where('dist_id', 0)->where('parent_id', 0)->get(); return $accounts; } /* * 查找所有用户账号(只显示有效的账号) */ public static function getUserAccounts() { $model = new Model(); $accounts = $model->where('dist_id','>', 0)->where('parent_id','>',0)->where('expires_at','>', Carbon::now())->orderBy('parent_id', 'asc')->get(); return $accounts; } /* * 查找所有用户账号 */ public static function getAccountsByIds($ids) { $model = new Model(); $accounts = $model->whereIn('id', $ids)->get(); return $accounts; } public static function getAccountById($id) { $model = new Model(); $account = $model->find($id); return $account; } /* * 返回子账号数量 */ public static function returnChildCount($id) { $model = new Model(); $count = $model->where('parent_id', $id)->count(); return $count; } }