report.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. $rc = $_POST ['rc'];
  36. if ($rc == - 1) {
  37. $sql = "select count(*) from public.kln_report_template";
  38. $rc = common::excuteOneSql($sql);
  39. }
  40. $tp = ceil($rc / $ps);
  41. if ($rc > 0) {
  42. $sql = "select * from public.kln_report_template";
  43. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  44. $rs = common::excuteListSql($sql);
  45. $arrTmp = array('searchData' => $rs,
  46. 'rc' => intval($rc),
  47. 'ps' => intval($ps),
  48. 'cp' => intval($cp),
  49. 'tp' => intval($tp));
  50. common::echo_json_encode(200,$arrTmp);
  51. exit();
  52. }else{
  53. $arrTmp = array('searchData' => array());
  54. common::echo_json_encode(200, $arrTmp);
  55. exit();
  56. }
  57. }
  58. if ($operate == "add"){
  59. $id = common::deCode($_REQUEST['id'], 'D');
  60. if(!empty($id)){
  61. //代表编辑
  62. $reportMain = common::excuteObjectSql("select * from kln_report_template where id = $id");
  63. $reportField = common::excuteListSql("select * from kln_report_field_config where template_id = $id order by order_index");
  64. $data = array("reportMain" => $reportMain,"reportField" =>$reportField);
  65. }else{
  66. $data = array("reportMain" =>array(),"reportField" =>array());
  67. }
  68. common::echo_json_encode(200,$data);
  69. exit();
  70. }
  71. if ($operate == "report_field_load"){
  72. $level = common::check_input($_POST['level']);
  73. $template_id = common::check_input($_POST['template_id']);
  74. $all_field = common::excuteListSql("select * from public.kln_report_field where level = '$level' order by id");
  75. $right_field = common::excuteListSql("select * from public.kln_report_field_config where template_id = '$template_id' order by id");
  76. $left_field = common::excuteListSql("select * from public.kln_report_field where level = '$level'
  77. and id != ALL(select field_ids from public.kln_report_template where id = '$template_id') order by id");
  78. }
  79. if ($operate == "save"){
  80. $template_id = common::deCode($_POST['template_id'], 'D');
  81. $name = common::check_input($_POST['name']);
  82. $description = common::check_input($_POST['description']);
  83. $level = common::check_input($_POST['level']);
  84. $access_type = common::check_input($_POST['access_type']);
  85. $party_ids = $_POST['party_ids'];
  86. $group_names = $_POST['group_names'];
  87. $sql = "";
  88. if (!empty($serial_no)){
  89. $updateSqlSet = " modify_by = '"._getLoginName()."',update_time = now()";
  90. if (!empty($name)) {
  91. $updateSqlSet.= ", name = '$name' ";
  92. }
  93. if (!empty($description)) {
  94. $updateSqlSet.= ", description = '$description' ";
  95. }
  96. if (!empty($level)) {
  97. $updateSqlSet.= ", level = '$level' ";
  98. }
  99. if (!empty($access_type)) {
  100. $updateSqlSet.= ", access_type = '$access_type' ";
  101. }
  102. if (!empty($party_ids)) {
  103. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
  104. $updateSqlSet.= ", party_ids = '{".$pgsql_array."}'::text[]";
  105. }
  106. if (!empty($group_names)) {
  107. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
  108. $updateSqlSet.= ", group_names = '{".$pgsql_array."}'::text[]";
  109. }
  110. //代表update
  111. $sql .= "update public.kln_report_config set ".$updateSqlSet."
  112. where serial_no = '$serial_no';";
  113. } else {
  114. //检查配置的站点是否于以前的配置的,是否重合
  115. }
  116. $errmsg = "";
  117. //柜子是先删除,后添加
  118. $sql .= "delete from public.kln_report_rule where recommended_delivery_serial_no = '';";
  119. if (empty($errmsg) && !empty($sql)){
  120. common::excuteUpdateSql($sql);
  121. $data = array("msg" =>"success");
  122. } else {
  123. $data = array("msg" =>$errmsg);
  124. }
  125. common::echo_json_encode(200,$data);
  126. exit();
  127. }
  128. if ($operate == "delete"){
  129. $serial_no = common::deCode($_POST['a'], 'D');
  130. $sql = "delete from public.kln_report_config where serial_no = '$serial_no';";
  131. $sql .= "delete from public.kln_report_rule where recommended_delivery_serial_no = '$serial_no';";
  132. error_log($sql);
  133. common::excuteUpdateSql($sql);
  134. $data = array("msg" =>"success");
  135. common::echo_json_encode(200,$data);
  136. exit();
  137. }
  138. }
  139. /**
  140. * shipment_status_report
  141. */
  142. public function shipment_status_report(){
  143. $operate = utils::_get('operate');
  144. $operate = strtolower($operate);
  145. if ($operate == "report_search") {
  146. //search
  147. //栏位信息
  148. $column = column::getInstance()->getDisplayColumn('report_Search');
  149. $BookingTableColumns = column::getInstance()->tableColumns('report_Search',$column);
  150. $data['TrackingTableColumns'] = $BookingTableColumns;
  151. common::echo_json_encode(200,$data);
  152. exit();
  153. }
  154. }
  155. /**
  156. * 关于report 页面的所有的静态加载数据查询
  157. */
  158. public function report_load(){
  159. $operate = utils::_get('operate');
  160. $operate = strtolower($operate);
  161. /**
  162. * select country
  163. */
  164. if ($operate == "country") {
  165. $term = $_POST['term'];
  166. $term = trim($term);
  167. $sql = "select DISTINCT category AS country_code from public.kerry_system_code
  168. where description='COUNTRY-STATION'
  169. and category ilike '" . common::check_input($term) . "%'";
  170. $sql .= " order by category";
  171. $rs = common::excuteListSql($sql);
  172. //前端要加上id 从1开始
  173. $retData = array();
  174. foreach($rs as $key => $val){
  175. if(!empty($val['country_code'])){
  176. $retData[] = array("value" =>$val['country_code'] ,"label"=>$val['country_code']);
  177. }
  178. }
  179. common::echo_json_encode(200,$retData);
  180. exit();
  181. }
  182. }
  183. }
  184. ?>