87 lines
1.9 KiB
PHP
87 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\admin\model;
|
||
|
|
|
||
|
|
use think\Model;
|
||
|
|
use think\model\concern\SoftDelete;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* pdm_partlist
|
||
|
|
* <!--partlist-->
|
||
|
|
* BOM查询
|
||
|
|
* Class PdmPartlist
|
||
|
|
* @package app\admin\model
|
||
|
|
*/
|
||
|
|
class PdmPartlist extends Model
|
||
|
|
{
|
||
|
|
|
||
|
|
use SoftDelete;
|
||
|
|
|
||
|
|
// 定义时间戳字段名
|
||
|
|
protected $createTime = 'create_time';
|
||
|
|
protected $updateTime = 'update_time';
|
||
|
|
protected $deleteTime = 'delete_time';
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 定义 sa_admin 关联模型
|
||
|
|
* @localKey creatorid
|
||
|
|
* @bind name,nickname
|
||
|
|
*/
|
||
|
|
public function admin()
|
||
|
|
{
|
||
|
|
return $this->hasOne(\app\common\model\system\Admin::Class,'id','creatorid')->bind(['name','nickname']);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 定义 sa_admin 关联模型
|
||
|
|
* @localKey creatorid
|
||
|
|
* @bind name,nickname
|
||
|
|
*/
|
||
|
|
public function partitemview()
|
||
|
|
{
|
||
|
|
return $this->hasOne(\app\admin\model\PdmPartitemView::Class,'partnumber','partnumber')->bind(['purchasecode','parttype','value','description','mpn','mfgname','footprint','manufacture']);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 字段修改器
|
||
|
|
public function setSortAttr($value)
|
||
|
|
{
|
||
|
|
if (is_empty($value)) {
|
||
|
|
return self::max('id') + 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $value;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取字典信息
|
||
|
|
* @param string $value
|
||
|
|
* @return array
|
||
|
|
* @throws DataNotFoundException
|
||
|
|
* @throws DbException
|
||
|
|
* @throws ModelNotFoundException
|
||
|
|
*/
|
||
|
|
public static function getValueList(string $value = ''): array
|
||
|
|
{
|
||
|
|
$list = [];
|
||
|
|
$data = self::where(['pid' => 0,'value' => $value])->find();
|
||
|
|
if (!empty($data)) {
|
||
|
|
$list = self::where('pid', $data['id'])->select()->toArray();
|
||
|
|
}
|
||
|
|
|
||
|
|
return $list;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 返回最小id
|
||
|
|
* @return int
|
||
|
|
*/
|
||
|
|
public static function minId(): int
|
||
|
|
{
|
||
|
|
return (int)self::where('pid', '0')->min('id');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|