海南旅游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\AdminAgent\Actions\Grid;
  3. use App\Common\ProductStatus;
  4. use App\Jobs\AgentProductShelve;
  5. use App\Models\Product;
  6. use Dcat\Admin\Actions\Response;
  7. use Dcat\Admin\Admin;
  8. use Dcat\Admin\Grid\Tools\AbstractTool;
  9. use Dcat\Admin\Traits\HasPermissions;
  10. use Illuminate\Contracts\Auth\Authenticatable;
  11. use Illuminate\Database\Eloquent\Model;
  12. use Illuminate\Http\Request;
  13. class ShelveAllSupplierProduct extends AbstractTool
  14. {
  15. /**
  16. * @return string
  17. */
  18. protected $title = '上架所有供应商产品';
  19. protected function html()
  20. {
  21. $this->appendHtmlAttribute('class', 'btn btn-primary btn-outline');
  22. return <<<HTML
  23. <button {$this->formatHtmlAttributes()}>{$this->title()}</button>
  24. HTML;
  25. }
  26. /**
  27. * Handle the action request.
  28. *
  29. * @param Request $request
  30. *
  31. * @return Response
  32. */
  33. public function handle(Request $request)
  34. {
  35. Product::select(['id'])->where([
  36. ['status', '=', ProductStatus::ON_SALE],
  37. ['stock', '>', 0]
  38. ])->chunk(200, function ($products) {
  39. foreach ($products as $product) {
  40. AgentProductShelve::dispatch(Admin::user()->id, $product->id);
  41. }
  42. });
  43. return $this->response()->success('操作成功,此操作可能需要几分钟,请耐心等待')->refresh();
  44. }
  45. /**
  46. * @return string|void
  47. */
  48. protected function href()
  49. {
  50. // return admin_url('auth/users');
  51. }
  52. /**
  53. * @return string|array|void
  54. */
  55. public function confirm()
  56. {
  57. return ['确定要上架所有供应商的全部产品吗?'];
  58. }
  59. /**
  60. * @param Model|Authenticatable|HasPermissions|null $user
  61. *
  62. * @return bool
  63. */
  64. protected function authorize($user): bool
  65. {
  66. return true;
  67. }
  68. /**
  69. * @return array
  70. */
  71. protected function parameters()
  72. {
  73. return [];
  74. }
  75. }