| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -122,34 +122,35 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//特殊字段处理
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->hidden('supplier_id'); //表单没有的字段,必须加上这句才能重置值
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->supplier_id = Admin::user()->id; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isCreating()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							})->saved(function (Form $form, $result) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($form->isEditing() && $result) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$ap_ids = AgentProductItem::where('product_id', $form->getKey())->pluck('agent_product_id')->toArray(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									DB::beginTransaction(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$data = [ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'title' => $form->title, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'pictures' => explode(',', $form->pictures), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'know' => $form->know, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'content' => $form->content, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										//如果修改标题、价格、产品图片、旅游须知、产品详情,状态将变为未审核
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										if ($form->model()->wasChanged(['title', 'price', 'original_price', 'pictures', 'know', 'content'])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$form->model()->update(['status' => ProductStatus::UNAUDITED]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//下架所有代理商产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$data['status'] = ProductStatus::SOLD_OUT; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//下架所有代理商产品,未审核的产品,不能同步信息到代理商产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											AgentProduct::whereIn('id', $ap_ids)->where('type', 0)->update(['status' => ProductStatus::SOLD_OUT]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										} else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//不需要审核的修改信息同步信息到代理商产品,注:组合产品不同步
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											AgentProduct::whereIn('id', $ap_ids)->where('type', 0)->update([ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												'title' => $form->title, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												'pictures' => explode(',', $form->pictures), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												'know' => $form->know, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												'content' => $form->content, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										//同步信息到代理商产品,注:组合产品不同步
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										AgentProduct::whereIn('id', $ap_ids)->where('type', 0)->update($data); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::commit(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->success('更新成功!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->success('更新成功!')->script('history.go(-1)'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} catch (\Exception $exception) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::rollBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->error($exception->getMessage()); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |