| 
					
					
						
							
						
					
					
				 | 
				@ -14,6 +14,7 @@ use Dcat\Admin\Form; | 
			
		
		
	
		
			
				 | 
				 | 
				use Dcat\Admin\Grid; | 
				 | 
				 | 
				use Dcat\Admin\Grid; | 
			
		
		
	
		
			
				 | 
				 | 
				use Dcat\Admin\Show; | 
				 | 
				 | 
				use Dcat\Admin\Show; | 
			
		
		
	
		
			
				 | 
				 | 
				use Dcat\Admin\Http\Controllers\AdminController; | 
				 | 
				 | 
				use Dcat\Admin\Http\Controllers\AdminController; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				use Dcat\Admin\Widgets\Alert; | 
			
		
		
	
		
			
				 | 
				 | 
				use Dcat\Admin\Widgets\Table; | 
				 | 
				 | 
				use Dcat\Admin\Widgets\Table; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				class AgentProductController extends AdminController | 
				 | 
				 | 
				class AgentProductController extends AdminController | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -56,12 +57,11 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
							$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); | 
				 | 
				 | 
							$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); | 
			
		
		
	
		
			
				 | 
				 | 
							$grid->column('channel_id', '频道') | 
				 | 
				 | 
							$grid->column('channel_id', '频道') | 
			
		
		
	
		
			
				 | 
				 | 
								->display('查看') | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
								->modal('关联频道', function ($modal) use ($channels) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->display(function ($modal) use ($channels) { | 
			
		
		
	
		
			
				 | 
				 | 
									$data = array_flip(explode(',', $this->channel_id)); | 
				 | 
				 | 
									$data = array_flip(explode(',', $this->channel_id)); | 
			
		
		
	
		
			
				 | 
				 | 
									$data = array_intersect_key($channels, $data); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
									return Table::make(['频道ID', '频道名称'], $data); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
								}); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									return join(',',array_intersect_key($channels, $data)); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								}) | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->limit(10); | 
			
		
		
	
		
			
				 | 
				 | 
				            $grid->column('category.name', '分类')->label(); | 
				 | 
				 | 
				            $grid->column('category.name', '分类')->label(); | 
			
		
		
	
		
			
				 | 
				 | 
				            $grid->column('status') | 
				 | 
				 | 
				            $grid->column('status') | 
			
		
		
	
		
			
				 | 
				 | 
								->using(ProductStatus::array()) | 
				 | 
				 | 
								->using(ProductStatus::array()) | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -98,7 +98,7 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
				     */ | 
				 | 
				 | 
				     */ | 
			
		
		
	
		
			
				 | 
				 | 
				    protected function detail($id) | 
				 | 
				 | 
				    protected function detail($id) | 
			
		
		
	
		
			
				 | 
				 | 
				    { | 
				 | 
				 | 
				    { | 
			
		
		
	
		
			
				 | 
				 | 
				        return Show::make($id, new AgentProduct(), function (Show $show) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        return Show::make($id, new AgentProduct(['agent:id,name', 'product.supplier:id,name']), function (Show $show) { | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('id'); | 
				 | 
				 | 
				            $show->field('id'); | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('agent_id'); | 
				 | 
				 | 
				            $show->field('agent_id'); | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('product_id'); | 
				 | 
				 | 
				            $show->field('product_id'); | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -110,6 +110,19 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('status'); | 
				 | 
				 | 
				            $show->field('status'); | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('created_at'); | 
				 | 
				 | 
				            $show->field('created_at'); | 
			
		
		
	
		
			
				 | 
				 | 
				            $show->field('updated_at'); | 
				 | 
				 | 
				            $show->field('updated_at'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->html(Alert::make(null, '供应商产品详情')->info()); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.id', '供应商产品ID'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.supplier.name'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.title'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.pictures')->image(80, 80); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.original_price'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.price'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.sale'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.stock'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.created_at', '创建时间'); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$show->field('product.updated_at', '更新时间'); | 
			
		
		
	
		
			
				 | 
				 | 
						}); | 
				 | 
				 | 
						}); | 
			
		
		
	
		
			
				 | 
				 | 
				    } | 
				 | 
				 | 
				    } | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -120,15 +133,16 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
				     */ | 
				 | 
				 | 
				     */ | 
			
		
		
	
		
			
				 | 
				 | 
				    protected function form() | 
				 | 
				 | 
				    protected function form() | 
			
		
		
	
		
			
				 | 
				 | 
				    { | 
				 | 
				 | 
				    { | 
			
		
		
	
		
			
				 | 
				 | 
				        return Form::make(new AgentProduct(), function (Form $form) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				        return Form::make(new AgentProduct(['product:id,title']), function (Form $form) { | 
			
		
		
	
		
			
				 | 
				 | 
							$agent_id = Admin::user()->id; | 
				 | 
				 | 
							$agent_id = Admin::user()->id; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				            $form->display('id'); | 
				 | 
				 | 
				            $form->display('id'); | 
			
		
		
	
		
			
				 | 
				 | 
				            $form->hidden('agent_id')->value($agent_id); | 
				 | 
				 | 
				            $form->hidden('agent_id')->value($agent_id); | 
			
		
		
	
		
			
				 | 
				 | 
				            $form->multipleSelectTable('product_id', '供应商产品') | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				            $form->selectTable('product_id', '供应商产品') //multipleSelectTable
 | 
			
		
		
	
		
			
				 | 
				 | 
								->title('选择产品') | 
				 | 
				 | 
								->title('选择产品') | 
			
		
		
	
		
			
				 | 
				 | 
								->dialogWidth('80%;min-width:825px;') | 
				 | 
				 | 
								->dialogWidth('80%;min-width:825px;') | 
			
		
		
	
		
			
				 | 
				 | 
								->from(SelectProduct::make()) | 
				 | 
				 | 
								->from(SelectProduct::make()) | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								->model(Product::class) | 
			
		
		
	
		
			
				 | 
				 | 
								->required(); | 
				 | 
				 | 
								->required(); | 
			
		
		
	
		
			
				 | 
				 | 
				            $form->text('price')->required(); | 
				 | 
				 | 
				            $form->text('price')->required(); | 
			
		
		
	
		
			
				 | 
				 | 
				            $form->text('original_price')->required(); | 
				 | 
				 | 
				            $form->text('original_price')->required(); | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -155,7 +169,7 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
							$agent_id = Admin::user()->id; | 
				 | 
				 | 
							$agent_id = Admin::user()->id; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
							//判断供应商产品是否存在或下架
 | 
				 | 
				 | 
							//判断供应商产品是否存在或下架
 | 
			
		
		
	
		
			
				 | 
				 | 
							if (!Product::query()->where(['id' => $form->product_id, 'status' => ProductStatus::ON_SALE])->exists()) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							if (!Product::where(['id' => $form->product_id, 'status' => ProductStatus::ON_SALE])->exists()) { | 
			
		
		
	
		
			
				 | 
				 | 
								return $form->response()->error('供应商不存在该产品或已下架,不可销售'); | 
				 | 
				 | 
								return $form->response()->error('供应商不存在该产品或已下架,不可销售'); | 
			
		
		
	
		
			
				 | 
				 | 
							} | 
				 | 
				 | 
							} | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -167,13 +181,21 @@ class AgentProductController extends AdminController | 
			
		
		
	
		
			
				 | 
				 | 
							$form->status = ($form->status == ProductStatus::ON_SALE) ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; | 
				 | 
				 | 
							$form->status = ($form->status == ProductStatus::ON_SALE) ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
							//判断是否重复
 | 
				 | 
				 | 
							//判断是否重复
 | 
			
		
		
	
		
			
				 | 
				 | 
							$agent_product = $form->repository()->model()->withTrashed()->where(['agent_id' => $agent_id, 'product_id' => $form->product_id])->first(); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$where = [ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								['agent_id', '=', $agent_id], | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								['product_id', '=', $form->product_id], | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							]; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							if ($form->isEditing()) { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								$where[] = ['id', '<>', $form->getKey()]; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							} | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$agent_product = $form->repository()->model()->withTrashed()->where($where)->first(); | 
			
		
		
	
		
			
				 | 
				 | 
							if ($agent_product) { | 
				 | 
				 | 
							if ($agent_product) { | 
			
		
		
	
		
			
				 | 
				 | 
								//如果已经软删除了,解除软删除后再更新
 | 
				 | 
				 | 
								//如果已经软删除了,解除软删除后再更新
 | 
			
		
		
	
		
			
				 | 
				 | 
								if ($agent_product->deleted_at) { | 
				 | 
				 | 
								if ($agent_product->deleted_at) { | 
			
		
		
	
		
			
				 | 
				 | 
									$agent_product->deleted_at = null; | 
				 | 
				 | 
									$agent_product->deleted_at = null; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$form->deleteInput('sale'); //保留原来的销量
 | 
			
		
		
	
		
			
				 | 
				 | 
									$agent_product->update($form->input()); | 
				 | 
				 | 
									$agent_product->update($form->input()); | 
			
		
		
	
		
			
				 | 
				 | 
									return $form->response()->success('保存成功'); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									return $form->response()->success('保存成功')->script('history.back();'); | 
			
		
		
	
		
			
				 | 
				 | 
								} | 
				 | 
				 | 
								} | 
			
		
		
	
		
			
				 | 
				 | 
								return $form->response()->error('该产品已经存在,请勿重复发布'); | 
				 | 
				 | 
								return $form->response()->error('该产品已经存在,请勿重复发布'); | 
			
		
		
	
		
			
				 | 
				 | 
							} | 
				 | 
				 | 
							} | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
					
				 | 
				
  |