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

88 lines
1.9 KiB

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