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

85 lines
1.8 KiB

  1. <?php
  2. namespace App\AdminSupplier\Extensions\Grid;
  3. use App\Models\IndustryOrder;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 行业订单审核
  8. * Class AuditSupplier
  9. * @package App\Admin\Extensions\Grid
  10. */
  11. class IndustryOrderAudit extends RowAction
  12. {
  13. private $action;
  14. public function __construct($title = null, $action = 1)
  15. {
  16. parent::__construct($title);
  17. $this->action = $action; //$action:1=通过;2=拒绝
  18. $this->title = $action == 1 ? '通过' : '拒绝';
  19. }
  20. protected function html()
  21. {
  22. $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
  23. $this->appendHtmlAttribute('class', $class);
  24. $this->defaultHtmlAttribute('href', 'javascript:;');
  25. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  26. }
  27. protected function actionScript()
  28. {
  29. if ($this->action == 2) {
  30. return <<<JS
  31. function (data, target, action) {
  32. data.audit_opinion = prompt('请输入拒绝理由');
  33. if (!data.audit_opinion) {
  34. return false;
  35. }
  36. }
  37. JS;
  38. }
  39. return parent::actionScript();
  40. }
  41. public function handle(Request $request)
  42. {
  43. $id = $this->getKey();
  44. $status = $request->action == 1 ? 1 : -1;
  45. try {
  46. $order = IndustryOrder::where('audit_status', 0)->find($id);
  47. if (!$order) {
  48. throw new \Exception('订单不存在或已经审核过了');
  49. }
  50. if (!is_null($request->audit_opinion)) {
  51. $order->audit_opinion = $request->audit_opinion;
  52. }
  53. $order->audit_status = $status;
  54. $order->save();
  55. return $this->response()->success('操作成功')->refresh();
  56. } catch (\Exception $e) {
  57. return $this->response()->error($e->getMessage())->refresh();
  58. }
  59. }
  60. public function confirm()
  61. {
  62. if ($this->action == 1) {
  63. return ['确定要设置为已通过吗?', ''];
  64. }
  65. }
  66. public function parameters()
  67. {
  68. return [
  69. 'action' => $this->action,
  70. ];
  71. }
  72. }