Attachment.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace addons\Wechat\common\models;
  3. use common\behaviors\MerchantBehavior;
  4. use addons\Wechat\common\enums\AttachmentTypeEnum;
  5. /**
  6. * This is the model class for table "{{%addon_wechat_attachment}}".
  7. *
  8. * @property int $id
  9. * @property int|null $merchant_id 商户id
  10. * @property int|null $store_id 店铺ID
  11. * @property string|null $file_name 文件原始名
  12. * @property string|null $local_url 本地地址
  13. * @property string|null $media_type 类别
  14. * @property string|null $media_id 微信资源ID
  15. * @property string|null $media_url 资源Url
  16. * @property int|null $width 宽度
  17. * @property int|null $height 高度
  18. * @property int|null $year 年份
  19. * @property int|null $month 月份
  20. * @property int|null $day 日
  21. * @property string|null $description 视频描述
  22. * @property string|null $is_temporary 类型[临时:tmp永久:perm]
  23. * @property int|null $link_type 1微信2本地
  24. * @property int $status 状态[-1:删除;0:禁用;1启用]
  25. * @property int|null $created_at 创建时间
  26. * @property int|null $updated_at 修改时间
  27. */
  28. class Attachment extends \common\models\base\BaseModel
  29. {
  30. use MerchantBehavior;
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%addon_wechat_attachment}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['merchant_id', 'store_id', 'width', 'height', 'year', 'month', 'day', 'link_type', 'status', 'created_at', 'updated_at'], 'integer'],
  45. [['file_name', 'local_url'], 'string', 'max' => 150],
  46. [['media_type'], 'string', 'max' => 15],
  47. [['media_id'], 'string', 'max' => 200],
  48. [['media_url'], 'string', 'max' => 5000],
  49. [['description'], 'string', 'max' => 200],
  50. [['is_temporary'], 'string', 'max' => 10],
  51. ];
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function attributeLabels()
  57. {
  58. return [
  59. 'id' => 'ID',
  60. 'merchant_id' => '商户id',
  61. 'store_id' => '店铺ID',
  62. 'file_name' => '文件原始名',
  63. 'local_url' => '本地地址',
  64. 'media_type' => '类别',
  65. 'media_id' => '微信资源ID',
  66. 'media_url' => '资源Url',
  67. 'width' => '宽度',
  68. 'height' => '高度',
  69. 'year' => '年份',
  70. 'month' => '月份',
  71. 'day' => '日',
  72. 'description' => '视频描述',
  73. 'is_temporary' => '类型[临时:tmp永久:perm]',
  74. 'link_type' => '1微信2本地',
  75. 'status' => '状态[-1:删除;0:禁用;1启用]',
  76. 'created_at' => '创建时间',
  77. 'updated_at' => '修改时间',
  78. ];
  79. }
  80. /**
  81. * 关联图文
  82. *
  83. * @return \yii\db\ActiveQuery
  84. */
  85. public function getNews()
  86. {
  87. return $this->hasMany(AttachmentNews::class, ['attachment_id' => 'id']);
  88. }
  89. /**
  90. * @throws \Throwable
  91. * @throws \yii\db\StaleObjectException
  92. */
  93. public function afterDelete()
  94. {
  95. AttachmentNews::deleteAll(['attachment_id' => $this->id]);
  96. if ($this->media_type == AttachmentTypeEnum::NEWS) {
  97. Rule::deleteAll(['module' => $this->media_type, 'data' => $this->id]);
  98. // MassRecord::deleteAll(['module' => $this->media_type, 'data' => $this->id]);
  99. } else {
  100. Rule::deleteAll(['module' => $this->media_type, 'data' => $this->media_type]);
  101. // MassRecord::deleteAll(['module' => $this->media_type, 'data' => $this->media_type]);
  102. }
  103. parent::afterDelete();
  104. }
  105. }
粤ICP备19079148号