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

50 lines
1.4 KiB

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