<?php

namespace Agent\Lib;

use Dever;

class User
{
    /**
     * 查看详情
     * @return mixed
     */
    public function show()
    {
        $id = Dever::input('id');
        $info = Dever::db('agent/user_bind')->one($id);
        $status = Dever::db('agent/user_bind')->config['status'];
        $audit_date='';
        if(isset($info['aduit_date']) && $info['aduit_date']){
            $audit_date = date('Y-m-d H:i', $info['audit_date']);
        }else{
            $audit_date = '-';
        }
        /*
        $idcard_pic = '<a href="'.$info['idcard_front'].'" target="_blank"><img src="'.$info['idcard_front'].'" width="150" /></a>';
        if ($info['idcard_back']) {
            $idcard_pic .= '&nbsp;&nbsp;<a href="'.$info['idcard_back'].'" target="_blank"><img src="'.$info['idcard_back'].'" width="150" /></a>';
        }

        $result['小程序账号'] = array
        (
            'type' => 'info',
            'content' => array
            (
                array
                (
                    array('手机号', $info['mobile']),
                    array('姓名', $info['name']),
                    array('身份证号', $info['idcard']),
                ),

                array
                (
                    array('身份证照片', $idcard_pic),
                ),
            ),
        );
        */

        $user = Dever::db('passport/user')->find($info['uid']);

        $result['审核信息'] = array
        (
            'type' => 'user',
            'content' => array
            (
                array('状态', $status[$info['status']]),
                array('时间', $audit_date),
                array('审核人', Dever::load("manage/admin-find#username", $info['admin'])),
                array('审核备注', $info['audit_desc']),
            ),
        );

        $result['小程序账号'] = array
        (
            'type' => 'user',
            'content' => array
            (
                //array('手机号', $user['mobile']),
                array('昵称', $user['username']),
                array('身份证号', $info['idcard']),
            ),
        );

        $member = Dever::db('agent/member')->find($info['mid']);

        if ($member) {
        	$where['id'] = $member['id'];
        	$where['idcard'] = $member['idcard'];
            $where['status'] = '1,2';
        	//$other = Dever::db('agent/member')->getData($where);
        	$other = false;
        	$idcard_pic = '<a href="'.$member['idcard_front'].'" target="_blank"><img src="'.$member['idcard_front'].'" width="150" /></a>';
	        if ($member['idcard_back']) {
	            $idcard_pic .= '&nbsp;&nbsp;<a href="'.$member['idcard_back'].'" target="_blank"><img src="'.$member['idcard_back'].'" width="150" /></a>';
	        }
	        $role = Dever::db('setting/role')->find($member['role']);

        	$result['代理商账号：' . $member['name']] = array
	        (
	            'type' => 'user',
	            'content' => array
	            (
	            	array('姓名', $member['name']),
                    array('手机号', $member['mobile']),
                    array('角色', $role['name']),
                    array('身份证号', $member['idcard']),
                    array('身份证照片', $idcard_pic),
	            ),
	        );

        	if ($other) {
        		foreach ($other as $k => $v) {
        			$role = Dever::db('setting/role')->find($v['role']);
        			$idcard_pic = '<a href="'.$v['idcard_front'].'" target="_blank"><img src="'.$v['idcard_front'].'" width="150" /></a>';
			        if ($v['idcard_back']) {
			            $idcard_pic .= '&nbsp;&nbsp;<a href="'.$v['idcard_back'].'" target="_blank"><img src="'.$v['idcard_back'].'" width="150" /></a>';
			        }

        			$result['代理商账号：' . $v['name']] = array
			        (
			            'type' => 'user',
			            'content' => array
			            (
			                array('姓名', $v['name']),
		                    array('手机号', $v['mobile']),
		                    array('角色', $role['name']),
		                    array('身份证号', $v['idcard']),
			                array('身份证照片', $idcard_pic),
			            ),
			        );
        		}
        	}
        }

        $head_btn = array();
        //Dever::url('lib/user.setStatus?id=' . $info['id'] . '&value=2', 'agent'),
        //Dever::url('lib/user.setStatus?id=' . $info['id'] . '&value=3', 'agent'),

        /*
        $head_btn[] = array
        (
            'type' => 'link',
            'link' => Dever::url('project/database/list?project=agent&table=user_bind&page_type=2', 'manage'),
            'name' => '返回上一页',
        );*/

        if ($info['status'] == 1) {
            $head_btn[] = array
            (
                'type' => 'edit',
                'link' => Dever::url('project/database/update?project=agent&table=user_bind&where_id='.$id.'&col=audit,audit_desc', 'manage'),
                'name' => '审核',
            );
        }
        $head = array
        (
            'name' => '账号绑定',
            'btn' => $head_btn,
        );
        $html = Dever::show($head, $result, false, false, 'dls-user-box');

        return $html;
    }


    public function setStatus_api()
    {
        $where['where_id'] = Dever::input('id');
        $where['status'] = Dever::input('value');

        Dever::db('agent/user_bind')->update($where);

        return 'reload';
    }
}