WechatService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=1&openid=
  18. }
  19. public function pushWechatCancel() {
  20. }
  21. public function pushWechatComplete() {
  22. }
  23. private function getPushOpenId($exam_id) {
  24. $exams = DB::table("exams")
  25. ->alias('e')
  26. ->join('studies s', 'e.study_id = s.id')
  27. ->join('patient_infos pi', 'e.patient_id = pi.id')
  28. ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone')
  29. ->where('e.id', $exam_id)
  30. ->find();
  31. if(!$exams) {
  32. return false;
  33. }
  34. $options = [];
  35. $accession_num = $exams['accession_num'];
  36. $studyid = $exams['studyid'];
  37. $patient_id = $exams['patient_id'];
  38. $temp_patient_id = $exams['temp_patient_id'];
  39. $card_num = $exams['card_num'];
  40. $phone = $exams['phone'];
  41. $sql1 = "select user_id as uid from user_bind where patient_id = ?";
  42. $options[] = $patient_id;
  43. $sql2 = "select uid from wechat_bind where ";
  44. $sql2 .= "(patientCode = ?";
  45. $options[] = $temp_patient_id;
  46. if(!empty($accession_num)) {
  47. $sql2 .= " or patientCode = ?";
  48. $options[] = $accession_num;
  49. }
  50. if(!empty($studyid)) {
  51. $sql2 .= " or patientCode = ?";
  52. $options[] = $studyid;
  53. }
  54. $sql2 .=")";
  55. if($card_num) {
  56. $sql2 .= " or idcard = ?";
  57. $options[] = $card_num;
  58. }
  59. if($card_num) {
  60. $sql2 .= " or phone = ?";
  61. $options[] = $phone;
  62. }
  63. $sql = "select wx_openid as openid from user where id in (".$sql1." union ".$sql2.")";
  64. log::record('---------微信推送sql--------');
  65. log::record($sql);
  66. return Db::query($sql, $options);
  67. }
  68. }