AccountLoginDomain.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. class AccountLoginDomain extends Model
  6. {
  7. const TABLE = 'QPAccountsDB.dbo.AccountLoginDomain';
  8. protected $table = self::TABLE;
  9. public $timestamps = false;
  10. protected $fillable = [
  11. 'UserID',
  12. 'Channel',
  13. 'Domain',
  14. 'Scheme',
  15. 'UpdatedAt',
  16. 'CreatedAt',
  17. ];
  18. public static function record($userId, $origin, $channel = 0)
  19. {
  20. $userId = (int) $userId;
  21. $channel = (int) $channel;
  22. $origin = trim((string) $origin);
  23. if ($userId <= 0 || $origin === '') {
  24. return false;
  25. }
  26. $now = date('Y-m-d H:i:s');
  27. return DB::connection('write')->table(self::TABLE)->updateOrInsert(
  28. ['UserID' => $userId],
  29. [
  30. 'Channel' => $channel,
  31. 'Domain' => $origin,
  32. 'Scheme' => '',
  33. 'UpdatedAt' => $now,
  34. ]
  35. );
  36. }
  37. }