MemberModel.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 getBonusTotalAttribute($value)
  52. {
  53. return $value? floatval($value) : 0;
  54. }
  55. // 累计提现
  56. public function getWithdrawTotalAttribute($value)
  57. {
  58. return $value? floatval($value) : 0;
  59. }
  60. // 累计资产提现
  61. public function getWithdrawPropertyAttribute($value)
  62. {
  63. return $value? floatval($value) : 0;
  64. }
  65. // 数字资产
  66. public function getPropertyAttribute($value)
  67. {
  68. return $value? floatval($value) : 0;
  69. }
  70. /**
  71. * @return array
  72. */
  73. public function getmobileTextAttribute()
  74. {
  75. return $this->mobile? format_mobile($this->mobile):'';
  76. }
  77. /**
  78. * 会员等级数据
  79. */
  80. public function levelData()
  81. {
  82. return $this->hasOne(MemberLevelModel::class, 'id','member_level')
  83. ->where(['mark'=>1])
  84. ->select(['id', 'name','upper_count','bonus','status']);
  85. }
  86. /**
  87. * 推荐人
  88. */
  89. public function parent()
  90. {
  91. return $this->hasOne(MemberModel::class, 'id','parent_id')
  92. ->where(['status'=>1,'mark'=>1])
  93. ->select(['id', 'nickname','realname','avatar','member_level','parent_id','point_id', 'mobile', 'status']);
  94. }
  95. /**
  96. * 邀请用户
  97. */
  98. public function invites()
  99. {
  100. return $this->hasMany(MemberModel::class, 'parent_id','id')
  101. ->where(['mark'=>1])
  102. ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']);
  103. }
  104. /**
  105. * 节点推荐人
  106. */
  107. public function point()
  108. {
  109. return $this->hasOne(MemberModel::class, 'id','point_id')
  110. ->where(['status'=>1,'mark'=>1])
  111. ->select(['id', 'nickname','parent_id','point_id','realname','avatar', 'mobile', 'status']);
  112. }
  113. /**
  114. * 下级节点
  115. */
  116. public function points()
  117. {
  118. return $this->hasOne(MemberModel::class, 'point_id','id')
  119. ->where(['mark'=>1])
  120. ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']);
  121. }
  122. /**
  123. * 获取会员信息
  124. * @param int $id 会员ID
  125. * @return array|string
  126. * @author laravel开发员
  127. * @since 2020/11/11
  128. */
  129. public function getInfo($id)
  130. {
  131. $info = $this->where(['id'=>$id])->first(); // TODO: Change the autogenerated stub
  132. if ($info) {
  133. // 头像
  134. if ($info['avatar']) {
  135. $info['avatar'] = get_image_url($info['avatar']);
  136. }
  137. }
  138. return $info;
  139. }
  140. }