Wechat.php 4.3 KB

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