Block.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace app\admin\controller\manage;
  3. use app\common\library\Redis;
  4. use app\common\model\AdminConfig;
  5. use app\common\model\ManagePage;
  6. use app\common\controller\Backend;
  7. /**
  8. * 书城管理-块管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Block extends Backend
  13. {
  14. /**
  15. * ManageBlock模型对象
  16. */
  17. protected $model = null;
  18. protected $pageData = [];
  19. protected $searchFields = 'page_id';
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('ManageBlock');
  24. $this->view->assign("typeList", $this->model->getTypeList());
  25. $pageList = collection(ManagePage::field('id,sex,name')->select())->toArray();
  26. foreach ($pageList as $k => $v) {
  27. $this->pageData[$v['id']] = $v['name'];
  28. }
  29. $this->view->assign('pageData', $this->pageData);
  30. }
  31. /*
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. if ($this->request->isAjax()) {
  37. $page_id = $this->request->get('page_id');
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. $total = $this->model
  40. ->where($where)
  41. ->where('page_id', 'in', $page_id)
  42. ->order($sort, $order)
  43. ->count();
  44. $list = $this->model
  45. ->where($where)
  46. ->where('page_id', 'in', $page_id)
  47. ->order($sort, $order)
  48. ->limit($offset, $limit)
  49. ->select();
  50. foreach ($list as $k => &$v) {
  51. $v['page_text'] = $this->pageData[$v['page_id']];
  52. }
  53. unset($v);
  54. $result = array("total" => $total, "rows" => $list);
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. public function add()
  60. {
  61. if ($this->request->isPost()) {
  62. $params = $this->request->post('row/a');
  63. if ($params) {
  64. $result = $this->model->validate('ManageBlock.add')->save($params);
  65. if ($result === false) {
  66. $this->error($this->model->getError());
  67. }
  68. $this->model->save($params);
  69. $this->success();
  70. }
  71. $this->error();
  72. }
  73. $this->view->assign('page_id', $this->request->get('page_id'));
  74. return $this->view->fetch();
  75. }
  76. /**
  77. * 清空缓存
  78. */
  79. public function rmcache()
  80. {
  81. if ($this->request->get()) {
  82. $redis = Redis::instance();
  83. $key = $this->request->get('key');
  84. switch ($key) {
  85. case 'RANK:0':
  86. $position = '首页不区分男女';
  87. $redis->del('RANK:0:W');
  88. break;
  89. case 'P:1':
  90. $position = '首页男频';
  91. $redis->del('RANK:1');
  92. $redis->del('RANK:1:W');
  93. break;
  94. case 'P:2':
  95. $position = '首页女频';
  96. $redis->del('RANK:2');
  97. $redis->del('RANK:2:W');
  98. break;
  99. case 'P:3':
  100. $position = '男生版(清水)';
  101. $redis->del('RANK:3');
  102. break;
  103. case 'P:4':
  104. $position = '女生版(清水)';
  105. $redis->del('RANK:4');
  106. break;
  107. case 'keyword':
  108. $position = '搜索框关键词';
  109. Redis::delScan('HS:*');
  110. break;
  111. case 'goods':
  112. $position = '商品数据';
  113. break;
  114. case AdminConfig::CACHE_KEY_ADMIN_INFO:
  115. $position = '标题及配置信息';
  116. $key = AdminConfig::CACHE_KEY_ADMIN_INFO. $this->auth->id;
  117. $redis->del('ADMIN');
  118. break;
  119. case 'GUIDE':
  120. $position = '书籍推广列表缓存';
  121. $key = 'GUIDE:' . $this->auth->id;
  122. $redis->del($key);
  123. break;
  124. case 'referral':
  125. $position = '导粉推广列表缓存';
  126. $key = 'referral' . $this->auth->id;
  127. $redis->del('referral');
  128. break;
  129. default:
  130. break;
  131. }
  132. if (stristr($key, '*')) {
  133. header("Content-Encoding: none\r\n");
  134. echo str_pad("即将开始清除操作,脚本最大执行时间为10分钟,请耐心等待。<br>若触发超时异常错误,请联系技术处理!<br><br>正在清除中…… 时间:".date('Y-m-d H:i:s'),4096);
  135. ob_flush();
  136. flush();
  137. ob_end_flush();
  138. Redis::delScan($key);
  139. if ($key == 'CC:*') {
  140. Redis::delScan("BCA:*");
  141. }
  142. } else {
  143. if(stristr($key, 'BBL:')){
  144. $redis->del($key);
  145. $key = str_replace('BBL:', 'BBL:W:', $key);
  146. }
  147. if(stristr($key, 'BL:')){
  148. $redis->del($key);
  149. $key = str_replace('BL:', 'BL:W:', $key);
  150. }
  151. $redis->del($key);
  152. if ($redis->exists($key)) {
  153. $this->error('清空缓存失败');
  154. }
  155. }
  156. if (isset($position)) {
  157. $this->success("已清空缓存位置:" . $position);
  158. }else{
  159. $this->success('清空缓存成功!');
  160. }
  161. }
  162. }
  163. }