UserModel.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\common\model;
  3. use app\utils\CurlUtil;
  4. use think\Db;
  5. use think\Model;
  6. /**
  7. * 动态评论
  8. */
  9. class UserModel extends Model
  10. {
  11. // 表名
  12. protected $name = 'user';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = false;
  15. // 定义时间戳字段名
  16. protected $createTime = false;
  17. protected $updateTime = false;
  18. protected $deleteTime = false;
  19. /**
  20. * 获取头像
  21. * @param string $value
  22. * @param array $data
  23. * @return string
  24. */
  25. public function getAvatarAttr($value, $data)
  26. {
  27. if (!$value) {
  28. //如果不需要启用首字母头像,请使用
  29. $value = CurlUtil::getHttp('/assets/img/avatar.png');
  30. // $value = letter_avatar($data['nickname']);
  31. }else{
  32. $value = cdnurl($value);
  33. }
  34. return $value;
  35. }
  36. public static function getInfoById($id)
  37. {
  38. $info = self::where('id', $id)->find();
  39. unset(
  40. $info['username'],
  41. $info['password'],
  42. $info['salt'],
  43. $info['successions'],
  44. $info['maxsuccessions'],
  45. $info['prevtime'],
  46. $info['loginip'],
  47. $info['loginfailure'],
  48. $info['joinip'],
  49. $info['jointime'],
  50. $info['updatetime'],
  51. );
  52. return $info;
  53. }
  54. public static function getInfoByUserNo($user_no)
  55. {
  56. $info = self::where('user_no', $user_no)->find();
  57. unset(
  58. $info['username'],
  59. $info['password'],
  60. $info['salt'],
  61. $info['successions'],
  62. $info['maxsuccessions'],
  63. $info['prevtime'],
  64. $info['loginip'],
  65. $info['loginfailure'],
  66. $info['joinip'],
  67. $info['jointime'],
  68. $info['updatetime'],
  69. );
  70. return $info;
  71. }
  72. public static function getInfoByChatId($chat_id)
  73. {
  74. $info = self::where('chat_id', $chat_id)->find();
  75. unset(
  76. $info['username'],
  77. $info['password'],
  78. $info['salt'],
  79. $info['successions'],
  80. $info['maxsuccessions'],
  81. $info['prevtime'],
  82. $info['loginip'],
  83. $info['loginfailure'],
  84. $info['joinip'],
  85. $info['jointime'],
  86. $info['updatetime'],
  87. );
  88. return $info;
  89. }
  90. }