123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\admin\v1\system;
- use app\services\other\HotDataServices;
- use app\services\product\product\StoreDescriptionServices;
- use app\services\product\product\StoreProductCouponServices;
- use app\services\product\product\StoreProductRelationServices;
- use app\services\user\UserRelationServices;
- use app\services\product\product\StoreProductReplyServices;
- use app\services\product\sku\StoreProductAttrResultServices;
- use app\services\product\sku\StoreProductAttrServices;
- use app\services\product\sku\StoreProductAttrValueServices;
- use crmeb\services\CacheService;
- use think\exception\ValidateException;
- use think\facade\App;
- use app\controller\admin\AuthController;
- use app\services\system\SystemClearServices;
- use app\services\product\product\StoreProductServices;
- use app\services\system\attachment\SystemAttachmentServices;
- /**
- * 清除默认数据理控制器
- * Class SystemClearData
- * @package app\controller\admin\v1\system
- */
- class SystemClearData extends AuthController
- {
- /**
- * 构造方法
- * SystemClearData constructor.
- * @param App $app
- * @param SystemClearServices $services
- */
- public function __construct(App $app, SystemClearServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- //生产模式下不允许清除数据
- if (!env('APP_DEBUG', false)) {
- throw new ValidateException('生产模式下,禁止操作');
- }
- }
- /**
- * 清除方法入口
- * @param $type
- * @return mixed
- */
- public function index($type)
- {
- switch ($type) {
- case 'temp':
- return $this->userTemp();
- break;
- case 'recycle':
- return $this->recycleProduct();
- break;
- case 'store':
- return $this->storeData();
- break;
- case 'order':
- return $this->orderData();
- break;
- case 'kefu':
- return $this->kefuData();
- break;
- case 'wechat':
- return $this->wechatData();
- break;
- case 'attachment':
- return $this->attachmentData();
- break;
- case 'article':
- return $this->articledata();
- break;
- case 'system':
- return $this->systemdata();
- break;
- case 'user':
- return $this->userRelevantData();
- break;
- default:
- return $this->fail('参数有误');
- }
- }
- /**
- * 清除用户生成的临时文件
- * @return mixed
- */
- public function userTemp()
- {
- /** @var SystemAttachmentServices $services */
- $services = app()->make(SystemAttachmentServices::class);
- $ids = implode(',', $services->getColumn(['module_type' => 2], 'att_id'));
- $services->del($ids);
- $services->delete(2, 'module_type');
- return $this->success('清除数据成功!');
- }
- /**
- * 清除回收站商品
- * @return mixed
- */
- public function recycleProduct()
- {
- /** @var StoreProductServices $product */
- $product = app()->make(StoreProductServices::class);
- $ids = $product->getColumn(['is_del' => 1], 'id');
- //清除规格表数据
- /** @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]]);
- $product->delete(1, 'is_del');
- return $this->success('清除数据成功!');
- }
- /**
- * 清除用户数据
- * @return mixed
- */
- public function userRelevantData()
- {
- $this->services->clearData([
- 'wechat_user', 'wechat_message', 'user_search', 'user_visit', 'user_sign', 'user_recharge', 'user_notice_see', 'user_notice',
- 'user_level', 'user_label_relation', 'user_label', 'user_invoice', 'user_group', 'user_friends', 'user_extract', 'user_enter',
- 'user_brokerage_frozen', 'user_bill', 'user_address', 'user', 'system_store_staff', 'store_visit', 'store_service_record',
- 'store_service_speechcraft', 'store_service_record', 'store_service_log', 'store_service_feedback', 'store_service',
- 'store_product_reply', 'user_relation', 'store_product_log', 'store_pink', 'store_order_status', 'store_order_invoice',
- 'store_order_economize', 'store_order_cart_info', 'store_order', 'store_coupon_user', 'store_coupon_issue_user', 'store_cart',
- 'store_bargain_user_help', 'store_bargain_user', 'sms_record', 'qrcode', 'other_order_status', 'other_order', 'member_card',
- 'member_card_batch', 'delivery_service', 'queue_auxiliary', 'queue_list', 'luck_lottery_record', 'agent_level_task_record',
- 'user_brokerage', 'user_money', 'system_message', 'award_lake', 'user_integral'
- ], true);
- $this->services->delDirAndFile('./public/uploads/store/comment');
- return $this->success('清除数据成功!');
- }
- /**
- * 清除商城数据
- * @return mixed
- */
- public function storeData()
- {
- $this->services->clearData([
- 'store_product_category', 'live_anchor', 'live_goods', 'live_room', 'live_room_goods', 'store_bargain', 'store_bargain_user',
- 'store_bargain_user_help', 'store_cart', 'store_product_category', 'store_combination', 'store_coupon_issue', 'store_coupon_issue_user',
- 'store_coupon_product', 'store_coupon_user', 'store_product', 'store_product_attr', 'store_product_attr_result',
- 'store_product_attr_value', 'store_product_cate', 'store_product_coupon', 'store_product_description', 'store_product_log',
- 'user_relation', 'store_product_reply', 'store_product_rule', 'store_seckill', 'store_visit', 'store_integral'
- ], true);
- return $this->success('清除数据成功!');
- }
- /**
- * 清除订单数据
- * @return mixed
- */
- public function orderData()
- {
- $this->services->clearData([
- 'queue_list', 'queue_auxiliary', 'other_order_status', 'store_order', 'store_order_cart_info', 'store_order_economize', 'store_order_invoice', 'store_order_refund',
- 'store_order_status', 'store_pink', 'other_order', 'store_integral_order', 'store_integral_order_status'
- ], true);
- return $this->success('清除数据成功!');
- }
- /**
- * 清除客服数据
- * @return mixed
- */
- public function kefuData()
- {
- $this->services->clearData([
- 'queue_auxiliary', 'store_service', 'store_service_feedback', 'store_service_log', 'store_service_record', 'store_service_speechcraft'
- ], true);
- $this->services->delDirAndFile('./public/uploads/store/service');
- return $this->success('清除数据成功!');
- }
- /**
- * 清除微信管理数据
- * @return mixed
- */
- public function wechatData()
- {
- $this->services->clearData([
- 'wechat_key', 'wechat_media', 'wechat_message', 'wechat_news_category', 'wechat_reply'
- ], true);
- $this->services->delDirAndFile('./public/uploads/wechat');
- return $this->success('清除数据成功!');
- }
- /**
- * 清除所有附件
- * @return mixed
- */
- public function attachmentData()
- {
- $this->services->clearData([
- 'system_attachment', 'system_attachment_category'
- ], true);
- $this->services->delDirAndFile('./public/uploads/');
- return $this->success('清除上传文件成功!');
- }
- /**
- * 清楚内容数据
- * @return mixed
- */
- public function articledata()
- {
- $this->services->clearData([
- 'article_category', 'article', 'article_content'
- ], true);
- return $this->success('清除数据成功!');
- }
- /**
- * 清楚系统记录
- * @return mixed
- */
- public function systemdata()
- {
- $this->services->clearData([
- 'system_notice_admin', 'system_log'
- ], true);
- return $this->success('清除数据成功!');
- }
- /**
- * 替换域名方法
- * @return mixed
- */
- public function replaceSiteUrl()
- {
- [$url] = $this->request->postMore([
- ['url', '']
- ], true);
- if (!$url)
- return $this->fail('请输入需要更换的域名');
- if (!verify_domain($url))
- return $this->fail('域名不合法');
- $this->services->replaceSiteUrl($url);
- return $this->success('替换成功!');
- }
- /**
- * 预热营销商品库存
- * @param HotDataServices $hotDataServices
- * @return mixed
- */
- public function hotProductStock(HotDataServices $hotDataServices)
- {
- $key = 'hot_product_stock';
- $re = CacheService::get($key);
- if (!$re) {
- $f = [1, 2, 3, 4, 5];
- try {
- foreach ($f as $type) {
- $hotDataServices->hot($type);
- }
- } catch (\Throwable $e) {
- }
- CacheService::set($key, time(), 86400);
- }
- return $this->success('预热成功!');
- }
- }
|