Wechat.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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, 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. $application = DB::table('remote_application')->where('id', $order['application_id'])->field('exam_id')->find();
  51. $exam_id = $application['exam_id'];
  52. $r_info = DB::table('report')->where('exam_id',$exam_id)->where('remote_application_id', $aid)->find();
  53. $t = '收到一条远程诊断申请';
  54. $ins = DB::table('institution')->where('id',$order['hospital_id'])->field('name')->find();
  55. $doctor = DB::table('doctor')->where('id',$order['doctor_id'])->field('realname')->find();
  56. $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';
  57. $type = '1';
  58. $url = Message::url(null, $exam_id,1,$order['exam_class'],$r_info['id'],$aid);
  59. Log::record('-----系统内消息通知-----');
  60. Message::insert($t,$c,$d,$type,$url,1,$aid);
  61. //保存 申请
  62. if(empty($d)) {
  63. Log::record('---微信支付回调---结束---没有远程医生');
  64. return;
  65. }
  66. $dinfo = DB::table('doctors')->where('id',$d)->find();
  67. $d_phone = $dinfo['phone'];
  68. $d_name = $dinfo['realname'];
  69. if($order['is_urgent'] === 1) {
  70. $d_time = date('H:i',strtotime('+30 min'));
  71. } else {
  72. $d_time = date('H:i',strtotime('+1 hour'));
  73. }
  74. if($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1){ //魏庙
  75. Log::record('-----短信通知-----');
  76. $repsone = send_message::sendSms2Apply($d_phone,$d_time,$d_name);
  77. }
  78. }
  79. Log::record('---微信支付回调---结束---');
  80. // $order_id = $param['order_id'];
  81. // $remote_order = DB::table('remote_order')->where('id', $order_id)->find();
  82. // if(!$remote_order) {
  83. // return json_encode(['status'=>'fail','code'=>'3001','msg'=> "没有找到该订单"]);
  84. // }
  85. // if($remote_order !== Application::ORDER_STATUS['CREATE']) {
  86. // return json_encode(['status'=>'fail','code'=>'3002','msg'=> "订单状态出错"]);
  87. // }
  88. // DB::table('remote_order')->where('id', $order_id)->update(["status" => Application::ORDER_STATUS['PAYCOMPLTET']]);
  89. // return json_encode(['status'=>'ok','code'=>'0000','msg'=> "支付回调成功"]);
  90. }
  91. }