MemberModel.php 2.4 KB

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