WechatService.php 2.1 KB

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