121 lines
5.6 KiB
PHP
121 lines
5.6 KiB
PHP
<?php
|
||
|
||
defined('IN_MET') or exit('No permission');
|
||
|
||
//所有公用方法
|
||
class cloud{
|
||
|
||
public $tsql;
|
||
|
||
public function __construct() {
|
||
global $_M, $_YW;
|
||
$this->tsql = load::own_class('tsql','new');
|
||
}
|
||
|
||
/*
|
||
* 把数组转成JSON,用于ajax返回,可以用于普通json请求返回,也可以用于跨域的ajax的jsonp格式的数据请求返回。
|
||
* @param array $back 输出字符串或数组
|
||
* @param string $callback ajax的回调函数的名称
|
||
*/
|
||
public function jsoncallback($back, $callback = 'callback') {
|
||
global $_M;
|
||
header('Content-type: application/x-javascript');
|
||
$callback = $_M['form'][$callback];
|
||
$json = json_encode($back,JSON_UNESCAPED_UNICODE);
|
||
echo $callback?$callback . '(' . $json . ')':$json;
|
||
}
|
||
|
||
//城市信息
|
||
public function citydata() {
|
||
global $_M,$_YW;
|
||
$dirfile = PATH_APP_FILE.'public/js/city/city.min.json';
|
||
if (!file_exists($dirfile)){
|
||
$citys = json_decode(file_get_contents(PATH_SYS."include/static2/vendor/select-linkage/citydata.min.json"),true);
|
||
$i = 0;
|
||
$array = [];
|
||
foreach ($citys['citylist'] as $key => $val) {
|
||
if(version_compare($_M['config']['metcms_v'],'6.2.0','>=')){
|
||
$val['p'] = substr($val['p'],0,stripos($val['p'],'('));
|
||
$array[$key] = $val;
|
||
}else{
|
||
foreach ($val as $pkey => $pval) {
|
||
array_unshift($pval,['n'=>'请选择']);
|
||
if(array_level($pval) == 4){
|
||
foreach ($pval as $akey => $aval) {
|
||
if(array_level($aval['a']) == 2) array_unshift($aval['a'],['s'=>'请选择']);
|
||
$array[$key][$pkey][$akey] = $aval;
|
||
}
|
||
//跳过
|
||
continue;
|
||
}
|
||
$array[$key][$pkey] = $pval;
|
||
}
|
||
}
|
||
}
|
||
$citydata = ['citylist'=>$array];
|
||
//生成缓存
|
||
$jsonstr = json_encode($citydata,JSON_UNESCAPED_UNICODE);
|
||
load::sys_func('file');
|
||
makefile($dirfile);
|
||
file_put_contents($dirfile, $jsonstr);
|
||
$citystr = self::jsoncallback($citydata);
|
||
}else{
|
||
$citystr = file_get_contents($dirfile);
|
||
}
|
||
//返回信息
|
||
echo $citystr;
|
||
}
|
||
|
||
public function city_url() {
|
||
global $_M,$_YW;
|
||
$dirfile = PATH_APP_FILE.'public/js/city/city.min.json';
|
||
if(file_exists($dirfile)){
|
||
$url = $_M['url']['app']."{$_YW['n']}/public/js/city/city.min.json";
|
||
}else{
|
||
$url = class_exists('appadmin')?$_M['url']['own_name']."c=ajax&a=docitys":$_M['url']['own_name']."c=index&a=docitys";
|
||
}
|
||
return $url;
|
||
}
|
||
|
||
//计算时间相差天数
|
||
public function summary() {
|
||
global $_M,$_YW;
|
||
$summoney = $this->tsql->table('contract')->qfield(" Sum(h_tprice) as tprice ")->where(" h_tprice IS NOT NULL ")->one();
|
||
return [
|
||
'village' => $this->tsql->table('village')->count(),
|
||
'elevator' => $this->tsql->table('elevator')->count(),
|
||
'vfree' => $this->tsql->table_unset()
|
||
->tables(['elevator','el'], 'LEFT JOIN')
|
||
->tables(['launch','la'], 'ON find_in_set( el.e_number, la.l_enumber )')
|
||
->where(" la.l_endtime < CURDATE() OR la.l_starttime > CURDATE() OR la.id IS NULL ")
|
||
->count(" distinct e_number "),
|
||
'vlease' => $this->tsql->table_unset()
|
||
->tables(['elevator','el'], 'LEFT JOIN')
|
||
->tables(['launch','la'], 'ON find_in_set( el.e_number, la.l_enumber )')
|
||
->where(" NOT(la.l_endtime < CURDATE() OR la.l_starttime > CURDATE() ) ")
|
||
->count(" distinct e_number "),
|
||
'vendday' => $this->tsql->table_unset()
|
||
->tables(['elevator','el'], 'LEFT JOIN')
|
||
->tables(['launch','la'], 'ON find_in_set( el.e_number, la.l_enumber )')
|
||
->where(" la.l_endtime BETWEEN CURDATE( ) AND date_add( CURDATE( ), INTERVAL 7 DAY ) ")
|
||
->count(" distinct e_number "),
|
||
'vprerow' => $this->tsql->table_unset()
|
||
->tables(['elevator','el'], 'LEFT JOIN')
|
||
->tables(['launch','la'], 'ON find_in_set( el.e_number, la.l_enumber )')
|
||
->where(" la.l_starttime > CURDATE() ")
|
||
->count(" distinct e_number "),
|
||
'contract' => $this->tsql->table('contract')->count(),
|
||
'launch' => $this->tsql->table('launch')->count(),
|
||
'endcontract' => $this->tsql->table('contract')->where(" h_endtime < CURDATE() ")->count(),
|
||
'endlaunch' => $this->tsql->table('launch')->where(" l_endtime < CURDATE() ")->count(),
|
||
'customer' => $this->tsql->table('customer')->count(),
|
||
// 'workers' => $this->tsql->table('workers')->count(),
|
||
'summoney' => intval($summoney['tprice']),
|
||
];
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
?>
|