123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace catchAdmin\hydraulic\model;
- use catchAdmin\api\Listen;
- use catcher\base\CatchModel as Model;
- use catchAdmin\system\model\SysDictData;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use \think\facade\Db;
- class maintenancemapper extends Model
- {
- use Listen;
- use DataRangScopeTrait;
- // 表名
- public $name = 'maintenance_mapper';
- // 数据库字段映射
- public $field = array(
- 'id',
- // 设备类型
- 'device_type',
- // 唯一值
- 'value',
- // 名称
- 'name',
- //部件
- 'parts',
- //风机型号
- 'fan_model',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- );
- /**
- * 获取列表
- */
- public function getList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['device_type_name', 'creator_name', 'fan_model_name'])
- ->order($this->aliasField('id'), 'desc')
- ->paginate();
- return $res;
- }
- /**
- * 名称搜索
- */
- public function searchNameAttr($query, $value, $data)
- {
- return $query->where('name', 'like', '%' . $value . '%');
- }
- /**
- * 设备类型搜索
- */
- public function searchDeviceTypeAttr($query, $value, $data)
- {
- return $query->where('device_type', '=', $value);
- }
- /**
- * 设备类型名称
- */
- public function getDeviceTypeNameAttr()
- {
- $value = $this->getData('device_type');
- return (new SysDictData())->getValueByCode('Maintenance', $value) ?: '';
- }
- public function getFanModelAttr()
- {
- $value = $this->getData('fan_model');
- return $value ? intval($value) : null;
- }
- public function getFanModelNameAttr()
- {
- $value = $this->getData('fan_model');
- $where[] = ['device_type', '=', 4];
- $where[] = ['id', '=', $value];
- $name = Db::name('device_mold')->where($where)->value('name');
- return $name;
- }
- //下发数据 工作部件/工作位置
- public function addContent(&$obj)
- {
- //var_dump($obj);
- $data = null;
- $content = null;
- if ($obj->device_type == 1) {
- $data = [
- 'id' => $obj->id,
- 'name' => $obj['name'],
- ];
- $content['data'] = $data;
- $content['type'] = 'WorkingParts';
- } else if ($obj->device_type == 2) {
- $fmodel = Db::name('device_mold')->where('id', $obj->fan_model)->value('name');
- $parts = $this->where('device_type', 1)->where('value', $obj->parts)->value('name');
- $data = [
- 'id' => $obj->id,
- 'fmodel' => $fmodel ? $fmodel : '',
- 'name' => $obj['name'],
- 'Parts' => $parts ? $parts : ''
- ];
- $content['data'] = $data;
- $content['type'] = 'WorkingPosition';
- } else {
- $content['is_filter'] = true;
- }
- return $content;
- }
- }
|