MemberModel.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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->vip_expired || $this->vip_expired=='0000-00-00 00:00:00') && $this->member_level>0? $vipTypes[$this->member_level]: '普通会员';
  40. }
  41. public function getMemberLevelAttribute($value)
  42. {
  43. return ($this->vip_expired >= date('Y-m-d H:i:s') || !$this->vip_expired || $this->vip_expired=='0000-00-00 00:00:00') && $value>0? $value: 0;
  44. }
  45. public function getVipExpiredAttribute($value)
  46. {
  47. if($value >= date('Y-m-d H:i:s')){
  48. return $value;
  49. }else if(!$value || $value=='0000-00-00 00:00:00'){
  50. return '永久有效';
  51. }else{
  52. return 0;
  53. }
  54. }
  55. // 时间
  56. public function getLoginTimeAttribute($value)
  57. {
  58. return $value? datetime($value,'Y-m-d H:i:s') : '';
  59. }
  60. // 身份证
  61. public function getIdcardTextAttribute()
  62. {
  63. return $this->idcard? substr($this->idcard,0,4).'**************' : '';
  64. }
  65. /**
  66. * @return array
  67. */
  68. public function getmobileTextAttribute()
  69. {
  70. return $this->mobile? format_mobile($this->mobile):'';
  71. }
  72. /**
  73. * 推荐人
  74. */
  75. public function parent()
  76. {
  77. return $this->hasOne(MemberModel::class, 'id','parent_id')
  78. ->where(['status'=>1,'mark'=>1])
  79. ->select(['id', 'nickname','realname','avatar', 'mobile', 'status']);
  80. }
  81. /**
  82. * 邀请用户
  83. */
  84. public function invites()
  85. {
  86. return $this->hasOne(MemberModel::class, 'parent_id','id')
  87. ->where(['mark'=>1])
  88. ->select(['id', 'nickname','avatar', 'realname','parent_id', 'mobile', 'status']);
  89. }
  90. /**
  91. * 获取会员信息
  92. * @param int $id 会员ID
  93. * @return array|string
  94. * @author laravel开发员
  95. * @since 2020/11/11
  96. */
  97. public function getInfo($id)
  98. {
  99. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  100. if ($info) {
  101. // 头像
  102. if ($info['avatar']) {
  103. $info['avatar'] = get_image_url($info['avatar']);
  104. }
  105. }
  106. return $info;
  107. }
  108. }