2 changed files with 90 additions and 0 deletions
-
85app/AdminAgent/Actions/Grid/ShelveAllSupplierProduct.php
-
5app/AdminAgent/Controllers/AgentProductController.php
@ -0,0 +1,85 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Actions\Grid; |
||||
|
|
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Jobs\AgentProductShelve; |
||||
|
use App\Models\Product; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\Tools\AbstractTool; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ShelveAllSupplierProduct extends AbstractTool |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '上架所有供应商产品'; |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
$this->appendHtmlAttribute('class', 'btn btn-primary btn-outline'); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<button {$this->formatHtmlAttributes()}>{$this->title()}</button> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
Product::select(['id'])->where([ |
||||
|
['status', '=', ProductStatus::ON_SALE], |
||||
|
['stock', '>', 0] |
||||
|
])->chunk(200, function ($products) { |
||||
|
foreach ($products as $product) { |
||||
|
AgentProductShelve::dispatch(Admin::user()->id, $product->id); |
||||
|
} |
||||
|
}); |
||||
|
return $this->response()->success('操作成功,此操作可能需要几分钟,请耐心等待')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|void |
||||
|
*/ |
||||
|
protected function href() |
||||
|
{ |
||||
|
// return admin_url('auth/users');
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定要上架所有供应商的全部产品吗?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue