Commondata.php 654 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\admin\model\dict;
  3. use think\Model;
  4. /**
  5. * Commondata
  6. */
  7. class Commondata extends Model
  8. {
  9. // 表名
  10. protected $name = 'dict_common_data';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'datetime';
  13. protected static function onAfterInsert($model): void
  14. {
  15. if ($model->weigh == 0) {
  16. $pk = $model->getPk();
  17. if (strlen($model[$pk]) >= 19) {
  18. $model->where($pk, $model[$pk])->update(['weigh' => $model->count()]);
  19. } else {
  20. $model->where($pk, $model[$pk])->update(['weigh' => $model[$pk]]);
  21. }
  22. }
  23. }
  24. }