<?php

namespace Setting\Lib;

use Dever;

class Manage
{
    public function role()
    {
        $data = Dever::db('setting/role')->state();
        if ($data) {
            foreach ($data as $k => $v) {
                if ($v['isbuy'] == 2 && $v['id'] > 1) {
                    $data[$k]['name'] .= '（已关停）';
                } else {
                    $data[$k]['name'] = $v['name'];
                }
            }
        }
        return $data;
    }

    public function getAgreementData()
    {
        $data = Dever::db('setting/agreement')->select();
        if ($data) {
            $config = Dever::db('setting/agreement')->config['config_type'];
            foreach ($data as $k => $v) {
                $data[$k]['name'] = $config[$v['type']];
            }
        }
        return $data;
    }

    public function showSource($id)
    {
        $url = 'http://daili.churenyiliao.com/pages/dailishang/apply/apply/';
        $url .= '?source_id=' . $id;

        $code = Dever::url('setting/lib/code.show?id=' . $id);
        $table['二维码'] = '<img src="'.$code.'" width="150"/>';
        $table['链接'] = $url;
        return Dever::table($table);
    }

    public function showReward($id)
    {
        $info = Dever::db('setting/role_reward')->one($id);

        if ($info) {
            $role = Dever::db('setting/role')->one($info['role_id']);
            $t_role = Dever::db('setting/role')->one($info['t_role_id']);

            return $role['name'] . ' 邀请 ' . $t_role['name'];
        }
        return '';
    }

}