AttachmentController.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use common\models\common\Attachment;
  5. use common\services\mall\aliyunsts\AliyunStsServices;
  6. use common\services\mall\QiniuAuto;
  7. use Yii;
  8. class AttachmentController extends MallController
  9. {
  10. public function actionIndex()
  11. {
  12. return $this->render($this->action->id);
  13. }
  14. public function actionGetOssConfig()
  15. {
  16. $mall_id = $this->mall_id;
  17. // $mall_id = 5;
  18. $config = \Yii::$app->services->attachment->getStorageConfig($mall_id);
  19. $data = [
  20. 'is_show_long_vide' => 1,
  21. // 'config' => $config,
  22. ];
  23. // if ($config['dirve'] == Attachment::DRIVE_LOCAL) $data['is_show_long_vide'] = 0;
  24. switch ($config['drive']) {
  25. //本地上传
  26. case Attachment::DRIVE_LOCAL:
  27. $data['is_show_long_vide'] = 0;
  28. break;
  29. //七牛云
  30. case Attachment::DRIVE_QINIU:
  31. //获取token
  32. $qiniu_auto = new QiniuAuto($config['access_key_id'], $config['access_key_secret']);
  33. $qiniu_token = $qiniu_auto->uploadToken($config['bucket']);
  34. $data['token'] = $qiniu_token;
  35. $data['bucket'] = $config['bucket'];
  36. $data['domain'] = $config['domain'];
  37. $data['secret_id'] = $config['access_key_id'];
  38. $data['secret_key'] = $config['access_key_secret'];
  39. break;
  40. //腾讯云
  41. case Attachment::DRIVE_COS:
  42. $data['bucket'] = $config['bucket'];
  43. $data['area'] = $config['area'];
  44. $data['domain'] = $config['domain'];
  45. $data['secret_id'] = $config['secret_id'];
  46. $data['secret_key'] = $config['secret_key'];
  47. break;
  48. //阿里云
  49. case Attachment::DRIVE_OSS:
  50. $arr = explode('.', $config['storage_aliyun_endpoint']);
  51. $data['bucket'] = $config['storage_aliyun_bucket'];
  52. // $data['area'] = $config['area'];
  53. $data['region'] = $arr[0];
  54. $data['domain'] = $config['storage_aliyun_user_url'];
  55. $data['endpoint'] = $config['storage_aliyun_endpoint'];
  56. $data['protocols'] = $config['storage_aliyun_transport_protocols'];
  57. if (!empty($config['arn'])) {
  58. $sts_config = (new AliyunStsServices())->getSts($mall_id, $config);
  59. $data['security_token'] = $sts_config['SecurityToken'];
  60. $data['secret_id'] = $sts_config['AccessKeyId'];
  61. $data['secret_key'] = $sts_config['AccessKeySecret'];
  62. } else {
  63. $data['is_show_long_vide'] = 0;
  64. }
  65. break;
  66. }
  67. $data['drive'] = $config['drive'];
  68. return $this->success('获取成功', $data);
  69. }
  70. public function actionSetLongVideoData()
  71. {
  72. $mall = Yii::$app->session->get('mall');
  73. $mall_id = !empty($mall) ? $mall['id'] : 0;
  74. $post = Yii::$app->request->post();
  75. try {
  76. Yii::$app->services->attachment->setLongVideoData($mall_id, $post);
  77. } catch (\Exception $e) {
  78. return $this->error($e->getMessage());
  79. }
  80. return $this->success('操作成功');
  81. }
  82. }