- 删除 Addon 相关控制器、模型、语言包和视图文件 - 新增服务类型支持一口价属性配置 - 新增系统监控、用户资料、订单评价等后端管理页面 - 新增数据库表结构及索引优化脚本 - 更新应用版本号至 1.0.44 - 更新小程序应用标识 - 完善 .gitignore 配置
71 行
1.7 KiB
PHP
71 行
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
|
|
class Service extends Model
|
|
{
|
|
// 表名
|
|
protected $name = 'service';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = 'updatetime';
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'price_type_text',
|
|
'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]]);
|
|
}
|
|
});
|
|
|
|
self::afterDelete(function ($row) {
|
|
$pk = $row->getPk();
|
|
Db::name('service_spec')->where('service_id', $row[$pk])->delete();
|
|
});
|
|
}
|
|
|
|
public function getPriceTypeList()
|
|
{
|
|
return ['fixed' => __('Fixed'), 'quote' => __('Quote'), 'range' => __('Range')];
|
|
}
|
|
|
|
public function getStatusList()
|
|
{
|
|
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
|
|
}
|
|
|
|
public function getPriceTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['price_type'] ?? '');
|
|
$list = $this->getPriceTypeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['status'] ?? '');
|
|
$list = $this->getStatusList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
public function cat()
|
|
{
|
|
return $this->belongsTo('app\\admin\\model\\service\\Cat', 'cat_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
|
}
|
|
}
|