post(); $data['org_id'] = cur_org_id(); // if (isset($data['dep'])){ // if ($data['dep'] == '[]'||$data['dep'] == '""') // { // $data['dep'] = ''; // } // } // if (isset($data['address'])){ if ($data['address'] == '0' || $data['address'] == '[]'){ $data['address'] = ''; } } if (($data['parent_id'] != '0')){ $result = validate('EnergyElectricity')->check($data,[],'add1'); }else{ $result = validate('EnergyElectricity')->check($data,[],'add2'); } if(true !== $result){ $this->error = validate('EnergyElectricity')->getError(); return false; } if (isset($data['percent']) && $data['percent']){ $data['percent'] = str_replace(':',':',$data['percent']); } $id = $data['id']; unset($data['id']); if($id > 0){ $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $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 showAllTree(){ $map['enable'] = 1; $map['del'] = 0; $map['org_id'] = cur_org_id(); //部门的就不显示了 $lists = Db::name('energy_electricity')->where($map)->where('del',0)->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; } }