Index.php 801 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\model\content\article;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Index extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'article';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. if (!$row['sort']) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['sort' => $row[$pk]]);
  25. }
  26. });
  27. }
  28. }