ImageSearchSettingFrom.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models\imageSearch;
  8. use app\models\Option;
  9. use yii\base\Model;
  10. class ImageSearchSettingFrom extends Model
  11. {
  12. public $secretId;
  13. public $secretKey;
  14. public $region;
  15. public $status;
  16. public $storeId;
  17. public function rules()
  18. {
  19. return [
  20. [['secretId','secretKey','region'],'string'],
  21. [['secretId','secretKey','region'],'required'],
  22. ['status','default','value'=>0],
  23. [['storeId'], 'safe'],
  24. ];
  25. }
  26. public function afterValidate() {
  27. if(!isset($this->storeId)){
  28. $this->storeId = get_store_id();
  29. }
  30. }
  31. public function attributes()
  32. {
  33. return [
  34. 'secretId' => '腾讯云账号',
  35. 'secretKey' => '腾讯云密钥',
  36. 'region' => '区域',
  37. 'status' => '是否允许商城使用'
  38. ];
  39. }
  40. public function save(){
  41. if(!$this->validate()){
  42. return [
  43. 'code' => 1,
  44. "msg" => $this->getErrorSummary(false)[0]
  45. ];
  46. }
  47. $setting = [
  48. 'secretId' => $this->secretId,
  49. 'secretKey' => $this->secretKey,
  50. 'region' => $this->region
  51. ];
  52. Option::set('tencent_image_setting',json_encode($setting), $this->storeId ,'saas');
  53. Option::set('tencent_image_setting_status',$this->status, $this->storeId ,'saas');
  54. return ['code'=>0,'msg'=>'保存成功', 'storeId' => $this->storeId];
  55. }
  56. }