validate()){ return [ 'code' => 1, "msg" => $this->getErrorSummary(false)[0] ]; } $store_id = 0; $status = Option::get('tencent_image_setting_status',0,'saas',0)['value']; if(!$status){ // return ['code' => 1,'msg' => '平台未开启以图搜图功能']; $store_id = $this->store_id; $status = Option::get('tencent_image_setting_status',$store_id,'saas',0)['value']; if (!$status) { return ['code' => 1,'msg' => '平台未开启以图搜图功能']; } } $t = \Yii::$app->db->beginTransaction(); try { $tiia = new TiiaHelper(['store_id' => $store_id]); // 查询图库是否存在 返回code==0的时候标识图库已存在 $checkRes = $tiia::describeGroup($this->group_id.'_'.get_store_id()); if($checkRes['code'] == 0){ // 图库已存在 $t->rollBack(); return ['code'=>100,'msg'=>$checkRes['data']]; } // 在腾讯云创建图库 $createRes = $tiia::createGroup($this->group_id.'_'.get_store_id(),$this->group_name,(int)$this->max_capacity); if($createRes['code'] == 1){ // 图库创建失败 $t->rollBack(); return $createRes; } $this->model->store_id = get_store_id(); $this->model->group_id = $this->group_id.'_'.get_store_id(); $this->model->group_name = $this->group_name; $this->model->max_capacity = $this->max_capacity; $this->model->image_num = 0; $this->model->created_at = time(); if(!$this->model->save()){ $t->rollBack(); // 腾讯云没有提供删除图库的接口 return ['code'=>1,'msg'=>'保存失败']; } $t->commit(); return ['code'=> 0 ,'msg' => '图库生成成功']; }catch (\Exception $e){ $t->rollBack(); return ['code'=>1,'msg' => $e->getMessage() ]; } } /** * 更新图片库图片数量数据 * @return array * User: hankaige * DATE TIME: 2023/1/12 16:23 */ public function refresh(){ $tiia = new TiiaHelper(); // 获取图片库信息 这里不需要再拼接store_id 数据表中的store_id与腾讯云的store_id相同 $checkRes = $tiia::describeGroup($this->model->group_id); if($checkRes['code'] == 0){ $this->model->image_num = $checkRes['data']['Groups'][0]['PicCount']; if($this->model->save()){ return ['code'=>0,'msg'=>'更新成功','data'=>['pic_count'=>$checkRes['data']['Groups'][0]['PicCount']]]; }else{ return ['code'=>1,'msg'=>'更新失败']; } }else{ return $checkRes; } } }