Operating.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\inter\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use app\common\library\UUIDs;
  6. use think\Session;
  7. use app\common\library\ResultTools;
  8. use think\Log;
  9. use think\Cache;
  10. class Operating extends Controller
  11. {
  12. public function index(){
  13. }
  14. /**
  15. * 医生运营统计
  16. *
  17. * @ApiTitle (医生运营统计)
  18. * @ApiSummary (医生运营统计)
  19. * @ApiSector (远程诊断)
  20. * @ApiMethod (POST)
  21. * @ApiRoute (/inter/operating/doctor)
  22. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  23. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  24. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  25. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  26. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  27. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  28. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  29. * @ApiReturnParams (name="msg", type="object", sample="{}", description="返回消息")
  30. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  31. * @ApiReturn (data="
  32. {
  33. 'status': ok,
  34. 'code': '0000',
  35. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  36. 'msg': '请求成功',
  37. 'info' : ''
  38. }
  39. *")
  40. **/
  41. public function doctor(){
  42. try{
  43. $sessionid = $_REQUEST['sessionid'];
  44. log::record('-------运营------------');
  45. log::record($sessionid);
  46. $doctor = Cache::get($sessionid);
  47. log::record($doctor);
  48. log::record('-------------------');
  49. $operate = DB::table('operating')->where('type',1)->where('role_id',$doctor['id'])->field('nums,month,exam_num,remote_num,danger_num')->order('month asc')->limit(6)->select();
  50. if($operate){
  51. return json_encode(['code'=>'0000','status'=>'ok','msg'=>'请求成功','info'=>$operate,'sessionid'=>$sessionid]);
  52. }else{
  53. return json_encode(['code'=>'0000','status'=>'ok','msg'=>'请求成功','info'=>$operate,'sessionid'=>$sessionid]);
  54. }
  55. }catch(\Exception $e){
  56. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  57. }
  58. }
  59. public function getOperating(){
  60. $sessionid = $_REQUEST['sessionid'];
  61. $doctor = Cache::get($sessionid);
  62. $time = $_REQUEST['searchtime'];
  63. if($time){
  64. // where('id','between',[1,8]);
  65. }
  66. }
  67. public function saveYykExam()
  68. {
  69. $startTime = strtotime(date('Y-m-d H:00:00',strtotime('-150 day')));
  70. $finishTime = strtotime(date('Y-m-d H:59:59',strtotime('-1 day')));
  71. $key = 'YgpxjVeIx0yoK6Atz413IAj7hU9dygH4';
  72. $data = ['start_time'=>$startTime,'end_time'=>$finishTime];
  73. $sign = $this->getSign($key,$data);
  74. $url = 'https://pacs.yunyikang.cn/pacs/zskk/getPayList';
  75. $info = json_encode(['timestamp'=>time(),'signature'=>$sign,'data'=>json_encode($data,true)]);
  76. $return = $this->curlHttpsJsonPost($url,$info);
  77. $handleInfo = json_decode($return,true);
  78. $handleInfo['code'] = 0;
  79. if($handleInfo['code'] == 0)
  80. {
  81. $insert_handle = $handleInfo['data'];
  82. $history = DB::table('yyk')->column('exam_id');
  83. $insert = [];
  84. foreach ($insert_handle as $k=>$v)
  85. {
  86. if(in_array($v['exam_id'],$history))
  87. {
  88. continue;
  89. }
  90. $insert[$k] = $v;
  91. $insert[$k]['start_time'] = $startTime;
  92. $insert[$k]['end_time'] = $finishTime;
  93. }
  94. if(!empty($insert)){
  95. DB::table('yyk')->insertAll($insert);
  96. }
  97. return json_encode(['code'=>'0000','status'=>'ok','msg'=>'请求成功']);
  98. }else{
  99. return $return;
  100. }
  101. }
  102. public function curlHttpsJsonPost($url,$data)
  103. {
  104. $curl = curl_init(); // 启动一个CURL会话
  105. curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
  106. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
  107. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
  108. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
  109. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
  110. curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
  111. curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
  112. curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
  113. curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
  114. curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
  115. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
  116. curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  117. 'Content-Type: application/json; charset=utf-8',
  118. )
  119. );
  120. $tmpInfo = curl_exec($curl); // 执行操作
  121. curl_close($curl); // 关闭CURL会话
  122. return $tmpInfo; // 返回数据
  123. }
  124. public function getSign($secret, $data) {
  125. // 对数组的值按key排序
  126. ksort($data);
  127. // 生成url的形式
  128. $params = http_build_query($data);
  129. // 生成sign
  130. $sign = md5($params . $secret);
  131. return $sign;
  132. }
  133. }