Attachment.php 746 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Attachment extends Model
  5. {
  6. // 开启自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. // 定义字段类型
  12. protected $type = [
  13. ];
  14. public function setUploadtimeAttr($value)
  15. {
  16. return is_numeric($value) ? $value : strtotime($value);
  17. }
  18. protected static function init()
  19. {
  20. // 如果已经上传该资源,则不再记录
  21. self::beforeInsert(function ($model) {
  22. if (self::where('url', '=', $model['url'])->find()) {
  23. return false;
  24. }
  25. });
  26. }
  27. }