MemberModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 会员-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * Class MemberModel
  17. * @package App\Models
  18. */
  19. class MemberModel extends BaseModel
  20. {
  21. // 设置数据表
  22. protected $table = 'member';
  23. protected $appends = ['time_text','level_name','idcard_text','mobile_text'];
  24. // 头像
  25. public function getAvatarAttribute($value)
  26. {
  27. $value = $value ? get_image_url($value) : '';
  28. return $value;
  29. }
  30. // 时间
  31. public function getTimeTextAttribute()
  32. {
  33. return $this->create_time? datetime($this->create_time,'Y-m-d H:i:s') : '';
  34. }
  35. // VIP等级名称
  36. public function getLevelNameAttribute()
  37. {
  38. $vipTypes = ['普通会员','黄金会员','白金会员'];
  39. return $this->vip_expired >= date('Y-m-d H:i:s') && $this->member_level>0? $vipTypes[$this->member_level]: '普通用户';
  40. }
  41. public function getMemberLevelAttribute()
  42. {
  43. return $this->vip_expired >= date('Y-m-d H:i:s') && $this->member_level>0? $this->member_level: 0;
  44. }
  45. // 时间
  46. public function getLoginTimeAttribute($value)
  47. {
  48. return $value? datetime($value,'Y-m-d H:i:s') : '';
  49. }
  50. // 身份证
  51. public function getIdcardTextAttribute()
  52. {
  53. return $this->idcard? substr($this->idcard,0,4).'**************' : '';
  54. }
  55. /**
  56. * @return array
  57. */
  58. public function getmobileTextAttribute()
  59. {
  60. return $this->mobile? format_mobile($this->mobile):'';
  61. }
  62. /**
  63. * 推荐人
  64. */
  65. public function parent()
  66. {
  67. return $this->hasOne(MemberModel::class, 'id','parent_id')
  68. ->where(['status'=>1,'mark'=>1])
  69. ->select(['id', 'nickname','realname','avatar', 'mobile', 'status']);
  70. }
  71. /**
  72. * 邀请用户
  73. */
  74. public function invites()
  75. {
  76. return $this->hasOne(MemberModel::class, 'parent_id','id')
  77. ->where(['mark'=>1])
  78. ->select(['id', 'nickname','avatar', 'realname','parent_id', 'mobile', 'status']);
  79. }
  80. /**
  81. * 获取会员信息
  82. * @param int $id 会员ID
  83. * @return array|string
  84. * @author laravel开发员
  85. * @since 2020/11/11
  86. */
  87. public function getInfo($id)
  88. {
  89. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  90. if ($info) {
  91. // 头像
  92. if ($info['avatar']) {
  93. $info['avatar'] = get_image_url($info['avatar']);
  94. }
  95. }
  96. return $info;
  97. }
  98. }