1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace catchAdmin\yunying\model;
- use catcher\base\CatchModel as Model;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use catchAdmin\yunying\model\Vehicle;
- use catchAdmin\yunying\model\Insurance;
- use catchAdmin\permissions\model\Users;
- class InsureRecords extends Model
- {
- use DataRangScopeTrait;
- // 表名
- public $name = 'insure_records';
- // 数据库字段映射
- public $field = array(
- 'id',
- // 车辆id
- 'vehicle_id',
- // 保险id
- 'insurance_id',
- // 开始时间
- 'start_at',
- // 结束时间
- 'end_at',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- );
- /**
- * 获取车辆列表
- */
- public function getList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['creator_name', 'insurance_name', 'vehicle_plate'])
- ->order($this->aliasField('id'), 'desc')
- ->paginate();
- return $res;
- }
- /**
- * 获取保险记录导出列表
- */
- public function getInsureExportList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['creator_name', 'insurance_name'])
- ->order($this->aliasField('id'), 'desc')
- ->select();
- return $res;
- }
- //根据车牌搜索
- public function searchVehiclePlateAttr($query, $value, $data)
- {
- $value = (new Vehicle())->where('license_plate', $value)->value('id');
- return $query->where('vehicle_id', $value);
- }
- //根据保险搜索
- public function searchInsuranceNameAttr($query, $value, $data)
- {
- $value = (new Insurance())->where('name', $value)->value('id');
- return $query->where('insurance_id', $value);
- }
- //获取车牌号码
- public function getVehiclePlateAttr($value)
- {
- return (new Vehicle())->where('id', $this->getData('vehicle_id'))->value('license_plate');
- }
- //获取保险名称
- public function getInsuranceNameAttr($value)
- {
- return (new Insurance())->where('id', $this->getData('insurance_id'))->value('name');
- }
- //获取操作用户
- public function getCreatorNameAttr($value)
- {
- return (new Users())->where('id', $this->getData('creator_id'))->value('username');
- }
- //获取生效时间
- public function getStartAtAttr($value)
- {
- return date('Y-m-d H:i:s',$value);
- }
- //获取过期时间
- public function getEndAtAttr($value)
- {
- return date('Y-m-d H:i:s',$value);
- }
- }
|