| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -29,6 +29,16 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    protected function grid() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							//下架供应商产品状态不是上架或库存不足的产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							\App\Models\AgentProduct::where('agent_id', Admin::user()->id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->whereHas('agentProductItem', function ($query) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return $query->whereHas('product', function ($query) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								}) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->orWhere('stock', '<=', 0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->update(['status' => ProductStatus::SOLD_OUT]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return Grid::make(new AgentProduct(['product.supplier:id,name', 'category:id,name']), function (Grid $grid) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$agent_id = Admin::user()->id; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        	$grid->model()->where('agent_id', $agent_id); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -287,7 +297,7 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return $form->response()->error('数据不存在'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isEditing() && $form->product_id === null && $form->product_ids === null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isEditing() && $form->type === null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//推荐按钮开关
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									if ($form->is_rec !== null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$form->model()->is_rec = $form->is_rec ? 1 : 0; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -324,6 +334,11 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//库存不足,上架失败
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											if ($form->model()->stock <= 0 && $form->status == 1) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												return $form->response()->error('库存不足,上架失败!')->refresh(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$form->model()->status = $form->status == 1 ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$form->model()->save(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											return $form->response()->success('更新成功!'); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -454,7 +469,7 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} else if ($form->isEditing() && in_array($form->model()->status, [ProductStatus::UNAUDITED, ProductStatus::REFUSE])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$form->deleteInput('status'); //待审核和拒绝的状态不允许修改
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} else if ($form->type == 0 || $form->type == 2) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -475,10 +490,11 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//不允许编辑的字段
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->ignore(['id', 'agent_id', 'status', 'created_at', 'updated_at', 'deleted_at']); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->ignore(['id', 'agent_id', 'created_at', 'updated_at', 'deleted_at']); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//判断是否重复发布产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$where = [ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									['type', '=', $form->type], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									['agent_id', '=', $agent_id], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									['product_id', '=', $form->product_id], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									['product_ids', '=', $form->product_ids], | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -504,7 +520,7 @@ class AgentProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								}, $product); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//组合产品编辑关键字段需要审核
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isEditing() && $form->model()->wasChanged(['title', 'pictures', 'know', 'content'])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isEditing() && $form->type == 1 && $form->model()->wasChanged(['title', 'pictures', 'know', 'content'])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->model()->update(['status' => ProductStatus::UNAUDITED]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |