作者 赵彬吉

update

... ... @@ -52,12 +52,16 @@ class ProductController extends BaseController
* @time :2024/3/20 11:09
*/
public function saveProduct(){
$api_key = '8242LYUGaOfUQ1koc4Rq6MhEEOG7NW68oRaB7iO9coJDjG5L5gA1Q';
if($this->request->header('api-key') != $api_key){
$this->response('非法请求',Code::SYSTEM_ERROR);
}
$this->request->validate([
'project_id'=>'required',
'title'=>'required',
],[
'project_id.required' => 'project_id不能为空',
'title.required' => 'keyword不能为空',
'title.required' => 'title不能为空',
]);
$project = ProjectServer::useProject($this->param['project_id']);
if (!$project) {
... ... @@ -65,7 +69,7 @@ class ProductController extends BaseController
}
$gallery = [];
$thumb = [];
if(!empty($this->param['image']) && in_array($this->param['image'])){
if(!empty($this->param['image']) && is_array($this->param['image'])){
foreach ($this->param['image'] as $k => $v){
//TODO::图片转存
$url = CosService::uploadRemote($this->param['project_id'],'image_product',$v);
... ... @@ -76,6 +80,8 @@ class ProductController extends BaseController
}
}
try {
$product = Product::where('title', $this->param['title'])->first();
if(!$product){
$param = [
'project_id'=>$this->param['project_id'],
'title'=>$this->param['title'],
... ... @@ -86,6 +92,7 @@ class ProductController extends BaseController
];
$productModel = new Product();
$productModel->add($param);
}
} catch (\Exception $e) {
LogUtils::error('Project Id: ' . $this->param['project_id'] . ' saveProduct error:' . $e->getMessage());
$this->response('保存失败,请联系管理员',Code::SYSTEM_ERROR);
... ...