ImageSearchController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\imageSearch;
  8. use app\models\Goods;
  9. use app\models\Option;
  10. use app\models\StoreImageSearchSetting;
  11. use app\models\UploadGoodsImage;
  12. use app\modules\admin\controllers\BaseController;
  13. use app\modules\admin\models\imageSearch\ImageSearchSettingFrom;
  14. use app\modules\admin\models\imageSearch\StoreImageSearchSettingForm;
  15. use app\modules\admin\models\imageSearch\UploadImageForm;
  16. use app\utils\TiiaHelper;
  17. class ImageSearchController extends BaseController
  18. {
  19. /**
  20. * 获取腾讯云以图搜图设置信息
  21. * @return \yii\web\Response
  22. * User: hankaige
  23. * DATE TIME: 2023/1/12 09:54
  24. */
  25. public function actionGetSetting(){
  26. $setting = Option::get('tencent_image_setting', get_store_id(),'saas','')['value'];
  27. if(empty($setting)){
  28. $setting = json_encode([
  29. 'secretId' => '',
  30. 'secretKey' => '',
  31. 'region' => '',
  32. ]);
  33. }
  34. $setting = json_decode($setting,true);
  35. $setting['status'] = (int)Option::get('tencent_image_setting_status', get_store_id(),'saas',0)['value'];
  36. $setting['storeId'] = get_store_id();
  37. return $this->asJson([
  38. 'code' => 0,
  39. 'data' => $setting,
  40. 'get_store_id' => get_store_id(),
  41. ]);
  42. }
  43. /**
  44. * 保存腾讯云以图搜图设置信息
  45. * @return \yii\web\Response
  46. * User: hankaige
  47. * DATE TIME: 2023/1/12 09:55
  48. */
  49. public function actionSaveSetting(){
  50. $form = new ImageSearchSettingFrom();
  51. $form->attributes = post_params();
  52. $result = $form->save();
  53. return $this->asJson($result);
  54. }
  55. /**
  56. * 获取商城对应图库信息 生成商城图库
  57. * @return \yii\web\Response
  58. * User: hankaige
  59. * DATE TIME: 2023/1/12 13:43
  60. */
  61. public function actionStoreSetting(){
  62. $storeId = get_store_id();
  63. $model = StoreImageSearchSetting::findOne(['store_id'=>$storeId]);
  64. if(empty($model)){
  65. $model = new StoreImageSearchSetting();
  66. $err_num = 0;
  67. }else{
  68. /*// 查询一下当前图库的信息
  69. $tiia = new TiiaHelper();
  70. // 查询图库是否存在 返回code==0的时候标识图库已存在
  71. $checkRes = $tiia::describeGroup($model->group_id);
  72. $model['image_num'] = $checkRes['data']['Groups'][0]['PicCount'];*/
  73. $err_num = UploadGoodsImage::find()->where(['store_id'=>get_store_id(),'status'=>2])->count();
  74. }
  75. if(\Yii::$app->request->isPost){
  76. $form = new StoreImageSearchSettingForm();
  77. $form->attributes = post_params();
  78. $form->store_id = $storeId;
  79. $form->model = $model;
  80. $result = $form->save();
  81. return $this->asJson($result);
  82. }else{
  83. // 平台以图搜索是否开启状态
  84. $status = (int)Option::get('tencent_image_setting_status',0,'saas',0)['value'];
  85. return $this->asJson([
  86. 'code'=>0,
  87. 'data'=>[
  88. 'model'=>!empty($model->id) ? $model : [
  89. 'id' => 0,
  90. 'group_id' => '',
  91. 'group_name' => '',
  92. 'max_capacity' => '',
  93. ],'status'=>$status,'err_num' => $err_num]]);
  94. }
  95. }
  96. /**
  97. * 请求更新图库信息
  98. * @return \yii\web\Response
  99. * User: hankaige
  100. * DATE TIME: 2023/1/12 15:52
  101. */
  102. public function actionUploadImage(){
  103. $form = new UploadImageForm();
  104. $res = $form->uploadImage();
  105. return $this->asJson($res);
  106. }
  107. /**
  108. * 更新图片库图片数量数据
  109. * @return \yii\web\Response
  110. * User: hankaige
  111. * DATE TIME: 2023/1/12 16:24
  112. */
  113. public function actionRefreshImageGroup(){
  114. $storeId = get_store_id();
  115. $model = StoreImageSearchSetting::findOne(['store_id'=>$storeId]);
  116. $form = new StoreImageSearchSettingForm();
  117. $form->model = $model;
  118. $res = $form->refresh();
  119. return $this->asJson($res);
  120. }
  121. /**
  122. * 查看异常图片列表
  123. * @return \yii\web\Response
  124. * User: hankaige
  125. * DATE TIME: 2023/1/30 14:46
  126. */
  127. public function actionGetErrImage(){
  128. $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');
  129. $list = pagination_make($query);
  130. return $this->asJson(['code'=>0,'data'=>['data'=>$list['list'],'pageNo'=>$list['pageNo'],'totalCount'=>$list['totalCount']]]);
  131. }
  132. }