Notify.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. //张家界中医院,张家界人民医院--公众号
  109. public function phOrderZjj(){
  110. $config = config('app.wx_config_zjj');
  111. $app = Factory::payment($config);
  112. $response = $app->handlePaidNotify(function ($message, $fail) {
  113. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  114. // 用户是否支付成功
  115. $tradeNo = $message['out_trade_no'];
  116. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  117. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  118. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  119. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  120. }
  121. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  122. if(!$ret){
  123. trace('订单修改失败');
  124. $fail('订单修改失败');
  125. }
  126. } else {
  127. return $fail('通信失败,请稍后再通知我');
  128. }
  129. return true; // 返回处理完成
  130. });
  131. $response->send();
  132. }
  133. //张家界中医院,张家界人民医院--小程序
  134. public function phOrderZjj2(){
  135. $config = config('app.wx_mini_config_ph_zjj');
  136. $app = Factory::payment($config);
  137. $response = $app->handlePaidNotify(function ($message, $fail) {
  138. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  139. // 用户是否支付成功
  140. $tradeNo = $message['out_trade_no'];
  141. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  142. $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
  143. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  144. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  145. }
  146. $ret = model('PhOrderPay')->paySuccess($order['id'],2);
  147. if(!$ret){
  148. trace('订单修改失败');
  149. $fail('订单修改失败');
  150. }
  151. } else {
  152. return $fail('通信失败,请稍后再通知我');
  153. }
  154. return true; // 返回处理完成
  155. });
  156. $response->send();
  157. }
  158. public function xshopOrder(){
  159. $config = config('app.wx_config');
  160. $app = Factory::payment($config);
  161. $response = $app->handlePaidNotify(function ($message, $fail) {
  162. if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
  163. // 用户是否支付成功
  164. $tradeNo = $message['out_trade_no'];
  165. // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  166. $order = Db::name('g_orders')->where('order_sn',$tradeNo)->find();
  167. if (!$order || $order['status'] != 0) { // 如果订单不存在 或者 订单已经支付过了
  168. return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
  169. }
  170. $ret = Db::name('g_orders')->where('id',$order['id'])->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
  171. $goods = Db::name('g_order_goods')->where('order_id',$order['id'])->select();
  172. //增加销量
  173. foreach ($goods as $k=>$v){
  174. Db::name('g_goods')
  175. ->where('id',$v['id'])
  176. ->inc('sale',$v['nums'])
  177. ->update();
  178. }
  179. if(!$ret){
  180. trace('订单修改失败');
  181. $fail('订单修改失败');
  182. }
  183. } else {
  184. return $fail('通信失败,请稍后再通知我');
  185. }
  186. return true; // 返回处理完成
  187. });
  188. $response->send();
  189. }
  190. }