<?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);

        $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),
                ),
            ),
        );

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

        if ($member) {
        	$where['id'] = $member['id'];
        	$where['idcard'] = $member['idcard'];
        	$other = Dever::db('agent/member')->getData($where);
        	$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' => 'info',
	            'content' => array
	            (
	                array
	                (
	                	array('姓名', $member['name']),
	                    array('手机号', $member['mobile']),
	                    array('角色', $role['name']),
	                ),

	                array
	                (
	                	array('身份证号', $member['idcard']),
	                ),

	                array
	                (
	                    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' => 'info',
			            'content' => array
			            (
			                array
			                (
			                	array('姓名', $v['name']),
			                    array('手机号', $v['mobile']),
			                    array('角色', $role['name']),
			                ),

			                array
			                (
			                	array('身份证号', $v['idcard']),
			                ),

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

        $button = array();
        if ($info['status'] == 1) {
        	$button['btn'][] = array
	        (
	            'type' => 'action',
	            'link' => Dever::url('lib/user.setStatus?id=' . $info['id'] . '&value=2', 'agent'),
	            'name' => '对比核实通过',
	        );
	        $button['btn'][] = array
	        (
	            'type' => 'action',
	            'link' => Dever::url('lib/user.setStatus?id=' . $info['id'] . '&value=3', 'agent'),
	            'name' => '拒绝',
	        );
        }

        $head_btn[] = array
        (
            'type' => 'link',
            'link' => Dever::url('project/database/list?project=agent&table=user_bind&page_type=2', 'manage'),
            'name' => '返回上一页',
        );
        $head = array
        (
            'name' => '零售账号绑定',
            'btn' => $head_btn,
        );
        $foot = $button;
        $html = Dever::show($head, $result, $foot);

        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';
    }
}