12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\common\model;
- use think\Db;
- use tools\Phptree;
- class AssetCate extends Base
- {
- public function addSave(){
- $data = request()->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;
- }
- }
|