<?php

namespace App\Distributor\Repositories;

use App\Models\DistAdminDistributor as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class DistAdminDistributor extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    /*
     * 得到分销商信息
     */
    public static function getInfo()
    {
        $id = getDistributorId();
        $row = Model::find($id);
        return $row;
    }

    /*
     * 修改域名名称
     */
    public static function updateDomain($domainType,$customDomain)
    {
        $id = getDistributorId();
        $row = Model::find($id);
        $row->domain_type = $domainType;
        if ($domainType == 1) {
            $row->custom_domain = $customDomain;
        }
        $row->save();
    }

    /*
     * 分销商切换主题
     */
    public static function enableTheme($appearanceId)
    {
        $appearanceId = intval($appearanceId);
        $distId = getDistributorId();
        $distAppearance = new DistAppearance();
        $appearanceRow = $distAppearance->model()->find($appearanceId);
        if ($appearanceRow && $appearanceRow->enabled == 1) {
            //修改分销商主题
            $row = Model::find($distId);
            $row->appearance_id = $appearanceId;
            $row->save();
            //切换主题
            DistAppearance::switchTheme($appearanceId, $distId);
            return true;
        }
        return false;
    }



}
