FlightPlan.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\common\model;
  3. use think\model;
  4. class FlightPlan extends model
  5. {
  6. // 表名
  7. protected $name = 'flight_plan';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. protected $createTime = 'createtime';
  11. protected $updateTime = false;
  12. protected $deleteTime = false;
  13. public function setCityAttr($value): string
  14. {
  15. return is_array($value) ? implode(',', $value) : $value;
  16. }
  17. public function getCityTextAttr($value, $row): string
  18. {
  19. if ($row['city'] === '' || $row['city'] === null) return '';
  20. $cityNames = \think\facade\Db::name('area')->whereIn('id', $row['city'])->column('name');
  21. return $cityNames ? implode(',', $cityNames) : '';
  22. }
  23. public function unique($field, $msg = '')
  24. {
  25. $map = [];
  26. foreach ($field as $key => $val) {
  27. if (is_numeric($key)) {
  28. $map[$val] = $this->data[$val];
  29. } else {
  30. $map[$key] = $val;
  31. }
  32. }
  33. $result = $this->where($map)->find();
  34. if ($result) {
  35. $this->error = $msg ?: '数据已存在';
  36. return false;
  37. }
  38. return true;
  39. }
  40. }