WechatService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <?php
  2. namespace app\api\servies\wechat;
  3. use app\api\model\application\ApplicationModel;
  4. use app\api\model\doctor\DoctorModel;
  5. use app\api\model\exam\ExamModel;
  6. use app\api\model\institution\InstitutionModel;
  7. use app\api\model\message\MessageModel;
  8. use app\api\model\moneywater\MoneywaterModel;
  9. use app\api\model\order\OrderModel;
  10. use app\api\model\patientsearch\PatientsearchModel;
  11. use app\api\model\paylog\PaylogModel;
  12. use app\api\model\payprogresslog\PayprogresslogModel;
  13. use app\api\model\refundlog\RefundlogModel;
  14. use app\api\model\remote\RemoteModel;
  15. use app\api\model\report\ReportModel;
  16. use app\api\model\user\UserModel;
  17. use app\api\model\userbind\UserbindModel;
  18. use app\api\model\wechatbind\WechatbindModel;
  19. use app\api\servies\ZskkDefaultService;
  20. use app\api\utils\MsgUtils;
  21. use app\api\utils\UUIDUtils;
  22. use app\common\library\send_message;
  23. use think\Db;
  24. use think\facade\Cache;
  25. use think\facade\Config;
  26. use think\facade\Log;
  27. class WechatService extends ZskkDefaultService
  28. {
  29. private const PUSH_TYPE = [
  30. 'REMOTE_DIAGNOSIS_PATIENT_PAY' => 1,
  31. 'REMOTE_DIAGNOSIS_FINISH' => 2,
  32. 'REMOTE_DIAGNOSIS_CANCEL' => 3,
  33. 'REMOTE_DIAGNOSIS_REFUND' => 4
  34. ];
  35. private const SUCCESS = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
  36. private const BASE_URL = "/wx_patient/api/";
  37. public function pushWechatOrder($order_id)
  38. {
  39. $order = $this->getPushOrder($order_id);
  40. $orderStr = $this->getPushContent($order);
  41. $openids = $this->getPushOpenId($order['exam_id']);
  42. if (!$openids) {
  43. log::record('---------没有找到对应openid--------');
  44. return false;
  45. }
  46. foreach ($openids as $v) {
  47. $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_PATIENT_PAY'], $v['wx_openid'], $v['source'], $orderStr);
  48. // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
  49. // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
  50. // 请求
  51. log::record('---------发送微信通知-发起订单-------');
  52. log::record($url);
  53. $res = $this->curl_request($url, 'GET');
  54. log::record('---------微信通知结果--------');
  55. log::record($res);
  56. }
  57. return true;
  58. }
  59. public function pushWechatCancel($order_id)
  60. {
  61. $order = $this->getPushOrder($order_id);
  62. $orderStr = $this->getPushContent($order);
  63. $openids = $this->getPushOpenId($order['exam_id']);
  64. if (!$openids) {
  65. log::record('---------没有找到对应openid--------');
  66. return false;
  67. }
  68. foreach ($openids as $v) {
  69. $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_CANCEL'], $v['wx_openid'], $v['source'], $orderStr);
  70. // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
  71. // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
  72. // 请求
  73. log::record('---------发送微信通知-取消订单-------');
  74. log::record($url);
  75. $res = $this->curl_request($url, 'GET');
  76. log::record('---------微信通知结果--------');
  77. log::record($res);
  78. }
  79. return true;
  80. }
  81. public function pushWechatComplete($order_id)
  82. {
  83. $order = $this->getPushOrder($order_id);
  84. $orderStr = $this->getPushContent($order);
  85. $openids = $this->getPushOpenId($order['exam_id']);
  86. if (!$openids) {
  87. log::record('---------没有找到对应openid--------');
  88. return false;
  89. }
  90. foreach ($openids as $v) {
  91. $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_FINISH'], $v['wx_openid'], $v['source'], $orderStr);
  92. // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
  93. // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
  94. // 请求
  95. log::record('---------发送微信通知-完成订单-------');
  96. log::record($url);
  97. $res = $this->curl_request($url, 'GET');
  98. log::record('---------微信通知结果--------');
  99. log::record($res);
  100. }
  101. return true;
  102. }
  103. public function pushWechatRefund($order_id)
  104. {
  105. $order = $this->getPushOrder($order_id);
  106. $orderStr = $this->getPushContent($order);
  107. $openids = $this->getPushOpenId($order['exam_id']);
  108. if (!$openids) {
  109. log::record('---------没有找到对应openid--------');
  110. return false;
  111. }
  112. foreach ($openids as $v) {
  113. $url = $this->getFullUrl(self::PUSH_TYPE['REMOTE_DIAGNOSIS_REFUND'], $v['wx_openid'], $v['source'], $orderStr);
  114. // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
  115. // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
  116. // 请求
  117. log::record('---------发送微信通知-退款-------');
  118. log::record($url);
  119. $res = $this->curl_request($url, 'GET');
  120. log::record('---------微信通知结果--------');
  121. log::record($res);
  122. }
  123. return true;
  124. }
  125. private function getPushContent($order)
  126. {
  127. $content = [
  128. 'out_trade_no' => $order['order_id'],
  129. 'name' => urlencode($order['name']),
  130. 'total_fee' => $order['order_money']
  131. ];
  132. return json_encode($content);
  133. }
  134. // $url = "http://wechat.pacsonline.cn/wx_patient/api/sendMsg?pushType=".."&openid=";
  135. // $full_url = $url . $v['openid']."&source=".$v['source']."&content=".$orderStr;
  136. private function getFullUrl($pushType, $openid, $source, $content)
  137. {
  138. $wechat = Config::get('wechat_url');
  139. return $wechat.self::BASE_URL . "sendMsg?pushType=" . $pushType . "&openid=" . $openid . "&source=" . urlencode($source) . "&content=" . urlencode($content);
  140. }
  141. private function getPushOrder($order_id)
  142. {
  143. $order = OrderModel::where('id', $order_id)->field('application_id, order_money')->find();
  144. if ($order) {
  145. $application = RemoteModel::where('id', $order['application_id'])->field('odd_number,exam_id,name')->find();
  146. if ($application) {
  147. return [
  148. 'order_id' => $application['odd_number'],
  149. 'order_money' => $order['order_money'],
  150. 'exam_id' => $application['exam_id'],
  151. 'name' => $application['name']
  152. ];
  153. }
  154. }
  155. }
  156. private function getPushOpenId($exam_id)
  157. {
  158. $exam = ExamModel::alias('e')
  159. ->join('studies s', 'e.study_id = s.id')
  160. ->join('patient_infos pi', 'e.patient_id = pi.id')
  161. ->field('e.patient_id, s.accession_num, s.studyid, pi.temp_patient_id, pi.card_num, pi.phone, e.institution_id')
  162. ->where('e.id', $exam_id)
  163. ->find();
  164. if (!$exam) {
  165. log::record('---------没有对应检查--------');
  166. return false;
  167. }
  168. $institution = InstitutionModel::where('id', $exam['institution_id'])->find();
  169. if (!$institution) {
  170. log::record('---------没有对应医院--------');
  171. return false;
  172. }
  173. $wx_source = $institution['wx_source'];
  174. $options = [];
  175. $accession_num = $exam['accession_num'];
  176. $studyid = $exam['studyid'];
  177. $patient_id = $exam['patient_id'];
  178. $temp_patient_id = $exam['temp_patient_id'];
  179. $card_num = $exam['card_num'];
  180. $phone = $exam['phone'];
  181. $id1 = UserbindModel::where('patient_id', $patient_id)->field('user_id as uid')->select();
  182. $where1 = "search_criteria ='$temp_patient_id' ";
  183. if (!empty($accession_num)) {
  184. $where1 .= " or search_criteria = '$accession_num' ";
  185. }
  186. // if (!empty($studyid)) {
  187. // $where1 .= " or patientCode = '$studyid'";
  188. // }
  189. // $where2 = [];
  190. if ($card_num) {
  191. $where1 .= " or search_criteria = '$card_num' ";
  192. }
  193. $where3 = [];
  194. if ($phone) {
  195. $where1 .= " or search_criteria = '$phone' ";
  196. $where3['phone'] = $phone;
  197. }
  198. // $id2 = WechatbindModel::where($where1)
  199. // ->whereor($where2)
  200. // ->whereor($where3)
  201. // ->select();
  202. $id2 = PatientsearchModel::where($where1)
  203. ->whereOr($where3)
  204. ->where('institution_id',$exam['institution_id'])
  205. ->select();
  206. $ids = [];
  207. foreach ($id1 as $k => $v) {
  208. $ids[] = $v['uid'];
  209. }
  210. foreach ($id2 as $k => $v) {
  211. $ids[] = $v['patient_uid'];
  212. }
  213. $wherein[] = ['id', 'in', $ids];
  214. $data = UserModel::where($wherein)
  215. ->where('source', $wx_source)
  216. ->select();
  217. // log::record('---------微信推送sql--------');
  218. // log::record(UserModel::where($wherein)->where('source',$wx_source)->buildSql());
  219. // log::record($options);
  220. return $data;
  221. }
  222. private function curl_request($url, $method = 'get', $data = null, $https = true)
  223. {
  224. //1.初识化curl
  225. $ch = curl_init($url);
  226. //2.根据实际请求需求进行参数封装
  227. //返回数据不直接输出
  228. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  229. //如果是https请求
  230. if ($https === true) {
  231. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  232. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  233. }
  234. //如果是post请求
  235. if ($method === 'post') {
  236. //开启发送post请求选项
  237. curl_setopt($ch, CURLOPT_POST, true);
  238. //发送post的数据
  239. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  240. }
  241. //3.发送请求
  242. $result = curl_exec($ch);
  243. //4.返回返回值,关闭连接
  244. curl_close($ch);
  245. return $result;
  246. }
  247. public function wechatRefund($xml)
  248. {
  249. $api_key = '9759a66938e8411ad5889e2b5b394d94';
  250. Log::record('-----微信退款----开始----');
  251. Log::record('-----微信退款----xml----');
  252. Log::record($xml);
  253. Log::record('-----xml转数组--------');
  254. $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); //将微信返回的XML 转换成数组
  255. Log::record($data);
  256. $req_info = $data['req_info'];
  257. // $req_info = 'Jsb+/EIaoJhD0BVWMEiFWeRuivKbS7/bs/wpgwHowHyvVNC+Kj3aiCsLHzQobul1mKwuKT/slYfoVgUQibGH+mEFcA2N10r6Qv5v+rwd7IXvMOM7iS7p9ciDD3fn+jZukjJdGME6KajDtD2rFs0MyZTqsKUTGQN1I8Q1w5aK7OISs437bXp5s4VgrxQWKNe5s18+ts2jrMoA91VXmHy024p010BiB1TJHr46cXC4zpZkeLtECkABhVlBGmDQPfw0JknMqaTriXRZPQcz2Ff/WuRPKPImiL9i0nVpcPuiFjIP863lWLfr2Aif7plPA/mJrAZ6K95hGRvAiiHqxEet7OjYMHu50OKnY/8j2pZjtBUX8Yr1fRnY+v8INLL8+CKS1tZRY0dAkilymPVOSN/naNkVILgwDrlYq5XisDMmXz2HzF1UBX0ZWNs5ltarJC8fyhLpZm1cd/prxcTB6KUm1mTnEYhToZLUlB0N2a0dCT9pm58oj8myMC6mJutCW79QCaHCtV6JIxjueErZkbWYEVSZWG+m7hcKcmcgGhqTcnXPLte5vE0imYoABZnw4uMnv9sMSVP0PhMJ8/JeeP/He/6oAHenvhPrh/J4Xpv/vCbDjVJo8Qo5xWFFG9pk/Aj1rlZiCqmJffy+TXkXceDp+wg4lEOIbZfENaqbj7gtN9RWFTjrtPapPBZzxGJQvEQKzF2TNoP7owsTUup3grDMuw/zreVYt+vYCJ/umU8D+YnTBdx9Q0Bog3qHSlEMnQten+v2X7cSwDcIzvf3UJKVD1041tiBKfJTJFvfbiT+q4vHLKcRn5q7QyWowKrGO/ZrWTIotM0m+1IRqVDHeCTGYDUMGDiQ/+1BupV135PlUg2tKHr0wIUS0wThD3z2ZZxcJ3VioCDcFmjPu128k1xqsjfz+1Np4DxiTZFR1W44wpF/E6Hwi11A440fABYGX4AF7UFBSNfStMCTjVAhcHaYY9P5AbNiUcENjwZEBWE5bcCKm2adIsdqT5isumPoFi6M5H7hL5slQoKqLadEPfazBMHE8r+m+UYLTHlCk9L/DLPmrkVk2HJzlATcg9VYTX+IPYqqv2kY/9BYW+q+O+a8gA==';
  258. // 对加密信息进行解密,需要用到商户秘钥
  259. $req_info_xml = openssl_decrypt(base64_decode($req_info), 'aes-256-ecb', md5($api_key), OPENSSL_RAW_DATA);
  260. Log::record($req_info_xml);
  261. $refund = (array)simplexml_load_string($req_info_xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  262. $refund['timestamp'] = time();
  263. Log::record($refund);
  264. unset($data['return_code']);
  265. $info = array_merge($refund, $data);
  266. RefundlogModel::insert($info);
  267. $order_id = $refund['out_trade_no'];
  268. $order = OrderModel::where('id', $order_id)->field('status,hospital_id,application_id')->find();
  269. if (!empty($order) && $order['status'] === Config::get('ORDER_STATUS')['CANCEL']) {
  270. OrderModel::where('id', $order_id)->update(['status' => Config::get('ORDER_STATUS')['REDUCE']]);
  271. $this->pushWechatRefund($order_id);
  272. // todo 微信消息推送
  273. }
  274. if(!empty($order['hospital_id'])){
  275. //存储支出流水
  276. $exam_id = ApplicationModel::where('id', $order['application_id'])->value('exam_id');
  277. $money_water = [
  278. 'money'=>$info['refund_fee'],
  279. 'order_type'=>Config::get('order_type')['patientPay'],
  280. 'type'=>'1', //远程诊断
  281. 'exam_id'=>$exam_id,
  282. 'institution_id'=>$order['hospital_id'],
  283. 'pay_way'=>'1', //患者支付
  284. 'status'=>'2',
  285. 'pay_type'=>'2' //退款
  286. ];
  287. MoneywaterModel::insert($money_water);
  288. $pay_pregress_log = [
  289. 'id'=>UUIDUtils::uuid(),
  290. 'operator_id'=>$info['appid'],
  291. 'operator_name'=>UserModel::where('wx_openid',$info['appid'])->value('wx_nickname'),
  292. 'current_step'=>2,
  293. 'application_id'=>$order['application_id'],
  294. 'remark'=>'患者支付'
  295. ];
  296. PayprogresslogModel::insert($pay_pregress_log);
  297. }
  298. $this->pushWechatCancel($order_id);
  299. Log::record('-----微信结束----xml----');
  300. return self::SUCCESS;
  301. }
  302. public function wechatCallback($xml)
  303. {
  304. try {
  305. Log::record('-----微信支付回调----开始----');
  306. Log::record('-----微信支付返回----xml----');
  307. Log::record($xml);
  308. Log::record('-----xml转数组--------');
  309. $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); //将微信返回的XML 转换成数组
  310. Log::record($data);
  311. $out_trade_no = $data['out_trade_no'];
  312. $data['timestamp'] = time();
  313. Log::record('-----添加流水记录----');
  314. Log::record($data);
  315. PaylogModel::insert($data);
  316. Log::record('-----获取订单信息-----');
  317. $order = OrderModel::where("id", $out_trade_no)->field("id, status, super_doctor_id, application_id, hospital_id, doctor_id, exam_class, is_urgent,super_hospital_id")->find();
  318. $aid = $order['application_id'];
  319. $application = ApplicationModel::where('id', $aid)->field('exam_id,remote_doctor_id,remote_institution_id,remote_doctor_name')->find();
  320. $exam_id = $application['exam_id'];
  321. $money_water = [
  322. 'money'=>$data['cash_fee'],
  323. 'order_type'=>Config::get('order_type')['patientPay'],
  324. 'type'=>'1', //远程诊断
  325. 'exam_id'=>$exam_id,
  326. 'institution_id'=>$order['hospital_id'],
  327. 'pay_way'=>'1', //患者支付
  328. 'status'=>'2',
  329. 'pay_type'=>'1' //支入
  330. ];
  331. MoneywaterModel::insert($money_water);
  332. Log::record($order);
  333. if ($order && $order['status'] === Config::get('ORDER_STATUS')['CREATE']) {
  334. // $order['status'] = Config::get('ORDER_STATUS')['PAYCOMPLTET'];
  335. $d = $order['super_doctor_id'];
  336. // todo 消息通知
  337. Log::record('-----更新订单状态-----');
  338. $update = ['status'=>Config::get('ORDER_STATUS')['PAYCOMPLTET']];
  339. OrderModel::where("id", $out_trade_no)->update($update);
  340. $r_info = ReportModel::where('exam_id', $exam_id)->where('remote_application_id', $aid)->field('id')->find();
  341. ApplicationModel::where('id', $aid)->update(['report_status'=>'4']);
  342. $ins = InstitutionModel::where('id', $order['hospital_id'])->field('name,handling_time')->find();
  343. if($ins['handling_time'] == '0')
  344. {
  345. $ins['handling_time'] = 7200;
  346. }
  347. $date = date('Y-m-d H:i:s',(time()+$ins['handling_time']));
  348. $dinfo = DoctorModel::where('id', $d)->find();
  349. $d_name = $dinfo['realname'];
  350. $d_phone = $dinfo['phone'];
  351. $pay_pregress_log = [
  352. 'id'=>UUIDUtils::uuid(),
  353. 'operator_id'=>$data['appid'],
  354. 'operator_name'=>UserModel::where('wx_openid',$data['appid'])->value('wx_nickname'),
  355. 'current_step'=>2,
  356. 'application_id'=>$aid,
  357. 'remark'=>'患者支付'
  358. ];
  359. PayprogresslogModel::insert($pay_pregress_log);
  360. $t = '收到一条远程诊断申请';
  361. $doctor = DoctorModel::where('id', $order['doctor_id'])->field('realname')->find();
  362. $c = $ins['name'] . $doctor['realname'] . '医师向您发起一条远程诊断申请';
  363. $type = '1';
  364. $url = $this->url(null, $exam_id, 1, $order['exam_class'], $r_info['id'], $aid);
  365. Log::record('-----系统内消息通知-----');
  366. $this->MessageInsert($t, $c, $d, $type, $url, $exam_id,1, $aid);
  367. //保存 申请
  368. if (empty($d)) {
  369. Log::record('---微信支付回调---结束---没有远程医生');
  370. return self::SUCCESS;
  371. }
  372. if ($order['is_urgent'] === 1) {
  373. $d_time = date('H:i', strtotime('+30 min'));
  374. } else {
  375. $d_time = date('H:i', strtotime('+1 hour'));
  376. }
  377. if ($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1) { //魏庙
  378. Log::record('-----短信通知-----');
  379. send_message::sendSms2Apply($d_phone, $d_time, $d_name);
  380. }
  381. }
  382. Log::record('---微信支付回调---结束---');
  383. return self::SUCCESS;
  384. } catch (\Throwable $th) {
  385. Log::record('支付回调异常');
  386. Log::record($th->getMessage());
  387. //throw $th;
  388. }
  389. }
  390. public function url($sessionid,$id,$is_remote,$exam_class,$report_id='',$rid=''){
  391. $url = '/remotereport/edit/6?id='.$id.'&is_remote='.$is_remote.'&exam_class='.$exam_class.'&report_id='.$report_id.'&rid='.$rid;
  392. return $url;
  393. }
  394. public function MessageInsert($title,$content,$did,$type,$url,$exam_id,$count =1,$aid = ''){
  395. Cache::rm('messages_'.$did);
  396. try{
  397. $info['id'] = UUIDUtils::uuid();
  398. $info['title'] = $title;
  399. $info['content'] = $content;
  400. $info['doctor_id'] = $did;
  401. $info['type'] = $type;
  402. $info['ctime'] = date('Y-m-d H:i:s',time());
  403. $info['is_read'] = 0;
  404. $info['status'] = 0;
  405. $info['url'] = $url;
  406. $info['count'] = $count;
  407. $info['application_id'] = $aid;
  408. $info['exam_id'] = $exam_id;
  409. MessageModel::insert($info);
  410. }catch(\Exception $e){
  411. Log::record($e->getMessage());
  412. }
  413. }
  414. public function wechatStudyPayCallback($xml)
  415. {
  416. try {
  417. // $param = $_REQUEST['param'];
  418. Log::record('---电子胶片--微信支付回调----开始----');
  419. Log::record('---电子胶片--微信支付返回----xml----');
  420. Log::record($xml);
  421. Log::record('-----xml转数组--------');
  422. $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); //将微信返回的XML 转换成数组
  423. Log::record($data);
  424. $out_trade_no = $data['out_trade_no'];
  425. $data['timestamp'] = time();
  426. Log::record('---电子胶片--添加流水记录----');
  427. Log::record($data);
  428. PaylogModel::insert($data);
  429. Log::record('-----获取订单信息-----');
  430. $order = ExamModel::where("id", $out_trade_no)->field("id,phone,exam_class,exam_datetime,study_id, name,pay_status,institution_id")->find();
  431. Log::record($order);
  432. if ($order && $order['pay_status'] === '0') {
  433. $order = json_decode(json_encode($order,true),true);
  434. $order['pay_status'] = '1';
  435. // todo 消息通知
  436. Log::record('-----更新检查状态-----');
  437. ExamModel::where("id", $out_trade_no)->update($order);
  438. }
  439. $money_water = [
  440. 'money'=>$data['cash_fee'],
  441. 'order_type'=>Config::get('order_type')['patientPay'],
  442. 'type'=>'2', //电子胶片
  443. 'exam_id'=>$out_trade_no,
  444. 'institution_id'=>$order['institution_id'],
  445. 'pay_way'=>'1', //患者支付
  446. 'status'=>'2',
  447. 'pay_type'=>'1' //支入
  448. ];
  449. $wa = MoneywaterModel::insert($money_water);
  450. Log::record('--支付流水存储---'.$wa.'----');
  451. ExamModel::where("id", $out_trade_no)->update(['pay_status'=>1]);
  452. if(!empty($order['id'])){
  453. $ids = PatientsearchModel::where('exam_id',$order['id'])->distinct(true)->column('patient_uid');
  454. $pushType = 5;
  455. $cont = [
  456. 'name'=>$order['name'],
  457. 'modality'=>$order['exam_class'],
  458. 'examDate'=>$order['exam_datetime'],
  459. 'study_id'=>$order['study_id']
  460. ];
  461. $content = json_encode($cont,true);
  462. $openids = UserModel::where('id','in',$ids)->column('wx_openid');;
  463. foreach ($openids as $k=>$v){
  464. $this->new_wechat_push($v,$pushType,$content);
  465. }
  466. }
  467. Log::record('--电子胶片---微信支付回调---结束---');
  468. return self::SUCCESS;
  469. } catch (\Throwable $th) {
  470. Log::record('支付回调异常');
  471. Log::record($th->getMessage());
  472. //throw $th;
  473. }
  474. }
  475. }