<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Model;
use Think\Model;

/**
 * 分类模型
 */
class SiteApplyModel extends Model{

    /**
     * 构造函数
     * @param string $name 模型名称
     * @param string $tablePrefix 表前缀
     * @param mixed $connection 数据库连接信息
     */
    public function __construct($name = '', $tablePrefix = '', $connection = '') {
        /* 设置默认的表前缀 */
        $this->tablePrefix ='tab_';
        /* 执行构造方法 */
        parent::__construct($name, $tablePrefix, $connection);
    }

    protected $_validate = array(
        array('site_url', 'require', '站点域名不能为空', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('url_type', 'require', '站点来源不能为空', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('site_url', 'url', '站点域名不正确', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
//        array('name', '', '标识已经存在', self::VALUE_VALIDATE, 'unique', self::MODEL_BOTH),
    );

    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('promote_id', PID, self::MODEL_BOTH),
    );

    /**
     * 获取站点信息
     * @param int $promote_id
     * @return mixed
     */
    public function get_promote_data($promote_id=PID){
        $map['promote_id'] = $promote_id;
        $data = $this->where($map)->find();
        return $data;
    }

		
	/*
	 * 未审核混服申请列表
	 * @return array   检测结果数据集
	 * @author 鹿文学
	 */
	public function checkSiteApply() {
		
		$list = $this->field('tab_site_apply.id,tab_site_apply.promote_id,tab_promote.account')
				
				->join('tab_promote on (tab_promote.id = tab_site_apply.promote_id)','left')
			
				->where(array('tab_site_apply.status'=>0))->select();
		$type=301;
		if ($list[0]) {
			
			$list = D('check')->dealWithCheckList($type,$list);
			
			if (empty($list[0])) {return '';}
			
			foreach ($list as $k => $v) {
				$data[$k]['info'] = '混服申请,推广员账号:'.$v['account'].',账号状态:未审核';
				$data[$k]['type'] = $type;
				$data[$k]['url'] = U('Promote/lists',array('type'=>2,'promote_id'=>$v['promote_id']));
				$data[$k]['create_time'] = time();
				$data[$k]['status']=0;
				$data[$k]['position'] = $v['id'];
			}
			return $data;
		}else {
			D('check')->dealWithCheckListOnNull($type);
			return '';
		}
		
	}		
		
	
}