RunapiModel.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Api\Model;
  3. use Api\Model\BaseModel;
  4. /**
  5. *
  6. * @author star7th
  7. */
  8. class RunapiModel {
  9. Protected $autoCheckFields = false;
  10. //获取全局参数
  11. public function getGlobalParam($item_id){
  12. $item_id = intval($item_id) ;
  13. $return = array(
  14. 'query'=>array(),
  15. 'body'=>array(),
  16. 'header'=>array(),
  17. );
  18. $res = D("RunapiGlobalParam")->where(" param_type = 'query' and item_id = {$item_id} ")->find();
  19. if($res){
  20. $return['query'] = json_decode( htmlspecialchars_decode($res['content_json_str']) ,true);
  21. $return['query'] = $return['query'] ? $return['query'] : array() ;
  22. }else{
  23. D("RunapiGlobalParam")->add(array(
  24. "param_type"=>"query",
  25. "item_id"=>$item_id,
  26. "content_json_str"=>'[]',
  27. "addtime" => date("Y-m-d H:i:s") ,
  28. "last_update_time" => date("Y-m-d H:i:s") ,
  29. ));
  30. }
  31. $res = D("RunapiGlobalParam")->where(" param_type = 'body' and item_id = {$item_id} ")->find();
  32. if($res){
  33. $return['body'] = json_decode( htmlspecialchars_decode($res['content_json_str']) ,true);
  34. $return['body'] = $return['body'] ? $return['body'] : array() ;
  35. }else{
  36. D("RunapiGlobalParam")->add(array(
  37. "param_type"=>"body",
  38. "item_id"=>$item_id,
  39. "content_json_str"=>'[]',
  40. "addtime" => date("Y-m-d H:i:s") ,
  41. "last_update_time" => date("Y-m-d H:i:s") ,
  42. ));
  43. }
  44. $res = D("RunapiGlobalParam")->where(" param_type = 'header' and item_id = {$item_id} ")->find();
  45. if($res){
  46. $return['header'] = json_decode( htmlspecialchars_decode($res['content_json_str']) ,true);
  47. $return['header'] = $return['header'] ? $return['header'] : array() ;
  48. }else{
  49. D("RunapiGlobalParam")->add(array(
  50. "param_type"=>"header",
  51. "item_id"=>$item_id,
  52. "content_json_str"=>'[]',
  53. "addtime" => date("Y-m-d H:i:s") ,
  54. "last_update_time" => date("Y-m-d H:i:s") ,
  55. ));
  56. }
  57. return $return ;
  58. }
  59. }