ControlAlarm.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace catchAdmin\alarm\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use catchAdmin\system\model\SysDictData;
  6. class ControlAlarm extends Model
  7. {
  8. use DataRangScopeTrait;
  9. // 表名
  10. public $name = 'control_alarm';
  11. // 数据库字段映射
  12. public $field = array(
  13. 'id',
  14. // 车牌
  15. 'plate_no',
  16. // 车辆标签
  17. 'rfid_sn',
  18. // 报警地点
  19. 'address',
  20. // 报警类型
  21. 'alarm_type',
  22. // 状态
  23. 'state',
  24. // 备注
  25. 'remark',
  26. // 创建人ID
  27. 'creator_id',
  28. // 创建时间
  29. 'created_at',
  30. // 更新时间
  31. 'updated_at',
  32. // 软删除
  33. 'deleted_at',
  34. );
  35. /**
  36. * 列表
  37. */
  38. public function getList()
  39. {
  40. $res=$this->dataRange()
  41. ->catchSearch()
  42. ->append(['state_text'])
  43. ->order($this->aliasField('id'), 'desc')
  44. ->paginate();
  45. return $res;
  46. }
  47. public function searchPlateNoAttr($query, $value, $data)
  48. {
  49. return $query->where('plate_no', 'like', '%' . $value . '%');
  50. }
  51. public function searchRfidSnAttr($query, $value, $data)
  52. {
  53. return $query->where('rfid_sn', 'like', '%' . $value . '%');
  54. }
  55. public function searchAlarmTypeAttr($query, $value, $data)
  56. {
  57. return $query->where('alarm_type', $value);
  58. }
  59. public function getStateTextAttr($value){
  60. $state = $this->getData('state');
  61. return (new SysDictData())->getValueByCode('AlarmHandleState', $state) ?: '';
  62. }
  63. public function getAlarmTypeAttr($value){
  64. return (new SysDictData())->getValueByCode('AlarmType', $value) ?: '';
  65. }
  66. }