2024-11-07 18:11:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\model\school\classes;
|
|
|
|
|
2024-11-15 18:26:03 +08:00
|
|
|
use app\common\model\BaseModel;
|
2024-11-07 18:11:08 +08:00
|
|
|
use think\Model;
|
|
|
|
use traits\model\SoftDelete;
|
|
|
|
|
2024-11-15 18:26:03 +08:00
|
|
|
class Label extends BaseModel
|
2024-11-07 18:11:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
use SoftDelete;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
|
|
protected $name = 'school_classes_label';
|
|
|
|
|
|
|
|
// 自动写入时间戳字段
|
|
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
|
|
|
|
// 定义时间戳字段名
|
|
|
|
protected $createTime = 'createtime';
|
|
|
|
protected $updateTime = 'updatetime';
|
|
|
|
protected $deleteTime = 'deletetime';
|
|
|
|
|
|
|
|
// 追加属性
|
|
|
|
protected $append = [
|
|
|
|
'status_text'
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
protected static function init()
|
|
|
|
{
|
|
|
|
self::afterInsert(function ($row) {
|
|
|
|
if (!$row['weigh']) {
|
|
|
|
$pk = $row->getPk();
|
|
|
|
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getStatusList()
|
|
|
|
{
|
|
|
|
return ['1' => __('Status 1'), '2' => __('Status 2')];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
|
|
{
|
|
|
|
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
|
|
|
$list = $this->getStatusList();
|
|
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-15 18:26:03 +08:00
|
|
|
/**得到基础条件
|
|
|
|
* @param $status
|
|
|
|
* @param null $model
|
|
|
|
* @param string $alisa
|
|
|
|
*/
|
|
|
|
public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!$model) {
|
|
|
|
$model = new static;
|
|
|
|
if ($alisa&&!$with) $model = $model->alias($alisa);
|
|
|
|
}
|
|
|
|
if ($alisa) $alisa = $alisa . '.';
|
|
|
|
$tableFields = (new static)->getTableFields();
|
|
|
|
foreach ($tableFields as $fields)
|
|
|
|
{
|
|
|
|
if(in_array($fields, ['status']))continue;
|
|
|
|
// if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
|
|
|
|
|
|
|
|
if (isset($whereData[$fields]) && $whereData[$fields]){
|
|
|
|
if(is_array($whereData[$fields])){
|
|
|
|
$model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]);
|
|
|
|
}else{
|
|
|
|
$model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (isset($whereData['status'])) $model = $model->where("{$alisa}status", 'in', $whereData['status']);
|
|
|
|
if (isset($whereData['keywords'])&&$whereData['keywords']) $model = $model->where("{$alisa}id|{$alisa}name", 'Like', "%{$whereData['keywords']}%");
|
|
|
|
if (isset($whereData['time'])&&$whereData['time']){
|
|
|
|
$model = $model->time($whereData['time']);
|
|
|
|
}
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function showList($page, $limit,$keywords){
|
|
|
|
$field = ['*'];
|
|
|
|
$sort = "weigh desc,id desc";
|
|
|
|
$serch_where = ['keywords'=>$keywords,"status"=>"1"];
|
|
|
|
return (new self)->getBaseList($serch_where, $page, $limit,$sort,$field);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-07 18:11:08 +08:00
|
|
|
|
|
|
|
}
|