| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?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 = ['time_text','level_name','idcard_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') : '';
- }
- // VIP等级名称
- public function getLevelNameAttribute()
- {
- $vipTypes = ['普通会员','黄金会员','白金会员'];
- return ($this->vip_expired >= date('Y-m-d H:i:s') || !$this->vip_expired || $this->vip_expired=='0000-00-00 00:00:00') && $this->member_level>0? $vipTypes[$this->member_level]: '普通会员';
- }
- public function getMemberLevelAttribute($value)
- {
- return ($this->vip_expired >= date('Y-m-d H:i:s') || !$this->vip_expired || $this->vip_expired=='0000-00-00 00:00:00') && $value>0? $value: 0;
- }
- public function getVipExpiredAttribute($value)
- {
- if($value >= date('Y-m-d H:i:s')){
- return $value;
- }else if(!$value || $value=='0000-00-00 00:00:00'){
- return '永久有效';
- }else{
- return 0;
- }
- }
- // 时间
- public function getLoginTimeAttribute($value)
- {
- return $value? datetime($value,'Y-m-d H:i:s') : '';
- }
- // 身份证
- public function getIdcardTextAttribute()
- {
- return $this->idcard? substr($this->idcard,0,4).'**************' : '';
- }
- /**
- * @return array
- */
- public function getmobileTextAttribute()
- {
- return $this->mobile? format_mobile($this->mobile):'';
- }
- /**
- * 推荐人
- */
- public function parent()
- {
- return $this->hasOne(MemberModel::class, 'id','parent_id')
- ->where(['status'=>1,'mark'=>1])
- ->select(['id', 'nickname','realname','avatar', 'mobile', 'status']);
- }
- /**
- * 邀请用户
- */
- public function invites()
- {
- return $this->hasOne(MemberModel::class, 'parent_id','id')
- ->where(['mark'=>1])
- ->select(['id', 'nickname','avatar', 'realname','parent_id', '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;
- }
- }
|