MemberModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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','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. * @return array
  42. */
  43. public function getmobileTextAttribute()
  44. {
  45. return $this->mobile? format_mobile($this->mobile):'';
  46. }
  47. /**
  48. * 推荐人
  49. */
  50. public function parent()
  51. {
  52. return $this->hasOne(MemberModel::class, 'id','parent_id')
  53. ->where(['status'=>1,'mark'=>1])
  54. ->select(['id', 'nickname','realname','avatar','parent_id','point_id', 'mobile', 'status']);
  55. }
  56. /**
  57. * 邀请用户
  58. */
  59. public function invites()
  60. {
  61. return $this->hasMany(MemberModel::class, 'parent_id','id')
  62. ->where(['mark'=>1])
  63. ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']);
  64. }
  65. /**
  66. * 节点推荐人
  67. */
  68. public function point()
  69. {
  70. return $this->hasOne(MemberModel::class, 'id','point_id')
  71. ->where(['status'=>1,'mark'=>1])
  72. ->select(['id', 'nickname','parent_id','point_id','realname','avatar', 'mobile', 'status']);
  73. }
  74. /**
  75. * 下级节点
  76. */
  77. public function points()
  78. {
  79. return $this->hasOne(MemberModel::class, 'point_id','id')
  80. ->where(['mark'=>1])
  81. ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']);
  82. }
  83. /**
  84. * 获取会员信息
  85. * @param int $id 会员ID
  86. * @return array|string
  87. * @author laravel开发员
  88. * @since 2020/11/11
  89. */
  90. public function getInfo($id)
  91. {
  92. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  93. if ($info) {
  94. // 头像
  95. if ($info['avatar']) {
  96. $info['avatar'] = get_image_url($info['avatar']);
  97. }
  98. }
  99. return $info;
  100. }
  101. }