InsureRecords.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace catchAdmin\yunying\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use catchAdmin\yunying\model\Vehicle;
  6. use catchAdmin\yunying\model\Insurance;
  7. use catchAdmin\permissions\model\Users;
  8. class InsureRecords extends Model
  9. {
  10. use DataRangScopeTrait;
  11. // 表名
  12. public $name = 'insure_records';
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. // 车辆id
  17. 'vehicle_id',
  18. // 保险id
  19. 'insurance_id',
  20. // 开始时间
  21. 'start_at',
  22. // 结束时间
  23. 'end_at',
  24. // 创建人ID
  25. 'creator_id',
  26. // 创建时间
  27. 'created_at',
  28. // 更新时间
  29. 'updated_at',
  30. // 软删除
  31. 'deleted_at',
  32. );
  33. /**
  34. * 获取车辆列表
  35. */
  36. public function getList()
  37. {
  38. $res = $this->dataRange()
  39. ->catchSearch()
  40. ->append(['creator_name', 'insurance_name', 'vehicle_plate'])
  41. ->order($this->aliasField('id'), 'desc')
  42. ->paginate();
  43. return $res;
  44. }
  45. /**
  46. * 获取保险记录导出列表
  47. */
  48. public function getInsureExportList()
  49. {
  50. $res = $this->dataRange()
  51. ->catchSearch()
  52. ->append(['creator_name', 'insurance_name'])
  53. ->order($this->aliasField('id'), 'desc')
  54. ->select();
  55. return $res;
  56. }
  57. //根据车牌搜索
  58. public function searchVehiclePlateAttr($query, $value, $data)
  59. {
  60. $value = (new Vehicle())->where('license_plate', $value)->value('id');
  61. return $query->where('vehicle_id', $value);
  62. }
  63. //根据保险搜索
  64. public function searchInsuranceNameAttr($query, $value, $data)
  65. {
  66. $value = (new Insurance())->where('name', $value)->value('id');
  67. return $query->where('insurance_id', $value);
  68. }
  69. //获取车牌号码
  70. public function getVehiclePlateAttr($value)
  71. {
  72. return (new Vehicle())->where('id', $this->getData('vehicle_id'))->value('license_plate');
  73. }
  74. //获取保险名称
  75. public function getInsuranceNameAttr($value)
  76. {
  77. return (new Insurance())->where('id', $this->getData('insurance_id'))->value('name');
  78. }
  79. //获取操作用户
  80. public function getCreatorNameAttr($value)
  81. {
  82. return (new Users())->where('id', $this->getData('creator_id'))->value('username');
  83. }
  84. //获取生效时间
  85. public function getStartAtAttr($value)
  86. {
  87. return date('Y-m-d H:i:s',$value);
  88. }
  89. //获取过期时间
  90. public function getEndAtAttr($value)
  91. {
  92. return date('Y-m-d H:i:s',$value);
  93. }
  94. }