MemberModel.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 getIdcardTextAttribute()
  37. {
  38. return $this->idcard? substr($this->idcard,0,4).'**************' : '';
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function getmobileTextAttribute()
  44. {
  45. return $this->mobile? format_mobile($this->mobile):'';
  46. }
  47. /**
  48. * 收益账户
  49. * @return \Illuminate\Database\Eloquent\Relations\hasOne
  50. */
  51. public function account()
  52. {
  53. return $this->hasOne(AccountStatisticsModel::class, 'user_id','id');
  54. }
  55. /**
  56. * 推荐人
  57. */
  58. public function parent()
  59. {
  60. return $this->hasOne(MemberModel::class, 'id','parent_id')
  61. ->with(['account'])
  62. ->where(['status'=>1,'mark'=>1])
  63. ->select(['id', 'nickname','realname','avatar', 'mobile','company','department','position', 'status']);
  64. }
  65. /**
  66. * 邀请用户
  67. */
  68. public function invites()
  69. {
  70. return $this->hasOne(MemberModel::class, 'parent_id','id')
  71. ->with(['account'])
  72. ->where(['mark'=>1])
  73. ->select(['id', 'nickname','avatar', 'realname','company','parent_id','department','position', 'mobile', 'status']);
  74. }
  75. /**
  76. * 获取会员信息
  77. * @param int $id 会员ID
  78. * @return array|string
  79. * @author laravel开发员
  80. * @since 2020/11/11
  81. */
  82. public function getInfo($id)
  83. {
  84. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  85. if ($info) {
  86. // 头像
  87. if ($info['avatar']) {
  88. $info['avatar'] = get_image_url($info['avatar']);
  89. }
  90. }
  91. return $info;
  92. }
  93. }