123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\inter\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use app\common\library\UUIDs;
- use think\Cache;
- use think\Log;
- use app\common\library\Verify;
- use think\File;
- use app\common\library\send_message;
- use app\common\library\Message;
- class Wechat extends Base {
- public function _initialize() {
- }
- public function wechatCallback() {
- // $param = $_REQUEST['param'];
- Log::record('-----微信支付回调----开始----');
- Log::record('-----微信支付返回----xml----');
- $xml = file_get_contents("php://input");
- Log::record($xml);
- Log::record('-----xml转数组--------');
- $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); //将微信返回的XML 转换成数组
- Log::record($data);
- $out_trade_no = $data['out_trade_no'];
- $data['timestamp'] = time();
- Log::record('-----添加流水记录----');
- Log::record($data);
- Db::table("wechat_pay_log")->insert($data);
- Log::record('-----获取订单信息-----');
- $order = Db::table("remote_order")->where("id", $out_trade_no)->field("id, status")->find();
- Log::record($order);
- if($order && $order['status'] === 1) {
- $order['status'] = 2;
- $d = $order['super_doctor_id'];
- $aid = $order['application_id'];
- // todo 消息通知
- Log::record('-----更新订单状态-----');
- Db::table("remote_order")->where("id", $out_trade_no)->update($order);
- $r_info = DB::table('report')->where('exam_id',$order['exam_id'])->where('remote_application_id', $aid)->find();
- $t = '收到一条远程诊断申请';
- $ins = DB::table('institution')->where('id',$order['hospital_id'])->field('name')->find();
- $doctor = DB::table('doctor')->where('id',$order['doctor_id'])->field('realname')->find();
- $c = $ins['name'].$doctor['realname'].'医师向您发起一条远程诊断申请';
- $type = '1';
- $url = Message::url(null, $order['exam_id'],1,$order['exam_class'],$r_info['id'],$aid);
- Log::record('-----系统内消息通知-----');
- Message::insert($t,$c,$d,$type,$url,1,$aid);
- //保存 申请
- if(empty($d)) {
- Log::record('---微信支付回调---结束---没有远程医生');
- return;
- }
- $dinfo = DB::table('doctors')->where('id',$d)->find();
- $d_phone = $dinfo['phone'];
- $d_name = $dinfo['realname'];
- if($order['is_urgent'] === 1) {
- $d_time = date('H:i',strtotime('+30 min'));
- } else {
- $d_time = date('H:i',strtotime('+1 hour'));
- }
- if($dinfo['institution_id'] == '22100003' || $dinfo['send_sms'] == 1){ //魏庙
- Log::record('-----短信通知-----');
- $repsone = send_message::sendSms2Apply($d_phone,$d_time,$d_name);
- }
- }
- Log::record('---微信支付回调---结束---');
- // $order_id = $param['order_id'];
- // $remote_order = DB::table('remote_order')->where('id', $order_id)->find();
- // if(!$remote_order) {
- // return json_encode(['status'=>'fail','code'=>'3001','msg'=> "没有找到该订单"]);
- // }
- // if($remote_order !== Application::ORDER_STATUS['CREATE']) {
- // return json_encode(['status'=>'fail','code'=>'3002','msg'=> "订单状态出错"]);
- // }
- // DB::table('remote_order')->where('id', $order_id)->update(["status" => Application::ORDER_STATUS['PAYCOMPLTET']]);
- // return json_encode(['status'=>'ok','code'=>'0000','msg'=> "支付回调成功"]);
- }
- }
|