report.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 = common::deCode($_REQUEST['serial_no'], 'D');
  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 field_id,field_level,field_type,field_db,field_display_name,
  84. field_display_name_user,data_type,custom_value_type,
  85. custom_fixed_value,is_filter_enabled,is_sort_enabled
  86. from kln_report_field_config where template_serial_no = '$serial_no' order by order_index");
  87. foreach($reportField as $_reportField){
  88. $_reportField['is_filter_enabled'] = $_reportField['is_filter_enabled'] == 't' ? true : false;
  89. $_reportField['is_sort_enabled'] = $_reportField['is_sort_enabled'] == 't' ? true : false;
  90. $reportFields[] = $_reportField;
  91. }
  92. $reportAccess = array("type"=>$reportMain['access_type'],
  93. "partyId"=>json_decode($reportMain['party_ids_json'],true),
  94. "groupName"=>json_decode($reportMain['group_names_json'],true));
  95. $data = array("reportName"=>$reportMain['name'],"reportLevel"=>$reportMain['level'],"reportDescription"=>$reportMain['description'],
  96. "reportFields"=>$reportFields,"reportAccess"=>$reportAccess);
  97. }else{
  98. $data = array();
  99. }
  100. common::echo_json_encode(200,$data);
  101. exit();
  102. }
  103. if ($operate == "report_field_load"){
  104. column::getInstance()->settingDisplayForVIPReport();
  105. }
  106. if ($operate == "save"){
  107. $serial_no = common::deCode($_POST['serial_no'], 'D');
  108. $name = common::check_input($_POST['report_name']);
  109. $description = common::check_input($_POST['report_description']);
  110. $level = common::check_input($_POST['report_level']);
  111. $access_type = common::check_input($_POST['access_type']);
  112. $party_ids = $_POST['party_ids'];
  113. $group_names = $_POST['group_names'];
  114. //字段配置信息
  115. $field_ids = $_POST['field_id'];
  116. $field_level = $_POST['field_level'];
  117. $field_type = $_POST['field_type'];
  118. $field_db = $_POST['field_db'];
  119. $field_code = $_POST['field_code'];
  120. $display_name = $_POST['display_name'];
  121. $data_type = $_POST['data_type'];
  122. $value_type = $_POST['value_type'];
  123. $fixed_value = $_POST['fixed_value'];
  124. $is_filter_enabled = $_POST['is_filter_enabled'];
  125. $is_sort_enabled = $_POST['is_sort_enabled'];
  126. $report_sql = common::excuteOneSql("select sql from public.kln_report_sql_manage where level = '$level'");
  127. $sql = "";
  128. if (!empty($serial_no)){
  129. $updateSqlSet = " report_sql = '$report_sql', modify_by = '"._getLoginName()."',update_time = now()";
  130. if (!empty($name)) {
  131. $updateSqlSet.= ", name = '$name' ";
  132. }
  133. if (!empty($description)) {
  134. $updateSqlSet.= ", description = '$description' ";
  135. }
  136. if (!empty($level)) {
  137. $updateSqlSet.= ", level = '$level' ";
  138. }
  139. if (!empty($access_type)) {
  140. $updateSqlSet.= ", access_type = '$access_type' ";
  141. }
  142. if (!empty($party_ids)) {
  143. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
  144. $updateSqlSet.= ", party_ids = '{".$pgsql_array."}'::text[]";
  145. }
  146. if (!empty($group_names)) {
  147. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
  148. $updateSqlSet.= ", group_names = '{".$pgsql_array."}'::text[]";
  149. }
  150. if (!empty($field_ids)) {
  151. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
  152. $updateSqlSet.= ", field_ids = '{".$pgsql_array."}'::INTEGER[]";
  153. }
  154. //代表update
  155. $sql .= "update public.kln_report_template set ".$updateSqlSet."
  156. where serial_no = '$serial_no';";
  157. } else {
  158. $party_ids_filed = null;
  159. if (!empty($party_ids)) {
  160. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
  161. $party_ids_filed= "'{".$pgsql_array."}'::text[]";
  162. }
  163. $group_names_filed = null;
  164. if (!empty($group_names)) {
  165. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
  166. $group_names_filed = "'{".$pgsql_array."}'::text[]";
  167. }
  168. $ids_filed = null;
  169. if (!empty($field_ids)) {
  170. $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
  171. $ids_filed = "'{".$pgsql_array."}'::INTEGER[]";
  172. }
  173. $serial_no = common::uuid();
  174. $sql .= "INSERT INTO public.kln_report_template(
  175. serial_no,name, description, level, field_ids, access_type, report_sql,
  176. party_ids, group_names, create_by, created_time, modify_by, update_time )
  177. VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type', '$report_sql'
  178. $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
  179. }
  180. $errmsg = "";
  181. //柜子是先删除,后添加
  182. $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  183. foreach($field_ids as $key =>$_field_id){
  184. $_field_level = $field_level[$key];
  185. $_ield_type = $field_type[$key];
  186. $_field_db = $field_db[$key];
  187. $_field_code = $field_code[$key];
  188. $_display_name = $display_name[$key];
  189. $_data_type = $data_type[$key];
  190. $_value_type = $value_type[$key];
  191. $_fixed_value = $fixed_value[$key];
  192. $_is_filter_enabled = $is_filter_enabled[$key];
  193. $_is_sort_enabled = $is_sort_enabled[$key];
  194. $sql .= "INSERT INTO public.kln_report_field_config(
  195. template_serial_no, field_id, field_level, field_type, field_db,
  196. field_display_name, field_display_name_user, data_type, custom_value_type,
  197. custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
  198. VALUES ('$serial_no', '$_field_id', '$_field_level', '$_ield_type', '$_field_db',
  199. '$_field_code', '$_display_name', '$_data_type', '$_value_type',
  200. '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
  201. }
  202. if (empty($errmsg) && !empty($sql)){
  203. common::excuteUpdateSql($sql);
  204. $data = array("msg" =>"success");
  205. } else {
  206. $data = array("msg" =>$errmsg);
  207. }
  208. common::echo_json_encode(200,$data);
  209. exit();
  210. }
  211. if ($operate == "delete"){
  212. $serial_no = common::deCode($_POST['a'], 'D');
  213. $sql = "delete from public.kln_report_template where serial_no = '$serial_no';";
  214. $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
  215. common::excuteUpdateSql($sql);
  216. $data = array("msg" =>"success");
  217. common::echo_json_encode(200,$data);
  218. exit();
  219. }
  220. }
  221. /**
  222. * shipment_status_report
  223. */
  224. public function shipment_status_report(){
  225. $operate = utils::_get('operate');
  226. $operate = strtolower($operate);
  227. if ($operate == "report_search") {
  228. $cp = common::check_input($_POST ['cp']); //current_page
  229. $ps = common::check_input($_POST ['ps']); //ps
  230. if (empty($ps))
  231. $ps = 100;
  232. if (empty($cp))
  233. $cp = 1;
  234. $sqlWhere = "1=1 and is_active = true";
  235. $text_search = $_POST['text_search'];
  236. if (!empty($text_search)){
  237. $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
  238. }
  239. $rc = $_POST ['rc'];
  240. if ($rc == - 1) {
  241. $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
  242. $rc = common::excuteOneSql($sql);
  243. }
  244. $tp = ceil($rc / $ps);
  245. if ($rc > 0) {
  246. $sql = "select name,description from public.kln_report_template where " .$sqlWhere;
  247. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  248. $rs = common::excuteListSql($sql);
  249. $arrTmp = array('searchData' => $rs,
  250. 'rc' => intval($rc),
  251. 'ps' => intval($ps),
  252. 'cp' => intval($cp),
  253. 'tp' => intval($tp));
  254. common::echo_json_encode(200,$arrTmp);
  255. exit();
  256. }else{
  257. $arrTmp = array('searchData' => array());
  258. common::echo_json_encode(200, $arrTmp);
  259. exit();
  260. }
  261. }
  262. if ($operate == "report_detail") {
  263. $serial_no = common::check_input($_POST ['serial_no']);
  264. common::excuteListSql("select * from kln_report_field_config where template_serial_no = '".$serial_no."' and field_type = 'System' order by id ");
  265. //第一次进来,把查询放到一起了
  266. $cp = 10;
  267. $ps = 1;
  268. $rc = $_POST ['rc'];
  269. if ($rc == - 1) {
  270. $sql = "select count(*) from public.kln_report_template where " ;
  271. $rc = common::excuteOneSql($sql);
  272. }
  273. $tp = ceil($rc / $ps);
  274. if ($rc > 0) {
  275. $sql = "select name,description from public.kln_report_template where " ;
  276. $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  277. $rs = common::excuteListSql($sql);
  278. $arrTmp = array('searchData' => $rs,
  279. 'rc' => intval($rc),
  280. 'ps' => intval($ps),
  281. 'cp' => intval($cp),
  282. 'tp' => intval($tp));
  283. common::echo_json_encode(200,$arrTmp);
  284. exit();
  285. }else{
  286. $arrTmp = array('searchData' => array());
  287. common::echo_json_encode(200, $arrTmp);
  288. exit();
  289. }
  290. }
  291. }
  292. }
  293. ?>