Block.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lytian
  5. * Date: 2019/4/9
  6. * Time: 10:28
  7. */
  8. namespace app\admin\controller\clientmanage\bookcity;
  9. use app\common\library\Redis;
  10. use app\common\model\AdminConfig;
  11. use app\common\controller\Backend;
  12. use app\common\model\ClientManagePage;
  13. /**
  14. * 书城管理-块管理
  15. *
  16. * @icon fa fa-circle-o
  17. */
  18. class Block extends Backend
  19. {
  20. /**
  21. * ManageBlock模型对象
  22. */
  23. protected $model = null;
  24. protected $pageData = [];
  25. protected $searchFields = 'page_id';
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = model("ClientManageBlock");
  30. $this->view->assign("typeList", $this->model->getTypeList($this->request->get('page_id')));
  31. $pageList = collection(ClientManagePage::field('id,sex,name')->select())->toArray();
  32. foreach ($pageList as $k => $v) {
  33. $this->pageData[$v['id']] = $v['name'];
  34. }
  35. $this->view->assign('pageData', $this->pageData);
  36. }
  37. /*
  38. * 查看
  39. */
  40. public function index()
  41. {
  42. if ($this->request->isAjax()) {
  43. $page_id = $this->request->get('page_id');
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $total = $this->model
  46. ->where($where)
  47. ->where('page_id', 'in', $page_id)
  48. ->order($sort, $order)
  49. ->count();
  50. $list = $this->model
  51. ->where($where)
  52. ->where('page_id', 'in', $page_id)
  53. ->order($sort, $order)
  54. ->limit($offset, $limit)
  55. ->select();
  56. foreach ($list as $k => &$v) {
  57. $v['page_text'] = $this->pageData[$v['page_id']];
  58. }
  59. unset($v);
  60. $result = array("total" => $total, "rows" => $list);
  61. return json($result);
  62. }
  63. return $this->view->fetch();
  64. }
  65. public function add()
  66. {
  67. if ($this->request->isPost()) {
  68. $params = $this->request->post('row/a');
  69. if ($params) {
  70. $result = $this->model->validate('ClientManageBlock.add')->save($params);
  71. if ($result === false) {
  72. $this->error($this->model->getError());
  73. }
  74. $this->model->save($params);
  75. $this->success();
  76. }
  77. $this->error();
  78. }
  79. $this->view->assign('page_id', $this->request->get('page_id'));
  80. return $this->view->fetch();
  81. }
  82. /**
  83. * 清空缓存
  84. */
  85. public function rmcache()
  86. {
  87. if ($this->request->get()) {
  88. $redis = Redis::instance();
  89. $key = $this->request->get('key');
  90. switch ($key) {
  91. case 'CP:1':
  92. $position = '首页男频';
  93. $redis->del('CRANK:1');
  94. break;
  95. case 'CP:2':
  96. $position = '首页女频';
  97. $redis->del('CRANK:2');
  98. break;
  99. case 'CP:3':
  100. $position = '限免男频';
  101. $redis->del('RANK:3');
  102. break;
  103. case 'CP:4':
  104. $position = '限免女频';
  105. $redis->del('CRANK:4');
  106. break;
  107. case 'keyword':
  108. $position = '搜索框关键词';
  109. Redis::delScan('CHS:*');
  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. } else {
  140. $redis->del($key);
  141. if ($redis->exists($key)) {
  142. $this->error('清空缓存失败');
  143. }
  144. }
  145. if (isset($position)) {
  146. $this->success("已清空缓存位置:" . $position);
  147. }else{
  148. $this->success('清空缓存成功!');
  149. }
  150. }
  151. }
  152. }