Wechat.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\inter\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use app\common\library\UUIDs;
  7. use think\Cache;
  8. use think\Log;
  9. use app\common\library\Verify;
  10. use think\File;
  11. use app\common\library\send_message;
  12. use app\common\library\Message;
  13. class Wechat extends Base {
  14. public function _initialize() {
  15. }
  16. public function wechatCallback() {
  17. // $param = $_REQUEST['param'];
  18. Log::record('-----微信支付回调----开始----');
  19. Log::record('-----微信支付返回----xml----');
  20. $xml = file_get_contents("php://input");
  21. Log::record($xml);
  22. Log::record('-----xml转数组--------');
  23. $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); //将微信返回的XML 转换成数组
  24. Log::record($data);
  25. $out_trade_no = $data['out_trade_no'];
  26. $data['timestamp'] = time();
  27. Log::record('-----添加流水记录----');
  28. Log::record($data);
  29. Db::table("wechat_pay_log")->insert($data);
  30. Log::record('-----获取订单信息-----');
  31. $order = Db::table("remote_order")->where("id", $out_trade_no)->field("id, status")->find();
  32. Log::record($order);
  33. if($order && $order['status'] === 1) {
  34. $order['status'] = 2;
  35. $d = $order['super_doctor_id'];
  36. $aid = $order['application_id'];
  37. // todo 消息通知
  38. Log::record('-----更新订单状态-----');
  39. Db::table("remote_order")->where("id", $out_trade_no)->update($order);
  40. $r_info = DB::table('report')->where('exam_id',$order['exam_id'])->where('remote_application_id', $aid)->find();
  41. $t = '收到一条远程诊断申请';
  42. $ins = DB::table('institution')->where('id',$order['hospital_id'])->field('name')->find();
  43. $doctor = DB::table('doctor')->where('id',$order['doctor_id'])->field('realname')->find();
  44. $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';
  45. $type = '1';
  46. $url = Message::url(null, $order['exam_id'],1,$order['exam_class'],$r_info['id'],$aid);
  47. Log::record('-----系统内消息通知-----');
  48. Message::insert($t,$c,$d,$type,$url,1,$aid);
  49. //保存 申请
  50. if(empty($d)) {
  51. Log::record('---微信支付回调---结束---没有远程医生');
  52. return;
  53. }
  54. $dinfo = DB::table('doctors')->where('id',$d)->find();
  55. $d_phone = $dinfo['phone'];
  56. $d_name = $dinfo['realname'];
  57. if($order['is_urgent'] === 1) {
  58. $d_time = date('H:i',strtotime('+30 min'));
  59. } else {
  60. $d_time = date('H:i',strtotime('+1 hour'));
  61. }
  62. if($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1){ //魏庙
  63. Log::record('-----短信通知-----');
  64. $repsone = send_message::sendSms2Apply($d_phone,$d_time,$d_name);
  65. }
  66. }
  67. Log::record('---微信支付回调---结束---');
  68. // $order_id = $param['order_id'];
  69. // $remote_order = DB::table('remote_order')->where('id', $order_id)->find();
  70. // if(!$remote_order) {
  71. // return json_encode(['status'=>'fail','code'=>'3001','msg'=> "没有找到该订单"]);
  72. // }
  73. // if($remote_order !== Application::ORDER_STATUS['CREATE']) {
  74. // return json_encode(['status'=>'fail','code'=>'3002','msg'=> "订单状态出错"]);
  75. // }
  76. // DB::table('remote_order')->where('id', $order_id)->update(["status" => Application::ORDER_STATUS['PAYCOMPLTET']]);
  77. // return json_encode(['status'=>'ok','code'=>'0000','msg'=> "支付回调成功"]);
  78. }
  79. }