<?php

class Orders_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->HT = $this->load->database('HT', TRUE);
    }

    //获取当天传统订单信息
    function get_confirm_line_info($sitecode) {
        $sql = "SELECT clit.COLI_ID, n"
                . "       clit.COLI_WebCode, n"
                . "       clit.COLI_SenderIP n"
                . "FROM   ConfirmLineInfoTmp clit n"
                . "WHERE  DAY(GETDATE()) = DAY(COLI_ApplyDate) n"
                . "       AND MONTH(GETDATE()) = MONTH(COLI_ApplyDate) n"
                . "       AND YEAR(GETDATE()) = YEAR(COLI_ApplyDate) n"
                . "       AND clit.COLI_WebCode = ? n"
                . "ORDER BY coli_sn DESC";
        $query = $this->HT->query($sql, array($sitecode));
        return $query->result();
    }

    function get_detail_confirm($COLI_ID) {
        $sql = "SELECT colit.COLI_Name, n"
                . "       colit.COLI_ID, n"
                . "       colit.COLI_SN, n"
                . "       colit.COLI_SenderIP, n"
                . "       colit.COLI_ApplyDate, n"
                . "       colit.COLI_WebCode, n"
                . "       colit.COLI_OrderDetailText n"
                . "FROM   ConfirmLineInfoTmp colit n"
                . "WHERE  colit.COLI_ID = ? ";
        $query = $this->HT->query($sql, array($COLI_ID));
        if ($query->num_rows() > 0) {
            $row = $query->row();
            return $row;
        } else {
            return FALSE;
        }
    }

    function tour_count() {
        $date_start = date('Y-m-d', time() - 86400);//减一天
        $date_end = date('Y-m-d', time() + 86400);//加一天
        $sql = "
            SELECT COUNT(1) AS CLI_COUNT
            FROM   ConfirmLineInfoTmp clit
            WHERE  clit.COLI_ApplyDate BETWEEN '$date_start 00:00:00' AND  '$date_end 23:59:59' 
            ";
        $query = $this->HT->query($sql);
        //echo $sql;
        if ($query->num_rows() > 0) {
            $row = $query->row();
            return $row->CLI_COUNT;
        } else {
            return FALSE;
        }
    }

    //获取当天商务订单
    function biz_count() {
        $date_start = date('Y-m-d', time() - 86400);//减一天
        $date_end = date('Y-m-d', time() + 86400);//加一天
        $sql = "
            SELECT COUNT(1) AS CLI_COUNT
            FROM   BIZ_ConfirmLineInfo bcli
            WHERE  bcli.COLI_ApplyDate BETWEEN '$date_start 00:00:00' AND  '$date_end 23:59:59' 
            ";
        $query = $this->HT->query($sql);
        if ($query->num_rows() > 0) {
            $row = $query->row();
            return $row->CLI_COUNT;
        } else {
            return FALSE;
        }
    }

    //获取当天商务订单
    function get_biz_info($sitecode) {
        $sql = "SELECT bcli.COLI_ID, n"
                . "       bcli.COLI_ApplyDate, n"
                . "       bcli.COLI_SenderIP, n"
                . "       bcli.COLI_WebCode n"
                . "FROM   BIZ_ConfirmLineInfo bcli n"
                . "WHERE  DAY(GETDATE()) = DAY(COLI_ApplyDate) n"
                . "       AND MONTH(GETDATE()) = MONTH(COLI_ApplyDate) n"
                . "       AND YEAR(GETDATE()) = YEAR(COLI_ApplyDate) n"
                . "       AND bcli.COLI_WebCode = ? n"
                . "ORDER BY coli_sn DESC";
        $query = $this->HT->query($sql, array($sitecode));
        return $query->result();
    }

    //获取测试订单情况
    function get_test_order($start_date, $end_date) {
        $sql = "
					 SELECT MEI_FirstName, MEI_LastName, MEI_MailList, WCI_Describe, SYC2_CodeDiscribe
						 , DateAdd(hh, 13, COLI_ApplyDate) AS COLI_ApplyDate
					 FROM (SELECT TOP 300 *
						 FROM V_Check_Order
						 WHERE DateAdd(hh, 13, COLI_ApplyDate) BETWEEN ? AND ?
							 AND MEI_MailList = 'jstest@chinahighlights.com'
						 ) temp
					 ORDER BY temp.COLI_ApplyDate
			  ";
        $query = $this->HT->query($sql, array($start_date, $end_date));
        return $query->result();
    }

}
