| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -305,76 +305,31 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} else if ($form->isEditing()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//如果原来是下架或上架状态才允许修改
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									if (in_array($form->model()->status, $user_status) && in_array($form->status, $user_status)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									if (in_array($form->status, $user_status) && in_array($form->model()->status, $user_status)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$form->deleteInput('status'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//因extends是数组,具有一定的特殊性,不能直接用$form->saved方法中的wasChanged判断是否修改,所以只能在这里做特殊处理
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									if (!is_null($form->extends)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$old_extends = array_filter($form->model()->extends, fn($v, $k) => str_contains($k, 'field_' . $form->model()->type) && !empty($v), ARRAY_FILTER_USE_BOTH); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$new_extends = array_filter($form->extends, fn($v, $k) => str_contains($k, 'field_' . $form->model()->type) && !empty($v), ARRAY_FILTER_USE_BOTH); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$old = $new = []; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										array_walk_recursive($old_extends, function($v) use (&$old) {if ($v !== null) $old[] = $v;}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										array_walk_recursive($new_extends, function($v) use (&$new) {if ($v !== null) $new[] = $v;}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										if (array_diff($old, $new)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//删除规格不处理,新增规格、修改规格价格或日期,状态都要变为已审核
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$new_spec = array_filter($form->spec, fn($v) => $v['_remove_'] === null); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//判断是否新增规格
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									if (array_filter($new_spec, fn($v) => $v['id'] === null)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//判断是否修改价格
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									else if ($new_spec) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										// $item是旧数据,$form->spec是新修改的数据
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										foreach ($form->model()->spec as $item) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//删除的规格不处理
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											if (!isset($new_spec[$item->id])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												continue; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//修改价格或日期的,设置为未审核,退出循环
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											if ($item->price != $new_spec[$item->id]['price'] || $item->date != $new_spec[$item->id]['date']) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												break; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->deleteInput('status'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							})->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 { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										//如果修改标题、价格、产品图片、旅游须知、产品详情,状态将变为未审核
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										if ($form->model()->wasChanged(['title', 'price', 'original_price', 'pictures', 'know', 'content', 'spec'])) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$form->model()->update(['status' => ProductStatus::UNAUDITED]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											//下架所有代理商产品,未审核的产品,不能同步信息到代理商产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											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, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::commit(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->success('更新成功!')->redirect('product/list'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										//修改信息同步信息到代理商产品,注:组合产品不同步
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										AgentProduct::whereIn('id', $ap_ids)->where('type', 0)->update([ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'title' => $form->title, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'pictures' => explode(',', $form->pictures), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'know' => $form->know, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											'content' => $form->content, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->success('更新成功!')->script('history.go(-1)'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} catch (\Exception $exception) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::rollBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->error($exception->getMessage()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									//TODO 还需要规格同步到代理商
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							})->deleting(function (Form $form) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//不允许删除非自己的数据
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |