TestController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\order\classes\OrderClass;
  4. use common\components\util;
  5. use Yii;
  6. class TestController extends BaseController
  7. {
  8. public function actionTestPayAfter()
  9. {
  10. $get = Yii::$app->request->get();
  11. $id = $get['order_id'];
  12. $order = OrderClass::getById($id, true);
  13. if (empty($order)) {
  14. util::fail('没有找到订单');
  15. }
  16. if ($order->mainId != $this->mainId) {
  17. util::fail('不是你的订单');
  18. }
  19. $payWay = 1; // balancePay
  20. $connection = Yii::$app->db;
  21. $transaction = $connection->beginTransaction();
  22. try {
  23. $actPrice = $order->actPrice;
  24. $order->debtPrice = $actPrice;
  25. $order->remainDebtPrice = $actPrice;
  26. $order->debt = 1;
  27. $order->save();
  28. OrderClass::payAfter($order, $payWay);
  29. $transaction->commit();
  30. util::complete('付款成功');
  31. } catch (\Exception $exception) {
  32. $transaction->rollBack();
  33. Yii::info("付款失败原因:" . $exception->getMessage());
  34. util::fail('操作失败');
  35. }
  36. }
  37. }