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
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							85 lines
						
					
					
						
							1.8 KiB
						
					
					
				
								<?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 [];
							 | 
						|
								    }
							 | 
						|
								}
							 |