1234567891011121314151617181920212223242526272829 |
- <?php
- namespace app\admin\model\dict;
- use think\Model;
- /**
- * Commondata
- */
- class Commondata extends Model
- {
- // 表名
- protected $name = 'dict_common_data';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'datetime';
- protected static function onAfterInsert($model): void
- {
- if ($model->weigh == 0) {
- $pk = $model->getPk();
- if (strlen($model[$pk]) >= 19) {
- $model->where($pk, $model[$pk])->update(['weigh' => $model->count()]);
- } else {
- $model->where($pk, $model[$pk])->update(['weigh' => $model[$pk]]);
- }
- }
- }
- }
|