UserCompany.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%user_company}}".
  6. *
  7. * @property string $id
  8. * @property integer $uid
  9. * @property string $logo
  10. * @property string $company
  11. * @property integer $age
  12. * @property integer $level
  13. * @property string $licence
  14. * @property integer $created_at
  15. * @property string $tel
  16. * @property string $city
  17. * @property string $district
  18. * @property string $adress
  19. * @property integer $updated_at
  20. * @property string $introduction
  21. * @property integer $vip_start
  22. * @property integer $vip_end
  23. */
  24. class UserCompany extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * @inheritdoc
  28. */
  29. const ISMEMBER = 10;//会员
  30. const NOMEMBER = 0;//非会员
  31. public static function tableName()
  32. {
  33. return '{{%user_company}}';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['uid','company','created_at'], 'required'],
  42. [['uid','member', 'age', 'level', 'created_at', 'updated_at','vip_start','vip_end'], 'integer'],
  43. [['introduction', 'address'], 'string'],
  44. [['logo', 'licence','openid'], 'string', 'max' => 255],
  45. [['company'], 'string', 'max' => 120],
  46. [['tel', 'city', 'district','province'], 'string', 'max' => 32],
  47. ];
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'uid' => '用户ID',
  57. 'logo' => 'logo地址',
  58. 'company' => '公司名称',
  59. 'age' => '年限',
  60. 'level' => '等级',
  61. 'licence' => 'Licence',
  62. 'created_at' => '创建时间',
  63. 'tel' => '联系电话',
  64. 'city' => '城市',
  65. 'district' => '地区',
  66. 'address' => '地址',
  67. 'updated_at' => 'Updated At',
  68. 'introduction' => '公司简介',
  69. 'openid' =>'openid',
  70. 'member' =>'是否会员',
  71. 'vip_start' =>'会员开始时间',
  72. 'vip_end' =>'会员结束时间',
  73. ];
  74. }
  75. static public function _getToken($uid)
  76. {
  77. $auth_str = $uid;
  78. $expiry = 0;
  79. $key = 'building';
  80. $timeExpiry = sprintf('%010d', $expiry ? $expiry + time() : 0);
  81. $topAuth = substr(md5($auth_str . $timeExpiry . $key), 0, 6);
  82. $enString = base64_encode($timeExpiry . $auth_str);
  83. return $topAuth . $enString;
  84. }
  85. static public function _checkToken($token)
  86. {
  87. $string = $token;
  88. $key = 'building';
  89. $topAuth = substr($string, 0, 6);
  90. $enString = substr($string, 6);
  91. $str = base64_decode($enString);
  92. $timeExpiry = substr($str, 0, 10);
  93. $deString = substr($str, 10);
  94. if ($topAuth != substr(md5($deString . $timeExpiry . $key), 0, 6)) {
  95. return false;
  96. }
  97. $timeExpiry *= 1;
  98. if ($timeExpiry != 0 && $timeExpiry < time()) {
  99. return false;
  100. }
  101. return $deString;
  102. }
  103. }