Model.php 730 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\extra\basic;
  3. class Model extends \think\Model
  4. {
  5. /**
  6. * 数据操作
  7. * @param array $data
  8. * @param string $id
  9. * @return bool|int
  10. */
  11. public function setAutoData(array $data = [],string $id = "id"): bool|int
  12. {
  13. try {
  14. if (isset($data[$id]) && $this->where($id,$data[$id])->count()) {
  15. $state = $this->where($id,$data[$id])->strict(false)->update($data);
  16. } else {
  17. $state = $this->strict(false)->insertGetId($data);
  18. }
  19. } catch (\Throwable $throwable) {
  20. echo $throwable->getMessage()."\n";
  21. return false;
  22. }
  23. return $state;
  24. }
  25. }