<?php
/**
 * 供应商缓存
 * Created by PhpStorm.
 * User: haoren
 * Date: 2020/12/17
 * Time: 17:00
 */

namespace JinDouYun\Cache;

use Mall\Framework\Factory;
use Mall\Framework\Core\ResultWrapper;
use Mall\Framework\Core\ErrorCode;

class SupplierCache
{
    private $cache;
    protected $SupplierToken = 'SupplierToken';//供应商token

    public function __construct()
    {
        $this->cache = Factory::cache('default');
    }
    /**
     * 缓存供应商token
     * @param $enterpriseId
     * @param $supplierId
     * @param $token
     * @return bool
     */
    public function setSupplierToken($enterpriseId, $supplierId, $token)
    {
        return $this->cache->zadd($this->SupplierToken.'::'.$enterpriseId, $supplierId, $token);
    }

    /**
     * 根据token获取供应商id  反解token需要
     * @param $enterpriseId
     * @param $token
     * @return float
     */
    public function getSupplierToken($enterpriseId, $token)
    {
        return $this->cache->zscore($this->SupplierToken.'::'.$enterpriseId, $token);
    }
}