WechatService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\inter\service;
  3. use think\Db;
  4. class WechatService {
  5. public function pushWechatOrder($exam_id) {
  6. var_dump($exam_id);
  7. $openids = $this->getPushOpenId($exam_id);
  8. var_dump($openids);
  9. if(!$openids) {
  10. log::record('---------没有找到对应openid--------');
  11. return false;
  12. }
  13. foreach($openids as $v) {
  14. $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=";
  15. $full_url = $url . $v['openid'];
  16. // 请求
  17. $res = $this->curl_request($full_url, 'GET');
  18. }
  19. return true;
  20. // http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=
  21. }
  22. public function pushWechatCancel() {
  23. }
  24. public function pushWechatComplete() {
  25. }
  26. private function getPushOpenId($exam_id) {
  27. $exams = DB::table("exams")
  28. ->alias('e')
  29. ->join('studies s', 'e.study_id = s.id')
  30. ->join('patient_infos pi', 'e.patient_id = pi.id')
  31. ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone')
  32. ->where('e.id', $exam_id)
  33. ->find();
  34. if(!$exams) {
  35. return false;
  36. }
  37. $options = [];
  38. $accession_num = $exams['accession_num'];
  39. $studyid = $exams['studyid'];
  40. $patient_id = $exams['patient_id'];
  41. $temp_patient_id = $exams['temp_patient_id'];
  42. $card_num = $exams['card_num'];
  43. $phone = $exams['phone'];
  44. $sql1 = "select user_id as uid from user_bind where patient_id = ?";
  45. $options[] = $patient_id;
  46. $sql2 = "select uid from wechat_bind where ";
  47. $sql2 .= "(patientCode = ?";
  48. $options[] = $temp_patient_id;
  49. if(!empty($accession_num)) {
  50. $sql2 .= " or patientCode = ?";
  51. $options[] = $accession_num;
  52. }
  53. if(!empty($studyid)) {
  54. $sql2 .= " or patientCode = ?";
  55. $options[] = $studyid;
  56. }
  57. $sql2 .=")";
  58. if($card_num) {
  59. $sql2 .= " or idcard = ?";
  60. $options[] = $card_num;
  61. }
  62. if($card_num) {
  63. $sql2 .= " or phone = ?";
  64. $options[] = $phone;
  65. }
  66. $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")";
  67. log::record('---------微信推送sql--------');
  68. log::record($sql);
  69. return Db::query($sql, $options);
  70. }
  71. }