No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

116 líneas
2.4 KiB

  1. <?php
  2. namespace common\models;
  3. use yii\db\ActiveRecord;
  4. /**
  5. * This is the model class for table "sh_user".
  6. *
  7. * @property integer $uid
  8. * @property string $openid
  9. * @property string $phone
  10. * @property integer $fx_uid
  11. * @property integer $status
  12. * @property string $nickname
  13. * @property string $headimgurl
  14. * @property integer $sex
  15. * @property string $country
  16. * @property string $province
  17. * @property string $city
  18. * @property string $reg_time
  19. */
  20. class ShUser extends ActiveRecord
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return 'sh_user';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['status'], 'integer'],
  36. [['reg_time', 'last_login'], 'safe'],
  37. [['phone'], 'string', 'max' => 20],
  38. [['phone'], 'unique'],
  39. ];
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'uid' => 'Uid',
  48. 'phone' => 'Phone',
  49. 'status' => 'Status',
  50. 'reg_time' => 'Reg Time',
  51. 'last_login' => 'Last Login',
  52. ];
  53. }
  54. /**
  55. * Des:根据手机号获取用户ID 没有则注册一个
  56. * Name: getUidByPhone
  57. * @param $phone
  58. * @return int|mixed
  59. * @author 倪宗锋
  60. */
  61. public function getUidByPhone($phone)
  62. {
  63. $info = $this->getUserInfoByPhone($phone);
  64. if (empty($info['uid'])) {
  65. $this->addUser(['phone' => $phone]);
  66. $info = $this->getUserInfoByPhone($phone);
  67. }
  68. if (empty($info['uid'])) {
  69. return 0;
  70. }
  71. return $info['uid'];
  72. }
  73. /**
  74. * Des:根据手机号获取用户的信息
  75. * Name: getUserInfoByPhone
  76. * @param $phone
  77. * @return array
  78. * @author 倪宗锋
  79. */
  80. public function getUserInfoByPhone($phone)
  81. {
  82. $info = self::find()
  83. ->where(['=', 'phone', $phone])
  84. ->asArray()
  85. ->one();
  86. if (empty($info['uid'])) {
  87. return [];
  88. }
  89. return $info;
  90. }
  91. /**
  92. * Des: 添加用户
  93. * Name: addUser
  94. * @param $param
  95. * @return bool
  96. * @author 倪宗锋
  97. */
  98. public function addUser($param)
  99. {
  100. $this->setAttributes($param);
  101. $return = $this->insert(true);
  102. return $return;
  103. }
  104. }