You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommonModel.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class CommonModel extends Model
  5. {
  6. public function itemsByIds($ids)
  7. {
  8. $return = [];
  9. if (empty($ids)) return $return;
  10. $data = $this->whereIn($this->pk, $ids)->select();
  11. foreach ($data as $val) {
  12. $return[$val[$this->pk]] = $val;
  13. }
  14. return $return;
  15. }
  16. /**
  17. * 模型写入前事件(钩子函数)
  18. */
  19. public static function onBeforeInsert($model)
  20. {
  21. $model->set("add_time", request()->time());
  22. $model->set("add_ip", request()->ip());
  23. }
  24. public function getAddTimeFormatAttr($value,$data)
  25. {
  26. return $data['add_time'] > 0 ? date('Y-m-d H:i:s',$data['add_time']) : '-';
  27. }
  28. public function getSmallAddTimeFormatAttr($value,$data)
  29. {
  30. return $data['add_time'] > 0 ? date('Y-m-d',$data['add_time']) : '-';
  31. }
  32. public function getLastTimeFormatAttr($value,$data){
  33. return $data['last_time'] > 0 ? date('Y-m-d H:i:s',$data['last_time']) : '-';
  34. }
  35. }