| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 | 
							- <?php
 
- namespace app\h5\controller;
 
- use EasyWeChat\Factory;
 
- use think\Controller;
 
- use think\Db;
 
- class Notify extends Controller
 
- {
 
-     public function pay(){
 
-         $config = config('app.wx_config');
 
-         $app = Factory::payment($config);
 
-         $response = $app->handlePaidNotify(function ($message, $fail) {
 
-             if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
 
-                 // 用户是否支付成功
 
-                 $tradeNo = $message['out_trade_no'];
 
-                 // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
 
-                 $order = Db::name('order_convey_pay')->where('sn',$tradeNo)->find();
 
-                 if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
 
-                     return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
 
-                 }
 
-                 $ret = Db::name('order_convey_pay')->where('id',$order['id'])->update([
 
-                     'type' => 2,
 
-                     'status' => 1,
 
-                     'pay_time' => date('Y-m-d H:i:s')
 
-                 ]);
 
-                 if(!$ret){
 
-                     trace('订单修改失败');
 
-                     $fail('订单修改失败');
 
-                 }
 
-             } else {
 
-                 return $fail('通信失败,请稍后再通知我');
 
-             }
 
-             return true; // 返回处理完成
 
-         });
 
-         $response->send();
 
-     }
 
-     public function payDinner(){
 
-         $org_id = input('org_id',0);
 
-         $config = get_pay_wechat($org_id);
 
-         $app = \EasyWeChat\Factory::payment($config);
 
-         $response = $app->handlePaidNotify(function ($message, $fail) {
 
-             if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
 
-                 // 用户是否支付成功
 
-                 $ret = false;
 
-                 $tradeNo = $message['out_trade_no'];
 
-                 $info = Db::name('dinner_order')
 
-                     ->where('sn',$tradeNo)
 
-                     ->find();
 
-                 if(!$info){
 
-                     $ret = true;
 
-                 }else{
 
-                     if($info['state'] != 0){
 
-                         $ret = true;
 
-                     }else{
 
-                         $data = array(
 
-                             'state'         => 1,
 
-                             'pay_time'         => date('Y-m-d H:i:s'),
 
-                             'update_time'=>date('Y-m-d H:i:s'),
 
-                         );
 
-                         $ret = Db::name('dinner_order')
 
-                             ->where('sn',$tradeNo)
 
-                             ->update($data);
 
-                     }
 
-                 }
 
-                 if($ret){
 
-                     return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
 
-                 }else{
 
-                     $fail('订单修改失败');
 
-                 }
 
-                 //这儿通知打印机打印
 
- //                $this->print($ordernumber);
 
-             } else {
 
-                 return $fail('通信失败,请稍后再通知我');
 
-             }
 
-             return true; // 返回处理完成
 
-         });
 
-         $response->send();
 
-     }
 
- }
 
 
  |