<?php

class Order_model extends CI_Model {

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

    public function get_order_by_id($order_id) {
        // [syn123].tourmanager.dbo.
        $order_query = $this->hunter->query("select COLI_Name, COLI_OrderDetailText, COLI_OrderStartDate
            from ConfirmLineInfoTmp
            where
                COLI_ID = ?", $order_id);
        $order_array = $order_query->row_array();
        if (empty($order_array)) {
            $order_array = [
                'COLI_Name' => '无法查到该订单',
                'COLI_OrderDetailText' => '请检查订单号是否正确',
                'COLI_OrderStartDate' => 'NULL'
            ];
        }
        return $order_array;
    }

    public function get_order_by_id_in_ht($order_id) {
        $order_query = $this->hunter->query("select COLI_Name, COLI_OrderDetailText, COLI_OrderStartDate from ConfirmLineInfo where COLI_AddCode IN
            (select cast(coli_sn as varchar(20))
            from ConfirmLineInfoTmp
            where
              COLI_ID = ?)", $order_id);
        $order_array = $order_query->row_array();
        
        if (empty($order_array)) {
            $order_array = [
                'COLI_Name' => '无法查到该订单',
                'COLI_OrderDetailText' => '订单可能没有同步回来',
                'COLI_OrderStartDate' => 'NULL'
            ];
        }
        return $order_array;
    }
}
