123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
-
- namespace app\admin\model;
-
- use think\Db;
- use think\Model;
-
-
- class RecycleBin extends Model
- {
-
- protected function initialize()
- {
-
- parent::initialize();
- }
-
-
-
- public function clear($type = 'all')
- {
- try {
-
- if (in_array($type, ['all','arctype'])) {
- $typeids = Db::name('arctype')->where(['is_del'=>1])->column('id');
- if (!empty($typeids)) {
- Db::name('arctype')->where(['id'=>['IN', $typeids]])->delete();
- Db::name('archives')->where(['typeid'=>['IN', $typeids],'channel'=>6])->delete();
- Db::name('single_content')->where(['typeid'=>['IN', $typeids]])->delete();
- }
- }
-
- if (in_array($type, ['all','archives'])) {
- $condition = array();
- $condition['channel'] = array('neq', 6);
- $condition['is_del'] = 1;
- $row = Db::name('archives')->field('aid,channel')->where($condition)->select();
- $list = array();
- foreach ($row as $key => $val) {
- $list[$val['channel']][] = $val['aid'];
- }
- $channeltypeRow = Db::name('channeltype')->field('id,table')->where(['id'=>['gt',0]])->getAllWithIndex('id');
- foreach ($list as $key => $val) {
- $aids = $list[$key];
- $table_name = $channeltypeRow[$key]['table'];
- Db::name('archives')->where(['aid'=>['IN', $aids]])->delete();
- Db::name("{$table_name}_content")->where(['aid'=>['IN', $aids]])->delete();
- }
- }
-
- if (in_array($type, ['all','customvar'])) {
- $names = Db::name('config')->where(['is_del'=>1])->column('name');
- if (!empty($names)) {
- Db::name('config')->where(['name'=>['IN', $names], 'is_del'=>1])->delete();
- Db::name('config_attribute')->where(['attr_var_name'=>['IN', $names]])->delete();
- }
- }
-
- if (in_array($type, ['all','gbookattr'])) {
- $attr_ids = Db::name('guestbook_attribute')->where(['is_del'=>1])->column('attr_id');
- if (!empty($attr_ids)) {
- Db::name('guestbook_attribute')->where(['attr_id'=>['IN', $attr_ids], 'is_del'=>1])->delete();
- Db::name('guestbook_attr')->where(['attr_id'=>['IN', $attr_ids]])->delete();
- }
- }
- } catch (\Exception $e) {
-
- }
- }
- }
|