Storage.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\behaviors\TimestampBehavior;
  9. /**
  10. * Class Storage
  11. * @package app\models
  12. * @property integer $id
  13. * @property integer $parent_id
  14. * @property string $name
  15. * @property string $mime
  16. * @property string $ext
  17. * @property integer $size
  18. * @property string $path
  19. * @property string $url
  20. * @property string $platform
  21. * @property integer $type
  22. * @property integer $created_at
  23. * @property integer $updated_at
  24. * @property integer $is_delete
  25. * @property integer $store_id
  26. * @property integer $mch_id
  27. * @property integer $supplier_id
  28. * @property integer $bd_id
  29. */
  30. class Storage extends \yii\db\ActiveRecord
  31. {
  32. const PLATFORM_LOCAL = 'local';
  33. const PLATFORM_ALIYUN = 'aliyun';
  34. const PLATFORM_QINIU = 'qiniu';
  35. const PLATFORM_QCLOUD = 'qcloud';
  36. const PLATFORMS = [
  37. self::PLATFORM_LOCAL => '本地',
  38. self::PLATFORM_ALIYUN => '阿里云',
  39. self::PLATFORM_QINIU => '七牛',
  40. self::PLATFORM_QCLOUD => '腾讯云',
  41. ];
  42. const TYPE_IMAGE = 0; // 图片
  43. const TYPE_VIDEO = 1; // 视频
  44. const TYPE_DIR = 2; // 目录
  45. const TYPE_XlSX = 3; // excel文件
  46. const TYPE_CRT = 4; // 证书文件
  47. const TYPE_APK = 5; // APP包
  48. const TYPE_PFX = 6; // PFX文件
  49. const TYPE_CER = 7; // CER文件
  50. const TYPE_PEM = 8; // PFX文件
  51. const STATUS_NORMAL = 0; // 正常
  52. const STATUS_DELETE = 1; // 删除
  53. const IMAGE_TYPE = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
  54. const IMAGE_MIME = [
  55. 'image/jpeg',
  56. 'image/jpg',
  57. 'image/png',
  58. 'image/gif',
  59. 'image/bmp',
  60. 'image/webp',
  61. '', // 支付宝小程序上传图片获取不到mime
  62. ];
  63. const VIDEO_TYPE = ['mp4', 'flv', 'ogg', 'mov'];
  64. const VIDEO_MIME = [
  65. 'video/mp4',
  66. 'video/x-flv',
  67. 'video/ogg',
  68. 'video/quicktime'
  69. ];
  70. const XlSX_TYPE = ['xlsx'];
  71. const XlSX_MIME = [
  72. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  73. ];
  74. const CRT_TYPE = ['crt', 'cer'];
  75. const CRT_MIME = [
  76. 'application/x-x509-ca-cert'
  77. ];
  78. const APK_TYPE = ['apk'];
  79. const APK_MIME = [
  80. 'application/vnd.android.package-archive'
  81. ];
  82. const PFX_TYPE = ['pfx'];
  83. const PFX_MIME = [
  84. 'application/x-pkcs12'
  85. ];
  86. const PEM_TYPE = ['pem'];
  87. const PEM_MIME = [
  88. 'application/octet-stream',
  89. 'application/x-x509-ca-cert'
  90. ];
  91. /**
  92. * @inheritdoc
  93. */
  94. public static function tableName()
  95. {
  96. return '{{%storage}}';
  97. }
  98. public function behaviors()
  99. {
  100. return [
  101. [
  102. // 自动更新创建和更新时间
  103. 'class' => TimestampBehavior::class,
  104. 'value' => time()
  105. ]
  106. ];
  107. }
  108. /**
  109. * @inheritdoc
  110. */
  111. public function rules()
  112. {
  113. return [
  114. [['parent_id', 'size', 'type', 'created_at', 'updated_at', 'is_delete', 'store_id', 'mch_id', 'supplier_id', 'bd_id'], 'integer'],
  115. [['name', 'mime', 'ext', 'path', 'url', 'platform'], 'string'],
  116. [['name', 'path', 'url'], 'string', 'max' => 255],
  117. [['mime'], 'string', 'max' => 100],
  118. [['platform'], 'string', 'max' => 10],
  119. [['ext'], 'string', 'max' => 6],
  120. [['created_at', 'update_at'], 'safe']
  121. ];
  122. }
  123. /**
  124. * @inheritdoc
  125. */
  126. public function attributeLabels()
  127. {
  128. return [
  129. 'id' => 'ID',
  130. 'parent_id' => '父级ID',
  131. 'name' => '文件别名',
  132. 'mime' => 'mime类型',
  133. 'ext' => '扩展名',
  134. 'size' => '文件大小',
  135. 'path' => '文件路径',
  136. 'url' => '文件url',
  137. 'platform' => '存储平台',
  138. 'type' => '类型',
  139. 'created_at' => '创建时间',
  140. 'updated_at' => '更新时间',
  141. 'is_delete' => '是否已删除',
  142. 'store_id' => '商城ID',
  143. 'mch_id' => '入驻商ID',
  144. 'supplier_id' => '供货商ID',
  145. 'bd_id' => '推广代理ID',
  146. ];
  147. }
  148. }