<?php

namespace app\common\model;

use liuniu\BaseModel;
use think\Model;

class UserRelation extends BaseModel
{

    // 表名
    protected $name = 'user_relation';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    // 追加属性
    protected $append = [
    ];

    /**
     * 获取用户编号
     * @param $openid
     * @param string $field
     * @return float|mixed|string
     */
    public static function openidToUid($openid,$field="openid")
    {
        $model = new self;
        return $model->where($field,$openid)->value('user_id');
    }

    /**
     * 获取OPENDID
     * @param $user_id
     * @param string $field
     * @return float|mixed|string
     */
    public static function userIdToOpenId($user_id,$field = "openid")
    {
        return self::where('user_id',$user_id)->value($field);
    }
}
