HT = $this->load->database('HT', TRUE); } //根据订单号获取外联邮箱 public function get_order($COLI_ID, $orderinfo = false, $ordertype = 'N') { $result = ''; $fieldsql = $orderinfo == false ? '' : " ,* "; //先查商务订单B,APP订单A、再查传统订单T if ($ordertype == 'B' || $ordertype == 'A') { $sql = "SELECT TOP 1 0 as order_type,COLI_SN,COLI_ID,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode,COLI_State $fieldsql from BIZ_ConfirmLineInfo LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN where COLI_ID =?"; $query = $this->HT->query($sql, array($COLI_ID)); $result = $query->result(); } //后查传统订单的原因是因为传统订单的订单号去掉外联名字首字母后可能会和商务订单的重合。 if (empty($result) && ($ordertype == 'T')) { $sql = "SELECT TOP 1 1 as order_type, COLI_SN,COLI_ID,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode,COLI_State $fieldsql from ConfirmLineInfo LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN where COLI_ID like '%$COLI_ID'"; $query = $this->HT->query($sql); $result = $query->result(); } //查传统订单add_code,网前实时支付会先生成一个临时订单号存在add_code里,如订单45103248 if (empty($result) && ($ordertype == 'M')) { $sql = "SELECT TOP 1 1 as order_type, COLI_SN,COLI_ID,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode $fieldsql from ConfirmLineInfo LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN where COLI_AddCode =? "; $query = $this->HT->query($sql, array($COLI_ID)); $result = $query->result(); } if (empty($result) && ($ordertype == 'M')) { $sql = "SELECT TOP 1 1 as order_type, COLI_SN,COLI_ID,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode $fieldsql from ConfirmLineInfo cli LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN where EXISTS ( SELECT TOP 1 1 FROM ConfirmLineInfoTmp clit WHERE clit.COLI_ID = ? AND cli.COLI_AddCode = CAST(clit.COLI_SN AS VARCHAR(10)) ) "; $query = $this->HT->query($sql, array($COLI_ID)); $result = $query->result(); } //订单号查询不到尝试使用团号查询 if (empty($result) && $ordertype == 'B') { $sql = "SELECT TOP 1 0 as order_type,COLI_SN,COLI_ID,OPI_Email,OPI_FirstName,OPI_Name,COLI_WebCode,COLI_State $fieldsql from BIZ_ConfirmLineInfo LEFT JOIN OperatorInfo ON COLI_OPI_ID=OPI_SN where COLI_GroupCode like '%-$COLI_ID%'"; $query = $this->HT->query($sql); $result = $query->result(); } //团号查询不到尝试使用客人邮箱查询(预订多次的老客户得按日期新旧排序,取最新的数据) if (!empty($result)) { //print_r($result[0]); //die(); $result = $result[0]; } return $result; } //获取收款记录(商务订单) public function get_money_list($GAI_COLI_ID, $GAI_SQJE, $GAI_SQJECurrency) { $sql = "SELECT GAI_SN,GAI_CusEmail,GAI_Memo FROM BIZ_GroupAccountInfo bgai WHERE bgai.GAI_COLI_ID = ? and GAI_SQJE=? and GAI_SQJECurrency=? ORDER BY bgai.GAI_SN ASC"; $query = $this->HT->query($sql, array($GAI_COLI_ID, $GAI_SQJE, $GAI_SQJECurrency)); $result = $query->result(); return $result; } //获取收款记录(传统订单) public function get_money_list2($COLI_ID, $GAI_SQJE, $GAI_SQJECurrency) { $sql = "SELECT COLI_ID,GroupAccountInfo.* from GroupAccountInfo left join ConfirmLineInfo on GAI_COLI_SN=COLI_SN where COLI_ID=? and GAI_SQJE=? and GAI_SQJECurrency=? ORDER BY GAI_SN ASC"; $query = $this->HT->query($sql, array($COLI_ID, $GAI_SQJE, $GAI_SQJECurrency)); $result = $query->result(); return $result; } //更新收款记录(商务订单) public function update_account_info($GAI_CusEmail, $GAI_Memo, $GAI_SN, $GAI_AccreditNo) { $sql = "UPDATE BIZ_GroupAccountInfo SET GAI_CusEmail=?, GAI_Memo=?,GAI_AccreditNo=? WHERE GAI_SN=?"; $query = $this->HT->query($sql, array($GAI_CusEmail, $GAI_Memo, $GAI_AccreditNo, $GAI_SN)); return $query; } //更新收款记录(传统订单) public function update_account_info2($GAI_CusEmail, $GAI_Memo, $GAI_SN) { $sql = "UPDATE GroupAccountInfo SET GAI_CusEmail=?, GAI_Memo=? WHERE GAI_SN=?"; $query = $this->HT->query($sql, array($GAI_CusEmail, $GAI_Memo, $GAI_SN)); return $query; } //修改订单状态 public function update_biz_coli_state($coli_sn, $coli_state) { $sql = " UPDATE BIZ_ConfirmLineInfo SET COLI_State = ? WHERE COLI_SN = ? "; $query = $this->HT->query($sql, array($coli_state, $coli_sn)); return $query; } //添加收款记录(商务订单),APP会自动增加记录,所以添加前根据金额来判断是否有重复记录 public function add_account_info_forAPP($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { //先判断是否有这条数据 $sql = " IF NOT EXISTS( SELECT TOP 1 1 FROM BIZ_GroupAccountInfo WHERE GAI_COLI_SN = ? AND GAI_SQJE=? ) INSERT INTO BIZ_GroupAccountInfo ( GAI_COLI_SN ,GAI_COLI_ID ,GAI_Type ,GAI_SQJE ,GAI_SQDate ,GAI_SQJECurrency ,GAI_SSDate ,GAI_AccountDate ,GAI_SubmitDate ,GAI_CusName ,GAI_CusEmail ,GAI_AccreditNo ,GAI_Memo ,GAI_State ,DeleteFlag ) VALUES (?,?,15015,?,?,?,?,?,?,?,?,?,?,0,0)"; $query = $this->HT->query($sql, array($GAI_COLI_SN, $GAI_SQJE, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); return $query; } //添加收款记录(商务订单) public function add_account_info($GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { //先判断是否有这条数据 $sql = " IF NOT EXISTS( SELECT TOP 1 1 FROM BIZ_GroupAccountInfo WHERE GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%' ) INSERT INTO BIZ_GroupAccountInfo ( GAI_COLI_SN ,GAI_COLI_ID ,GAI_Type ,GAI_SQJE ,GAI_SQDate ,GAI_SQJECurrency ,GAI_Money ,GAI_SSDate ,GAI_AccountDate ,GAI_SubmitDate ,GAI_CusName ,GAI_CusEmail ,GAI_AccreditNo ,GAI_Memo ,GAI_State ,DeleteFlag ) VALUES (?,?,15015,?,?,?,?,?,?,?,?,?,?,?,0,0)"; $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_Money, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); return $query; } //添加收款记录(传统订单) public function add_tour_account_info($GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo) { //先判断是否有这条数据 $sql = " IF NOT EXISTS( SELECT TOP 1 1 FROM GroupAccountInfo WHERE GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%' ) INSERT INTO GroupAccountInfo ( GAI_COLI_SN ,GAI_Type ,GAI_SQJE ,GAI_SQDate ,GAI_SQJECurrency ,GAI_SSDate ,GAI_AccountDate ,GAI_SubmitDate ,GAI_CusName ,GAI_CusEmail ,GAI_AccreditNo ,GAI_Memo ,GAI_State ,DeleteFlag ) VALUES (?,15015,?,?,?,?,?,?,?,?,?,?,0,0)"; $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); $insertid = $this->HT->last_id('GroupAccountInfo'); return $query; } //更新线路提醒 public function update_coli_introduction($coli_sn, $msg) { $sql = " update ConfirmLineInfo set COLI_Introduction=ISNULL(COLI_Introduction,'')+' '+? where 1=1 AND ISNULL(COLI_Introduction,'')='' AND COLI_SN=? "; // isnull(COLI_Sended,0) in (0,1) 之前判断是新订单或者未分配状态才添加提示的,有些团是后面付款的,所以把限制取消掉 $query = $this->HT->query($sql, array($msg, $coli_sn)); return $query; } //存储paypal的实时通知 public function save_paypal_note($pn_txn_id, $pn_invoice, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer_email, $pn_payment_date, $pn_memo) { $sql = " INSERT INTO paypal_note ( pn_txn_id,pn_invoice, pn_mc_gross, pn_item_name, pn_item_number,pn_mc_currency, pn_payment_status,pn_payer_email,pn_payment_date, pn_memo,pn_datetime ) VALUES ( ?,?,?,N?,N?,?,?,N?,?, N?, GETDATE() ) "; $query = $this->HT->query($sql, array($pn_txn_id, $pn_invoice, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer_email, $pn_payment_date, $pn_memo)); $insertid = $this->HT->last_id('paypal_note'); return $query; } public function update_mail($mail_sn, $mail_to, $mail_to_name, $mail_sendstate = 0) { $sql = "UPDATE Email_AutomaticSend SET M_ToEmail=N?,M_ToName=N?,M_State=? WHERE M_SN =? "; $query = $this->HT->query($sql, array($mail_to, $mail_to_name, $mail_sendstate, $mail_sn)); return $query; } public function save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo = '', $M_State = 0, $M_AddTime = '', $frominfo = 'paypal msg', $M_Web = 'paypal msg') { $sql = "INSERT INTO Email_AutomaticSend ( M_ReplyToName, M_ReplyToEmail, M_ToName, M_ToEmail, M_Title, M_Body, M_Web, M_FromName, M_ServiceSN, M_State, M_AddTime ) VALUES (N?, N?, N?, N?, N?, N?, ?, N?, ?,?,getdate()) "; $query = $this->HT->query($sql, array($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_Web, $frominfo, $M_RelatedInfo, $M_State)); return $query; } /*! * 调用数据库函数,转换为美金 */ public function get_USD($amount, $currency='RMB') { $sql = "SELECT dbo.ConvertCurrencyToCurrency(?,?,?,?) as ssje"; $query = $this->HT->query($sql, array(1, mb_strtolower($currency), 'usd', $amount)); $result = $query->result(); if ( ! empty($result)) { return $result[0]->ssje; } return 0; } }