海南旅游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.

47 lines
1.2 KiB

  1. <?php
  2. namespace App\AdminAgent\Extensions\Grid;
  3. use App\Common\OrderStatus;
  4. use App\Models\Order;
  5. use Dcat\Admin\Admin;
  6. use Dcat\Admin\Grid\RowAction;
  7. /**
  8. * 改变订单状态
  9. * Class ChangeOrderStatus
  10. * @package App\AdminAgent\Extensions\Grid
  11. */
  12. class ChangeOrderStatus extends RowAction
  13. {
  14. protected $title = '设为 [线下]已付款';
  15. protected function html()
  16. {
  17. $this->appendHtmlAttribute('class', 'btn btn-sm btn-success');
  18. $this->defaultHtmlAttribute('href', 'javascript:;');
  19. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  20. }
  21. public function handle()
  22. {
  23. try {
  24. $order = Order::firstWhere(['id' => $this->getKey(), 'agent_id' => Admin::user()->id, 'status' => OrderStatus::OFFLINE_UNPAID]);
  25. if (!$order) {
  26. return $this->response()->error("订单不存在或已处理过了")->refresh();
  27. }
  28. $order->status = OrderStatus::OFFLINE_PAID;
  29. $order->verify_code = uniqid(); //生成核销码
  30. $order->save();
  31. return $this->response()->success("操作成功,已设置为“线下已付款”")->refresh();
  32. } catch (\Exception $e) {
  33. return $this->response()->error($e->getMessage());
  34. }
  35. }
  36. public function confirm()
  37. {
  38. return ['确定要设置为已付款吗?', ''];
  39. }
  40. }