123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace catchAdmin\yunying\model;
- use catchAdmin\permissions\controller\User;
- use catcher\base\CatchModel as Model;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use catchAdmin\permissions\model\Department;
- use catchAdmin\permissions\model\Users;
- use catchAdmin\yunying\model\VehicleBrand;
- use catchAdmin\yunying\model\VehicleColor;
- use catchAdmin\yunying\model\StolenVehicle;
- class Vehicle extends Model
- {
- use DataRangScopeTrait;
-
- public $name = 'vehicles';
-
- public $field = array(
- 'id',
-
- 'license_plate',
-
- 'department_id',
-
- 'user_id',
-
- 'license_time',
-
- 'frame_number',
-
- 'motor_number',
-
- 'brand_id',
-
- 'color_id',
- 'car_type',
- 'rfid_sn',
- 'installer',
-
- 'remark',
-
- 'buydate',
-
- 'open_user_id',
-
- 'creator_id',
-
- 'created_at',
-
- 'updated_at',
-
- 'deleted_at',
- );
-
- public function getVehicleList($field, $order)
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['depart_name', 'vehicle_state', 'owner', 'brand_name', 'color_name', 'open_user_name'])
- ->order($this->aliasField($field), $order)
- ->paginate();
- return $res;
- }
-
- public function getVehiclesExportList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['depart_name', 'vehicle_state', 'owner', 'brand_name', 'color_name', 'open_user_name'])
- ->order($this->aliasField('id'), 'desc')
- ->select();
- return $res;
- }
-
- public function searchDepartmentIdAttr($query, $value, $data)
- {
- if (count($value)) {
- $value = $value[count($value) - 1];
- return $query->where('department_id', $value);
- } else {
- return $query;
- }
- }
-
- public function searchLicensePlateAttr($query, $value, $data)
- {
- return $query->where('license_plate', 'like', '%' . $value . '%');
- }
-
- public function searchFrameNumberAttr($query, $value, $data)
- {
- return $query->where('frame_number', 'like', '%' . $value . '%');
- }
-
- public function searchMotorNumberAttr($query, $value, $data)
- {
- return $query->where('motor_number', 'like', '%' . $value . '%');
- }
-
- public function searchLicenseTimeAttr($query, $value, $data)
- {
- if (empty($value)) {
- return $query;
- }
- return $query->where('license_time', 'between', $value);
- }
-
- public function getDepartNameAttr($value)
- {
- $depart_id = $this->getData('department_id');
- return (new Department)->where('id', $depart_id)->value('department_name');
- }
-
- public function getOwnerAttr($value)
- {
- $uid = $this->getData('user_id');
- return (new Users)->where('id', $uid)->value('realname');
- }
-
- public function getOpenUserNameAttr($value)
- {
- $uid = $this->getData('open_user_id');
- return (new Users)->where('id', $uid)->value('username');
- }
-
- public function getBrandNameAttr($value)
- {
- $bid = $this->getData('brand_id');
- return (new VehicleBrand())->where('id', $bid)->value('name');
- }
-
- public function getColorNameAttr($value)
- {
- $cid = $this->getData('color_id');
- return (new VehicleColor())->where('id', $cid)->value('name');
- }
-
- public function getVehicleStateAttr($value)
- {
- $id = $this->getData('id');
- $stolen_info = (new StolenVehicle())->where('vehicle_id', $id)->find();
- if (!$stolen_info || in_array($stolen_info['result'], [2, 4])) {
- $value = 0;
- } else {
- $value = 1;
- }
- return $value;
- }
- }
|