12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\admin\model;
- use think\Model;
- /**
- * ServiceItem2
- */
- class ServiceItem2 extends Model
- {
- // 表名
- protected $name = 'service_item2';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- protected static function onAfterInsert($model)
- {
- 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]]);
- }
- }
- }
- public function admin()
- {
- return $this->belongsTo(\app\admin\model\Admin::class, 'user_id', 'id');
- }
- }
|