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

defined('IN_UQ') or exit('Access Denied'); class goods_sku_uqcms extends control { function __construct() { $this->aid = $_SESSION['admin']['aid']; parent::__construct(); } public function index() { $uq0 = isset($_GET['pid'])?$_GET['pid']:'0'; $uq1 = $this->db->get_all("select * from ".table("category")); if($uq1){ foreach($uq1 as $uq2){ $uq3[$uq2['cid']] = $uq2['name']; } } $uq4 = ' where pid = '.$uq0; $uq5 = $this->db->get_all("select * from ".table('goods_sku').$uq4." order by id desc"); if($uq5){ foreach($uq5 as $uq6=>$uq2){ if($uq2['cid']){ if(isset($uq3[$uq2['cid']])){ $uq2['gcname'] = $uq3[$uq2['cid']]; } }else{ $uq2['gcname'] = '<span style="color:red;font-weight:bold;">公共</span>'; } $uq7[] = $uq2; } $uq8['list'] = $uq7; $this->assign('data', $uq8); } $this->display(); } public function edit() { $uq9 = !empty($_GET['id'])?$_GET['id']:''; if($uq9){ $uq10 = $this->module('goods_sku')->get_one($uq9); if($uq10['cid'] != 0){ $uq11 = $this->module('category')->get_parents_cid($uq10['cid']); $this->assign('update_cats',$uq11); } $this->assign('row',$uq10); } $this->display(); } public function save() { if($_POST){ $uq0 = !empty($_POST['pid'])?$_POST['pid']:'0'; if($uq0){ $uq8['cid'] = '0'; $uq8['pid'] = $uq0; }else{ $uq8['cid'] = isset($_POST['cid'])?$_POST['cid']:'0'; $uq8['pid'] = '0'; } $uq8['px'] = !empty($_POST['px'])?$_POST['px']:'0'; $uq9 = isset($_POST['id'])?$_POST['id']:false; $uq12 = P('name', '名称不能为空'); if($uq9){ $uq8['name'] = $uq12; $uq5 = $this->db->update(table('goods_sku'), $uq8,'id = '.$uq9); if($uq5){ right_json(); }else{ error_json('保存失败'); } }else{ $uq13 = explode(',', $uq12); $this->db->autocommit(); foreach($uq13 as $uq2){ $uq8['name'] = $uq2; $uq14 = $this->db->add(table('goods_sku'), $uq8); $uq15 = $this->db->insert_id(); if($uq14){ $uq16[] = ''; } } if((count($uq13) == count($uq16)) && (count($uq16) > '0')){ $this->db->commit(); $uq17['id'] = $uq15; right_json($uq17); }else{ $this->db->rollback(); error_json('保存失败'); } } }else{ error_json('提交错误'); } } public function del() { $uq9 = P('id', '提交编号错误'); $uq5 = $this->db->delete(table('goods_sku'),'id = '.$uq9); if($uq5){ right_json(); }else{ error_json('删除失败'); } } } 