post(); $data['org_id'] = cur_org_id(); $result = validate('AssetCate')->check($data,[],'add'); if(true !== $result){ $this->error = validate('AssetCate')->getError(); return false; } $data['create_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($data); if(!$ret){ $this->error = '操作失败'; return false; } return true; } public function editSave(){ $data = request()->post(); $result = validate('AssetCate')->check($data,[],'edit'); if(true !== $result){ $this->error = validate('AssetCate')->getError(); return false; } $data['update_time'] = date('Y-m-d H:i:s'); $id = $data['id']; unset($data['id']); $ret = $this->allowField(true)->save($data,['id'=>$id]); if(!$ret){ $this->error = '操作失败'; return false; } return true; } public function showAllTree(){ $lists = Db::name('asset_cate')->field('id,title,parent_id')->where('org_id',cur_org_id())->order('id asc')->select(); if (empty($lists)) { return array(); } $tree = []; if($lists){ $tree = Phptree::makeTree(($lists), array( 'primary_key'=>'id', 'parent_key'=>'parent_id', 'expanded' => true )); } return $tree; } public function formatAllTree(){ $lists = Db::name('asset_cate')->field('id as value,title as label,parent_id')->where('org_id',cur_org_id())->order('id asc')->select(); if (empty($lists)) { return array(); } $tree = []; if($lists){ $tree = Phptree::makeTree(($lists), array( 'primary_key'=>'id', 'parent_key'=>'parent_id', 'expanded' => true )); } return $tree; } }