123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace app\admin\controller\manage;
- use app\common\library\Redis;
- use app\common\model\AdminConfig;
- use app\common\model\ManagePage;
- use app\common\controller\Backend;
- /**
- * 书城管理-块管理
- *
- * @icon fa fa-circle-o
- */
- class Block extends Backend
- {
- /**
- * ManageBlock模型对象
- */
- protected $model = null;
- protected $pageData = [];
- protected $searchFields = 'page_id';
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('ManageBlock');
- $this->view->assign("typeList", $this->model->getTypeList());
- $pageList = collection(ManagePage::field('id,sex,name')->select())->toArray();
- foreach ($pageList as $k => $v) {
- $this->pageData[$v['id']] = $v['name'];
- }
- $this->view->assign('pageData', $this->pageData);
- }
- /*
- * 查看
- */
- public function index()
- {
- if ($this->request->isAjax()) {
- $page_id = $this->request->get('page_id');
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->where('page_id', 'in', $page_id)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where('page_id', 'in', $page_id)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- foreach ($list as $k => &$v) {
- $v['page_text'] = $this->pageData[$v['page_id']];
- }
- unset($v);
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post('row/a');
- if ($params) {
- $result = $this->model->validate('ManageBlock.add')->save($params);
- if ($result === false) {
- $this->error($this->model->getError());
- }
- $this->model->save($params);
- $this->success();
- }
- $this->error();
- }
- $this->view->assign('page_id', $this->request->get('page_id'));
- return $this->view->fetch();
- }
- /**
- * 清空缓存
- */
- public function rmcache()
- {
- if ($this->request->get()) {
- $redis = Redis::instance();
- $key = $this->request->get('key');
- switch ($key) {
- case 'RANK:0':
- $position = '首页不区分男女';
- $redis->del('RANK:0:W');
- break;
- case 'P:1':
- $position = '首页男频';
- $redis->del('RANK:1');
- $redis->del('RANK:1:W');
- break;
- case 'P:2':
- $position = '首页女频';
- $redis->del('RANK:2');
- $redis->del('RANK:2:W');
- break;
- case 'P:3':
- $position = '男生版(清水)';
- $redis->del('RANK:3');
- break;
- case 'P:4':
- $position = '女生版(清水)';
- $redis->del('RANK:4');
- break;
- case 'keyword':
- $position = '搜索框关键词';
- Redis::delScan('HS:*');
- break;
- case 'goods':
- $position = '商品数据';
- break;
- case AdminConfig::CACHE_KEY_ADMIN_INFO:
- $position = '标题及配置信息';
- $key = AdminConfig::CACHE_KEY_ADMIN_INFO. $this->auth->id;
- $redis->del('ADMIN');
- break;
- case 'GUIDE':
- $position = '书籍推广列表缓存';
- $key = 'GUIDE:' . $this->auth->id;
- $redis->del($key);
- break;
- case 'referral':
- $position = '导粉推广列表缓存';
- $key = 'referral' . $this->auth->id;
- $redis->del('referral');
- break;
- default:
- break;
- }
- if (stristr($key, '*')) {
- header("Content-Encoding: none\r\n");
- echo str_pad("即将开始清除操作,脚本最大执行时间为10分钟,请耐心等待。<br>若触发超时异常错误,请联系技术处理!<br><br>正在清除中…… 时间:".date('Y-m-d H:i:s'),4096);
- ob_flush();
- flush();
- ob_end_flush();
- Redis::delScan($key);
- if ($key == 'CC:*') {
- Redis::delScan("BCA:*");
- }
- } else {
- if(stristr($key, 'BBL:')){
- $redis->del($key);
- $key = str_replace('BBL:', 'BBL:W:', $key);
- }
- if(stristr($key, 'BL:')){
- $redis->del($key);
- $key = str_replace('BL:', 'BL:W:', $key);
- }
- $redis->del($key);
- if ($redis->exists($key)) {
- $this->error('清空缓存失败');
- }
- }
- if (isset($position)) {
- $this->success("已清空缓存位置:" . $position);
- }else{
- $this->success('清空缓存成功!');
- }
- }
- }
- }
|