MemberModel.php 2.5 KB

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