WechatService.php 24 KB

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