MemberModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * @return array
  37. */
  38. public function getmobileTextAttribute()
  39. {
  40. return $this->mobile? format_mobile($this->mobile):'';
  41. }
  42. /**
  43. * 收益账户
  44. * @return \Illuminate\Database\Eloquent\Relations\hasOne
  45. */
  46. public function account()
  47. {
  48. return $this->hasOne(AccountStatisticsModel::class, 'user_id','id');
  49. }
  50. /**
  51. * 推荐人
  52. */
  53. public function parent()
  54. {
  55. return $this->hasOne(MemberModel::class, 'id','parent_id')
  56. ->with(['account'])
  57. ->where(['status'=>1,'mark'=>1])
  58. ->select(['id', 'nickname','realname','avatar', 'mobile','company','department','position', 'status']);
  59. }
  60. /**
  61. * 邀请用户
  62. */
  63. public function invites()
  64. {
  65. return $this->hasOne(MemberModel::class, 'parent_id','id')
  66. ->with(['account'])
  67. ->where(['mark'=>1])
  68. ->select(['id', 'nickname','avatar', 'realname','company','parent_id','department','position', '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. }