StuckSection.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace catchAdmin\transport\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use think\facade\Db;
  6. class StuckSection extends Model
  7. {
  8. use DataRangScopeTrait;
  9. // 表名
  10. public $name = 'stuck_section';
  11. // 数据库字段映射
  12. public $field = array(
  13. 'id',
  14. // 名称
  15. 'name',
  16. // 前置卡点
  17. 'pre_spot',
  18. // 后置卡点
  19. 'pos_spot',
  20. // 区间长度
  21. 'distance',
  22. // 最大限速(km/h)
  23. 'max_speed',
  24. // 启用逆行状态
  25. 'retrograde_stat',
  26. // 启用超速状态
  27. 'over_speed_stat',
  28. // 创建人ID
  29. 'creator_id',
  30. // 创建时间
  31. 'created_at',
  32. // 更新时间
  33. 'updated_at',
  34. // 软删除
  35. 'deleted_at',
  36. );
  37. /**
  38. * 列表
  39. */
  40. public function getList()
  41. {
  42. $res=$this->dataRange()
  43. ->catchSearch()
  44. ->append(['pos_spot_text','pre_spot_text'])
  45. ->order($this->aliasField('id'), 'desc')
  46. ->paginate();
  47. return $res;
  48. }
  49. //根据name搜索
  50. public function searchNameAttr($query, $value, $data)
  51. {
  52. return $query->where('name', 'like', '%' . $value . '%');
  53. }
  54. public function getPosSpotTextAttr($value){
  55. $value=$this->getData('pos_spot');
  56. return Db::table('stuck_point')->where('id',$value)->value('name');
  57. }
  58. public function getPreSpotTextAttr($value){
  59. $value=$this->getData('pre_spot');
  60. return Db::table('stuck_point')->where('id',$value)->value('name');
  61. }
  62. public function getRetrogradeStatAttr($value){
  63. return $value?true:false;
  64. }
  65. public function getOverSpeedStatAttr($value){
  66. return $value?true:false;
  67. }
  68. public function getPreSpotAttr($value){
  69. return (string)$value;
  70. }
  71. public function getPosSpotAttr($value){
  72. return (string)$value;
  73. }
  74. public function getDistanceAttr($value){
  75. return (string)$value;
  76. }
  77. public function getMaxSpeedAttr($value){
  78. return (string)$value;
  79. }
  80. }