正在显示
1 个修改的文件
包含
19 行增加
和
12 行删除
| @@ -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,16 +80,19 @@ class ProductController extends BaseController | @@ -76,16 +80,19 @@ class ProductController extends BaseController | ||
| 76 | } | 80 | } |
| 77 | } | 81 | } |
| 78 | try { | 82 | try { |
| 79 | - $param = [ | ||
| 80 | - 'project_id'=>$this->param['project_id'], | ||
| 81 | - 'title'=>$this->param['title'], | ||
| 82 | - 'intro'=>$this->param['intro'] ?? '', | ||
| 83 | - 'content'=>$this->param['content'] ?? '', | ||
| 84 | - 'thumb'=>json_encode($thumb,true), | ||
| 85 | - 'gallery'=>json_encode($gallery,true), | ||
| 86 | - ]; | ||
| 87 | - $productModel = new Product(); | ||
| 88 | - $productModel->add($param); | 83 | + $product = Product::where('title', $this->param['title'])->first(); |
| 84 | + if(!$product){ | ||
| 85 | + $param = [ | ||
| 86 | + 'project_id'=>$this->param['project_id'], | ||
| 87 | + 'title'=>$this->param['title'], | ||
| 88 | + 'intro'=>$this->param['intro'] ?? '', | ||
| 89 | + 'content'=>$this->param['content'] ?? '', | ||
| 90 | + 'thumb'=>json_encode($thumb,true), | ||
| 91 | + 'gallery'=>json_encode($gallery,true), | ||
| 92 | + ]; | ||
| 93 | + $productModel = new Product(); | ||
| 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); |
-
请 注册 或 登录 后发表评论