report.class.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of operation_log
  7. *
  8. * @author Administrator
  9. */
  10. class report {
  11. private static $_report;
  12. public static function getInstance() {
  13. if (!self::$_report) {
  14. $c = __CLASS__;
  15. self::$_report = new $c;
  16. }
  17. return self::$_report;
  18. }
  19. /**
  20. * report 配置
  21. */
  22. public function report_config(){
  23. // $config = [
  24. // 'delivery_frequency' => 'monthly',
  25. // 'timezone' => 'UTC+05',
  26. // 'monthly_day' => [2,3,4],
  27. // 'monthly_time' => '09:00:00',
  28. // ];
  29. // $config = [
  30. // 'delivery_frequency' => 'daily',
  31. // 'timezone' => 'UTC+05',
  32. // 'daily_time' => '09:00:00',
  33. // ];
  34. // $config = [
  35. // 'delivery_frequency' => 'weekly',
  36. // 'timezone' => 'UTC+05',
  37. // 'weekly_day' => [1],
  38. // 'weekly_time' => '09:00:00',
  39. // ];
  40. // $config = [
  41. // 'delivery_frequency' => 'quarterly',
  42. // 'timezone' => 'UTC+05',
  43. // 'quarterly_month' =>'1',
  44. // 'quarterly_day' =>'1',
  45. // 'quarterly_time' => '09:00:00',
  46. // ];
  47. // $config = [
  48. // 'delivery_frequency' => 'yearly',
  49. // 'timezone' => 'UTC+05',
  50. // 'yearly_month' =>[1,2],
  51. // 'yearly_day' =>'1',
  52. // 'yearly_time' => '09:00:00',
  53. // ];
  54. // $next = common::calculateNextRunTime($config);
  55. //echo $next->format('Y-m-d H:i:s');
  56. $operate = utils::_get('operate');
  57. $operate = strtolower($operate);
  58. if ($operate == "parity_id"){
  59. //search parity id
  60. if(_isCustomerLogin()){
  61. //$ocean_contact_id = _getContactIDHandNew($_SESSION["ONLINE_USER"], 'public');
  62. $ocean_contact_id = _getCompanyContactHandNew($_SESSION["ONLINE_USER"]);
  63. $air_contact_id = _getAirContactID('public');
  64. $all_id = "ALL;".$ocean_contact_id;
  65. if (utils::endWith($ocean_contact_id,";")){
  66. $all_id .=$air_contact_id;
  67. } else {
  68. $all_id .=";".$air_contact_id;
  69. }
  70. $arr = explode(';', $all_id);
  71. $unique_arr = array_unique($arr);
  72. }else{
  73. $unique_arr= ['ALL'];
  74. }
  75. $option = array();
  76. foreach($unique_arr as $temp){
  77. $option[] =array("label"=>$temp,"value"=>$temp);
  78. }
  79. common::echo_json_encode(200, $option);
  80. exit();
  81. }
  82. /**
  83. * report的配置查询,
  84. */
  85. if ($operate == "search"){
  86. $cp = common::check_input($_POST ['cp']); //current_page
  87. $ps = common::check_input($_POST ['ps']); //ps
  88. if (empty($ps))
  89. $ps = 100;
  90. if (empty($cp))
  91. $cp = 1;
  92. $sqlWhere = "1=1";
  93. $text_search = $_POST['text_search'];
  94. if (!empty($text_search)){
  95. $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
  96. }
  97. if(!empty($_POST['application_scope'])){
  98. $pplication_scope = $_POST['application_scope'] =='all' ? "All Users" : "Specific Users";
  99. $sqlWhere .= " and access_type ='". common::check_input($pplication_scope)."'";
  100. }
  101. if(!empty($_POST['is_active'])){
  102. if($_POST['is_active'] == 't'){
  103. $sqlWhere .= " and is_active = true";
  104. }else{
  105. $sqlWhere .= " and is_active = false";
  106. }
  107. }
  108. if(!empty($_POST['party_id'])){
  109. if($_POST['party_id'] != 'ALL'){
  110. $sqlWhere .= " and '".common::check_input($_POST['party_id'])."' = any(party_ids)";
  111. }
  112. }
  113. if(_isCustomerLogin()){
  114. $ocean_contact_id = _getCompanyContactHandNew($_SESSION["ONLINE_USER"]);
  115. $air_contact_id = _getAirContactID('public');
  116. $all_id = $ocean_contact_id;
  117. if (utils::endWith($ocean_contact_id,";")){
  118. $all_id .=$air_contact_id;
  119. } else {
  120. $all_id .=";".$air_contact_id;
  121. }
  122. $all_id = strtolower($all_id);
  123. $unique_arr = explode(';', $all_id);
  124. //构建安全的数组字面量用于 PostgreSQL 的 && 交集判断
  125. $sqlWhere_party_id = '';
  126. if (!empty($unique_arr)) {
  127. // 转义每个 ID 防注入
  128. $escaped_ids = array();
  129. foreach($unique_arr as $id){
  130. $id = trim($id);
  131. if (empty($id))
  132. continue;
  133. $escaped_ids[] = "'" .common::check_input($id) . "'";
  134. }
  135. if(!empty($escaped_ids)){
  136. $array_str = 'ARRAY[' . implode(',', $escaped_ids) . ']';
  137. $sqlWhere_party_id = " or party_ids && $array_str ";
  138. }
  139. }
  140. //Group Name 判断
  141. $company = _getCompanyHandNew($_SESSION["ONLINE_USER"],'public');
  142. $company = strtolower($company);
  143. $aa = explode(";", $company);
  144. $sqlWhere_group_name = '';
  145. if(!empty($aa)){
  146. $escaped_company = array();
  147. foreach ($aa as $value) {
  148. $value = trim($value);
  149. if (empty($value))
  150. continue;
  151. $escaped_company[] = "'" . common::check_input($value) . "'";
  152. }
  153. if(!empty($escaped_company)){
  154. $array_str = 'ARRAY[' . implode(',', $escaped_company) . ']';
  155. $sqlWhere_group_name = " or group_names && $array_str";
  156. }
  157. }
  158. $sqlWhere .= " and ( access_type = 'All Users' ".$sqlWhere_party_id . " ".$sqlWhere_group_name .")";
  159. }
  160. $sqlWhere .= " and (system_account IS NULL OR array_length(system_account, 1) = 0 OR '".common::check_input(_getLoginName())."' = any(system_account))";
  161. $rc = $_POST ['rc'];
  162. if ($rc == -1) {
  163. $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
  164. $rc = common::excuteOneSql($sql);
  165. }
  166. $tp = ceil($rc / $ps);
  167. if ($rc > 0) {
  168. $sql = "select * from public.kln_report_template where " .$sqlWhere;
  169. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  170. $rs = common::excuteListSql($sql);
  171. $arrTmp = array('searchData' => $rs,
  172. 'rc' => intval($rc),
  173. 'ps' => intval($ps),
  174. 'cp' => intval($cp),
  175. 'tp' => intval($tp));
  176. common::echo_json_encode(200,$arrTmp);
  177. exit();
  178. }else{
  179. $arrTmp = array('searchData' => array());
  180. common::echo_json_encode(200, $arrTmp);
  181. exit();
  182. }
  183. }
  184. if ($operate == "add"){
  185. $serial_no = $_REQUEST['serial_no'];
  186. if(!empty($serial_no)){
  187. //代表编辑
  188. $reportMain = common::excuteObjectSql("select *,
  189. array_to_json(party_ids) as party_ids_json,
  190. array_to_json(group_names) as group_names_json
  191. from kln_report_template where serial_no = '$serial_no'");
  192. $reportFields = array();
  193. $reportField = common::excuteListSql("select
  194. field_id as ids,
  195. field_level as \"fieldLevel\",
  196. field_type as \"fieldType\",
  197. field_group_name as \"groupName\",
  198. field_db as field,
  199. field_display_name as title,
  200. field_display_name_user as \"displayName\",
  201. data_type as \"dataType\",
  202. custom_fixed_value as value,
  203. is_filter_enabled as \"isFilter\",
  204. is_sort_enabled as \"isSort\"
  205. from kln_report_field_config where template_serial_no = '$serial_no' order by id");
  206. foreach($reportField as $_reportField){
  207. $_reportField['isFilter'] = $_reportField['isFilter'] == 't' ? true : false;
  208. $_reportField['isSort'] = $_reportField['isSort'] == 't' ? true : false;
  209. $reportFields[] = $_reportField;
  210. }
  211. $reportAccess = array("type"=>$reportMain['access_type'],
  212. "partyId"=>json_decode($reportMain['party_ids_json'],true),
  213. "groupName"=>json_decode($reportMain['group_names_json'],true));
  214. $data = array("reportName"=>$reportMain['name'],"reportLevel"=>$reportMain['level'],"reportDescription"=>$reportMain['description'],
  215. "reportFields"=>$reportFields,"reportAccess"=>$reportAccess);
  216. }else{
  217. $data = array();
  218. }
  219. common::echo_json_encode(200,$data);
  220. exit();
  221. }
  222. if ($operate == "report_field_load"){
  223. column::getInstance()->settingDisplayForVIPReport();
  224. }
  225. if ($operate == "save"){
  226. $serial_no = $_POST['serial_no'];
  227. $name = common::check_input($_POST['report_name']);
  228. $description = common::check_input($_POST['report_description']);
  229. $level = common::check_input($_POST['report_level']);
  230. $access_type = common::check_input($_POST['access_type']);
  231. $party_ids = $_POST['party_ids'];
  232. $group_names = $_POST['group_names'];
  233. //单独处理字段id
  234. $fieldsList = $_POST['fieldsList'];
  235. $field_ids = array();
  236. foreach($fieldsList as $_fieldsList){
  237. if (!empty($_fieldsList['ids'])){
  238. $field_ids[] = $_fieldsList['ids'];
  239. }
  240. }
  241. $report_sql_data = common::excuteObjectSql("select sql,count_sql from public.kln_report_sql_manage where level = '$level'");
  242. $sql = "";
  243. if (!empty($serial_no)){
  244. $updateSqlSet = " report_sql = '".common::check_input($report_sql_data['sql'])."',
  245. count_sql = '".common::check_input($report_sql_data['count_sql'])."',
  246. modify_by = '"._getLoginName()."',update_time = now()";
  247. if (!empty($name)) {
  248. $updateSqlSet.= ", name = '$name' ";
  249. }
  250. if (!empty($description)) {
  251. $updateSqlSet.= ", description = '$description' ";
  252. }
  253. if (!empty($level)) {
  254. $updateSqlSet.= ", level = '$level' ";
  255. }
  256. if (!empty($access_type)) {
  257. $updateSqlSet.= ", access_type = '$access_type' ";
  258. }
  259. if (!empty($party_ids)) {
  260. $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
  261. $updateSqlSet.= ", party_ids = $party_ids_filed";
  262. }
  263. if (!empty($group_names)) {
  264. $group_names_filed = common::toPgTextArrayLiteral($group_names);
  265. $updateSqlSet.= ", group_names = $group_names_filed";
  266. }
  267. if (!empty($field_ids)) {
  268. $ids_filed = common::toPgTextArrayLiteral($field_ids);
  269. $updateSqlSet.= ", field_ids = $ids_filed";
  270. }
  271. //代表update
  272. $sql .= "update public.kln_report_template set ".$updateSqlSet."
  273. where serial_no = '$serial_no';";
  274. } else {
  275. $party_ids_filed = "NULL";
  276. if (!empty($party_ids)) {
  277. $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
  278. }
  279. $group_names_filed = "NULL";
  280. if (!empty($group_names)) {
  281. $group_names_filed = common::toPgTextArrayLiteral($group_names);
  282. }
  283. $ids_filed = "NULL";
  284. if (!empty($field_ids)) {
  285. $ids_filed = common::toPgTextArrayLiteral($field_ids);
  286. }
  287. $serial_no = common::uuid();
  288. $sql .= "INSERT INTO public.kln_report_template(
  289. serial_no,name, description, level, field_ids, access_type, report_sql,count_sql,
  290. party_ids, group_names, create_by, created_time, modify_by, update_time )
  291. VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type',
  292. '".common::check_input($report_sql_data['sql'])."','".common::check_input($report_sql_data['count_sql'])."',
  293. $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
  294. }
  295. //先删除,后添加
  296. $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  297. foreach($fieldsList as $key =>$_tempFieldsList){
  298. $_field_id = empty($_tempFieldsList['ids'])? "NULL": $_tempFieldsList['ids'];
  299. $_field_level = common::check_input($_tempFieldsList['fieldLevel']);
  300. $_field_type = common::check_input($_tempFieldsList['fieldType']);
  301. $_field_group_name = common::check_input($_tempFieldsList['groupName']);
  302. $_field_db = common::check_input($_tempFieldsList['field']);
  303. $_field_code = common::check_input($_tempFieldsList['title']);
  304. $_display_name = common::check_input($_tempFieldsList['displayName']);
  305. $_data_type = common::check_input($_tempFieldsList['dataType']);
  306. $_value_type = $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
  307. $_fixed_value = common::check_input($_tempFieldsList['value']);
  308. //这两个不能配置查询和过滤
  309. if($_field_group_name == 'Container info' || $_field_group_name == 'Milestone'
  310. ||$_field_code == 'Other reference No.' || $_field_code == 'Shipper Zip Code' || $_field_code == 'Consignee Zip Code' ){
  311. $_is_filter_enabled = "false";
  312. } else {
  313. $_is_filter_enabled = $_tempFieldsList['isFilter'];
  314. }
  315. $_is_sort_enabled = $_tempFieldsList['isSort'];
  316. $sql .= "INSERT INTO public.kln_report_field_config(
  317. template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
  318. field_display_name, field_display_name_user, data_type, custom_value_type,
  319. custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
  320. VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
  321. '$_field_code', '$_display_name', '$_data_type', '$_value_type',
  322. '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
  323. }
  324. if (!empty($sql)){
  325. common::excuteUpdateSql($sql);
  326. $data = array("msg" =>"success");
  327. }
  328. common::echo_json_encode(200,$data);
  329. exit();
  330. }
  331. if ($operate == "active"){
  332. $serial_no =$_POST['serial_no'];
  333. $is_active = $_POST['is_active'];
  334. $sql = "update public.kln_report_template set is_active = '$is_active' where serial_no = '$serial_no';";
  335. common::excuteUpdateSql($sql);
  336. $data = array("msg" =>"success");
  337. common::echo_json_encode(200,$data);
  338. exit();
  339. }
  340. }
  341. /**
  342. * shipment_status_report
  343. */
  344. public function shipment_status_report(){
  345. $operate = utils::_get('operate');
  346. $operate = strtolower($operate);
  347. if ($operate == "report_search") {
  348. $cp = common::check_input($_POST ['cp']); //current_page
  349. $ps = common::check_input($_POST ['ps']); //ps
  350. if (empty($ps))
  351. $ps = 100;
  352. if (empty($cp))
  353. $cp = 1;
  354. $sqlWhere = "1=1 and is_active = true";
  355. $text_search = $_POST['text_search'];
  356. if (!empty($text_search)){
  357. $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
  358. }
  359. $rc = $_POST ['rc'];
  360. if ($rc == - 1) {
  361. $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
  362. $rc = common::excuteOneSql($sql);
  363. }
  364. $tp = ceil($rc / $ps);
  365. if ($rc > 0) {
  366. $sql = "select serial_no,name,description from public.kln_report_template where " .$sqlWhere;
  367. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  368. $rs = common::excuteListSql($sql);
  369. $arrTmp = array('searchData' => $rs,
  370. 'rc' => intval($rc),
  371. 'ps' => intval($ps),
  372. 'cp' => intval($cp),
  373. 'tp' => intval($tp));
  374. common::echo_json_encode(200,$arrTmp);
  375. exit();
  376. }else{
  377. $arrTmp = array('searchData' => array());
  378. common::echo_json_encode(200, $arrTmp);
  379. exit();
  380. }
  381. }
  382. if ($operate == "report_detail") {
  383. $serial_no = common::check_input($_POST ['serial_no']);
  384. $dataReturn = array();
  385. $tableColumns = array();
  386. $filtersList = array();
  387. $sortByOptions = array();
  388. $CustomFiled = "";
  389. $reportFiled = common::excuteListSql("select * from public.kln_report_field_config where template_serial_no = '".$serial_no."'
  390. and is_enabled = true order by id ");
  391. foreach($reportFiled as $filed){
  392. if($filed['is_filter_enabled'] == 't'){
  393. $type = $filed['data_type'] == "string" ? "input" : ($filed['data_type'] == "date" ? "date" : "input");
  394. $field_display_name = $filed['field_display_name'];
  395. $field_display_name = strtolower($field_display_name);
  396. $field_display_name = preg_replace('/[^a-z0-9]+/', '_', $field_display_name); // 非字母数字 → _
  397. $field_display_name = trim($field_display_name, '_');
  398. $filtersList[] = array(
  399. "label"=>$filed['field_display_name_user'],
  400. "field"=>$field_display_name,
  401. "field_real"=>$filed['field_display_name'],
  402. "type"=>$type,
  403. "data_type"=>$filed['data_type'],
  404. "value"=>[],"options"=>[]);
  405. }
  406. if($filed['is_sort_enabled'] == 't'){
  407. $sortByOptions[] = $filed['field_db'];
  408. }
  409. //用户自定义字段
  410. if($filed['field_type'] == 'Custom'){
  411. $CustomFiled = " , '".$filed['custom_fixed_value']."' AS \"".$filed['field_display_name_user']."\"";
  412. }
  413. $temp = array();
  414. $temp['field'] = $filed['field_display_name'];
  415. $temp['title'] = $filed['field_display_name_user'];
  416. $temp['type'] = $filed['field_db'] == "Status" ? "status" : "normal";
  417. $temp['formatter'] = "";
  418. $tableColumns[] = $temp;
  419. }
  420. $dataReturn['tableColumns'] = $tableColumns;
  421. $dataReturn['filtersList'] = $filtersList;
  422. if(!empty($sortByOptions)){
  423. $dataReturn['sortBy'] = array("field"=>$sortByOptions[0],"options"=>$sortByOptions,"order"=>"asc");
  424. }else{
  425. $dataReturn['sortBy'] = array("field"=>"","options"=>[],"order"=>"asc");
  426. }
  427. $reportFiled = common::excuteObjectSql("select report_sql,count_sql,level from public.kln_report_template where serial_no = '".$serial_no."'");
  428. $sqlManage = common::excuteObjectSql("select sql,count_sql,level from public.kln_report_sql_manage where level = '".$reportFiled['level']."'");
  429. $report_sql = $sqlManage["sql"];
  430. $count_sql = $sqlManage["count_sql"];
  431. $filterSQLArr = $this->returnFilterSql($filtersList);
  432. //return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
  433. $count_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $count_sql);
  434. $count_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $count_sql);
  435. $count_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $count_sql);
  436. $report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
  437. $report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
  438. $report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
  439. $report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
  440. //查询data
  441. $cp = common::check_input($_POST ['cp']); //current_page
  442. $ps = common::check_input($_POST ['ps']); //ps
  443. if (empty($ps))
  444. $ps = 10;
  445. if (empty($cp))
  446. $cp = 1;
  447. $rc = $_POST ['rc'];
  448. if ($rc == -1) {
  449. $count_sql = str_replace('<{orderby}>', "", $count_sql);
  450. error_log($count_sql);
  451. $rc = common::excuteOneSql($count_sql);
  452. }
  453. $tp = ceil($rc / $ps);
  454. if ($rc > 0) {
  455. $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
  456. $tmp_search_without_limit = $report_sql;
  457. $report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  458. error_log($report_sql);
  459. $rs = common::excuteListSql($report_sql);
  460. $arrTmp = array('searchData' => $rs,
  461. 'rc' => intval($rc),
  462. 'ps' => intval($ps),
  463. 'cp' => intval($cp),
  464. 'tp' => intval($tp));
  465. }else{
  466. $arrTmp = array('searchData' => array());
  467. }
  468. $dataReturn['tableData'] = $arrTmp;
  469. $dataReturn['tmp_search'] = common::deCode($tmp_search_without_limit, 'E');
  470. common::echo_json_encode(200, $dataReturn);
  471. exit();
  472. }
  473. /*
  474. * export excel
  475. */
  476. if ($operate == "excel") {
  477. $sql = common::deCode($_POST['tmp_search'], 'D');
  478. if(!empty($sql)){
  479. $rs = common::excuteListSql($sql);
  480. }
  481. //去除null
  482. foreach($rs as $index => $val) {
  483. foreach($val as $index_2 => $_val) {
  484. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  485. $rs[$index][$index_2] = "";
  486. }
  487. }
  488. }
  489. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  490. exit;
  491. }
  492. if ($operate == "manage_fileds") {
  493. $serial_no = common::check_input($_POST ['serial_no']);
  494. $reportFiled = common::excuteListSql("select * from public.kln_report_field_config
  495. where template_serial_no = '".$serial_no."' order by id ");
  496. $data = array();
  497. foreach($reportFiled as $_reportFiled){
  498. $_reportFiled['is_filter_enabled'] = $_reportFiled['is_filter_enabled'] == 't' ? true : false;
  499. $_reportFiled['is_sort_enabled'] = $_reportFiled['is_sort_enabled'] == 't' ? true : false;
  500. $_reportFiled['is_enabled'] = $_reportFiled['is_enabled'] == 't' ? true : false;
  501. $data[] = $_reportFiled;
  502. }
  503. common::echo_json_encode(200,array("msg"=>"success","data" => $data));
  504. exit;
  505. }
  506. if ($operate == "manage_fileds_save") {
  507. $serial_no = common::check_input($_POST['serial_no']);
  508. $fieldsList = $_POST['fieldsList'];
  509. //先删除,后添加 因为不涉及系统配置字段,全部用kln_report_field_config 字段name
  510. $sql = "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  511. foreach($fieldsList as $key =>$_tempFieldsList){
  512. $_field_id = empty($_tempFieldsList['field_id'])? "NULL": $_tempFieldsList['field_id'];
  513. $_field_level = common::check_input($_tempFieldsList['field_level']);
  514. $_field_type = common::check_input($_tempFieldsList['field_type']);
  515. $_field_group_name = common::check_input($_tempFieldsList['field_group_name']);
  516. $_field_db = common::check_input($_tempFieldsList['field_db']);
  517. $_field_code = common::check_input($_tempFieldsList['field_display_name']);
  518. $_display_name = common::check_input($_tempFieldsList['field_display_name_user']);
  519. $_data_type = common::check_input($_tempFieldsList['data_type']);
  520. $_value_type = common::check_input($_tempFieldsList['custom_value_type']);
  521. $_fixed_value = common::check_input($_tempFieldsList['custom_fixed_value']);
  522. $_is_filter_enabled = $_tempFieldsList['is_filter_enabled'];
  523. $_is_sort_enabled = $_tempFieldsList['is_sort_enabled'];
  524. $_is_enabled = $_tempFieldsList['is_enabled'];
  525. $sql .= "INSERT INTO public.kln_report_field_config(
  526. template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
  527. field_display_name, field_display_name_user, data_type, custom_value_type,
  528. custom_fixed_value, is_filter_enabled, is_sort_enabled,is_enabled, created_time)
  529. VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
  530. '$_field_code', '$_display_name', '$_data_type', '$_value_type',
  531. '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled','$_is_enabled',now());";
  532. }
  533. if (!empty($sql)){
  534. common::excuteUpdateSql($sql);
  535. $data = array("msg" =>"success");
  536. }
  537. common::echo_json_encode(200,array("msg"=>"success","Data" => ''));
  538. exit;
  539. }
  540. if ($operate == "report_schedule"){
  541. $serial_no = common::check_input($_POST ['serial_no']);
  542. $schedule = common::excuteObjectSql("select schedule_order_field,validity_type,valid_from,valid_to,
  543. data_reference_field,data_range_type,dynamic_start_offset,dynamic_end_offset,fixed_start_date,fixed_end_date,
  544. delivery_frequency,TO_CHAR(daily_time, 'HH24:MI') as daily_time,
  545. array_to_json(weekly_day) as weekly_days_json,TO_CHAR(weekly_time, 'HH24:MI') as weekly_time,
  546. array_to_json(monthly_day) as monthly_day_json,TO_CHAR(monthly_time, 'HH24:MI') as monthly_time,
  547. quarterly_month,quarterly_day,TO_CHAR(quarterly_time, 'HH24:MI') as quarterly_time,
  548. array_to_json(yearly_month) as yearly_month_json,yearly_day, TO_CHAR(yearly_time, 'HH24:MI') as yearly_time,
  549. timezone,email_recipients
  550. from public.kln_report_template where serial_no = '$serial_no'");
  551. $schedule["weekly_days"] = json_decode($schedule["weekly_days"],true);
  552. $schedule["monthly_day"] = json_decode($schedule["monthly_day"],true);
  553. $schedule["yearly_month"] = json_decode($schedule["yearly_month"],true);
  554. //处理成VUE 识别的格式
  555. $data = array();
  556. $data["validityPeriod"] = array("type"=>$schedule["validity_type"],"startDate"=>$schedule["valid_from"],"endDate"=>$schedule["valid_to"]);
  557. if($schedule["data_range_type"] == "dynamic_rolling"){
  558. $data["timeRange"] = array("fieldType"=>$schedule["data_reference_field"],"type"=>$schedule["data_range_type"],
  559. "startDate"=>$schedule["dynamic_start_offset"],"endDate"=>$schedule["dynamic_end_offset"]);
  560. }else{
  561. $data["timeRange"] = array("fieldType"=>$schedule["data_reference_field"],"type"=>$schedule["data_range_type"],
  562. "startDate"=>$schedule["fixed_start_date"],"endDate"=>$schedule["fixed_end_date"]);
  563. }
  564. $time = "";
  565. $week = array();
  566. $month = array();
  567. $quarterMonth = "";
  568. $day = array();
  569. $delivery_frequency = $schedule["delivery_frequency"];
  570. if($delivery_frequency == 'daily'){
  571. $time = $schedule["daily_time"];
  572. }elseif($delivery_frequency == 'weekly'){
  573. $week= json_decode($schedule["weekly_days_json"],true);
  574. $time = $schedule["weekly_time"];
  575. }elseif($delivery_frequency == 'monthly'){
  576. $monthlyDay= json_decode($schedule["monthly_day_json"],true);
  577. $time = $schedule["monthly_time"];
  578. }elseif($delivery_frequency == 'quarterly'){
  579. $quarterMonth = $schedule["quarterly_month"];
  580. $day = $schedule["quarterly_day"];
  581. $time = $schedule["quarterly_time"];
  582. }elseif($delivery_frequency == 'yearly'){
  583. $month= json_decode($schedule["yearly_month_json"],true);
  584. $day = $schedule["yearly_day"];
  585. $time = $schedule["yearly_time"];
  586. }
  587. $data["deliveryFrequency"] = array("emailRecipients"=>$schedule["email_recipients"],"orderBy"=>$schedule["schedule_order_field"],
  588. "timezone"=>$schedule["timezone"],"deliveryFrequency"=>$schedule["delivery_frequency"],
  589. "scheduleDetails" =>array("time"=>$time,"week"=>$week,"month"=>$month,"monthlyDay" =>$monthlyDay,"quarterMonth"=>$quarterMonth,"day"=>$day));
  590. common::echo_json_encode(200,array("msg"=>"success","showData" => $data));
  591. exit;
  592. }
  593. if ($operate == "report_schedule_search"){
  594. $dataReturn = array();
  595. $serial_no = common::check_input($_POST ['serial_no']);
  596. $data_reference_field = strtolower(common::check_input($_POST ['fieldType']));
  597. $data_range_type = common::check_input($_POST ['type']);
  598. if($data_range_type == "dynamic_rolling"){
  599. $dynamic_start_offset = common::check_input($_POST ['startDate']);
  600. $dynamic_end_offset = common::check_input($_POST ['endDate']);
  601. $fixed_start_date = "null";
  602. $fixed_end_date = "null";
  603. }else{
  604. $dynamic_start_offset = "null";
  605. $dynamic_end_offset = "null";
  606. $fixed_start_date = common::check_input($_POST ['startDate']);
  607. $fixed_end_date = common::check_input($_POST ['endDate']);
  608. }
  609. $schedule_order_field = common::check_input($_POST ['orderBy']);
  610. //查询列名
  611. $tableColumns = array();
  612. $CustomFiled = "";
  613. $reportFiled = common::excuteListSql("select * from public.kln_report_field_config where template_serial_no = '".$serial_no."'
  614. and is_enabled = true order by id ");
  615. foreach($reportFiled as $filed){
  616. $temp = array();
  617. $temp['field'] = $filed['field_display_name'];
  618. $temp['title'] = $filed['field_display_name_user'];
  619. $temp['type'] = $filed['field_db'] == "Status" ? "status" : "normal";
  620. $temp['formatter'] = "";
  621. $tableColumns[] = $temp;
  622. //用户自定义字段
  623. if($filed['field_type'] == 'Custom'){
  624. $CustomFiled = " , '".$filed['custom_fixed_value']."' AS \"".$filed['field_display_name_user']."\"";
  625. }
  626. }
  627. $dataReturn['tableColumns'] = $tableColumns;
  628. //形成sql
  629. $schedule_search = common::excuteObjectSql("select schedule_order_field,data_reference_field,data_range_type,
  630. dynamic_start_offset,dynamic_end_offset,
  631. fixed_start_date,fixed_end_date,
  632. report_sql,count_sql
  633. from public.kln_report_template where serial_no = '$serial_no'");
  634. $report_sql = $schedule_search["report_sql"];
  635. $count_sql = $schedule_search["count_sql"];
  636. //$klnOceanSearchKLN = " where " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  637. $klnOceanSearchKLN = " where created_time > CURRENT_DATE - INTERVAL '1 years' and " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  638. $orderby = "";
  639. if(!empty($data_range_type)){
  640. //代表有用户设置的查询参数
  641. if($data_range_type == "dynamic_rolling"){
  642. $klnOceanSearchKLN .= " and ".$data_reference_field." >= CURRENT_DATE - ".$dynamic_start_offset." and ".$data_reference_field." <= CURRENT_DATE + ".$dynamic_end_offset."";
  643. } else {
  644. if(!empty($fixed_start_date)){
  645. $klnOceanSearchKLN .= " and ".$data_reference_field." >= '".common::usDate2sqlDate($fixed_start_date)."'";
  646. }
  647. if(!empty($fixed_end_date)){
  648. $klnOceanSearchKLN .= " and ".$data_reference_field." <= '".common::usDate2sqlDate($fixed_end_date)."'";
  649. }
  650. }
  651. if(!empty($schedule_order_field)){
  652. $orderby = " order by \"".strtoupper($schedule_order_field)."\"";
  653. }
  654. } else {
  655. if($schedule_search["data_range_type"] == "dynamic_rolling"){
  656. $field_db = strtolower($schedule_search["data_reference_field"]);
  657. $dynamic_start_offset_db = empty($schedule_search["dynamic_start_offset"]) ? 0 : $schedule_search["dynamic_start_offset"];
  658. $dynamic_end_offset_db = empty($schedule_search["dynamic_end_offset"]) ? 0 : $schedule_search["dynamic_end_offset"];
  659. $klnOceanSearchKLN .= " and ".$field_db." >= CURRENT_DATE - ".$dynamic_start_offset_db." and ".$field_db." <= CURRENT_DATE + ".$dynamic_end_offset_db."";
  660. } else {
  661. $field_db = strtolower($schedule_search["data_reference_field"]);
  662. $fixed_start_date_db = $schedule_search["fixed_start_date"];
  663. $fixed_end_date_db = $schedule_search["fixed_end_date"];
  664. if(!empty($fixed_start_date_db)){
  665. $klnOceanSearchKLN .= " and ".$field_db." >= '".$fixed_start_date_db."'";
  666. }
  667. if(!empty($fixed_end_date_db)){
  668. $klnOceanSearchKLN .= " and ".$field_db." <= '".$fixed_end_date_db."'";
  669. }
  670. }
  671. if(!empty($schedule_search["schedule_order_field"])){
  672. $orderby = " order by \"".strtoupper($schedule_search["schedule_order_field"])."\"";
  673. }
  674. }
  675. $count_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $count_sql);
  676. $count_sql = str_replace('<{ocItemSearchKLN}>', " ", $count_sql);
  677. $count_sql = str_replace('<{vvSearchKLN}>', " ", $count_sql);
  678. $report_sql = str_replace('<{klnOceanSearchKLN}>', $klnOceanSearchKLN, $report_sql);
  679. $report_sql = str_replace('<{ocItemSearchKLN}>', " ", $report_sql);
  680. $report_sql = str_replace('<{CustomFiled}>', $CustomFiled, $report_sql);
  681. $report_sql = str_replace('<{vvSearchKLN}>', " ", $report_sql);
  682. //查询sql
  683. $cp = common::check_input($_POST ['cp']); //current_page
  684. $ps = common::check_input($_POST ['ps']); //ps
  685. if (empty($ps))
  686. $ps = 10;
  687. if (empty($cp))
  688. $cp = 1;
  689. $rc = $_POST ['rc'];
  690. if ($rc == -1) {
  691. $count_sql = str_replace('<{orderby}>', "", $count_sql);
  692. error_log($count_sql);
  693. $rc = common::excuteOneSql($count_sql);
  694. }
  695. $tp = ceil($rc / $ps);
  696. if ($rc > 0) {
  697. $report_sql = str_replace('<{orderby}>', $orderby, $report_sql);
  698. $tmp_search_without_limit = $report_sql;
  699. $report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  700. error_log($report_sql);
  701. $rs = common::excuteListSql($report_sql);
  702. $arrTmp = array('searchData' => $rs,
  703. 'rc' => intval($rc),
  704. 'ps' => intval($ps),
  705. 'cp' => intval($cp),
  706. 'tp' => intval($tp));
  707. }else{
  708. $arrTmp = array('searchData' => array(),
  709. 'rc' => intval($rc),
  710. 'ps' => intval($ps),
  711. 'cp' => intval($cp),
  712. 'tp' => intval($tp));
  713. }
  714. $dataReturn['tableData'] = $arrTmp;
  715. common::echo_json_encode(200, $dataReturn);
  716. exit();
  717. exit;
  718. }
  719. if ($operate == "report_schedule_save"){
  720. $serial_no = common::check_input($_POST ['serial_no']);
  721. $validity_type = common::check_input($_POST ['validityPeriodType']);
  722. $valid_from = "null";
  723. $valid_to = "null";
  724. if($validity_type == "custom"){
  725. $valid_from = "'".common::check_input($_POST ['validityPeriodStartDate'])."'";
  726. $valid_to = "'".common::check_input($_POST ['validityPeriodEndDate'])."'";
  727. }
  728. $data_reference_field = strtolower(common::check_input($_POST ['fieldType']));
  729. $data_range_type = common::check_input($_POST ['type']);
  730. if($data_range_type == "dynamic_rolling"){
  731. $dynamic_start_offset = "'".common::check_input($_POST ['startDate'])."'";
  732. $dynamic_end_offset = "'".common::check_input($_POST ['endDate'])."'";
  733. $fixed_start_date = "null";
  734. $fixed_end_date = "null";
  735. }else{
  736. $dynamic_start_offset = "null";
  737. $dynamic_end_offset = "null";
  738. $fixed_start_date = "'".common::check_input($_POST ['startDate'])."'";
  739. $fixed_end_date = "'".common::check_input($_POST ['endDate'])."'";
  740. }
  741. $schedule_order_field = common::check_input($_POST ['orderBy']);
  742. if(empty($schedule_order_field)){
  743. $schedule_order_field = "ETD";
  744. }
  745. $email_recipients = common::check_input($_POST ['emailRecipients']);
  746. $timezone = common::check_input($_POST ['timezone']);
  747. $daily_time = "null";
  748. $weekly_day = "null";
  749. $weekly_time = "null";
  750. $monthly_day = "null";
  751. $monthly_time = "null";
  752. $quarterly_month= "null";
  753. $quarterly_day= "null";
  754. $quarterly_time = "null";
  755. $yearly_month = "null";
  756. $yearly_day = "null";
  757. $yearly_time = "null";
  758. $delivery_frequency = common::check_input($_POST ['deliveryFrequency']);
  759. if($delivery_frequency == 'daily'){
  760. $daily_time = "'".common::check_input($_POST ['time'])."'";
  761. }elseif($delivery_frequency == 'weekly'){
  762. $weekly_day= common::toPgTextArrayLiteral($_POST ['week']);
  763. $weekly_time = "'".common::check_input($_POST ['time'])."'";
  764. }elseif($delivery_frequency == 'monthly'){
  765. $monthly_day= common::toPgTextArrayLiteral($_POST ['monthlyDay']);
  766. $monthly_time = "'".common::check_input($_POST ['time'])."'";
  767. }elseif($delivery_frequency == 'quarterly'){
  768. //检查数组是否有值
  769. $quarterly_month = "'".common::check_input($_POST ['quarterMonth'])."'";
  770. $quarterly_day = "'".common::check_input($_POST ['day'])."'";
  771. $quarterly_time = "'".common::check_input($_POST ['time'])."'";
  772. }elseif($delivery_frequency == 'yearly'){
  773. $yearly_month= common::toPgTextArrayLiteral($_POST ['yearlyMonth']);
  774. $yearly_day = "'".common::check_input($_POST ['day'])."'";
  775. $yearly_time = "'".common::check_input($_POST ['time'])."'";
  776. }
  777. $sql = "";
  778. $klnOceanSearchKLN = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  779. if (!empty($serial_no)){
  780. $updateSqlSet = " schedule_order_field = '".$schedule_order_field."',
  781. validity_type = '".$validity_type."',
  782. valid_from = ".$valid_from.",
  783. valid_to = ".$valid_to.",
  784. data_reference_field = '".$data_reference_field."',
  785. data_range_type = '".$data_range_type."',
  786. dynamic_start_offset = ".$dynamic_start_offset.",
  787. dynamic_end_offset = ".$dynamic_end_offset.",
  788. fixed_start_date = ".$fixed_start_date.",
  789. fixed_end_date = ".$fixed_end_date.",
  790. delivery_frequency = '".$delivery_frequency."',
  791. daily_time = ".$daily_time.",
  792. weekly_day = ".$weekly_day.",
  793. weekly_time = ".$weekly_time.",
  794. monthly_day = ".$monthly_day.",
  795. monthly_time = ".$monthly_time.",
  796. quarterly_month = ".$quarterly_month.",
  797. quarterly_day = ".$quarterly_day.",
  798. quarterly_time = ".$quarterly_time.",
  799. yearly_month = ".$yearly_month.",
  800. yearly_day = ".$yearly_day.",
  801. yearly_time = ".$yearly_time.",
  802. timezone = '".$timezone."',
  803. email_recipients = '".$email_recipients."',
  804. next_run_time = null,
  805. search_extend_hand = '".common::check_input($klnOceanSearchKLN)."',
  806. modify_by = '"._getLoginName()."',
  807. update_time = now()";
  808. //代表update
  809. $sql .= "update public.kln_report_template set ".$updateSqlSet."
  810. where serial_no = '$serial_no';";
  811. }
  812. if (!empty($sql)){
  813. common::excuteUpdateSql($sql);
  814. //执行成功后,处理next_run_time
  815. $config = common::excuteObjectSql("select delivery_frequency,daily_time,
  816. array_to_json(weekly_day) as weekly_day_json,weekly_time,
  817. array_to_json(monthly_day) as monthly_day_json,monthly_time,
  818. quarterly_month,quarterly_day,quarterly_time,
  819. array_to_json(yearly_month) as yearly_month_json,yearly_day,yearly_time,timezone
  820. from public.kln_report_template where serial_no = '$serial_no';");
  821. $config["weekly_day"] = json_decode($config["weekly_day_json"],true);
  822. $config["monthly_day"] = json_decode($config["monthly_day_json"],true);
  823. $config["yearly_month"] = json_decode($config["yearly_month_json"],true);
  824. $next = common::calculateNextRunTime($config);
  825. $next_run_time = $next->format('Y-m-d H:i:s');
  826. common::excuteUpdateSql("update public.kln_report_template set next_run_time = '$next_run_time' where serial_no = '$serial_no';");
  827. $data = array("msg" =>"success");
  828. }
  829. common::echo_json_encode(200,$data);
  830. exit();
  831. }
  832. }
  833. /**
  834. * 根据提交的参数动态的拼接filter sql
  835. */
  836. public function returnFilterSql($filtersList){
  837. $klnVipDb = common::getReportRealDBFiled();
  838. $vvSearchKLN = " where 1=1 ";
  839. $klnOceanSearchKLN = " where created_time > CURRENT_DATE - INTERVAL '1 years' and " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  840. //$klnOceanSearchKLN = " where " . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  841. $ocItemSearchKLN = " where 1=1 ";
  842. foreach($filtersList as $fiter){
  843. if(!empty($_POST[$fiter['field']])){
  844. $key = array_search($fiter['field'], $klnVipDb);
  845. if($key !== false){
  846. //找到给key
  847. $temp_sql_where = "";
  848. if ($fiter['data_type'] == "string"){
  849. $temp_sql_where .= " and ".$key." = '". common::check_input($_POST[$fiter['field']])."'";
  850. } elseif ($fiter['data_type'] == "number"){
  851. $temp_arr = $_POST [$fiter['field']];
  852. if(!empty($temp_arr[0])){
  853. $temp_sql_where .= " and ".$key."::integer >= '". common::check_input($temp_arr[0])."'";
  854. }
  855. if(!empty($temp_arr[1])){
  856. $temp_sql_where .= " and ".$key."::integer <= '". common::check_input($temp_arr[1])."'";
  857. }
  858. } elseif ($fiter['data_type'] == "date"){
  859. $temp_arr = $_POST [$fiter['field']];
  860. if(!empty($temp_arr[0])){
  861. $date_from = common::check_input(common::usDate2sqlDate($temp_arr[0]) . ' 00:00:00');
  862. $temp_sql_where .= " and ".$key." >= '". $date_from."'";
  863. }
  864. if(!empty($temp_arr[1])){
  865. $date_to = common::check_input(common::usDate2sqlDate($temp_arr[1]) . ' 23:59:59');
  866. $temp_sql_where .= " and ".$key." <= '". $date_to."'";
  867. }
  868. }
  869. if(utils::startWith($key,"oc") || utils::startWith($key,"oi")){
  870. $ocItemSearchKLN .= $temp_sql_where;
  871. } else {
  872. $klnOceanSearchKLN .= $temp_sql_where;
  873. }
  874. } else {
  875. //获取POST name 用户去别名得字段,放在vvSearchKLN上
  876. $_post_field = $fiter['field'];
  877. $_post_field = strtolower($_post_field);
  878. $_post_field = preg_replace('/[^a-z0-9]+/', '_', $_post_field); // 非字母数字 → _
  879. $_post_field = trim($_post_field, '_');
  880. if ($fiter['data_type'] == "string"){
  881. $vvSearchKLN .= " and \"".$fiter['field_real']."\" ilike '%". common::check_input($_POST [$_post_field])."%'";
  882. } elseif ($fiter['data_type'] == "number"){
  883. $temp_arr = $_POST [$_post_field];
  884. if(!empty($temp_arr[0])){
  885. $vvSearchKLN .= " and \"".$fiter['field_real']."\"::integer >= '". common::check_input($temp_arr[0])."'";
  886. }
  887. if(!empty($temp_arr[1])){
  888. $vvSearchKLN .= " and \"".$fiter['field_real']."\"::integer <= '". common::check_input($temp_arr[1])."'";
  889. }
  890. } elseif ($fiter['data_type'] == "date"){
  891. $temp_arr = $_POST [$_post_field];
  892. //先判断日期字符串是否为空,这里则有做 是因为sql 整合了柜子315时间,和 milestone的时间, 只能text转date
  893. if(!empty($temp_arr[0])){
  894. $date_from = common::check_input(common::usDate2sqlDate($temp_arr[0]) . ' 00:00:00');
  895. $vvSearchKLN .= " and COALESCE(\"".$fiter['field_real']."\",''::text)<> ''::text ";
  896. $vvSearchKLN .= " and to_timestamp(\"".$fiter['field_real']."\", 'MM/DD/YYYY HH24:MI:SS') >= '". $date_from."'";
  897. }
  898. if(!empty($temp_arr[1])){
  899. $date_to = common::check_input(common::usDate2sqlDate($temp_arr[1]) . ' 23:59:59');
  900. $vvSearchKLN .= " and COALESCE(\"".$fiter['field_real']."\",''::text)<> ''::text ";
  901. $vvSearchKLN .= " and to_timestamp(\"".$fiter['field_real']."\", 'MM/DD/YYYY HH24:MI:SS') <= '". $date_to."'";
  902. }
  903. }
  904. }
  905. }
  906. }
  907. return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
  908. }
  909. /**
  910. * 根据提交的参数动态的拼接sort by sql
  911. */
  912. public function returnSortBySql(){
  913. $sortByField = $_POST['sortByField'];
  914. $sortByOrder = $_POST['sortByOrder'];
  915. $sort_sql_temp = " ";
  916. if(!empty($sortByField) && !empty($sortByOrder)){
  917. $sort_sql_temp = " order by \"".$sortByField."\" ". $sortByOrder;
  918. }
  919. return $sort_sql_temp;
  920. }
  921. }
  922. ?>