| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -38,7 +38,7 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $grid->column('stock'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $grid->column('sale'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $grid->column('status')->using(ProductStatus::array()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$grid->column('verify_mobile','核销号码'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$grid->column('verify_mobile','核销员手机'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $grid->column('created_at'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $grid->column('updated_at'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -71,7 +71,7 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $show->field('status'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $show->field('know')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$show->field('verify_mobile','核销号码'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$show->field('verify_mobile','核销员手机'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $show->field('created_at'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $show->field('updated_at'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -101,9 +101,9 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $form->text('stock')->default(9999)->required(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $form->editor('know'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            $form->editor('content')->required(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->text('verify_mobile','核销号码'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->text('verify_mobile','核销员手机'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if ($form->isEditing()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->confirm('提示', '编辑产品需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									$form->confirm('提示', '修改标题、价格、产品图片、旅游须知、产品详情需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        })->saving(function (Form $form) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        	//不允许编辑非自己数据
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -111,7 +111,7 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return $form->response()->error('数据不存在'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//不允许编辑的字段 TODO 忽略字段不起作用
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//不允许编辑的字段,忽略字段不起作用?
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//null字段转为''
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -122,16 +122,38 @@ class ProductController extends AdminController | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//特殊字段处理
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->status = ProductStatus::UNAUDITED; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->hidden('supplier_id'); //表单没有的字段,必须加上这句才能重置值
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$form->supplier_id = Admin::user()->id; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							})->saved(function (Form $form, $result) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//下架代理商产品
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$id = $form->getKey(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if ($result) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									AgentProduct::where('product_id', $id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										->orWhere(DB::raw('FIND_IN_SET(' . $id . ', product_ids)')) //TODO product_ids字段可能会去掉
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										->update(['status' => ProductStatus::SOLD_OUT]); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								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($data); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::commit(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->success('更新成功!'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} catch (\Exception $exception) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										DB::rollBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $form->response()->error($exception->getMessage()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							})->deleting(function (Form $form) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//不允许删除非自己的数据
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |