FinalPaymentNotify.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace addons\DepositPresale\common\logic\notify;
  3. use addons\DepositPresale\common\models\DepositPresaleOrder;
  4. use common\models\order\Order;
  5. use common\traits\ErrorTrait;
  6. use Exception;
  7. /**
  8. * Class FinalPaymentNotify
  9. * @Author: hua
  10. * @DateTime: 2021/10/18 9:39
  11. * @Copyright: copyright (c) 2021 广东七件事集团
  12. * @package common\logic\notify
  13. */
  14. class FinalPaymentNotify
  15. {
  16. use ErrorTrait;
  17. /**
  18. * @Description: 支付尾款
  19. * @Author: code farmer 3
  20. * @DateTime 2022-04-23 17:26:14
  21. * @param array $order_info
  22. * @return void
  23. */
  24. public function notify($order_info)
  25. {
  26. try {
  27. $order = DepositPresaleOrder::findOne(['order_no' => $order_info['order_no']]);
  28. $res = DepositPresaleOrder::payFinalPayment($order, $order_info['pay_type']);
  29. if($res === false) throw new Exception(DepositPresaleOrder::getStaticError());
  30. $main_order = Order::findOne(['id' => $order['order_id']]);
  31. if($main_order && $main_order->created_at != $order->created_at){
  32. $main_order->created_at = $order->created_at;
  33. $result = $main_order->save();
  34. if(!$result){
  35. throw new Exception($main_order->getError());
  36. }
  37. }
  38. $main_res = Order::pay($main_order, $order_info['pay_type'], $main_order['out_trade_no']);
  39. if($main_res === false) throw new Exception(Order::getStaticError());
  40. return true;
  41. } catch (Exception $e) {
  42. echo $e->getMessage();
  43. $this->setStaticError($e->getMessage());
  44. return false;
  45. }
  46. }
  47. }