Notify.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\api\controller\h5;
  3. use app\hander\HelpHander;
  4. use EasyWeChat\Factory;
  5. use think\Controller;
  6. use think\Db;
  7. use think\Exception;
  8. class Notify extends Controller
  9. {
  10. public function phorder(){
  11. $config = config('app.wx_config');
  12. $app = Factory::payment($config);
  13. $response = $app->handlePaidNotify(function ($message, $fail) {
  14. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  15. // 用户是否支付成功
  16. $tradeNo = $message['out_trade_no'];
  17. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  18. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  19. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  20. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  21. }
  22. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  23. if(!$ret){
  24. trace('订单修改失败');
  25. $fail('订单修改失败');
  26. }
  27. } else {
  28. return $fail('通信失败,请稍后再通知我');
  29. }
  30. return true; // 返回处理完成
  31. });
  32. $response->send();
  33. }
  34. //萍乡市人民医院
  35. public function phOrderPx(){
  36. $config = config('app.wx_config_px');
  37. $app = Factory::payment($config);
  38. $response = $app->handlePaidNotify(function ($message, $fail) {
  39. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  40. // 用户是否支付成功
  41. $tradeNo = $message['out_trade_no'];
  42. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  43. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  44. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  45. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  46. }
  47. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  48. if(!$ret){
  49. trace('订单修改失败');
  50. $fail('订单修改失败');
  51. }
  52. } else {
  53. return $fail('通信失败,请稍后再通知我');
  54. }
  55. return true; // 返回处理完成
  56. });
  57. $response->send();
  58. }
  59. public function phorder2(){
  60. $config = config('app.wx_mini_config_ph');
  61. $app = Factory::payment($config);
  62. $response = $app->handlePaidNotify(function ($message, $fail) {
  63. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  64. // 用户是否支付成功
  65. $tradeNo = $message['out_trade_no'];
  66. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  67. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  68. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  69. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  70. }
  71. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  72. if(!$ret){
  73. trace('订单修改失败');
  74. $fail('订单修改失败');
  75. }
  76. } else {
  77. return $fail('通信失败,请稍后再通知我');
  78. }
  79. return true; // 返回处理完成
  80. });
  81. $response->send();
  82. }
  83. //萍乡市人民医院
  84. public function phOrderPx2(){
  85. $config = config('app.wx_mini_config_ph_px');
  86. $app = Factory::payment($config);
  87. $response = $app->handlePaidNotify(function ($message, $fail) {
  88. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  89. // 用户是否支付成功
  90. $tradeNo = $message['out_trade_no'];
  91. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  92. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  93. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  94. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  95. }
  96. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  97. if(!$ret){
  98. trace('订单修改失败');
  99. $fail('订单修改失败');
  100. }
  101. } else {
  102. return $fail('通信失败,请稍后再通知我');
  103. }
  104. return true; // 返回处理完成
  105. });
  106. $response->send();
  107. }
  108. public function xshopOrder(){
  109. $config = config('app.wx_config');
  110. $app = Factory::payment($config);
  111. $response = $app->handlePaidNotify(function ($message, $fail) {
  112. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  113. // 用户是否支付成功
  114. $tradeNo = $message['out_trade_no'];
  115. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  116. $order = Db::name('g_orders')->where('order_sn',$tradeNo)->find();
  117. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  118. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  119. }
  120. $ret = Db::name('g_orders')->where('id',$order['id'])->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
  121. $goods = Db::name('g_order_goods')->where('order_id',$order['id'])->select();
  122. //增加销量
  123. foreach ($goods as $k=>$v){
  124. Db::name('g_goods')
  125. ->where('id',$v['id'])
  126. ->inc('sale',$v['nums'])
  127. ->update();
  128. }
  129. if(!$ret){
  130. trace('订单修改失败');
  131. $fail('订单修改失败');
  132. }
  133. } else {
  134. return $fail('通信失败,请稍后再通知我');
  135. }
  136. return true; // 返回处理完成
  137. });
  138. $response->send();
  139. }
  140. }