关于最完整的ecshop删除商品函数记录
2016-09-11 20:38 来源:www.chinab4c.com 作者:ecshop专家
/**
* 从回收站删除多个商品
* @param mix $goods_id 商品id列表:可以逗号格开,也可以是数组
* @return void
*/
function delete_goods($goods_id)
{
if (empty($goods_id))
{
return;
}
/* 取得有效商品id */
$sql = "SELECT DISTINCT goods_id FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($goods_id) . " AND is_delete = 1";
$goods_id = $GLOBALS['db']->getCol($sql);
if (empty($goods_id))
{
return;
}
/* 删除商品图片和轮播图片文件 */
$sql = "SELECT goods_thumb, goods_img, original_img " .
"FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($goods_id);
$res = $GLOBALS['db']->query($sql);
while ($goods = $GLOBALS['db']->fetchRow($res))
{
if (!empty($goods['goods_thumb']))
{
@unlink('../' . $goods['goods_thumb']); // 节约空间
}
if (!empty($goods['goods_img']))
{
@unlink('../' . $goods['goods_img']);
}
if (!empty($goods['original_img']))
{
@unlink('../' . $goods['original_img']);
}
}
/* 删除商品 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods') .
" WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
/* 删除商品的货品记录 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('products') .
" WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
/* 删除商品相册的图片文件 */
$sql = "SELECT img_url, thumb_url, img_original " .
"FROM " . $GLOBALS['ecs']->table('goods_gallery') .
" WHERE goods_id " . db_create_in($goods_id);
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
if (!empty($row['img_url']))
{
@unlink('../' . $row['img_url']);
}
if (!empty($row['thumb_url']))
{
@unlink('../' . $row['thumb_url']);
}
if (!empty($row['img_original']))
{
@unlink('../' . $row['img_original']);
}
}
/* 删除商品相册 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_gallery') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
/* 删除相关表记录 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('collect_goods') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_article') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_cat') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('member_price') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE parent_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('link_goods') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('link_goods') . " WHERE link_goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('tag') . " WHERE goods_id " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('comment') . " WHERE comment_type = 0 AND id_value " . db_create_in($goods_id);
$GLOBALS['db']->query($sql);
/* 删除相应虚拟商品记录 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('virtual_card') . " WHERE goods_id " . db_create_in($goods_id);
if (!$GLOBALS['db']->query($sql, 'SILENT') && $GLOBALS['db']->errno() != 1146)
{
die($GLOBALS['db']->error());
}
/* 清除缓存 */
clear_cache_files();
}
竟然删了这么多东西
最近更新
常用插件
- ecshop2.7.1邮件发送插件
ecshop2.7.1邮件发送插件:该插件主要的开发思想是源于ecshop短信发送系统...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...
- ecshop二次开发商品购买增
图片1香...
- ecshop最小购买数量控制插
ecshop最小购买数量控制插件,这个插件主要是为我们提供一个十分方便...
- ecshop2.7.2生成虚拟订单2.
以前我们开发过ecshop下的虚拟订单,就是客户在访问的时候,会自动生...