dzadsod/include/traits/tdata.class.php

636 lines
35 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* 表格数据显示,以及数据导出公用处理方案
*/
trait tdata
{
//sql语句采用分组查询后调整为true 使用子查询计算总条数
public $multi_table = false;
//搜索的input字段用来处理表数据显示时的颜色加重问题
private $search_input = [];
//搜索的select字段不用考虑搜索结果
private $search_other = [];
//带有表前缀的搜索字段,主要用于跨表联合查询,要对照上面数组合并后的顺序
private $search_field = [];
//搜索的LIKE字段
private $search_link = [];
//跳过替换为突出显示的字段
private $skip_field = [];
// 场所统计查询内的公用where
private $villages_where = '';
// 根据社区类型和地图选择判断小区的ID
private $village_whereid = '';
// 计算社区类型地图选择返回被选中的小区ID
private function fun_sqlk_vid()
{
global $_M, $_YW;
$idArr = $vidArr = [];
if (is_array($this->form['vtype'])) {
$vtype = arrayto_string($this->form['vtype'], ',');
$vid = $this->tsql->table('village')->qfield('id')->where("v_type IN({$vtype})")->all();
$idArr = array_column($vid, 'id');
if (count($idArr) == 0) $idArr = [-1];
}
if ($this->form['v_id']) {
$vidArr = stringto_array($this->form['v_id'], ',');
// 取社区类型和地图筛选的交集重叠ID社区类型没有操作则直接按照地图筛选结果
// $idArr = count($idArr) > 0?array_intersect($vidArr,$idArr):$vidArr;
if (count($idArr) > 0) {
$idArr = array_intersect($vidArr, $idArr);
// 如果交集为空则确实通过此条件进行了筛选就要通知SQL没有任何值满足当前条件将ID设置为0肯定查找不到
if (count($idArr) == 0) $idArr = [-1];
} else {
$idArr = $vidArr;
}
}
return $idArr;
}
//表名
public function td_sqlk()
{
global $_M, $_YW;
//当天日期时间
$curdate = date('Y-m-d', time());
switch ($this->tname) {
case 'applan':
//判断是否可选的依据
if (!empty($this->form['slid'])) $where = " AND nla.id != '{$this->form['slid']}' ";
$ason = '';
// 计算是否区分广告位,不考虑导出
if (is_array($this->form['e_aps'])) {
$veaps = parent::strchange(array_filter($this->form['e_aps']));
$this->villages_where = " nel.e_aps IN({$veaps}) ";
$ason .= " {$this->villages_where} AND ";
}
// 根据小区单个ID
if ($this->form['e_vid']) {
$ason .= " nel.e_vid = '{$this->form['e_vid']}' AND ";
}
// 社区类型 不考虑导出
$idArr = self::fun_sqlk_vid();
// 通过ID筛选掉不需要的
if (count($idArr) > 0) {
$this->village_whereid = arrayto_string(array_unique($idArr), ',');
$ason .= " nel.e_vid IN({$this->village_whereid}) AND ";
}
//表
$sqlk = " {$_YW['k']['elevator']} AS el "
. "LEFT JOIN (SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nowe_number,ANY_VALUE( nla.id ) AS nowid,ANY_VALUE( nla.l_title ) AS nowtitle,ANY_VALUE( nla.l_starttime ) AS nowstime,ANY_VALUE( nla.l_endtime ) AS nowetime,if(NOT ( nla.l_endtime < '{$curdate}' OR nla.l_starttime > '{$curdate}' ) OR nla.l_starttime > '{$curdate}',1,0) AS estate FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE {$ason} NOT ( nla.l_endtime < '{$curdate}' OR nla.l_starttime > '{$curdate}' ) AND nla.id IS NOT NULL ORDER BY nowstime ASC ) eala GROUP BY nowe_number ) ala ON ala.nowe_number = el.e_number "
. "LEFT JOIN (SELECT nel.e_number AS ende_number, max( nla.l_endtime ) AS endtime FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE {$ason} nla.id IS NOT NULL GROUP BY ende_number) cla ON cla.ende_number = el.e_number "
. "LEFT JOIN ( SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nexte_number,ANY_VALUE( nla.id ) AS nextid,ANY_VALUE( nla.l_title ) AS nexttitle,ANY_VALUE( nla.l_starttime ) AS nextstime,ANY_VALUE( nla.l_endtime ) AS nextetime FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE {$ason} nla.l_starttime > '{$curdate}' AND nla.id IS NOT NULL ORDER BY nextstime ASC ) eala GROUP BY nexte_number ) bla ON bla.nexte_number = el.e_number "
. "LEFT JOIN (SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nend_number,ANY_VALUE( nla.id ) AS endid,ANY_VALUE( nla.l_title ) AS endtitle,ANY_VALUE( nla.l_starttime ) AS endstime,ANY_VALUE( nla.l_endtime ) AS endetime FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE {$ason} nla.l_endtime < '{$curdate}' AND nla.id IS NOT NULL ORDER BY endetime DESC ) eala GROUP BY nend_number ) dla ON dla.nend_number = el.e_number "
. "LEFT JOIN (SELECT nel.e_number AS lde_number,count(nel.e_number) AS lanum FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE {$ason} NOT ( nla.l_endtime < '{$this->form['l_starttime']}' OR nla.l_starttime > '{$this->form['l_endtime']}' ) {$where} GROUP BY lde_number) AS ela ON ela.lde_number = el.e_number ";
break;
case 'elevators':
$sqlk = " {$_YW['k']['elevator']} AS el LEFT JOIN {$_YW['k']['launch']} AS la ON find_in_set( el.e_number, la.l_enumber ) "
. "LEFT JOIN (SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nowe_number,ANY_VALUE( nla.id ) AS nowid,ANY_VALUE( nla.l_title ) AS nowtitle,ANY_VALUE( nla.l_starttime ) AS nowstime,ANY_VALUE( nla.l_endtime ) AS nowetime,if(NOT ( nla.l_endtime < '{$curdate}' OR nla.l_starttime > '{$curdate}' ) OR nla.l_starttime > '{$curdate}',1,0) AS estate FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE NOT ( nla.l_endtime < '{$curdate}' OR nla.l_starttime > '{$curdate}' ) AND nla.id IS NOT NULL ORDER BY nowstime ASC ) eala GROUP BY nowe_number ) ala ON ala.nowe_number = el.e_number "
. "LEFT JOIN ( SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nexte_number,ANY_VALUE( nla.id ) AS nextid,ANY_VALUE( nla.l_title ) AS nexttitle,ANY_VALUE( nla.l_starttime ) AS nextstime,ANY_VALUE( nla.l_endtime ) AS nextetime FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE nla.l_starttime > '{$curdate}' AND nla.id IS NOT NULL ORDER BY nextstime ASC ) eala GROUP BY nexte_number ) bla ON bla.nexte_number = el.e_number "
. "LEFT JOIN (SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nend_number,ANY_VALUE( nla.id ) AS endid,ANY_VALUE( nla.l_title ) AS endtitle,ANY_VALUE( nla.l_starttime ) AS endstime,ANY_VALUE( nla.l_endtime ) AS endetime FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE nla.l_endtime < '{$curdate}' AND nla.id IS NOT NULL ORDER BY endetime DESC ) eala GROUP BY nend_number ) cla ON cla.nend_number = el.e_number ";
break;
case 'patrol':
$sqlk = " {$_YW['k']['elevator']} AS el LEFT JOIN {$_YW['k']['launch']} AS la ON find_in_set( el.e_number, la.l_enumber ) "
. "LEFT JOIN (SELECT * FROM( SELECT DISTINCT( nel.e_number ) AS nowe_number,ANY_VALUE( nla.id ) AS nowid,ANY_VALUE( nla.l_title ) AS nowtitle,ANY_VALUE( nla.l_starttime ) AS nowstime,ANY_VALUE( nla.l_endtime ) AS nowetime,if(NOT ( nla.l_endtime < '{$curdate}' OR nla.l_starttime > '{$curdate}' ) OR nla.l_starttime > '{$curdate}',1,0) AS estate FROM {$_YW['k']['elevator']} AS nel LEFT JOIN {$_YW['k']['launch']} AS nla ON find_in_set( nel.e_number, nla.l_enumber ) WHERE nla.l_starttime <= '{$curdate}' AND nla.id IS NOT NULL ORDER BY nowstime DESC ) eala GROUP BY nowe_number ) ala ON ala.nowe_number = el.e_number ";
break;
case 'villages':
$son = " FROM {$_YW['k']['countela']} AS el WHERE ";
//判断执行默认还是时间区段
$bool = false;
if ($this->form['vs_starttime'] || $this->form['vs_endtime']) {
$bool = true;
$this->form['vs_starttime'] = $this->form['vs_starttime'] ?: $curdate;
$this->form['vs_endtime'] = $this->form['vs_endtime'] ?: $curdate;
if (strtotime($this->form['vs_starttime']) > strtotime($this->form['vs_endtime'])) {
$vs_starttime = $this->form['vs_endtime'];
$vs_endtime = $this->form['vs_starttime'];
} else {
$vs_starttime = $this->form['vs_starttime'];
$vs_endtime = $this->form['vs_endtime'];
}
}
// 计算是否区分广告位
// 检测是否通过JS传递的广告位参数也就是导出
if (isset($this->form['jsadd_veaps'])) $this->form['veaps'] = stringto_array($this->form['jsadd_veaps'], ',');
if (is_array($this->form['veaps'])) {
$veaps = parent::strchange(array_filter($this->form['veaps']));
$this->villages_where = " el.e_aps IN({$veaps}) ";
$son .= " {$this->villages_where} AND ";
}
// 社区类型
// 先查询出需要的ID
if (isset($this->form['jsadd_vtype'])) $this->form['vtype'] = stringto_array($this->form['jsadd_vtype'], ',');
$idArr = self::fun_sqlk_vid();
// 通过ID筛选掉不需要的
if (count($idArr) > 0) {
$this->village_whereid = arrayto_string(array_unique($idArr), ',');
$son .= " el.e_vid IN({$this->village_whereid}) AND ";
}
// 空置计算要排除当前排期中的广告位
if ($bool) {
//加上时间区块 那就是查看在区段内的情况
//增加 s_enable 判断是为了防止过去时间
//空置
$fwhere = " {$son} NOT EXISTS (SELECT ela.e_number FROM {$_YW['k']['countela']} AS ela WHERE NOT ( ela.l_endtime < '{$vs_starttime}' OR ela.l_starttime > '{$vs_endtime}' ) AND ela.e_number = el.e_number) AND ( (el.l_endtime < '{$vs_starttime}' OR el.l_starttime > '{$vs_endtime}' ) OR el.l_id IS NULL ) AND el.e_enable = 1 ";
// 之前的旧代码
// $fwhere = " {$son} NOT EXISTS (SELECT ela.e_number FROM {$_YW['k']['countela']} AS ela WHERE NOT ( ela.l_endtime < '{$vs_starttime}' OR ela.l_starttime > '{$vs_endtime}' ) AND NOT(ela.l_endtime < '{$curdate}' OR ela.l_starttime > '{$curdate}' ) AND ela.e_number = el.e_number) AND ( ((el.l_endtime < '{$vs_starttime}' OR el.l_starttime > '{$vs_endtime}') AND el.l_endtime < '{$curdate}' ) OR el.l_id IS NULL ) AND el.e_enable = 1 ";
//排期中的
$lwhere = " {$son} NOT(el.l_endtime < '{$vs_starttime}' OR el.l_starttime > '{$vs_endtime}') ";
// 之前的旧代码
// $lwhere = " {$son} NOT(el.l_endtime < '{$vs_starttime}' OR el.l_starttime > '{$vs_endtime}') AND NOT(el.l_endtime < '{$curdate}' OR el.l_starttime > '{$curdate}' ) ";
//多少天到期的
$dwhere = " {$son} el.l_endtime BETWEEN '{$vs_starttime}' AND '{$vs_endtime}' ";
//预排
$pwhere = " {$son} NOT(el.l_endtime < '{$vs_starttime}' OR el.l_starttime > '{$vs_endtime}') AND el.l_starttime > '{$curdate}' ";
} else {
//没有时间区段,则按照当天为准则,默认值
//空置,其他不包含当天的
$fwhere = " {$son} NOT EXISTS (SELECT ela.e_number FROM {$_YW['k']['countela']} AS ela WHERE NOT ( ela.l_endtime < '{$curdate}' OR ela.l_starttime > '{$curdate}' ) AND ela.e_number = el.e_number) AND (el.l_endtime < '{$curdate}' OR el.l_starttime > '{$curdate}' OR el.l_id IS NULL) AND el.e_enable = 1 ";
//排期中的,日期包含当天的
$lwhere = " {$son} NOT(el.l_endtime < '{$curdate}' OR el.l_starttime > '{$curdate}' ) ";
//多少天到期的
$dwhere = " {$son} el.l_endtime BETWEEN '{$curdate}' AND date_add( '{$curdate}', INTERVAL 7 DAY ) ";
//预排,开始时间大于当天的
$pwhere = " {$son} el.l_starttime > '{$curdate}' ";
}
$sqlk = "{$_YW['k']['village']} AS vi LEFT JOIN {$_YW['k']['elevator']} AS el ON vi.id = el.e_vid "
. "LEFT JOIN (SELECT el.e_vid AS ae_vid,COUNT( DISTINCT el.e_number ) AS v_free,COUNT( DISTINCT el.e_vid, el.e_bno ) AS v_bno {$fwhere} GROUP BY ae_vid ) AS anum ON anum.ae_vid = vi.id "
. "LEFT JOIN (SELECT el.e_vid AS be_vid,COUNT( DISTINCT el.e_number ) AS v_lease {$lwhere} GROUP BY be_vid ) AS bnum ON bnum.be_vid = vi.id "
. "LEFT JOIN (SELECT el.e_vid AS ce_vid,COUNT( DISTINCT el.e_number ) AS v_endday {$dwhere} GROUP BY ce_vid ) AS cnum ON cnum.ce_vid = vi.id "
. "LEFT JOIN (SELECT el.e_vid AS de_vid,COUNT( DISTINCT el.e_number ) AS v_prerow {$pwhere} GROUP BY de_vid ) AS dnum ON dnum.de_vid = vi.id ";
break;
case 'contract':
$sqlk = "{$_YW['k']['contract']} AS ch LEFT JOIN {$_YW['k']['launch']} AS la ON ch.h_number = la.l_hnumber ";
break;
case 'schedule':
$sqlk = "{$_YW['k']['elevator']} AS el LEFT JOIN {$_YW['k']['launch']} AS la ON find_in_set( el.e_number, la.l_enumber ) LEFT JOIN {$_YW['k']['contract']} AS ct ON la.l_hnumber = ct.h_number";
break;
case 'village':
$sqlk = "{$_YW['k']['village']} AS vi LEFT JOIN {$_YW['k']['elevator']} AS el ON vi.id = el.e_vid ";
break;
default:
$sqlk = $_YW['k'][ $this->tname ];
break;
}
return $sqlk;
}
//字段
public function td_field()
{
global $_M, $_YW;
switch ($this->tname) {
case 'elevators':
$field = ' el.*,max( la.l_endtime ) AS endtime,count( DISTINCT la.id ) AS e_totalnum,ala.*,if(ala.estate,1,0) AS etypes,bla.*,cla.* ';
break;
case 'patrol':
$field = ' el.*,la.l_hnumber,ala.* ';
break;
case 'contract':
$field = 'ch.*, count(la.id) AS h_totalnum ';
break;
case 'schedule':
$field = 'el.e_enable,el.e_number,el.e_vid,el.e_bno,el.e_aps,el.e_size,la.*,ct.h_cid';
break;
case 'villages':
$field = " vi.*, COUNT( DISTINCT el.e_number) AS v_enum,COUNT(DISTINCT el.e_vid, el.e_bno) AS v_ebnonum,COUNT( el.e_enable = 0 OR NULL ) AS noban,ANY_VALUE(anum.v_free) AS v_free,ANY_VALUE( anum.v_bno ) AS v_bno,ANY_VALUE(bnum.v_lease) AS v_lease,ANY_VALUE(cnum.v_endday) AS v_endday,ANY_VALUE(dnum.v_prerow) AS v_prerow ";
break;
case 'village':
$field = " vi.*, count( el.e_number ) AS total,count( el.e_enable = 0 OR NULL ) AS noban,count( el.e_enable = 1 OR NULL ) AS normal ";
break;
default:
$field = '*';
break;
}
return $field;
}
/*
* 【列出】
* 同时满足条件的非OR
*/
public function td_search($link = true)
{
global $_M, $_YW;
//默认input字段为link搜索
if ($link)
$this->search_link = array_unique(array_merge($this->search_input, $this->search_link));
//合成得带搜索字段
$field = array_unique(array_merge($this->search_input, $this->search_other));
//判断是否为链表查询
$join_field = array_combine($field, count($this->search_field) > 0 ? $this->search_field : $field);
//相对独立的搜索
$arrwhere = [];
foreach ($field as $val) {
$search = trim(strtoupper($this->form[ $val ]));
if (strlen($search) > 0) {
$str = $join_field[ $val ];
if (in_array($val, $this->search_link)) {
$arrwhere[] = " {$str} LIKE '%{$search}%' ";
continue;
}
$arrwhere[] = " {$str} = '{$search}' ";
}
}
//返回内容
$where = '';
if (count($arrwhere) > 0) {
$where = ' AND ';
$where .= arrayto_string($arrwhere, ' AND ');
}
return $where;
}
//OR 内容搜索
public function td_search_or($orfield, $search_field = [])
{
global $_M, $_YW;
//判断是否为链表查询
$join_field = array_combine($orfield, count($search_field) > 0 ? $search_field : $orfield);
//相对独立的搜索
$arrwhere = [];
foreach ($orfield as $val) {
$search = trim(strtoupper($this->form[ $val ]));
if (strlen($search) > 0) {
$str = $join_field[ $val ];
if (in_array($val, $this->search_link)) {
$arrwhere[] = " {$str} LIKE '%{$search}%' ";
continue;
}
$arrwhere[] = " {$str} = '{$search}' ";
}
}
//返回内容
$where = '';
if (count($arrwhere) > 0) {
$where .= arrayto_string($arrwhere, ' OR ');
}
return strlen($where) > 0 ? " AND ({$where}) " : '';
}
//时间区间
public function td_time_search($field, $search_field = [])
{
global $_M, $_YW;
list($start, $end) = $field;
//判断是否为链表查询
$join_field = array_combine($field, count($search_field) > 0 ? $search_field : $field);
//相对独立的搜索
$arrwhere = [];
foreach ($field as $val) {
$search = trim(strtoupper($this->form[ $val ]));
if (strlen($search) > 0) {
$str = $join_field[ $val ];
if ($val == $start) {
$arrwhere[] = " {$str} >= '{$search}' ";
} else {
$arrwhere[] = " {$str} <= '{$search}' ";
}
}
}
//返回内容
$where = '';
if (count($arrwhere) > 0) {
$where .= arrayto_string($arrwhere, " AND ");
}
return strlen($where) > 0 ? " AND ({$where}) " : '';
}
//获取重叠的时间区间
// $search_field 开始时间和结束时间的字段互相调换,结束的字段在前面
public function td_time_orsearch($field, $search_field = [])
{
global $_M, $_YW;
list($start, $end) = $field;
//判断是否为链表查询
$join_field = array_combine($field, count($search_field) > 0 ? $search_field : $field);
//相对独立的搜索
$arrwhere = [];
foreach ($field as $val) {
$search = trim(strtoupper($this->form[ $val ]));
if (strlen($search) > 0) {
$str = $join_field[ $val ];
if ($val == $start) {
$arrwhere[] = " {$str} < '{$search}' "; //结束字段,搜索为开始时间
} else {
$arrwhere[] = " {$str} > '{$search}' "; //开始字段,搜索为结束时间
}
}
}
//返回内容
$where = '';
if (count($arrwhere) > 0) {
$where .= arrayto_string($arrwhere, " OR ");
}
return strlen($where) > 0 ? " AND NOT({$where}) " : '';
}
/*
* 【列出】
* SQL判断语句$where .= $this->search();
*/
public function td_where()
{
global $_M, $_YW;
$where = " 1=1 ";
switch ($this->tname) {
case 'applan':
$this->search_input = ['e_number'];
$this->search_other = ['e_bno', 'e_vid', 'e_enable'];
$where .= self::td_search();
if (is_array($this->form['e_aps'])) {
// 不考虑导出的情况
$veaps = parent::strchange(array_filter($this->form['e_aps']));
$where .= " AND e_aps IN($veaps) ";
}
if (strlen($this->village_whereid) > 0) $where .= " AND el.e_vid IN({$this->village_whereid}) ";
break;
case 'elevators':
$this->search_input = ['e_number'];
$this->search_other = ['e_aps', 'e_bno', 'e_vid', 'e_enable', 'endid', 'nowid', 'nextid'];
$this->search_field = ['el.e_number', 'el.e_aps', 'el.e_bno', 'el.e_vid', 'el.e_enable', 'cla.endid', 'ala.nowid', 'bla.nextid'];
$where .= self::td_search();
//判断是否为备份
if ($this->bsign)
parent::where_id($where);
self::td_groupby($where);
break;
case 'patrol':
$this->search_input = ['e_number'];
$this->search_other = ['e_aps', 'e_bno', 'e_vid', 'e_enable', 'nowid', 'l_hnumber'];
$this->search_field = ['el.e_number', 'el.e_aps', 'el.e_bno', 'el.e_vid', 'el.e_enable', 'ala.nowid', 'la.l_hnumber'];
$where .= self::td_search();
//不看空位
$where .= " AND ala.nowid IS NOT NULL ";
self::td_groupby($where);
break;
case 'elevator':
$this->search_input = ['e_number', 'e_label', 'e_text'];
$this->search_other = ['e_aps', 'e_bno', 'e_vid', 'e_enable'];
$where .= self::td_search();
case 'village':
$this->search_input = ['v_name', 'v_text'];
$where .= self::td_search();
$this->search_link = ['v_province', 'v_city', 'v_district', 'v_address'];
$this->search_field = ['vi.v_name', 'vi.v_text', 'vi.v_province', 'vi.v_city', 'vi.v_district', 'vi.v_address'];
$this->form['v_province'] = $this->form['v_address'];
$this->form['v_city'] = $this->form['v_address'];
$this->form['v_district'] = $this->form['v_address'];
$where .= self::td_search_or($this->search_link, ['vi.v_province', 'vi.v_city', 'vi.v_district', 'vi.v_address']);
self::td_groupby($where);
break;
case 'customer':
$this->search_input = ['c_text'];
$this->search_link = ['c_allname', 'c_name', 'c_province', 'c_city', 'c_district', 'c_address'];
//名称
$this->form['c_name'] = $this->form['c_allname'];
$where .= self::td_search_or(['c_allname', 'c_name']);
//地址
$this->form['c_province'] = $this->form['c_address'];
$this->form['c_city'] = $this->form['c_address'];
$this->form['c_district'] = $this->form['c_address'];
$where .= self::td_search_or(['c_province', 'c_city', 'c_district', 'c_address']);
$where .= self::td_search();
break;
case 'workers':
$this->search_input = ['w_name', 'w_tel', 'w_text'];
$where .= self::td_search();
break;
case 'contract':
$this->search_input = ['h_number', 'h_text'];
$this->search_other = ['h_cid', 'h_wid'];
$this->search_link = ['h_wid'];
$this->search_field = ['ch.h_number', 'ch.h_text', 'ch.h_cid', 'ch.h_wid'];
$where .= self::td_time_orsearch(['h_starttime', 'h_endtime'], ['ch.h_endtime', 'ch.h_starttime']);
$where .= self::td_search();
self::td_groupby($where);
break;
case 'para':
$this->search_other = ['p_type'];
$where .= self::td_search();
break;
case 'launch':
$this->search_input = ['l_title', 'l_enumber', 'l_text'];
$this->search_other = ['l_hnumber'];
$where .= self::td_time_orsearch(['l_starttime', 'l_endtime'], ['l_endtime', 'l_starttime']);
$where .= self::td_search();
break;
case 'villages':
$this->search_input = ['v_name', 'v_text'];
$this->search_link = ['v_province', 'v_city', 'v_district', 'v_address'];
$this->form['v_province'] = $this->form['v_address'];
$this->form['v_city'] = $this->form['v_address'];
$this->form['v_district'] = $this->form['v_address'];
if (strlen($this->villages_where) > 0) $where .= " AND {$this->villages_where} ";
if (strlen($this->village_whereid) > 0) $where .= " AND vi.id IN({$this->village_whereid}) ";
$where .= self::td_search_or($this->search_link);
$where .= self::td_search();
//判断是否为备份
if ($this->bsign)
parent::where_id($where);
self::td_groupby($where);
break;
case 'schedule':
$where .= " AND la.id IS NOT NULL ";
$this->search_input = ['e_number', 'l_hnumber'];
$this->search_other = ['id', 'e_vid'];
$this->search_field = ['el.e_number', 'la.l_hnumber', 'la.id', 'el.e_vid'];
$where .= self::td_time_orsearch(['l_starttime', 'l_endtime'], ['la.l_endtime', 'la.l_starttime']);
$where .= self::td_search();
break;
case 'noticeday':
$where .= ' AND ( (endtime BETWEEN DATE_SUB( CURDATE(), INTERVAL 3 DAY ) AND CURDATE()) OR ' //到期提醒 展示3天 // DATE_SUB
. '(h_endtime BETWEEN DATE_SUB( CURDATE(), INTERVAL 3 DAY ) AND DATE_ADD( CURDATE(), INTERVAL 3 DAY ) ) )'; //订单到期前后展示3天 // DATE_ADD
break;
default:
// 如果$where 没有值 会导致计算结果出错,导致前台表格无法获取正确的值,分页显示异常
$where = "1=1";
break;
}
return $where;
}
//分组查询
public function td_groupby(&$where)
{
global $_M;
$this->multi_table = true;
switch ($this->tname) {
case 'elevators':
$where .= " GROUP BY el.e_number ";
if ($this->form['endtime'])
$where .= " HAVING endtime < '{$this->form['endtime']}' ";
break;
case 'patrol':
$where .= " GROUP BY el.e_number ";
break;
case 'contract':
$where .= " GROUP BY ch.id ";
break;
case 'villages':
$where .= " GROUP BY vi.id ";
break;
case 'village':
$where .= " GROUP BY vi.id ";
break;
default:
$this->multi_table = false;
break;
}
}
/*
* 【列出】
* SQL排序方式语句
*/
public function td_order()
{
global $_M;
switch ($this->tname) {
case 'applan':
$order = " `e_enable` DESC ";
//按照正常排序,对比相邻广告位的投放广告品类
// order_e_types 按照是否可投放进行排序
if ($this->form['eaps_order'] || $this->form['order_e_types']) {
if (!$this->form['order_e_types'])
$this->form['order_e_types'] = ' ASC ';
$order .= ", `lanum` {$this->form['order_e_types']} ";
}
if ($this->form['eaps_order'] == 2) {
// 传递进来的编号,不直接查数据是因为有些可能会出现错误,所以直接使用传递进来的,进行排序
$array = array_filter(stringto_array($this->form['l_selectenum'], ','));
$idstr = parent::strchange($array);
if (strlen($idstr))
$order = " `e_number` IN({$idstr}) DESC, " . $order;
}
$order .= ", `e_vid` ASC, `e_bno` ASC, `e_aps` ASC ";
break;
case 'elevators':
$order = " `etypes` DESC, endtime DESC, el.`e_vid` ASC, el.`e_bno` ASC, el.`e_aps` ASC ";
if ($this->form['order_e_number'])
$order = " el.e_number {$this->form['order_e_number']} ";
if ($this->form['order_endtime'])
$order = " endtime {$this->form['order_endtime']} ";
if ($this->form['order_e_totalnum'])
$order = " e_totalnum {$this->form['order_e_totalnum']} ";
if ($this->form['order_etypes'])
$order = " `etypes` {$this->form['order_etypes']} ";
if ($this->form['order_nowstime'])
$order = " nowstime {$this->form['order_nowstime']} ";
if ($this->form['order_nowetime'])
$order = " nowetime {$this->form['order_nowetime']} ";
if ($this->form['order_nextstime'])
$order = " nextstime {$this->form['order_nextstime']} ";
if ($this->form['order_nextetime'])
$order = " nextetime {$this->form['order_nextetime']} ";
if ($this->form['order_endstime'])
$order = " endstime {$this->form['order_endstime']} ";
if ($this->form['order_endetime'])
$order = " endetime {$this->form['order_endetime']} ";
if ($this->form['order_e_address']) {
$e_address = $this->form['order_e_address'];
$order = " el.e_vid {$e_address}, el.e_bno {$e_address}, el.e_aps {$e_address} ";
}
break;
case 'patrol':
$order = " el.`e_vid` ASC, el.`e_bno` ASC, el.`e_aps` ASC ";
break;
case 'elevator':
$order = " `id` DESC ";
break;
case 'launch':
$order = " `id` DESC ";
if ($this->form['order_l_starttime'])
$order = " l_starttime {$this->form['order_l_starttime']} ";
if ($this->form['order_l_endtime'])
$order = " l_endtime {$this->form['order_l_endtime']} ";
break;
case 'contract':
$order = ' ch.`id` DESC';
if ($this->form['order_h_starttime'])
$order = " ch.h_starttime {$this->form['order_h_starttime']} ";
if ($this->form['order_h_endtime'])
$order = " ch.h_endtime {$this->form['order_h_endtime']} ";
break;
case 'schedule':
$order = ' la.l_starttime DESC,la.`id` DESC';
//备份 按照场所排序
if ($this->bsign) {
$order = " el.`e_vid` ASC, el.`e_bno` ASC, el.`e_aps` ASC ";
}
if ($this->form['order_l_starttime'])
$order = " la.l_starttime {$this->form['order_l_starttime']} ";
if ($this->form['order_l_endtime'])
$order = " la.l_endtime {$this->form['order_l_endtime']} ";
break;
case 'villages':
// 默认按照街道排序
$order = ' CONVERT( vi.`v_address` USING gbk ) COLLATE gbk_chinese_ci ASC ';
if ($this->form['order_v_enum'])
$order = " v_enum {$this->form['order_v_enum']} ";
if ($this->form['order_v_free'])
$order = " v_free {$this->form['order_v_free']} ";
if ($this->form['order_v_lease'])
$order = " v_lease {$this->form['order_v_lease']} ";
if ($this->form['order_v_endday'])
$order = " v_endday {$this->form['order_v_endday']} ";
if ($this->form['order_v_prerow'])
$order = " v_prerow {$this->form['order_v_prerow']} ";
if ($this->form['order_v_ebnonum'])
$order = " v_ebnonum {$this->form['order_v_ebnonum']} ";
if ($this->form['order_v_bno'])
$order = " v_bno {$this->form['order_v_bno']} ";
break;
case 'para':
$order = ' `id` DESC';
if ($this->form['order_p_type'])
$order = " `p_type` {$this->form['order_p_type']} ";
if ($this->form['order_p_order'])
$order = " `p_order` {$this->form['order_p_order']} ";
break;
case 'noticeday':
$order = ' `endtime` ASC, `h_endtime` ASC ';
break;
case 'village':
$order = ' vi.`id` DESC';
break;
default:
$order = ' `id` DESC';
break;
}
return $order;
}
}