getRow('SELECT * FROM `' . $db_mymps . 'goods` WHERE goodsid = \'' . $id . '\'');
if (empty($edit['goodsid'])) {
write_msg('该商品已不存在!');
}
$acontent = get_editor('content', '', $edit['content'], '100%', '400px');
} else {
$goodslevel = array(1 => '已上架', 2 => '已下架', 3 => '推荐', 4 => '热卖', 5 => '促销');
$goodsname = isset($goodsname) ? trim($goodsname) : '';
$userid = isset($userid) ? trim($userid) : '';
$catid = isset($catid) ? intval($catid) : '';
$where = ' WHERE 1';
$where .= $gname != '' ? ' AND a.goodsname LIKE \'%' . $goodsname . '%\'' : '';
$where .= $userid != '' ? ' AND a.userid = \'' . $userid . '\'' : '';
$where .= !empty($catid) ? ' AND a.catid IN(' . get_goods_children($catid) . ')' : '';
$where .= $type == 1 ? ' AND onsale = \'1\'' : '';
$where .= $type == 2 ? ' AND onsale = \'2\'' : '';
$where .= $type == 3 ? ' AND tuijian = \'1\'' : '';
$where .= $type == 4 ? ' AND remai = \'1\'' : '';
$where .= $type == 5 ? ' AND cuxiao = \'1\'' : '';
$rows_num = $db->getOne('SELECT COUNT(a.goodsid) FROM `' . $db_mymps . 'goods` AS a ' . $where);
$param = setParam(array('part', 'goodsname', 'userid', 'catid', 'type'));
$goods = page1('SELECT a.*,b.catname FROM `' . $db_mymps . 'goods` AS a LEFT JOIN `' . $db_mymps . 'goods_category` AS b ON a.catid = b.catid ' . $where . ' ORDER BY a.dateline DESC');
}
include mymps_tpl('goods_' . $part);
} else {
if ($part == 'list') {
if (empty($selectedids)) {
write_msg('您没有选中任何一个商品!');
}
$create_in = create_in($selectedids);
if (!$action || !in_array($action, array('delall', 'goodslevel1', 'goodslevel2', 'goodslevel3', 'goodslevel4', 'goodslevel5'))) {
write_msg('您尚未指定处理动作!');
}
if ($action == 'delall') {
$query = $db->query('SELECT * FROM `' . $db_mymps . 'goods` WHERE goodsid ' . $create_in);
while ($row = $db->fetchRow($query)) {
$delete[$row['id']]['picture'] = $row['picture'];
$delete[$row['id']]['pre_picture'] = $row['pre_picture'];
}
foreach ($delete as $k => $v) {
@unlink(MYMPS_ROOT . $v['picture']);
@unlink(MYMPS_ROOT . $v['pre_picture']);
}
$db->query('DELETE FROM `' . $db_mymps . 'goods` WHERE goodsid ' . $create_in);
unset($delete);
unset($row);
unset($query);
unset($create_in);
} else {
if (in_array($action, array('goodslevel1', 'goodslevel2', 'goodslevel3', 'goodslevel4', 'goodslevel5'))) {
switch ($action) {
case 'goodslevel1':
$db->query('UPDATE `' . $db_mymps . 'goods` SET onsale = \'1\' WHERE goodsid ' . $create_in);
break;
case 'goodslevel2':
$db->query('UPDATE `' . $db_mymps . 'goods` SET onsale = \'2\' WHERE goodsid ' . $create_in);
break;
case 'goodslevel3':
$db->query('UPDATE `' . $db_mymps . 'goods` SET tuijian = \'1\' WHERE goodsid ' . $create_in);
break;
case 'goodslevel4':
$db->query('UPDATE `' . $db_mymps . 'goods` SET remai = \'1\' WHERE goodsid ' . $create_in);
break;
case 'goodslevel5':
$db->query('UPDATE `' . $db_mymps . 'goods` SET cuxiao = \'1\' WHERE goodsid ' . $create_in);
break;
}
unset($create_in);
unset($action);
}
}
} else {
if ($part == 'edit') {
if (empty($id)) {
write_msg('商品编号不能为空!');
}
if (empty($goodsname)) {
write_msg('商品名称不能为空!');
}
if (empty($content)) {
write_msg('商品详情不能为空!');
}
$name_file = 'goods_image';
$catid = intval($catid);
if ($_FILES[$name_file]['name']) {
require_once MYMPS_INC . '/upfile.fun.php';
$destination = '/goods/' . date('Ym') . '/';
$mymps_image = start_upload($name_file, $destination, 0, $mymps_mymps['cfg_goods_limit']['width'], $mymps_mymps['cfg_goods_limit']['height'], $picture, $pre_picture);
$picture = $mymps_image[0];
$pre_picture = $mymps_image[1];
unset($mymps_image);
}
unset($name_file);
$db->query('UPDATE `' . $db_mymps . 'goods` SET goodsname=\'' . $goodsname . '\',content=\'' . $content . '\',catid=\'' . $catid . '\',picture=\'' . $picture . '\',pre_picture=\'' . $pre_picture . '\',dateline=\'' . $timestamp . '\',userid=\'' . $userid . '\',oldprice=\'' . $oldprice . '\',nowprice=\'' . $nowprice . '\',gift=\'' . $gift . '\',huoyuan=\'' . $huoyuan . '\',rushi=\'' . $rushi . '\',tuihuan=\'' . $tuihuan . '\',jiayi=\'' . $jiayi . '\',weixiu=\'' . $weixiu . '\',fahuo=\'' . $fahuo . '\',zhengpin=\'' . $zhengpin . '\',onsale=\'' . $onsale . '\',tuijian=\'' . $tuijian . '\',remai=\'' . $remai . '\',cuxiao=\'' . $cuxiao . '\',baozhang=\'' . $baozhang . '\' WHERE goodsid = \'' . $id . '\'');
$url = '?part=edit&id=' . $id;
}
}
write_msg('操作成功!', $url ? $url : '?part=list');
}