新版订单消耗系统

Users.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2020/12/23
  6. * Time: 16:24
  7. */
  8. namespace App\Models;
  9. use Illuminate\Database\Eloquent\Builder;
  10. use Illuminate\Contracts\Auth\Authenticatable;
  11. use Illuminate\Database\Eloquent\Model;
  12. class Users extends Model implements Authenticatable
  13. {
  14. const LOGIN_TOKEN_REDIS_KEY_PRE = 'newMediaCa.loginToken:';
  15. protected $table = 'users';
  16. public $timestamps = false;
  17. protected $hidden = ['password', 'is_delete', 'created_at', 'updated_at'];
  18. protected static $unguarded = true;
  19. public function role()
  20. {
  21. return $this->hasOne(Roles::class, 'id', 'role_id');
  22. }
  23. public function scopeActive(Builder $query)
  24. {
  25. return $query->where('is_delete', 0);
  26. }
  27. public static function random($length = 6, $type = 'string', $convert = 0)
  28. {
  29. $config = array(
  30. 'number' => '1234567890',
  31. 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
  32. 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
  33. 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  34. );
  35. if (!isset($config[$type]))
  36. $type = 'string';
  37. $string = $config[$type];
  38. $code = '';
  39. $strlen = strlen($string) - 1;
  40. for ($i = 0; $i < $length; $i++) {
  41. $code .= $string{mt_rand(0, $strlen)};
  42. }
  43. if (!empty($convert)) {
  44. $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
  45. }
  46. return $code;
  47. }
  48. /**
  49. * 验证sign
  50. * @param $userId
  51. * @param $ttl
  52. * @param $random
  53. * @param $sign
  54. * @return bool
  55. */
  56. public static function validSign($userId,$ttl,$random,$sign){
  57. $params = array('user_id'=>$userId, 'ttl'=> $ttl, 'random'=>$random);
  58. $makesign = self::getSignature($params);
  59. if($makesign == $sign) {
  60. return true;
  61. }
  62. return false;
  63. }
  64. public static function getSignature($params)
  65. {
  66. // 按数组键名 正序排序
  67. ksort($params);
  68. $tem = array();
  69. foreach ($params as $k => $v) {
  70. if ($k !== 'sign') {
  71. $tem[] = "$k=$v";
  72. }
  73. }
  74. $sk = implode('&', $tem);
  75. return md5($sk);
  76. }
  77. /**
  78. * Get the name of the unique identifier for the user.
  79. *
  80. * @return string
  81. */
  82. public function getAuthIdentifierName()
  83. {
  84. // TODO: Implement getAuthIdentifierName() method.
  85. }
  86. /**
  87. * Get the unique identifier for the user.
  88. *
  89. * @return mixed
  90. */
  91. public function getAuthIdentifier()
  92. {
  93. // TODO: Implement getAuthIdentifier() method.
  94. return $this->id;
  95. }
  96. /**
  97. * Get the password for the user.
  98. *
  99. * @return string
  100. */
  101. public function getAuthPassword()
  102. {
  103. // TODO: Implement getAuthPassword() method.
  104. }
  105. /**
  106. * Get the token value for the "remember me" session.
  107. *
  108. * @return string
  109. */
  110. public function getRememberToken()
  111. {
  112. // TODO: Implement getRememberToken() method.
  113. }
  114. /**
  115. * Set the token value for the "remember me" session.
  116. *
  117. * @param string $value
  118. * @return void
  119. */
  120. public function setRememberToken($value)
  121. {
  122. // TODO: Implement setRememberToken() method.
  123. }
  124. /**
  125. * Get the column name for the "remember me" token.
  126. *
  127. * @return string
  128. */
  129. public function getRememberTokenName()
  130. {
  131. // TODO: Implement getRememberTokenName() method.
  132. }
  133. }