MemberModel.php 3.4 KB

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