<?php

namespace app\common\model\hu;

use think\Exception;
use think\Model;
use traits\model\SoftDelete;
use think\Db;
class UserInvite extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'hu_user_invite';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    /**
     * 获取上级用户列表
     * @param int $user_id 用户ID
     * @return array
     **/
    public function getUsetInviteOne(int $user_id){

       $list = self::where('user_id',$user_id)
           ->where('status',1)
           ->select();

       return $list;
    }

    /**
     * 获取上上级用户列表
     * @param int $user_id 用户ID
     * @return array
     **/
    public function getUsetInviteOneTop(int $user_id){

        $list = self::where("level like '".$user_id."-%'")
            ->where('status',1)
            ->select();
        if(!empty($list)){
            foreach ($list as $key=>$value){
                $level = explode('-',$value['level']);
                $list[$key]['top_id'] = $level[1];
            }
        }
        return $list;
    }
    

}
