<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */

defined('IN_UQ') or exit('Access Denied'); class common_uqcms extends control { function __construct() { $this->aid = $_SESSION['admin']['aid']; parent::__construct(); } public function index() { $uq0 = $_GET['pid']??false; if($uq0){ $uq1 = ' where pid = '.$uq0; }else{ $uq1 = ' where pid = 0 '; } $uq2 = $this->db->get_all("select * from ".table('category_com').$uq1." order by px desc ".$this->limit()); if($uq2){ $uq3['list'] = $uq2; $this->assign('data',$uq3); } $this->display(); } public function edit() { $uq4 = $_GET['id']??false; if($uq4){ $uq5 = $this->db->get_one("select * from ".table('category_com')." where id = ".$uq4); $this->assign('row',$uq5); } $this->assign('cats', $this->func_pcats()); $this->display(); } public function save() { if($_POST){ $uq0 = P('pid'); if($uq0 == ''){ $uq6['pid'] = '0'; $uq6['alias'] = P('alias', '别名不能为空'); }else{ $uq6['pid'] = P('pid/i', '父级编号不能为空'); $uq6['link'] = P('link'); $uq6['alias']= P('alias'); } $uq6['name'] = P('name', '名称不能为空'); $uq6['px'] = P('px/i', '', '0'); $uq6['status'] = P('status', '', '1'); $uq4 = P('id/i', false); if($uq4){ $uq7 = $this->db->update(table('category_com'), $uq6, 'id = '.$uq4); }else{ $uq7 = $this->db->add(table('category_com'), $uq6); } if($uq7){ $uq3['error'] = '0'; echo json_encode($uq3); }else{ error_json('保存失败'); } }else{ error_json('提交错误'); } } private function func_pcats() { return $this->db->get_all("select * from ".table('category_com')." where pid = 0"); } public function del() { $uq4 = P('id/i', '提交编号错误'); $uq5 = $this->db->get_one("select * from ".table('category_com')." where id = ".$uq4); if($uq5['id']){ $uq8 = $this->db->get_one("select count(id) as total from ".table('category_com')." where pid = ".$uq5['id']); if($uq8['total'] == '0'){ $uq7 = $this->db->delete(table('category_com'), 'id = '.$uq4); if($uq7){ right_json(); }else{ error_json('删除失败'); } }else{ error_json('请先删除下级分类'); } }else{ error_json('分类不存在'); } } } 