MemberModel.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. ->with(['account'])
  54. ->where(['status'=>1,'mark'=>1])
  55. ->select(['id', 'nickname','realname','avatar', 'mobile', 'status']);
  56. }
  57. /**
  58. * 邀请用户
  59. */
  60. public function invites()
  61. {
  62. return $this->hasOne(MemberModel::class, 'parent_id','id')
  63. ->with(['account'])
  64. ->where(['mark'=>1])
  65. ->select(['id', 'nickname','avatar', 'realname','parent_id', 'mobile', 'status']);
  66. }
  67. /**
  68. * 获取会员信息
  69. * @param int $id 会员ID
  70. * @return array|string
  71. * @author laravel开发员
  72. * @since 2020/11/11
  73. */
  74. public function getInfo($id)
  75. {
  76. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  77. if ($info) {
  78. // 头像
  79. if ($info['avatar']) {
  80. $info['avatar'] = get_image_url($info['avatar']);
  81. }
  82. }
  83. return $info;
  84. }
  85. }