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

81 lines
1.8 KiB

  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. private $type = null;
  22. /**
  23. * BatchAuditProduct constructor.
  24. * @param null $title
  25. * @param int $action 1:通过;2:拒绝
  26. * @param int $type 1:普通产品Product;2:行业产品IndustryProduct;
  27. */
  28. public function __construct($title = null, $action = 1, $type = 1)
  29. {
  30. $this->action = $action;
  31. $this->type = $type;
  32. $this->title_text = $action == 1 ? '审核通过' : '审核拒绝';
  33. $this->title = '<i class="fa '.($action == 1 ? 'fa-check-square' : 'fa-times-circle') . '"></i> ' . $this->title_text;
  34. parent::__construct($title);
  35. }
  36. /**
  37. * Handle the action request.
  38. *
  39. * @param Request $request
  40. *
  41. * @return Response
  42. */
  43. public function handle(Request $request)
  44. {
  45. $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  46. if ($request->type == 1) {
  47. Product::whereIn('id', $this->getKey())->update(['status' => $status]);
  48. } else {
  49. IndustryProduct::whereIn('id', $this->getKey())->update(['status' => $status]);
  50. }
  51. return $this->response()->success('操作成功!')->refresh();
  52. }
  53. /**
  54. * @return string|array|void
  55. */
  56. public function confirm()
  57. {
  58. return "确定要批量{$this->title_text}吗?";
  59. }
  60. /**
  61. * @return array
  62. */
  63. protected function parameters()
  64. {
  65. return [
  66. 'action' => $this->action,
  67. 'type' => $this->type,
  68. ];
  69. }
  70. }