diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 4e6121f98..e04d8c518 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -11,6 +11,12 @@ use app\admin\validate\store_product\StoreProductValidate; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use TencentCloud\Common\Credential; +use TencentCloud\Common\Profile\ClientProfile; +use TencentCloud\Common\Profile\HttpProfile; +use TencentCloud\Tiia\V20190529\Models\CreateImageRequest; +use TencentCloud\Tiia\V20190529\Models\SearchImageRequest; +use TencentCloud\Tiia\V20190529\TiiaClient; use Webman\RedisQueue\Redis; /** @@ -21,6 +27,7 @@ use Webman\RedisQueue\Redis; class StoreProductController extends BaseAdminController { + public $notNeedLogin = ['upload', 'recognition']; /** * @notes 获取商品列表列表 @@ -151,4 +158,49 @@ class StoreProductController extends BaseAdminController return $this->success('删除成功', [], 1, 1); } + public function upload() + { + $file = $this->request->file('file'); + $cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY')); + $httpProfile = new HttpProfile(); + $httpProfile->setEndpoint("tiia.tencentcloudapi.com"); + $clientProfile = new ClientProfile(); + $clientProfile->setHttpProfile($httpProfile); + $client = new TiiaClient($cred, "ap-guangzhou", $clientProfile); + $req = new CreateImageRequest(); + $file = file_get_contents(public_path() . '/可口可乐.jpg'); + $params = [ + 'GroupId' => 'default', + 'EntityId' => '可口可乐_330ml_听装', + 'PicName' => '可口可乐.jpg', + 'ImageBase64' => base64_encode($file) + ]; + $req->fromJsonString(json_encode($params)); + $resp = $client->CreateImage($req); + $result = json_decode($resp->toJsonString(), true); + return $this->data($result); + } + + public function recognition() + { + $cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY')); + $httpProfile = new HttpProfile(); + $httpProfile->setEndpoint("tiia.tencentcloudapi.com"); + $clientProfile = new ClientProfile(); + $clientProfile->setHttpProfile($httpProfile); + $client = new TiiaClient($cred, "ap-guangzhou", $clientProfile); + $req = new SearchImageRequest(); + $file = file_get_contents(public_path() . '/可口可乐.jpg'); +// $file = file_get_contents(public_path() . '/可口可乐2.jpg'); +// $file = file_get_contents(public_path() . '/百事可乐.jpg'); + $params = [ + 'GroupId' => 'default', + 'ImageBase64' => base64_encode($file) + ]; + $req->fromJsonString(json_encode($params)); + $resp = $client->SearchImage($req); + $result = json_decode($resp->toJsonString(), true); + return $this->data($result); + } + } diff --git a/app/common/model/store_product_price/StoreProductPrice.php b/app/common/model/store_product_price/StoreProductPrice.php index d65cf062a..641501f02 100644 --- a/app/common/model/store_product_price/StoreProductPrice.php +++ b/app/common/model/store_product_price/StoreProductPrice.php @@ -24,4 +24,9 @@ class StoreProductPrice extends BaseModel // 不生成该表的日志 public $doNotRecordLog = true; + public function product() + { + return $this->hasOne(StoreProduct::class, 'id', 'product_id')->field('id,store_name,top_cate_id,two_cate_id,cate_id'); + } + } \ No newline at end of file