FacilityType.php 638 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. /**
  5. * FacilityType
  6. */
  7. class FacilityType extends Model
  8. {
  9. // 表名
  10. protected $name = 'facility_type';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = true;
  13. protected static function onAfterInsert($model)
  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. }