模型文件规范迁移到common模块

This commit is contained in:
Dev
2026-09-24 15:58:01 +08:00
parent df5809abdd
commit 36fb0ab1ee
9 changed files with 11 additions and 38 deletions
@@ -0,0 +1,53 @@
<?php
namespace app\common\model;
use think\Model;
class Developers extends Model
{
// 表名
protected $name = 'developers';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['0' => __('Status 0'), '1' => __('Status 1')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function user()
{
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
@@ -0,0 +1,60 @@
<?php
namespace app\common\model\auto;
use think\Model;
class Commands extends Model
{
protected $auto = ['full_text'];
// 表名
protected $name = 'auto_commands';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
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 ['0' => __('Status 0'), '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] : '';
}
protected function setFullTextAttr()
{
// general:docker-compose restart #重启容器-docker,compose
return sprintf('%s:%s #%s-%s', $this->type_id, $this->command, $this->note, $this->cmd_tags);
}
}
@@ -2,7 +2,7 @@
namespace app\common\service;
use app\admin\model\Developers;
use app\common\model\Developers;
use app\common\traits\ServiceTrait;
use Exception;
use think\Db;
@@ -0,0 +1,27 @@
<?php
namespace app\common\validate;
use think\Validate;
class Developers extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
@@ -0,0 +1,27 @@
<?php
namespace app\common\validate\auto;
use think\Validate;
class Commands extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}