report.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. $operate = utils::_get('operate');
  24. $operate = strtolower($operate);
  25. /**
  26. * report的配置查询,
  27. */
  28. if ($operate == "search"){
  29. $cp = common::check_input($_POST ['cp']); //current_page
  30. $ps = common::check_input($_POST ['ps']); //ps
  31. if (empty($ps))
  32. $ps = 100;
  33. if (empty($cp))
  34. $cp = 1;
  35. $sqlWhere = "1=1";
  36. $text_search = $_POST['text_search'];
  37. if (!empty($text_search)){
  38. $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
  39. }
  40. if(!empty($_POST['application_scope'])){
  41. $pplication_scope = $_POST['application_scope'] =='all' ? "All Users" : "Specific Users";
  42. $sqlWhere .= " and access_type ='". common::check_input($pplication_scope)."'";
  43. }
  44. if(!empty($_POST['is_active'])){
  45. if($_POST['is_active'] == 't'){
  46. $sqlWhere .= " and is_active = true";
  47. }else{
  48. $sqlWhere .= " and is_active = false";
  49. }
  50. }
  51. $rc = $_POST ['rc'];
  52. if ($rc == -1) {
  53. $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
  54. $rc = common::excuteOneSql($sql);
  55. }
  56. $tp = ceil($rc / $ps);
  57. if ($rc > 0) {
  58. $sql = "select * from public.kln_report_template where " .$sqlWhere;
  59. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  60. $rs = common::excuteListSql($sql);
  61. $arrTmp = array('searchData' => $rs,
  62. 'rc' => intval($rc),
  63. 'ps' => intval($ps),
  64. 'cp' => intval($cp),
  65. 'tp' => intval($tp));
  66. common::echo_json_encode(200,$arrTmp);
  67. exit();
  68. }else{
  69. $arrTmp = array('searchData' => array());
  70. common::echo_json_encode(200, $arrTmp);
  71. exit();
  72. }
  73. }
  74. if ($operate == "add"){
  75. $serial_no = $_REQUEST['serial_no'];
  76. if(!empty($serial_no)){
  77. //代表编辑
  78. $reportMain = common::excuteObjectSql("select *,
  79. array_to_json(party_ids) as party_ids_json,
  80. array_to_json(group_names) as group_names_json
  81. from kln_report_template where serial_no = '$serial_no'");
  82. $reportFields = array();
  83. $reportField = common::excuteListSql("select
  84. field_id as ids,
  85. field_level as \"fieldLevel\",
  86. field_type as \"fieldType\",
  87. field_group_name as \"groupName\",
  88. field_db as field,
  89. field_display_name as title,
  90. field_display_name_user as \"displayName\",
  91. data_type as \"dataType\",
  92. custom_fixed_value as value,
  93. is_filter_enabled as \"isFilter\",
  94. is_sort_enabled as \"isSort\"
  95. from kln_report_field_config where template_serial_no = '$serial_no' order by id");
  96. foreach($reportField as $_reportField){
  97. $_reportField['isFilter'] = $_reportField['isFilter'] == 't' ? true : false;
  98. $_reportField['isSort'] = $_reportField['isSort'] == 't' ? true : false;
  99. $reportFields[] = $_reportField;
  100. }
  101. $reportAccess = array("type"=>$reportMain['access_type'],
  102. "partyId"=>json_decode($reportMain['party_ids_json'],true),
  103. "groupName"=>json_decode($reportMain['group_names_json'],true));
  104. $data = array("reportName"=>$reportMain['name'],"reportLevel"=>$reportMain['level'],"reportDescription"=>$reportMain['description'],
  105. "reportFields"=>$reportFields,"reportAccess"=>$reportAccess);
  106. }else{
  107. $data = array();
  108. }
  109. common::echo_json_encode(200,$data);
  110. exit();
  111. }
  112. if ($operate == "report_field_load"){
  113. column::getInstance()->settingDisplayForVIPReport();
  114. }
  115. if ($operate == "save"){
  116. $serial_no = $_POST['serial_no'];
  117. $name = common::check_input($_POST['report_name']);
  118. $description = common::check_input($_POST['report_description']);
  119. $level = common::check_input($_POST['report_level']);
  120. $access_type = common::check_input($_POST['access_type']);
  121. $party_ids = $_POST['party_ids'];
  122. $group_names = $_POST['group_names'];
  123. //单独处理字段id
  124. $fieldsList = $_POST['fieldsList'];
  125. $field_ids = array();
  126. foreach($fieldsList as $_fieldsList){
  127. if (!empty($_fieldsList['ids'])){
  128. $field_ids[] = $_fieldsList['ids'];
  129. }
  130. }
  131. $report_sql_data = common::excuteObjectSql("select sql,count_sql from public.kln_report_sql_manage where level = '$level'");
  132. $sql = "";
  133. if (!empty($serial_no)){
  134. $updateSqlSet = " report_sql = '".common::check_input($report_sql_data['sql'])."',
  135. count_sql = '".common::check_input($report_sql_data['count_sql'])."',
  136. modify_by = '"._getLoginName()."',update_time = now()";
  137. if (!empty($name)) {
  138. $updateSqlSet.= ", name = '$name' ";
  139. }
  140. if (!empty($description)) {
  141. $updateSqlSet.= ", description = '$description' ";
  142. }
  143. if (!empty($level)) {
  144. $updateSqlSet.= ", level = '$level' ";
  145. }
  146. if (!empty($access_type)) {
  147. $updateSqlSet.= ", access_type = '$access_type' ";
  148. }
  149. if (!empty($party_ids)) {
  150. $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
  151. $updateSqlSet.= ", party_ids = $party_ids_filed";
  152. }
  153. if (!empty($group_names)) {
  154. $group_names_filed = common::toPgTextArrayLiteral($group_names);
  155. $updateSqlSet.= ", group_names = $group_names_filed";
  156. }
  157. if (!empty($field_ids)) {
  158. $ids_filed = common::toPgTextArrayLiteral($field_ids);
  159. $updateSqlSet.= ", field_ids = $ids_filed";
  160. }
  161. //代表update
  162. $sql .= "update public.kln_report_template set ".$updateSqlSet."
  163. where serial_no = '$serial_no';";
  164. } else {
  165. $party_ids_filed = "NULL";
  166. if (!empty($party_ids)) {
  167. $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
  168. }
  169. $group_names_filed = "NULL";
  170. if (!empty($group_names)) {
  171. $group_names_filed = common::toPgTextArrayLiteral($group_names);
  172. }
  173. $ids_filed = "NULL";
  174. if (!empty($field_ids)) {
  175. $ids_filed = common::toPgTextArrayLiteral($field_ids);
  176. }
  177. $serial_no = common::uuid();
  178. $sql .= "INSERT INTO public.kln_report_template(
  179. serial_no,name, description, level, field_ids, access_type, report_sql,count_sql,
  180. party_ids, group_names, create_by, created_time, modify_by, update_time )
  181. VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type',
  182. '".common::check_input($report_sql_data['sql'])."','".common::check_input($report_sql_data['count_sql'])."',
  183. $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
  184. }
  185. //先删除,后添加
  186. $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  187. foreach($fieldsList as $key =>$_tempFieldsList){
  188. $_field_id = empty($_tempFieldsList['ids'])? "NULL": $_tempFieldsList['ids'];
  189. $_field_level = common::check_input($_tempFieldsList['fieldLevel']);
  190. $_field_type = common::check_input($_tempFieldsList['fieldType']);
  191. $_field_group_name = common::check_input($_tempFieldsList['groupName']);
  192. $_field_db = common::check_input($_tempFieldsList['field']);
  193. $_field_code = common::check_input($_tempFieldsList['title']);
  194. $_display_name = common::check_input($_tempFieldsList['displayName']);
  195. $_data_type = common::check_input($_tempFieldsList['dataType']);
  196. $_value_type = $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
  197. $_fixed_value = common::check_input($_tempFieldsList['value']);
  198. $_is_filter_enabled = $_tempFieldsList['isFilter'];
  199. $_is_sort_enabled = $_tempFieldsList['isSort'];
  200. $sql .= "INSERT INTO public.kln_report_field_config(
  201. template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
  202. field_display_name, field_display_name_user, data_type, custom_value_type,
  203. custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
  204. VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
  205. '$_field_code', '$_display_name', '$_data_type', '$_value_type',
  206. '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
  207. }
  208. if (!empty($sql)){
  209. common::excuteUpdateSql($sql);
  210. $data = array("msg" =>"success");
  211. }
  212. common::echo_json_encode(200,$data);
  213. exit();
  214. }
  215. if ($operate == "active"){
  216. $serial_no =$_POST['serial_no'];
  217. $is_active = $_POST['is_active'];
  218. $sql = "update public.kln_report_template set is_active = '$is_active' where serial_no = '$serial_no';";
  219. common::excuteUpdateSql($sql);
  220. $data = array("msg" =>"success");
  221. common::echo_json_encode(200,$data);
  222. exit();
  223. }
  224. }
  225. /**
  226. * shipment_status_report
  227. */
  228. public function shipment_status_report(){
  229. $operate = utils::_get('operate');
  230. $operate = strtolower($operate);
  231. if ($operate == "report_search") {
  232. $cp = common::check_input($_POST ['cp']); //current_page
  233. $ps = common::check_input($_POST ['ps']); //ps
  234. if (empty($ps))
  235. $ps = 100;
  236. if (empty($cp))
  237. $cp = 1;
  238. $sqlWhere = "1=1 and is_active = true";
  239. $text_search = $_POST['text_search'];
  240. if (!empty($text_search)){
  241. $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
  242. }
  243. $rc = $_POST ['rc'];
  244. if ($rc == - 1) {
  245. $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
  246. $rc = common::excuteOneSql($sql);
  247. }
  248. $tp = ceil($rc / $ps);
  249. if ($rc > 0) {
  250. $sql = "select name,description from public.kln_report_template where " .$sqlWhere;
  251. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  252. $rs = common::excuteListSql($sql);
  253. $arrTmp = array('searchData' => $rs,
  254. 'rc' => intval($rc),
  255. 'ps' => intval($ps),
  256. 'cp' => intval($cp),
  257. 'tp' => intval($tp));
  258. common::echo_json_encode(200,$arrTmp);
  259. exit();
  260. }else{
  261. $arrTmp = array('searchData' => array());
  262. common::echo_json_encode(200, $arrTmp);
  263. exit();
  264. }
  265. }
  266. if ($operate == "report_detail") {
  267. $serial_no = common::check_input($_POST ['serial_no']);
  268. $dataReturn = array();
  269. $tableColumns = array();
  270. $filtersList = array();
  271. $sortByOptions = array();
  272. $reportFiled = common::excuteListSql("select * from public.kln_report_field_config where template_serial_no = '".$serial_no."'
  273. and field_type = 'System' and is_enabled = true order by id ");
  274. foreach($reportFiled as $filed){
  275. if($filed['is_filter_enabled'] == 't'){
  276. $type = $filed['data_type'] == "string" ? "input" : ($filed['data_type'] == "date" ? "date" : "input");
  277. $filtersList[] = array(
  278. "label"=>$filed['field_display_name_user'],
  279. "field"=>$filed['field_display_name'],
  280. "type"=>$type,
  281. "data_type"=>$filed['data_type'],
  282. "value"=>[],"options"=>[]);
  283. }
  284. if($filed['is_sort_enabled'] == 't'){
  285. $sortByOptions[] = $filed['field_db'];
  286. }
  287. $temp = array();
  288. $temp['field'] = $filed['field_display_name'];
  289. $temp['title'] = $filed['field_display_name_user'];
  290. $temp['type'] = $filed['field_db'] == "Status" ? "status" : "normal";
  291. $temp['formatter'] = "";
  292. $tableColumns[] = $temp;
  293. }
  294. $dataReturn['tableColumns'] = $tableColumns;
  295. $dataReturn['filtersList'] = $filtersList;
  296. if(!empty($sortByOptions)){
  297. $dataReturn['sortBy'] = array("field"=>$sortByOptions[0],"options"=>$sortByOptions,"order"=>"asc");
  298. }else{
  299. $dataReturn['sortBy'] = array("field"=>"","options"=>[],"order"=>"asc");
  300. }
  301. $reportFiled = common::excuteObjectSql("select report_sql,count_sql from public.kln_report_template where serial_no = '".$serial_no."'");
  302. $report_sql = $reportFiled["report_sql"];
  303. $count_sql = $reportFiled["count_sql"];
  304. $filterSQLArr = $this->returnFilterSql($filtersList);
  305. //return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
  306. $report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
  307. $report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
  308. $report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
  309. //查询data
  310. $cp = common::check_input($_POST ['cp']); //current_page
  311. $ps = common::check_input($_POST ['ps']); //ps
  312. if (empty($ps))
  313. $ps = 10;
  314. if (empty($cp))
  315. $cp = 1;
  316. if (true) {
  317. $count_sql = str_replace('<{orderby}>', "", $count_sql);
  318. error_log($count_sql);
  319. $rc = common::excuteOneSql($count_sql);
  320. }
  321. $tp = ceil($rc / $ps);
  322. if ($rc > 0) {
  323. $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
  324. $tmp_search_without_limit = $report_sql;
  325. $report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  326. error_log($report_sql);
  327. $rs = common::excuteListSql($report_sql);
  328. $arrTmp = array('searchData' => $rs,
  329. 'rc' => intval($rc),
  330. 'ps' => intval($ps),
  331. 'cp' => intval($cp),
  332. 'tp' => intval($tp));
  333. }else{
  334. $arrTmp = array('searchData' => array());
  335. }
  336. $dataReturn['tableData'] = $arrTmp;
  337. $dataReturn['tmp_search'] = common::deCode($tmp_search_without_limit, 'E');
  338. common::echo_json_encode(200, $dataReturn);
  339. exit();
  340. }
  341. /*
  342. * export excel
  343. */
  344. if ($operate == "excel") {
  345. $sql = common::deCode($_POST['tmp_search'], 'D');
  346. if(!empty($sql)){
  347. $rs = common::excuteListSql($sql);
  348. }
  349. //去除null
  350. foreach($rs as $index => $val) {
  351. foreach($val as $index_2 => $_val) {
  352. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  353. $rs[$index][$index_2] = "";
  354. }
  355. }
  356. }
  357. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  358. exit;
  359. }
  360. if ($operate == "manage_fileds") {
  361. $serial_no = common::check_input($_POST ['serial_no']);
  362. $reportFiled = common::excuteListSql("select * from public.kln_report_field_config
  363. where template_serial_no = '".$serial_no."'
  364. and field_type = 'System' order by id ");
  365. $showData = array();
  366. $hideData = array();
  367. foreach($reportFiled as $_reportFiled){
  368. $_reportFiled['is_filter_enabled'] = $_reportFiled['is_filter_enabled'] == 't' ? true : false;
  369. $_reportFiled['is_sort_enabled'] = $_reportFiled['is_sort_enabled'] == 't' ? true : false;
  370. if($_reportFiled['is_enabled'] == 't'){
  371. $showData[] = $_reportFiled;
  372. }else{
  373. $hideData[] = $_reportFiled;
  374. }
  375. }
  376. common::echo_json_encode(200,array("msg"=>"success","showData" => $showData,"hideData" => $hideData));
  377. exit;
  378. }
  379. if ($operate == "manage_fileds_save") {
  380. $serial_no = common::check_input($_POST['serial_no']);
  381. $fieldsList = $_POST['fieldsList'];
  382. //先删除,后添加 因为不涉及系统配置字段,全部用kln_report_field_config 字段name
  383. $sql = "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  384. foreach($fieldsList as $key =>$_tempFieldsList){
  385. $_field_id = empty($_tempFieldsList['field_id'])? "NULL": $_tempFieldsList['field_id'];
  386. $_field_level = common::check_input($_tempFieldsList['field_level']);
  387. $_field_type = common::check_input($_tempFieldsList['field_type']);
  388. $_field_group_name = common::check_input($_tempFieldsList['field_group_name']);
  389. $_field_db = common::check_input($_tempFieldsList['field_db']);
  390. $_field_code = common::check_input($_tempFieldsList['field_display_name']);
  391. $_display_name = common::check_input($_tempFieldsList['field_display_name_user']);
  392. $_data_type = common::check_input($_tempFieldsList['data_type']);
  393. $_value_type = common::check_input($_tempFieldsList['custom_value_type']);
  394. $_fixed_value = common::check_input($_tempFieldsList['custom_fixed_value']);
  395. $_is_filter_enabled = $_tempFieldsList['is_filter_enabled'];
  396. $_is_sort_enabled = $_tempFieldsList['is_sort_enabled'];
  397. $sql .= "INSERT INTO public.kln_report_field_config(
  398. template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
  399. field_display_name, field_display_name_user, data_type, custom_value_type,
  400. custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
  401. VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
  402. '$_field_code', '$_display_name', '$_data_type', '$_value_type',
  403. '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
  404. }
  405. if (!empty($sql)){
  406. common::excuteUpdateSql($sql);
  407. $data = array("msg" =>"success");
  408. }
  409. common::echo_json_encode(200,array("msg"=>"success","Data" => ''));
  410. exit;
  411. }
  412. }
  413. /**
  414. * 根据提交的参数动态的拼接filter sql
  415. */
  416. public function returnFilterSql($filtersList){
  417. $klnOceanDb = common::getReportRealDBFiled("klnOceanDb");
  418. $ocItemDb = common::getReportRealDBFiled("ocItemDb");
  419. $vvSearchKLN = " where 1=1 ";
  420. $klnOceanSearchKLN = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  421. $ocItemSearchKLN = " where 1=1 ";
  422. foreach($filtersList as $fiter){
  423. if(!empty($_POST[$fiter['field']])){
  424. $key = array_search($fiter['field'], $klnOceanDb);
  425. $ockey = array_search($fiter['field'], $ocItemDb);
  426. if($key !== false){
  427. //找到给key
  428. if ($fiter['data_type'] == "string"){
  429. $klnOceanSearchKLN .= " and ".$key." = '". common::check_input($_POST[$fiter['field']])."'";
  430. } elseif ($fiter['data_type'] == "number"){
  431. $klnOceanSearchKLN .= " and ".$key." >= '". common::check_input($_POST[$fiter['field']."_from"])."'";
  432. $klnOceanSearchKLN .= " and ".$key." <= '". common::check_input($_POST[$fiter['field']."_to"])."'";
  433. } elseif ($fiter['data_type'] == "date"){
  434. $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
  435. $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
  436. $klnOceanSearchKLN .= " and ".$key." >= '". $date_from."'";
  437. $klnOceanSearchKLN .= " and ".$key." <= '". $date_to."'";
  438. }
  439. } elseif ($ockey !== false){
  440. //找到给key
  441. if ($fiter['data_type'] == "string"){
  442. $ocItemSearchKLN .= " and ".$ockey." = '". common::check_input($_POST[$fiter['field']])."'";
  443. } elseif ($fiter['data_type'] == "number"){
  444. $ocItemSearchKLN .= " and ".$ockey." >= '". common::check_input($_POST[$fiter['field']."_from"])."'";
  445. $ocItemSearchKLN .= " and ".$ockey." <= '". common::check_input($_POST[$fiter['field']."_to"])."'";
  446. } elseif ($fiter['data_type'] == "date"){
  447. $date_from = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_from"]) . ' 00:00:00');
  448. $date_to = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_to"]) . ' 23:59:59');
  449. $ocItemSearchKLN .= " and ".$ockey." >= '". $date_from."'";
  450. $ocItemSearchKLN .= " and ".$ockey." <= '". $date_to."'";
  451. }
  452. } else {
  453. if ($fiter['data_type'] == "string"){
  454. $vvSearchKLN .= " and \"".$fiter['field']."\" ilike '%". common::check_input($_POST [$fiter['field']])."%'";
  455. } elseif ($fiter['data_type'] == "number"){
  456. $vvSearchKLN .= " and \"".$fiter['field']."\" >= '". common::check_input($_POST [$fiter['field']."_from"])."'";
  457. $vvSearchKLN .= " and \"".$fiter['field']."\" <= '". common::check_input($_POST [$fiter['field']."_to"])."'";
  458. } elseif ($fiter['data_type'] == "date"){
  459. $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
  460. $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
  461. //先判断日期字符串是否为空,这里则有做 是因为sql 整合了柜子315时间,和 milestone的时间, 只能text转date
  462. $vvSearchKLN .= " and COALESCE(\"".$fiter['field']."\",''::text)<> ''::text ";
  463. $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') >= '". $date_from."'";
  464. $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') <= '". $date_to."'";
  465. }
  466. }
  467. }
  468. }
  469. return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
  470. }
  471. /**
  472. * 根据提交的参数动态的拼接sort by sql
  473. */
  474. public function returnSortBySql(){
  475. $sortByField = $_POST['sortByField'];
  476. $sortByOrder = $_POST['sortByOrder'];
  477. $sort_sql_temp = " ";
  478. if(!empty($sortByField) && !empty($sortByOrder)){
  479. $sort_sql_temp = " order by \"".$sortByField."\" ". $sortByOrder;
  480. }
  481. return $sort_sql_temp;
  482. }
  483. }
  484. ?>