MemberModel.php 2.1 KB

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