更新代码,完善功能

This commit is contained in:
2020-02-18 14:50:57 +08:00
parent 31fd944b9c
commit 8bc0f7534b
36 changed files with 283 additions and 280 deletions

View File

@@ -12,44 +12,44 @@ namespace app\model;
/**
* 设置模型
*/
class Attribute {
class Attribute extends \think\Model {
protected $type = array(
'id' => 'integer',
);
protected static function init() {
self::afterInsert(function ($data) {
if ($data['model_id']) {
$name = db('Model')->where('id', $data['model_id'])->value('name');
$db = new \com\Datatable();
$attr = $data->toArray();
$model_attr = array(
'model_id' => $data['model_id'],
'attr_id' => $data->id,
'group_id' => 0,
'is_add_table' => 1,
'is_show' => $data['is_show'],
'is_must' => $data['is_must'],
'sort' => 0,
);
$attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
return $db->columField(strtolower($name), $attr)->query();
}
});
self::beforeUpdate(function ($data) {
$attr = $data->toArray();
$attr['action'] = 'CHANGE';
$attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
if ($attr['id']) {
$name = db('Model')->where('id', $attr['model_id'])->value('name');
$db = new \com\Datatable();
return $db->columField(strtolower($name), $attr)->query();
} else {
return false;
}
});
}
// protected static function init() {
// self::afterInsert(function ($data) {
// if ($data['model_id']) {
// $name = db('Model')->where('id', $data['model_id'])->value('name');
// $db = new \com\Datatable();
// $attr = $data->toArray();
// $model_attr = array(
// 'model_id' => $data['model_id'],
// 'attr_id' => $data->id,
// 'group_id' => 0,
// 'is_add_table' => 1,
// 'is_show' => $data['is_show'],
// 'is_must' => $data['is_must'],
// 'sort' => 0,
// );
// $attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
// return $db->columField(strtolower($name), $attr)->query();
// }
// });
// self::beforeUpdate(function ($data) {
// $attr = $data->toArray();
// $attr['action'] = 'CHANGE';
// $attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
// if ($attr['id']) {
// $name = db('Model')->where('id', $attr['model_id'])->value('name');
// $db = new \com\Datatable();
// return $db->columField(strtolower($name), $attr)->query();
// } else {
// return false;
// }
// });
// }
protected function getTypeTextAttr($value, $data) {
$type = config('config_type_list');