海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. <?php
  2. namespace App\AdminSupplier\Extensions\Grid;
  3. use App\Common\OrderStatus;
  4. use App\Common\PayType;
  5. use App\Http\Controllers\Api\VerificationController;
  6. use App\Models\IndustryOrder;
  7. use App\Models\Order;
  8. use Dcat\Admin\Grid\RowAction;
  9. use Illuminate\Http\Request;
  10. /**
  11. * 订单核销
  12. * Class AuditSupplier
  13. * @package App\Admin\Extensions\Grid
  14. */
  15. class VerificationOrder extends RowAction
  16. {
  17. protected $title = '核销';
  18. protected function html()
  19. {
  20. $class = 'btn btn-sm btn-success';
  21. $this->appendHtmlAttribute('class', $class);
  22. $this->defaultHtmlAttribute('href', 'javascript:;');
  23. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  24. }
  25. public function handle(Request $request)
  26. {
  27. $id = $this->getKey();
  28. try {
  29. $order = Order::whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::REFUSED_REFUND])
  30. ->find($id);
  31. if (!$order) {
  32. throw new \Exception('订单不存在或已经核销过了');
  33. }
  34. $order->status = OrderStatus::SUCCESS;
  35. if ($order->save()) {
  36. //分账
  37. //线下订单不分账
  38. if ($order->pay_type != PayType::OFFLINE) {
  39. (new VerificationController)->fund($order);
  40. }
  41. }
  42. return $this->response()->success('操作成功')->refresh();
  43. } catch (\Exception $e) {
  44. return $this->response()->error($e->getMessage())->refresh();
  45. }
  46. }
  47. public function confirm()
  48. {
  49. return ['确定要核销该订单吗?', ''];
  50. }
  51. }