正在显示
1 个修改的文件
包含
9 行增加
和
2 行删除
| @@ -52,12 +52,16 @@ class ProductController extends BaseController | @@ -52,12 +52,16 @@ class ProductController extends BaseController | ||
| 52 | * @time :2024/3/20 11:09 | 52 | * @time :2024/3/20 11:09 |
| 53 | */ | 53 | */ |
| 54 | public function saveProduct(){ | 54 | public function saveProduct(){ |
| 55 | + $api_key = '8242LYUGaOfUQ1koc4Rq6MhEEOG7NW68oRaB7iO9coJDjG5L5gA1Q'; | ||
| 56 | + if($this->request->header('api-key') != $api_key){ | ||
| 57 | + $this->response('非法请求',Code::SYSTEM_ERROR); | ||
| 58 | + } | ||
| 55 | $this->request->validate([ | 59 | $this->request->validate([ |
| 56 | 'project_id'=>'required', | 60 | 'project_id'=>'required', |
| 57 | 'title'=>'required', | 61 | 'title'=>'required', |
| 58 | ],[ | 62 | ],[ |
| 59 | 'project_id.required' => 'project_id不能为空', | 63 | 'project_id.required' => 'project_id不能为空', |
| 60 | - 'title.required' => 'keyword不能为空', | 64 | + 'title.required' => 'title不能为空', |
| 61 | ]); | 65 | ]); |
| 62 | $project = ProjectServer::useProject($this->param['project_id']); | 66 | $project = ProjectServer::useProject($this->param['project_id']); |
| 63 | if (!$project) { | 67 | if (!$project) { |
| @@ -65,7 +69,7 @@ class ProductController extends BaseController | @@ -65,7 +69,7 @@ class ProductController extends BaseController | ||
| 65 | } | 69 | } |
| 66 | $gallery = []; | 70 | $gallery = []; |
| 67 | $thumb = []; | 71 | $thumb = []; |
| 68 | - if(!empty($this->param['image']) && in_array($this->param['image'])){ | 72 | + if(!empty($this->param['image']) && is_array($this->param['image'])){ |
| 69 | foreach ($this->param['image'] as $k => $v){ | 73 | foreach ($this->param['image'] as $k => $v){ |
| 70 | //TODO::图片转存 | 74 | //TODO::图片转存 |
| 71 | $url = CosService::uploadRemote($this->param['project_id'],'image_product',$v); | 75 | $url = CosService::uploadRemote($this->param['project_id'],'image_product',$v); |
| @@ -76,6 +80,8 @@ class ProductController extends BaseController | @@ -76,6 +80,8 @@ class ProductController extends BaseController | ||
| 76 | } | 80 | } |
| 77 | } | 81 | } |
| 78 | try { | 82 | try { |
| 83 | + $product = Product::where('title', $this->param['title'])->first(); | ||
| 84 | + if(!$product){ | ||
| 79 | $param = [ | 85 | $param = [ |
| 80 | 'project_id'=>$this->param['project_id'], | 86 | 'project_id'=>$this->param['project_id'], |
| 81 | 'title'=>$this->param['title'], | 87 | 'title'=>$this->param['title'], |
| @@ -86,6 +92,7 @@ class ProductController extends BaseController | @@ -86,6 +92,7 @@ class ProductController extends BaseController | ||
| 86 | ]; | 92 | ]; |
| 87 | $productModel = new Product(); | 93 | $productModel = new Product(); |
| 88 | $productModel->add($param); | 94 | $productModel->add($param); |
| 95 | + } | ||
| 89 | } catch (\Exception $e) { | 96 | } catch (\Exception $e) { |
| 90 | LogUtils::error('Project Id: ' . $this->param['project_id'] . ' saveProduct error:' . $e->getMessage()); | 97 | LogUtils::error('Project Id: ' . $this->param['project_id'] . ' saveProduct error:' . $e->getMessage()); |
| 91 | $this->response('保存失败,请联系管理员',Code::SYSTEM_ERROR); | 98 | $this->response('保存失败,请联系管理员',Code::SYSTEM_ERROR); |
-
请 注册 或 登录 后发表评论