<?php

class Order_update extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->HT = $this->load->database('HT', TRUE);
        //读取默认配置
        $this->COLI_WebCode = $this->config->item('Site_Code');
        $this->COLI_Area = $this->config->item('Site_Area');
        $this->COLI_CustomerType = $this->config->item('Site_DepartmentID');
        $this->COLI_department = $this->config->item('Site_Department');
        $this->COLI_Currency = $this->config->item('Site_Currency');
        $this->COLI_InterestRate = $this->config->item('Site_InterestRate');
        $this->COLI_TrueCardRate = $this->config->item('Site_TrueCardRate');
        $this->COLI_TouristLGC = $this->config->item('Site_ServiceLGC');
        $this->COLI_OrderStartDate = null;
        $this->COLI_Keywords = NULL;
    }

    public $coli_where_update = "";
    public function biz_confirmlineinfo_update($column_data)
    {
        if ($this->coli_where_update == "" || empty($column_data)) {
            return false;
        }
        $update_str = $this->HT->update_string('BIZ_ConfirmLineInfo', $column_data, $this->coli_where_update);
        $update_exc = $this->HT->query($update_str);
        return $update_exc;
    }

    public $cold_where_update = "";
    public function biz_confirmlinedetail_update($column_data)
    {
        if ($this->cold_where_update == "" || empty($column_data)) {
            return false;
        }
        $update_str = $this->HT->update_string('BIZ_ConfirmLineDetail', $column_data, $this->cold_where_update);
        $update_exc = $this->HT->query($update_str);
        return $update_exc;
    }

    /*!
     * 更新拼团信息
     * @date   2018-04-26
     * @param  array     $column_data 需要更新的列数据数组
     */
    public $gci_where_update = "";  // where 条件
    public function biz_groupcombineinfo_update($column_data)
    {
        if ($this->gci_where_update == "" || empty($column_data)) {
            return false;
        }
        $update_str = $this->HT->update_string('GroupCombineInfo', $column_data, $this->gci_where_update);
        $update_exc = $this->HT->query($update_str);
        return $this->HT->query("SELECT top 1 * from GroupCombineInfo WHERE " . $this->gci_where_update)->row();
    }

    /*!
     * 更新团信息
     */
    public $gri_where_update = "";  // where 条件
    public function biz_groupinfo_update($column_data)
    {
        if ($this->gri_where_update == "" || empty($column_data)) {
            return false;
        }
        $update_str = $this->HT->update_string('GroupInfo', $column_data, $this->gri_where_update);
        $update_exc = $this->HT->query($update_str);
        return $update_exc;
    }

    /*!
     * 地接计划状态变更
     * @param  [type]     $vas_sn      [description]
     * @param  string     $confirminfo [description]
     */
    public function vendorStatus_update($vas_sn, $lmi_sn, $confirminfo="")
    {
        $sql = "UPDATE VendorArrangeState
                SET VAS_IsConfirm=1
                    ,VAS_ConfirmInfo=?
                    ,VAS_ConfirmTime=getdate()
                    ,VAS_ConfirmSN=?
                WHERE VAS_SN=?";
        $query = $this->HT->query($sql, array($confirminfo, $lmi_sn, $vas_sn));
        // affected_rows() doesn't work with the 'sqlsrv' driver in CI2
        // The solution: Upgrade to the latest CodeIgniter 3.0.x version
        $ssql = "SELECT 1 as 'exist' from VendorArrangeState where VAS_IsConfirm=1 and VAS_SN=? ";
        $squery = $this->HT->query($ssql, array($vas_sn));
        $ret = $squery->result();
        return !empty($ret);
    }

}
