| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Models;
- /**
- * 会员-模型
- * @author laravel开发员
- * @since 2020/11/11
- * Class MemberModel
- * @package App\Models
- */
- class MemberModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'member';
- protected $appends = ['age','time_text','mobile_text'];
- // 头像
- public function getAvatarAttribute($value)
- {
- $value = $value ? get_image_url($value) : '';
- return $value;
- }
- // 时间
- public function getTimeTextAttribute()
- {
- return $this->create_time? datetime($this->create_time,'Y-m-d H:i:s') : '';
- }
- // 生日
- public function getAgeAttribute()
- {
- $time = $this->birthday? strtotime($this->birthday) : 0;
- $year = $time?date('Y', $time):0;
- $month = $time?date('m', $time):0;
- if(date('m') >= $month){
- $year = $year?date('Y') - $year:0;
- }else{
- $year = $year?date('Y') - $year-1:0;
- }
- return $year;
- }
- /**
- * @return array
- */
- public function getMobileTextAttribute()
- {
- return $this->mobile? format_mobile($this->mobile):'';
- }
- /**
- * 邀请用户
- */
- public function invites()
- {
- return $this->hasOne(MemberModel::class, 'parent_id','id')
- ->with(['account'])
- ->where(['mark'=>1])
- ->select(['id', 'nickname','avatar', 'realname','company','parent_id','department','position', 'mobile', 'status']);
- }
- /**
- * 获取会员信息
- * @param int $id 会员ID
- * @return array|string
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function getInfo($id)
- {
- $info = parent::getInfo($id); // TODO: Change the autogenerated stub
- if ($info) {
- // 头像
- if ($info['avatar']) {
- $info['avatar'] = get_image_url($info['avatar']);
- }
- }
- return $info;
- }
- }
|