You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
439 lines
19 KiB
PHP
439 lines
19 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Group_model extends CI_Model {
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->HT = $this->load->database('HT', TRUE);
|
|
}
|
|
|
|
public function get_plan_not_received($top=1, $gri_sn=0, $vendor_str=null, $start_date=null, $end_date=null)
|
|
{
|
|
$top_sql = $top>0 ? " TOP $top " : "";
|
|
$gri_sql = $gri_sn===0 ? "" : " and GRI_SN=$gri_sn ";
|
|
$sql = "SELECT $top_sql VAS_IsConfirm, VAS_SendVary,
|
|
GRI_OrderType, GRI_SN, GRI_No, GRI_operator,GRI_Name,
|
|
(select OPI_DEI_SN from OperatorInfo where OPI_SN=GRI_operator) as department,
|
|
(select OPI2_Name from OperatorInfo2 where OPI2_OPI_SN=GRI_operator and OPI2_LGC=2) as operator,
|
|
vas.*
|
|
from VendorArrangeState vas
|
|
inner join Eva_ObjectInfo eoi on EOI_GRI_SN=VAS_GRI_SN and EOI_Type=1 and EOI_ObjSN=VAS_VEI_SN
|
|
inner join GRoupInfo gri on GRI_SN=VAS_GRI_SN
|
|
where 1=1 AND VAS_VEI_SN in ($vendor_str)
|
|
AND isnull(VAS_IsCancel,0)=0 AND isnull(VAS_Delete,0)=0 AND isnull(vas.DeleteFlag,0)=0
|
|
AND VAS_IsSendSucceed=1 ";
|
|
$sql .= $gri_sn!==0 ? $gri_sql : "
|
|
AND isnull(VAS_IsReceive,0)=0
|
|
-- AND EOI_GetDate between '$start_date' AND '$end_date'
|
|
AND EOI_GetDate > CONVERT(date, GETDATE())
|
|
AND isnull(VAS_IsConfirm,0)=0 AND VAS_ConfirmSN IS NULL
|
|
and not exists (
|
|
select 1 from VendorPlanSendout where VPS_VAS_SN=VAS_SN
|
|
)
|
|
";
|
|
$sql .= " order by EOI_GetDate asc,vas.VAS_SendTime asc, vas.VAS_IsConfirm asc";
|
|
return $this->HT->query($sql)->result();
|
|
}
|
|
|
|
public function get_plan_eva($vas)
|
|
{
|
|
$sql = "SELECT
|
|
isnull(eoi_v.EOI_SendEvaluation,0) as need_tourguide,
|
|
isnull(eoi_g.EOI_SN,0) as has_tourguide,
|
|
vas.*,eoi_v.*
|
|
from VendorArrangeState vas
|
|
inner join Eva_ObjectInfo eoi_v on EOI_GRI_SN=VAS_GRI_SN
|
|
and EOI_Type=1 and EOI_ObjSN=VAS_VEI_SN
|
|
left join Eva_ObjectInfo eoi_g on eoi_g.EOI_GRI_SN=VAS_GRI_SN
|
|
and eoi_g.EOI_Type=3 and eoi_g.EOI_VEI_SN=eoi_v.EOI_ObjSN
|
|
where VAS_SN=?
|
|
order by has_tourguide desc ";
|
|
return $this->HT->query($sql, array($vas))->result();
|
|
}
|
|
|
|
public function get_vendor_plan_info($gri_sn, $vendor_id, $from_cold=false)
|
|
{
|
|
$sql = "SET NOCOUNT ON;EXEC Tourmanager.dbo.SP_VendorPlan_GetPlanInfo $gri_sn, $vendor_id, 0 ";
|
|
$grd_info = $this->call_sp_fun($sql);
|
|
$all_day_no = array_map(function($ele){return $ele->GRD_DayNo;}, $grd_info);
|
|
$day_no_str = implode(",", $all_day_no);
|
|
$cold_sn_str = implode(",", array_map(function ($ele){return $ele->GRD_COLD_SN;}, $grd_info));
|
|
if ($from_cold===false) {
|
|
$all_aci = $this->get_arrange_info($gri_sn, $vendor_id, $day_no_str);
|
|
$all_hotel = $this->get_arrange_hotel($gri_sn, $day_no_str);
|
|
foreach ($grd_info as $kgrd => &$vgrd) {
|
|
$vgrd->pag_code_arr = array();
|
|
$vgrd->PAG_Title = $vgrd->GRD_Landscape;
|
|
foreach ($all_aci as $kaci => $vaci) {
|
|
if ($vgrd->GRD_DayNo == $vaci->ACI_DayNo) {
|
|
$vgrd->day_no_raw = strstr($vaci->ACI_OrderDate, " ", true);
|
|
$vgrd->tocity = $vaci->tocity;
|
|
$vgrd->citycode = $vaci->citycode;
|
|
$vgrd->ACI_PersonNum = intval($vaci->ACI_PersonNum);
|
|
$vgrd->ACI_ChildNum = intval($vaci->ACI_ChildNum);
|
|
$vgrd->ACI_BabyNum = intval($vaci->ACI_BabyNum);
|
|
$vgrd->PAG_DEI_SN = $vaci->PAG_DEI_SN ? $vaci->PAG_DEI_SN : 0;
|
|
if ( strval($vaci->ACI_ServiceType)==='D') {
|
|
$vgrd->PAG_Code = mb_strtoupper($vaci->PAG_Code);
|
|
$vgrd->PAG_ExtendType = mb_strtoupper($vaci->PAG_ExtendType);
|
|
$vgrd->pag_code_arr[] = mb_strtoupper($vaci->PAG_Code);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
$vgrd->hotel_name = '';
|
|
foreach ($all_hotel as $kh => $vh) {
|
|
if ($vgrd->GRD_DayNo == $vh->ACI_DayNo) {
|
|
$vgrd->hotel_name = $vh->hotel;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$all_cold = $this->get_arrange_info_from_biz_cold($cold_sn_str);
|
|
foreach ($grd_info as $kgrd => &$vgrd) {
|
|
$vgrd->pag_code_arr = array();
|
|
$vgrd->PAG_Title = $vgrd->GRD_Landscape;
|
|
foreach ($all_cold as $kcold => $vcold) {
|
|
if ($vgrd->GRD_COLD_SN == $vcold->COLD_SN) {
|
|
$vgrd->day_no_raw = strstr($vcold->COLD_StartDate, " ", true);
|
|
$vgrd->tocity = $vcold->tocity;
|
|
$vgrd->citycode = $vcold->citycode;
|
|
$vgrd->ACI_PersonNum = intval($vcold->COLD_PersonNum);
|
|
$vgrd->ACI_ChildNum = intval($vcold->COLD_ChildNum);
|
|
$vgrd->ACI_BabyNum = intval($vcold->COLD_BabyNum);
|
|
$vgrd->PAG_DEI_SN = $vcold->PAG_DEI_SN ? $vcold->PAG_DEI_SN : 0;
|
|
$vgrd->PAG_sub_sn = intval($vcold->COLD_ServiceSN2);
|
|
$vgrd->vendor_memo = trim($vcold->COLD_vendorMemo);
|
|
$vgrd->is_biz = 1;
|
|
if ( strval($vcold->COLD_ServiceType)==='D') {
|
|
$vgrd->PAG_Code = mb_strtoupper($vcold->PAG_Code);
|
|
$vgrd->PAG_ExtendType = mb_strtoupper($vcold->PAG_ExtendType);
|
|
$vgrd->pag_code_arr[] = mb_strtoupper($vcold->PAG_Code);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $grd_info;
|
|
}
|
|
|
|
public function get_plan_request($gri_sn)
|
|
{
|
|
$sql = "SELECT * from GroupChangeInfo
|
|
where GCI_GRI_SN=?
|
|
order by LastEditTime desc
|
|
,case when GCI_Order IS null then 999 else GCI_Order end desc";
|
|
return $this->HT->query($sql, array($gri_sn))->row();
|
|
}
|
|
|
|
public function get_arrange_info($gri_sn, $vendor_id=0, $day_no="")
|
|
{
|
|
$param_arr = array($gri_sn);
|
|
$vendor_sql = "";
|
|
if ($vendor_id !== 0) {
|
|
$vendor_sql = " AND aci.ACI_VEI_SN=? ";
|
|
$param_arr[] = $vendor_id;
|
|
}
|
|
$day_no_sql = ($day_no !== "") ? " AND aci.ACI_DayNo IN ($day_no) " : "";
|
|
$sql = "SELECT
|
|
(select CII2_Name from CItyInfo2
|
|
where CII2_CII_SN=ACI_FromCity and CII2_LGC=2) as fromcity,
|
|
(select CII2_Name from CItyInfo2
|
|
where CII2_CII_SN=ACI_ToCity and CII2_LGC=2) as tocity,
|
|
(select CII_PKCode from CItyInfo
|
|
where CII_SN=ACI_ToCity ) as citycode,
|
|
PAG_Code,PAG_ExtendType,PAG_DEI_SN,
|
|
*
|
|
from ArrangeConfirmInfo aci
|
|
left join BIZ_PackageInfo on PAG_SN=ACI_ServiceSN
|
|
and ACI_ServiceType='D' and PAG_DefaultVEI_SN=ACI_VEI_SN
|
|
-- 增加是否目的地产品的判断
|
|
and SUBSTRING(CONVERT(varchar(10), PAG_SourceType) ,1,3)='132'
|
|
where 1=1
|
|
and aci.ACI_GRI_SN=?
|
|
$vendor_sql
|
|
$day_no_sql
|
|
order by ACI_DayNo,ACI_SNInOneDay ";
|
|
return $this->HT->query($sql, $param_arr)->result();
|
|
}
|
|
|
|
public function get_arrange_info_from_biz_cold($cold_sn_str)
|
|
{
|
|
$sql = "SELECT
|
|
(select CII2_Name from CItyInfo2
|
|
where CII2_CII_SN=PAG_CII_SN and CII2_LGC=2) as tocity,
|
|
(select CII_PKCode from CItyInfo
|
|
where CII_SN=PAG_CII_SN ) as citycode,
|
|
PAG_Code,PAG_ExtendType,PAG_DEI_SN,
|
|
* from BIZ_ConfirmLineDetail cold
|
|
left join BIZ_PackageInfo on PAG_SN=COLD_ServiceSN
|
|
and COLD_ServiceType='D' and PAG_DefaultVEI_SN=COLD_PlanVEI_SN
|
|
and SUBSTRING(CONVERT(varchar(10), PAG_SourceType) ,1,3)='132'
|
|
where 1=1
|
|
and COLD_SN in (
|
|
$cold_sn_str
|
|
)
|
|
order by COLD_StartDate asc ";
|
|
return $this->HT->query($sql)->result();
|
|
}
|
|
|
|
public function get_arrange_hotel($gri_sn, $day_no="")
|
|
{
|
|
$day_no_sql = ($day_no !== "") ? " AND aci.ACI_DayNo IN ($day_no) " : "";
|
|
$sql = "SELECT
|
|
aci.ACI_VEI_SN,
|
|
aci.ACI_SN,
|
|
aci.ACI_DayNo,
|
|
(select VEI2_CompanyN from vendorinfo2 where vei2_vei_sn=ACI_serviceSN and VEI2_LGC=2) as hotel,
|
|
ACI_ServiceType,ACI_ServiceSN,ACI_ServiceSN2,
|
|
ACI_OrderDate,
|
|
ACI_Amount
|
|
-- ,*
|
|
from ArrangeConfirmInfo aci
|
|
where 1=1
|
|
and aci.ACI_GRI_SN=?
|
|
and aci.ACI_ServiceType = 'A'
|
|
$day_no_sql
|
|
order by ACI_DayNo,ACI_SNInOneDay";
|
|
return $this->HT->query($sql, array($gri_sn))->result();
|
|
}
|
|
|
|
public function get_sync_info($vas, $external_id=null, $tour_code="")
|
|
{
|
|
$sql = "SELECT *
|
|
from VendorPlanSendout
|
|
where VPS_VAS_SN=? ";
|
|
$param_arr = array($vas);
|
|
if ($external_id !== null) {
|
|
$sql .= " AND VPS_externalId=? ";
|
|
$param_arr[] = $external_id;
|
|
}
|
|
if ($tour_code !== "") {
|
|
$sql .= " AND VPS_tourCode=? ";
|
|
$param_arr[] = $tour_code;
|
|
}
|
|
return $this->HT->query($sql, $param_arr)->row();
|
|
}
|
|
|
|
public function get_sync_info_by_vendororder($vendor_order_id)
|
|
{
|
|
$sql = "SELECT
|
|
opi.OPI_DEI_SN as department,
|
|
*
|
|
from VendorPlanSendout vps
|
|
inner join VendorArrangeState vas on vas.VAS_SN=vps.VPS_VAS_SN
|
|
inner join GRoupInfo gri on GRI_SN=vas.VAS_GRI_SN
|
|
left join OperatorInfo opi on opi.OPI_SN=GRI_operator
|
|
where VPS_externalId=? ";
|
|
$param_arr = array($vendor_order_id);
|
|
return $this->HT->query($sql, $param_arr)->row();
|
|
}
|
|
|
|
/*!
|
|
* 获取地接社接受计划的人员信息
|
|
* @param $vendor_id 地接社ID
|
|
*/
|
|
public function get_vendorContact($vendor_id)
|
|
{
|
|
$sql = "SELECT
|
|
lmi.LMI2_Name,lmi.LMI_SN,lmi.LMI_AutoFax
|
|
,lmi.LMI_Telephone,lmi.LMI_Mobile,lmi.LMI_ListMail
|
|
,vei2.VEI2_CompanyBN
|
|
from V_Link_Man_Info lmi
|
|
left join VEndorInfo2 vei2 on VEI2_VEI_SN=lmi.LMI_VEI_SN
|
|
and VEI2_LGC=2
|
|
where lmi.LMI_VEI_SN=?
|
|
and lmi.LMI_DefaultContactor='Yes'
|
|
and lmi.LGC_LGC=2";
|
|
$query = $this->HT->query($sql, array($vendor_id));
|
|
return $query->row();
|
|
}
|
|
|
|
public function search_tourguide($vendor, $cn_name, $en_name=null, $mobile=null)
|
|
{
|
|
$param_arr = array();
|
|
$en_sql = " ";
|
|
if (strval($en_name)!=="") {
|
|
$en_sql = " and tgi_en.TGI2_Name =? ";
|
|
$param_arr[] = $en_name;
|
|
}
|
|
$mobile_sql = " ";
|
|
if (strval($mobile)!=="") {
|
|
$mobile_sql = " or TGI_Mobile=? ";
|
|
$param_arr[] = $mobile;
|
|
}
|
|
$sql = "SELECT TGI_VEI_SN,TGI_Mobile,
|
|
tgi_cn.TGI2_Name cn_name,
|
|
tgi_en.TGI2_Name en_name,
|
|
TGI_SN
|
|
from TouristGuideInfo2 tgi_en
|
|
join TouristGuideInfo on TGI_SN=tgi_en.TGI2_TGI_SN and tgi_en.TGI2_LGC=1
|
|
join TouristGuideInfo2 tgi_cn on TGI_SN=tgi_cn.TGI2_TGI_SN and tgi_cn.TGI2_LGC=2
|
|
where (
|
|
( 1=1
|
|
and tgi_cn.TGI2_Name like '%" . $this->HT->escape_like_str($cn_name) . "%'
|
|
$en_sql
|
|
)
|
|
$mobile_sql
|
|
)
|
|
and TGI_VEI_SN in ($vendor)";
|
|
return $this->HT->query($sql, $param_arr)->row();
|
|
}
|
|
|
|
public function set_plan_tourguide($eva_g_sn=0, $column=array())
|
|
{
|
|
if ($eva_g_sn===0) {
|
|
// 第一次设置导游
|
|
$this->HT->insert("Eva_ObjectInfo", $column);
|
|
$eva_g_sn = $this->HT->query("SELECT MAX(EOI_SN) EOI_SN from Eva_ObjectInfo
|
|
where EOI_GRI_SN=?
|
|
and EOI_VEI_SN=?
|
|
and EOI_Type=3
|
|
", array($column['EOI_GRI_SN'], $column['EOI_VEI_SN']))
|
|
->row()->EOI_SN;
|
|
} else {
|
|
// 变更导游设置
|
|
$update_where = " EOI_SN=".$eva_g_sn;
|
|
$update_sql = $this->HT->update_string("Eva_ObjectInfo", $column, $update_where);
|
|
$this->HT->query($update_sql);
|
|
}
|
|
return $eva_g_sn;
|
|
}
|
|
|
|
public function set_plan_received($vas_sn=0, $gri_sn=null)
|
|
{
|
|
$sql = "UPDATE VendorArrangeState set VAS_IsReceive=1,VAS_ReceiveTime=GETDATE() where VAS_SN=$vas_sn ";
|
|
if ($gri_sn !== null) {
|
|
$sql = "UPDATE VendorArrangeState set VAS_IsReceive=1,VAS_ReceiveTime=GETDATE() where VAS_GRI_SN=$gri_sn ";
|
|
}
|
|
return $this->HT->query($sql);
|
|
}
|
|
|
|
/*!
|
|
* 地接计划状态变更
|
|
* @param [type] $vas_sn [description]
|
|
* @param string $confirminfo [description]
|
|
*/
|
|
public function set_plan_confirm($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);
|
|
}
|
|
|
|
public function insert_VendorPlanSync($sync_arr=array())
|
|
{
|
|
$ss = $this->HT->insert_string('VendorPlanSendout', $sync_arr); // testing
|
|
$this->HT->insert('VendorPlanSendout', $sync_arr);
|
|
return $this->HT->query("SELECT MAX(VPS_SN) VPS_SN from VendorPlanSendout")
|
|
->row()->VPS_SN;
|
|
}
|
|
|
|
public function update_VendorPlanSync($vps, $sync_arr=array())
|
|
{
|
|
$where = " VPS_SN=" . $vps;
|
|
$update_sql = $this->HT->update_string('VendorPlanSendout', $sync_arr, $where);
|
|
return $this->HT->query($update_sql);
|
|
}
|
|
|
|
/*
|
|
* 发送邮件
|
|
*/
|
|
public function save_automail($M_SenderName, $M_SenderEmail, $fromName, $fromEmail, $toName, $toEmail, $subject, $body, $frominfo = 'vendorConfirm msg', $M_RelatedInfo = '', $M_State = 0, $M_AddTime = '', $M_Web = 'vendorConfirm msg') {
|
|
$sql = "INSERT INTO
|
|
Email_AutomaticSend (
|
|
M_SenderName,
|
|
M_SenderEmail,
|
|
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?, N?, ?, N?, ?,?,getdate()) ";
|
|
$query = $this->HT->query($sql, array($M_SenderName, $M_SenderEmail, $fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_Web, $frominfo, $M_RelatedInfo, $M_State));
|
|
return $query;
|
|
}
|
|
|
|
public function get_vendor_city($vei_sn)
|
|
{
|
|
$sql = "SELECT
|
|
CII_PKCode citycode,CII2_Name cityname
|
|
from VEndorInfo
|
|
inner join CItyInfo on CII_SN=VEI_CII_Name
|
|
inner join CItyInfo2 on CII2_CII_SN=VEI_CII_Name and CII2_LGC=2
|
|
where VEI_SN=? ";
|
|
return $this->HT->query($sql, array($vei_sn))->row();
|
|
}
|
|
|
|
/*!
|
|
* @Author: LYT
|
|
* @Date: 2019-06-25 14:56:01
|
|
* @Desc: 生成计划最后的导游备注
|
|
* @return PHP ArrayObject
|
|
*/
|
|
public function get_plan_remark($gri_sn, $vei_sn)
|
|
{
|
|
$sql = "DECLARE @StrResult varchar(1000);SET NOCOUNT ON;
|
|
EXEC SP_VendorPlan_GetAddFeeProduct $gri_sn, $vei_sn, @StrResult out
|
|
SELECT @StrResult as remark
|
|
";
|
|
$result_obj = $this->call_sp_fun($sql);
|
|
return empty($result_obj) ? '' : $result_obj[0]->remark;
|
|
}
|
|
|
|
public function call_sp_fun($sql)
|
|
{
|
|
// SET NOCOUNT ON 才能这样调用, 否则需要遍历结果集
|
|
// $sql = " Tourmanager.dbo.SP_VendorPlan_GetPlanInfo ?, ?, 0 ";
|
|
// $grd_info = $this->HT->query($sql, array($gri_sn, $vendor_id))->result();
|
|
include('c:/database_conn.php');
|
|
$connection = array(
|
|
'UID' => $db['HT']['username'],
|
|
'PWD' => $db['HT']['password'],
|
|
'Database' => 'tourmanager',
|
|
'ConnectionPooling' => 1,
|
|
'CharacterSet' => 'utf-8',
|
|
'ReturnDatesAsStrings' => 1
|
|
);
|
|
$conn = sqlsrv_connect($db['HT']['hostname'], $connection);
|
|
$stmt = sqlsrv_query($conn, $sql);
|
|
$result_object = array();
|
|
if (false !== $stmt ) { // 无权限或执行错误返回false
|
|
// 存储过程中每个select都产生结果集
|
|
// 设置了SET NOCOUNT ON;就只有输出的结果集
|
|
$a = true;
|
|
while ($a !== false) {
|
|
$row = sqlsrv_fetch_object($stmt); // Retrieves the next row of data as a PHP object.
|
|
$a = !empty($row);
|
|
$a===true ? $result_object[] = $row : null;
|
|
}
|
|
sqlsrv_free_stmt($stmt);
|
|
}
|
|
sqlsrv_close($conn);
|
|
return $result_object;
|
|
}
|
|
|
|
}
|
|
|
|
/* End of file Group_model.php */
|
|
/* Location: ./third_party/vendorPlanSync/models/Group_model.php */
|