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

72 lines
1.5 KiB

4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Actions\Grid;
  3. use App\Common\ProductStatus;
  4. use App\Models\IndustryProduct;
  5. use App\Models\Product;
  6. use Dcat\Admin\Actions\Response;
  7. use Dcat\Admin\Grid\BatchAction;
  8. use Illuminate\Http\Request;
  9. /**
  10. * 批量审核产品
  11. * Class BatchAuditProduct
  12. * @package App\Admin\Actions\Grid
  13. */
  14. class BatchAuditProduct extends BatchAction
  15. {
  16. /**
  17. * @return string
  18. */
  19. protected $action;
  20. private ?string $title_text;
  21. /**
  22. * BatchAuditProduct constructor.
  23. * @param null $title
  24. * @param int $action 1:通过;2:拒绝
  25. */
  26. public function __construct($title = null, $action = 1)
  27. {
  28. $this->action = $action;
  29. $this->title_text = $action == 1 ? '审核通过' : '审核拒绝';
  30. $this->title = '<i class="fa '.($action == 1 ? 'fa-check-square' : 'fa-times-circle') . '"></i> ' . $this->title_text;
  31. parent::__construct($title);
  32. }
  33. /**
  34. * Handle the action request.
  35. *
  36. * @param Request $request
  37. *
  38. * @return Response
  39. */
  40. public function handle(Request $request)
  41. {
  42. $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  43. Product::whereIn('id', $this->getKey())->update(['status' => $status]);
  44. return $this->response()->success('操作成功!')->refresh();
  45. }
  46. /**
  47. * @return string|array|void
  48. */
  49. public function confirm()
  50. {
  51. return "确定要批量{$this->title_text}吗?";
  52. }
  53. /**
  54. * @return array
  55. */
  56. protected function parameters()
  57. {
  58. return [
  59. 'action' => $this->action,
  60. ];
  61. }
  62. }