| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\imageSearch;
- use app\models\Goods;
- use app\models\Option;
- use app\models\StoreImageSearchSetting;
- use app\models\UploadGoodsImage;
- use app\modules\admin\controllers\BaseController;
- use app\modules\admin\models\imageSearch\ImageSearchSettingFrom;
- use app\modules\admin\models\imageSearch\StoreImageSearchSettingForm;
- use app\modules\admin\models\imageSearch\UploadImageForm;
- use app\utils\TiiaHelper;
- class ImageSearchController extends BaseController
- {
- /**
- * 获取腾讯云以图搜图设置信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/12 09:54
- */
- public function actionGetSetting(){
- $setting = Option::get('tencent_image_setting', get_store_id(),'saas','')['value'];
- if(empty($setting)){
- $setting = json_encode([
- 'secretId' => '',
- 'secretKey' => '',
- 'region' => '',
- ]);
- }
- $setting = json_decode($setting,true);
- $setting['status'] = (int)Option::get('tencent_image_setting_status', get_store_id(),'saas',0)['value'];
- $setting['storeId'] = get_store_id();
- return $this->asJson([
- 'code' => 0,
- 'data' => $setting,
- 'get_store_id' => get_store_id(),
- ]);
- }
- /**
- * 保存腾讯云以图搜图设置信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/12 09:55
- */
- public function actionSaveSetting(){
- $form = new ImageSearchSettingFrom();
- $form->attributes = post_params();
- $result = $form->save();
- return $this->asJson($result);
- }
- /**
- * 获取商城对应图库信息 生成商城图库
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/12 13:43
- */
- public function actionStoreSetting(){
- $storeId = get_store_id();
- $model = StoreImageSearchSetting::findOne(['store_id'=>$storeId]);
- if(empty($model)){
- $model = new StoreImageSearchSetting();
- $err_num = 0;
- }else{
- /*// 查询一下当前图库的信息
- $tiia = new TiiaHelper();
- // 查询图库是否存在 返回code==0的时候标识图库已存在
- $checkRes = $tiia::describeGroup($model->group_id);
- $model['image_num'] = $checkRes['data']['Groups'][0]['PicCount'];*/
- $err_num = UploadGoodsImage::find()->where(['store_id'=>get_store_id(),'status'=>2])->count();
- }
- if(\Yii::$app->request->isPost){
- $form = new StoreImageSearchSettingForm();
- $form->attributes = post_params();
- $form->store_id = $storeId;
- $form->model = $model;
- $result = $form->save();
- return $this->asJson($result);
- }else{
- // 平台以图搜索是否开启状态
- $status = (int)Option::get('tencent_image_setting_status',0,'saas',0)['value'];
- return $this->asJson([
- 'code'=>0,
- 'data'=>[
- 'model'=>!empty($model->id) ? $model : [
- 'id' => 0,
- 'group_id' => '',
- 'group_name' => '',
- 'max_capacity' => '',
- ],'status'=>$status,'err_num' => $err_num]]);
- }
- }
- /**
- * 请求更新图库信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/12 15:52
- */
- public function actionUploadImage(){
- $form = new UploadImageForm();
- $res = $form->uploadImage();
- return $this->asJson($res);
- }
- /**
- * 更新图片库图片数量数据
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/12 16:24
- */
- public function actionRefreshImageGroup(){
- $storeId = get_store_id();
- $model = StoreImageSearchSetting::findOne(['store_id'=>$storeId]);
- $form = new StoreImageSearchSettingForm();
- $form->model = $model;
- $res = $form->refresh();
- return $this->asJson($res);
- }
- /**
- * 查看异常图片列表
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/30 14:46
- */
- public function actionGetErrImage(){
- $query = UploadGoodsImage::find()->alias('ugi')->where(['ugi.store_id'=>get_store_id(),'ugi.status'=>2,'ugi.is_delete'=>0])->leftJoin(['g' => Goods::tableName()],'g.id = ugi.goods_id')->select('ugi.*,g.name');
- $list = pagination_make($query);
- return $this->asJson(['code'=>0,'data'=>['data'=>$list['list'],'pageNo'=>$list['pageNo'],'totalCount'=>$list['totalCount']]]);
- }
- }
|