FlightPlan.php 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. /**
  5. * FlightPlan
  6. */
  7. class FlightPlan extends Model
  8. {
  9. // 表名
  10. protected $name = 'flight_plan';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = false;
  13. // 追加属性
  14. protected $append = [
  15. 'city_text',
  16. ];
  17. public function getCityAttr($value): array
  18. {
  19. if ($value === '' || $value === null) return [];
  20. if (!is_array($value)) {
  21. return explode(',', $value);
  22. }
  23. return $value;
  24. }
  25. public function setCityAttr($value): string
  26. {
  27. return is_array($value) ? implode(',', $value) : $value;
  28. }
  29. public function getCityTextAttr($value, $row): string
  30. {
  31. if ($row['city'] === '' || $row['city'] === null) return '';
  32. $cityNames = \think\facade\Db::name('area')->whereIn('id', $row['city'])->column('name');
  33. return $cityNames ? implode(',', $cityNames) : '';
  34. }
  35. }