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

defined('IN_UQ') or exit('Access Denied'); class category_attr_uqcms extends control { function __construct() { $this->aid = $_SESSION['admin']['aid']; parent::__construct(); } public function index() { $uq0 = isset($_GET['id'])?$_GET['id']:'0'; $uq1 = $this->db->query("select * from ".table("category")); while($uq2 = $this->db->fetch_array($uq1)){ $uq3[$uq2['cid']] = $uq2['name']; } $uq4 = $this->db->get_all("select * from ".table('category_attr')." where pid = 0 order by id desc ".$this->limit()); if($uq4){ foreach($uq4 as $uq5=>$uq6){ if(isset($uq3[$uq6['cid']])){ $uq6['gcname'] = $uq3[$uq6['cid']]; }else{ $uq6['gcname'] = '未分类'; } $uq6['addtime'] = _date($uq6['addtime']); $uq7[] = $uq6; } $uq8['list'] = $uq7; $uq9 = $this->db->get_one("select count(*) as total from ".table('category_attr')." where pid = 0"); $uq8['page'] = $this->page(['total'=>$uq9['total']]); $this->assign('data', $uq8); } $this->display(); } public function edit() { $uq0 = !empty($_GET['id'])?$_GET['id']:false; if($uq0){ $uq10 = $this->module('category_attr')->get_one($uq0); $this->assign('row',$uq10); } $this->display('category_attr/edit'); } public function save() { $uq8['cid'] = P('cid', '', '0'); $uq8['pid'] = '0'; $uq11 = P('name', '名称不能为空'); $uq8['px'] = P('px', '', '0'); $uq8['addtime'] = time(); $uq0 = isset($_POST['id'])?$_POST['id']:false; if($uq0){ $uq8['name'] = $uq11; $uq4 = $this->db->update(table('category_attr'), $uq8, 'id = '.$uq0); }else{ $uq12 = explode(',', $uq11); $uq13 = 0; $uq14 = 0; $this->db->autocommit(); foreach($uq12 as $uq6){ $uq8['name'] = $uq6; $uq15 = $this->db->add(table('category_attr'),$uq8); if($uq15){ $uq13 ++; } $uq14++; } if(($uq13 == $uq14) && ($uq13 > '0')){ $this->db->commit(); $uq4 = true; }else{ $this->db->rollback(); $uq4 = false; } } if($uq4){ right_json(); }else{ error_json('保存失败'); } } public function child_index() { $uq16 = isset($_GET['pid'])?$_GET['pid']:showmsg('访问错误'); $uq4 = $this->db->get_all("select * from ".table('category_attr')." where pid = ".$uq16." order by id desc ".$this->limit()); if($uq4){ foreach($uq4 as $uq6){ $uq6['addtime'] = _date($uq6['addtime']); $uq7[] = $uq6; } $uq8['list'] = $uq7; $this->assign('data', $uq8); } $this->display(); } public function child_edit() { $uq0 = !empty($_GET['id'])?$_GET['id']:false; if($uq0){ $uq10 = $this->module('category_attr')->get_one($uq0); $this->assign('row',$uq10); } $this->display(); } public function child_save() { $uq8['pid'] = P('pid', '提交PID错误'); $uq8['px'] = P('px', '', '0'); $uq8['addtime'] = time(); $uq11 = P('name', '名称不能为空'); $uq0 = isset($_POST['id'])?$_POST['id']:false; if($uq0){ $uq8['name'] = $uq11; $uq4 = $this->db->update(table('category_attr'), $uq8, 'id = '.$uq0); }else{ $uq12 = explode(',', $uq11); $uq13 = 0; $uq14 = 0; $this->db->autocommit(); foreach($uq12 as $uq6){ $uq8['name'] = $uq6; $uq4 = $this->db->add(table('category_attr'),$uq8); if($uq4){ $uq13 ++; } $uq14++; } if(($uq13 == $uq14) && ($uq13 > '0')){ $this->db->commit(); $uq4 = true; }else{ $this->db->rollback(); $uq4 = false; } } if($uq4){ right_json(); }else{ error_json('保存失败'); } } public function del() { $uq0 = P('id', 'CID参数错误'); $uq10 = $this->db->get_one("select id,pid from ".table('category_attr')." where pid = ".$uq0." limit 1"); if($uq10){ if($uq10['id']){ error_json('该分类下还有数据'); }else{ $uq4 = $this->db->delete(table('category_attr'), 'id = '.$uq0); if($uq4){ right_json(); }else{ error_json('删除失败'); } } }else{ error_json('操作失败'); } } public function child_del() { $uq0 = P('id', '参数错误'); $uq4 = $this->db->delete(table('category_attr'), 'id = '.$uq0); if($uq4){ right_json(); }else{ error_json('删除失败'); } } } 