1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /*
- * @Descripttion:
- * @version: 1.0.0
- * @Author: likang
- * @Date: 2022-05-27 13:34:31
- * @LastEditors: likang
- * @LastEditTime: 2022-06-25 16:36:52
- */
- namespace catchAdmin\hydraulic\model;
- use catcher\base\CatchModel as Model;
- use catchAdmin\system\model\SysDictData;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use \think\facade\Db;
- class DeviceMold extends Model
- {
- use DataRangScopeTrait;
- // 表名
- public $name = 'device_mold';
- // 数据库字段映射
- public $field = array(
- 'id',
- // 设备类型
- 'device_type',
- // 设备型号
- 'name',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- );
- /**
- * 获取列表
- */
- public function getList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['device_type_name','creator_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('DeviceType', $value) ?: '';
- }
- /**
- * 获取导入用户(文本)
- */
- public function getCreatorNameAttr($value)
- {
- $uid = $this->creator_id;
- return Db::table('users')->where('id', $uid)->value('username') ?: '';
- }
- }
|