MemberModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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','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. // 时间
  36. public function getLoginTimeAttribute($value)
  37. {
  38. return $value? datetime($value,'Y-m-d H:i:s') : '';
  39. }
  40. // 身份证
  41. public function getIdcardTextAttribute()
  42. {
  43. return $this->idcard? substr($this->idcard,0,4).'**************' : '';
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function getmobileTextAttribute()
  49. {
  50. return $this->mobile? format_mobile($this->mobile):'';
  51. }
  52. /**
  53. * 推荐人
  54. */
  55. public function parent()
  56. {
  57. return $this->hasOne(MemberModel::class, 'id','parent_id')
  58. ->where(['status'=>1,'mark'=>1])
  59. ->select(['id', 'nickname','realname','avatar', 'mobile', 'status']);
  60. }
  61. /**
  62. * 邀请用户
  63. */
  64. public function invites()
  65. {
  66. return $this->hasOne(MemberModel::class, 'parent_id','id')
  67. ->where(['mark'=>1])
  68. ->select(['id', 'nickname','avatar', 'realname','parent_id', 'mobile', 'status']);
  69. }
  70. /**
  71. * 获取会员信息
  72. * @param int $id 会员ID
  73. * @return array|string
  74. * @author laravel开发员
  75. * @since 2020/11/11
  76. */
  77. public function getInfo($id)
  78. {
  79. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  80. if ($info) {
  81. // 头像
  82. if ($info['avatar']) {
  83. $info['avatar'] = get_image_url($info['avatar']);
  84. }
  85. }
  86. return $info;
  87. }
  88. }