delDirAndFile("$dirName/$item", false); else @unlink("$dirName/$item"); } } closedir($handle); if (!$subdir) @rmdir($dirName); } } /** * 替换域名 * @param string $url * @return mixed */ public function replaceSiteUrl(string $url) { $siteUrl = sys_config('site_url'); $siteUrlJosn = str_replace('://', ':\\\/\\\/', $siteUrl); $valueJosn = str_replace('://', ':\\\/\\\/', $url); $prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix'); $sql = [ "UPDATE `{$prefix}system_attachment` SET `att_dir` = replace(att_dir ,'{$siteUrl}','{$url}'),`satt_dir` = replace(satt_dir ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}store_product` SET `image` = replace(image ,'{$siteUrl}','{$url}'),`slider_image` = replace(slider_image ,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}store_product_attr_value` SET `image` = replace(image ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}store_seckill` SET `image` = replace(image ,'{$siteUrl}','{$url}'),`images` = replace(images,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}store_combination` SET `image` = replace(image ,'{$siteUrl}','{$url}'),`images` = replace(images,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}store_bargain` SET `image` = replace(image ,'{$siteUrl}','{$url}'),`images` = replace(images,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}system_config` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}article_category` SET `image` = replace(`image` ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}article` SET `image_input` = replace(`image_input` ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}article_content` SET `content` = replace(`content` ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}store_product_category` SET `pic` = replace(`pic` ,'{$siteUrl}','{$url}')", "UPDATE `{$prefix}system_group_data` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')", "UPDATE `{$prefix}store_product_description` SET `description`= replace(description,'{$siteUrl}','{$url}')" ]; return $this->transaction(function () use ($sql) { try { foreach ($sql as $item) { Db::execute($item); } } catch (\Throwable $e) { throw new AdminException('替换失败,失败原因:' . $e->getMessage()); } }); } /** * 回收站商品彻底删除 * @param array $ids 商品ID数组 * @return bool */ public function recycleProduct(array $ids) { $product = app()->make(StoreProductServices::class); //清除规格表数据 /** @var StoreProductAttrServices $ProductAttr */ $productAttr = app()->make(StoreProductAttrServices::class); $productAttr->delete([['product_id', 'in', $ids], ['type', '=', '0']]); /** @var StoreProductAttrResultServices $productAttrResult */ $productAttrResult = app()->make(StoreProductAttrResultServices::class); $productAttrResult->delete([['product_id', 'in', $ids], ['type', '=', '0']]); /** @var StoreProductAttrValueServices $productAttrValue */ $productAttrValue = app()->make(StoreProductAttrValueServices::class); $productAttrValue->delete([['product_id', 'in', $ids], ['type', '=', '0']]); //删除商品详情 /** @var StoreDescriptionServices $productDescription */ $productDescription = app()->make(StoreDescriptionServices::class); $productDescription->delete([['product_id', 'in', $ids], ['type', '=', '0']]); //删除商品关联数据 /** @var StoreProductRelationServices $productRelation */ $productRelation = app()->make(StoreProductRelationServices::class); $productRelation->delete([['product_id', 'in', $ids]]); //删除商品关联优惠券数据 /** @var StoreProductCouponServices $productCoupon */ $productCoupon = app()->make(StoreProductCouponServices::class); $productCoupon->delete([['product_id', 'in', $ids]]); //删除商品收藏记录 /** @var UserRelationServices $productRelation */ $productRelation = app()->make(UserRelationServices::class); $productRelation->delete([['relation_id', 'in', $ids], ['category', '=', UserRelationServices::CATEGORY_PRODUCT]]); //删除商品的评论 /** @var StoreProductReplyServices $productReply */ $productReply = app()->make(StoreProductReplyServices::class); $productReply->delete([['product_id', 'in', $ids]]); //删除帖子里对应商品 $communityRelevanceServices = app()->make(CommunityRelevanceServices::class); $communityRelevanceServices->search(['right_id' => $ids, 'type' => CommunityRelevanceServices::TYPE_COMMUNITY_PRODUCT])->delete(); $product->search(['id' => $ids])->delete(); return true; } }