Payment.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use app\common\service\PayReturnService;
  5. use think\Db;
  6. /**
  7. * 第三方登录控制器
  8. */
  9. class Payment extends Frontend
  10. {
  11. protected $noNeedLogin='*';
  12. /**
  13. * 支付成功回调
  14. */
  15. public function notify($order_no)
  16. {
  17. Db::startTrans();
  18. $payment=\app\common\model\Payment::where('order_no',$order_no)
  19. ->lock(true)
  20. ->find();
  21. if(!$payment){
  22. Db::rollback();
  23. $this->result([],400);
  24. }
  25. user_log("payment/{$payment['order_no']}",[
  26. 'input'=>input(),
  27. '$_post'=>$_POST
  28. ]);
  29. $service=new PayReturnService();
  30. $service->setPayment($payment);
  31. list($isPay,$succ)=$service->process();
  32. user_log("payment/{$payment['order_no']}",compact('isPay','succ'));
  33. if(!$payment['pay_time'] && $isPay){
  34. $payment->payed();
  35. }
  36. Db::commit();
  37. if(!$isPay){
  38. $this->result($succ,400);
  39. }
  40. return $succ;
  41. }
  42. }