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 = ['age','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 getAgeAttribute()
  37. {
  38. $time = $this->birthday? strtotime($this->birthday) : 0;
  39. $year = $time?date('Y', $time):0;
  40. $month = $time?date('m', $time):0;
  41. if(date('m') >= $month){
  42. $year = $year?date('Y') - $year:0;
  43. }else{
  44. $year = $year?date('Y') - $year-1:0;
  45. }
  46. return $year;
  47. }
  48. /**
  49. * @return array
  50. */
  51. public function getMobileTextAttribute()
  52. {
  53. return $this->mobile? format_mobile($this->mobile):'';
  54. }
  55. /**
  56. * 邀请用户
  57. */
  58. public function invites()
  59. {
  60. return $this->hasOne(MemberModel::class, 'parent_id','id')
  61. ->with(['account'])
  62. ->where(['mark'=>1])
  63. ->select(['id', 'nickname','avatar', 'realname','company','parent_id','department','position', '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. }