1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?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 = 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 = Phptree::makeTree(($lists), array(
- 'primary_key'=>'value',
- 'parent_key'=>'parent_id',
- 'expanded' => true
- ));
- return $tree;
- }
- }
|