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

defined('IN_UQ') or exit('Access Denied'); class goods_brand_uqcms extends control { public function index() { $uq0 = isset($_GET['cid'])?$_GET['cid']:''; $uq1 = ''; if($uq0){ $uq1 = ' cid = '.$uq0.' and '; } if(!empty($uq1)){ $uq1 = ' where '.rtrim($uq1,' and '); } $uq2 = $this->db->get_all("select * from ".table('category')); if($uq2){ foreach($uq2 as $uq3){ $uq4[$uq3['cid']] = $uq3['name']; } } $uq5 = $this->db->get_all("select * from ".table('goods_brand').$uq1." order by id desc ".$this->limit()); if($uq5){ foreach($uq5 as $uq6=>$uq3){ if($uq3['cid']){ $uq3['category_cn'] = $uq4[$uq3['cid']]; }else{ $uq3['category_cn'] = '未分类'; } $uq3['addtime'] = _date($uq3['addtime']); $uq7[] = $uq3; } $uq8['list'] = $uq7; $uq9 = $this->db->get_one("select count(id) as total from ".table('goods_brand')); $uq8['page'] = $this->page(['total'=>$uq9['total']]); $this->assign('data', $uq8); } $this->display(); } public function edit() { $uq10 = $_GET['id']??false; if($uq10){ $uq11 = $this->db->get_one("select * from ".table('goods_brand')." where id = ".$uq10); $this->assign('row', $uq11); } $this->display(); } public function save() { if($_POST){ $uq12 = P('name','品牌名称不能为空'); $uq8['cid'] = P('cid'); $uq8['images'] = P('images'); $uq8['describe'] = P('describe'); $uq8['px'] = P('px','','0'); $uq8['status'] = P('status','','0'); $uq8['addtime'] = time(); $uq10 = P('id',0); if($uq10){ $uq8['name'] = $uq12; $uq13 = $this->db->update(table('goods_brand'), $uq8, 'id = '.$uq10); }else{ $uq14 = explode(',', $uq12); $uq15 = 0; $uq16 = 0; $this->db->autocommit(); foreach($uq14 as $uq3){ $uq8['name'] = $uq3; $uq17 = $this->db->add(table('goods_brand'), $uq8); if($uq17){ $uq15 ++; } $uq16++; } if(($uq15 == $uq16) && ($uq15 > '0')){ $this->db->commit(); $uq13 = true; }else{ $this->db->rollback(); $uq13 = false; } } if($uq13){ right_json(); }else{ error_json('保存失败'); } }else{ error_json('提交错误'); } } public function del() { $uq10 = P('id', '提交编号错误'); $uq13 = $this->db->delete(table('goods_brand'),"id in(".$uq10.")"); if($uq13){ right_json(); }else{ error_json('删除失败'); } } public function status() { $uq10 = $_GET['id']??error_json('提交错误'); $uq11 = $this->db->get_one("select id,status from ".table('goods_brand')." where id = ".$uq10); if($uq11['id'] && ($uq11['status'] == '1')){ $uq13 = $this->db->update(table('goods_brand'), ['status'=>'0'], 'id = '.$uq10); }elseif($uq11['id'] && ($uq11['status'] == '0')){ $uq13 = $this->db->update(table('goods_brand'), ['status'=>'1'], 'id = '.$uq10); } if($uq13){ right_json(); }else{ error_json('设置失败'); } } } 