1、修复几处bug;
2、完善内容管理中的细节功能
This commit is contained in:
@@ -22,26 +22,32 @@ class Attribute extends \think\Model {
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
/**
|
||||
* @title 新增后事件
|
||||
*/
|
||||
protected static function onAfterInsert($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
$db = new \com\Datatable();
|
||||
$name = Models::where('id', $data['model_id'])->value('name');
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id desc')->value('name');
|
||||
return $db->columField(strtolower($name), $data)->query();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新后事件
|
||||
*/
|
||||
protected static function onAfterUpdate($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
if (isset($data['model_id']) && isset($data['name'])) {
|
||||
$tablename = Models::where('id', $data['model_id'])->value('name');
|
||||
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
if ($db->CheckField($tablename, $data['name'])) {
|
||||
$data['action'] = 'CHANGE';
|
||||
}
|
||||
$data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('sort asc, id asc')->value('name');
|
||||
$result = $db->columField(strtolower($tablename), $data)->query();
|
||||
return $result;
|
||||
}else{
|
||||
@@ -49,6 +55,9 @@ class Attribute extends \think\Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除后事件
|
||||
*/
|
||||
protected static function onAfterDelete($data){
|
||||
$data = $data->toArray();
|
||||
if ($data['model_id']) {
|
||||
@@ -94,9 +103,14 @@ class Attribute extends \think\Model {
|
||||
}elseif($data['type'] == 'bool'){
|
||||
$list = [['key'=>0,'label'=>'禁用'],['key'=>1,'label'=>'启用']];
|
||||
}elseif($data['type'] == 'bind'){
|
||||
$map = [];
|
||||
$db = new \com\Datatable();
|
||||
if (strrpos($data['extra'], ":")) {
|
||||
$extra = explode(":", $data['extra']);
|
||||
$row = Db::name($extra[0])->select()->toArray();
|
||||
if ($db->CheckField($extra[0], 'model_id')) {
|
||||
$map[] = ['model_id', '=', $data['model_id']];
|
||||
}
|
||||
$row = Db::name($extra[0])->where($map)->select()->toArray();
|
||||
if ($extra[1] == 'tree') {
|
||||
$row = (new Tree())->toFormatTree($row);
|
||||
foreach ($row as $val) {
|
||||
@@ -108,7 +122,10 @@ class Attribute extends \think\Model {
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$row = Db::name($data['extra'])->select()->toArray();
|
||||
if ($db->CheckField($data['extra'], 'model_id')) {
|
||||
$map[] = ['model_id', '=', $data['model_id']];
|
||||
}
|
||||
$row = Db::name($data['extra'])->select($map)->toArray();
|
||||
foreach ($row as $val) {
|
||||
$list[] = ['key'=>$val['id'], 'label'=>$val['title']];
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ class Category extends \think\Model{
|
||||
'icon' => 'integer',
|
||||
);
|
||||
|
||||
protected static function onAfterUpdate($model){
|
||||
$data = $model->toArray();
|
||||
}
|
||||
|
||||
public static function getCategoryTree($map = []){
|
||||
$list = self::where($map)->select();
|
||||
|
||||
@@ -31,22 +35,6 @@ class Category extends \think\Model{
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function change() {
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data, array('id' => $data['id']));
|
||||
} else {
|
||||
unset($data['id']);
|
||||
$result = $this->save($data);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function info($id, $field = true) {
|
||||
return $this->db()->where(array('id' => $id))->field($field)->find();
|
||||
}
|
||||
|
||||
@@ -69,19 +69,28 @@ class Model extends \think\Model{
|
||||
}
|
||||
|
||||
protected static function onAfterUpdate($data){
|
||||
$data = $data->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
$attr = [];
|
||||
if (!empty($attribute_sort)) {
|
||||
foreach ($attribute_sort as $key => $value) {
|
||||
$attr[$key] = Attribute::where('id', 'IN', $value)->column('*', 'id');
|
||||
foreach ($value as $k => $v) {
|
||||
$attr[] = ['id' => $v, 'group_id' => $key, 'sort' => $k];
|
||||
$attr[$key][$v]['group'] = $key;
|
||||
$attr[$key][$v]['sort'] = $k;
|
||||
}
|
||||
}
|
||||
}
|
||||
$save = [];
|
||||
foreach($attr as $value){
|
||||
if(!empty($value)){
|
||||
$save = array_merge($save, $value);
|
||||
}
|
||||
}
|
||||
if (!empty($attr)) {
|
||||
(new Attribute())->saveAll($attr);
|
||||
(new Attribute())->saveAll($save);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user