From 7ea2a465bfd7d41cb3a6e9895a83de439a35c1cb Mon Sep 17 00:00:00 2001 From: yulingwei <2436953959@qq.com> Date: Thu, 9 Jan 2020 16:56:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ArticleController.class.php | 4 +- .../Admin/View/Article/pop_rule_edit.html | 17 +++++--- .../Controller/PromoteController.class.php | 39 +++++++++++++++---- .../View/default/Promote/pop_rule_detail.html | 22 +++++------ ThinkPHP/Library/Org/RedisSDK/Redis.class.php | 5 +++ 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Application/Admin/Controller/ArticleController.class.php b/Application/Admin/Controller/ArticleController.class.php index 1a148ef3f..e85f25567 100644 --- a/Application/Admin/Controller/ArticleController.class.php +++ b/Application/Admin/Controller/ArticleController.class.php @@ -930,7 +930,7 @@ class ArticleController extends AdminController { $data['operater_id'] = is_login(); $data['status'] = 1; $res = $pop_rules_model->add($data); - return $res ? $this->success("新增完成") : $this->error("新增失败"); + return $res ? $this->success("新增完成", U('Article/pop_rules')) : $this->error("新增失败"); } } else { if($id) { @@ -943,7 +943,7 @@ class ArticleController extends AdminController { if (!$rule) { return $this->error('记录不存在'); } - $rule['pop_time'] = date("Y-m-d", ($rule['pop_time'] <= 10 ? time() : $rule['pop_time'])); + $rule['pop_time'] = $rule['type'] == 1 ? date("Y-m-d", $rule['pop_time']) : $rule['pop_time']; $this->assign('rule', $rule); } } diff --git a/Application/Admin/View/Article/pop_rule_edit.html b/Application/Admin/View/Article/pop_rule_edit.html index 6385b498e..3232af106 100644 --- a/Application/Admin/View/Article/pop_rule_edit.html +++ b/Application/Admin/View/Article/pop_rule_edit.html @@ -21,7 +21,7 @@
  • - @@ -37,6 +37,7 @@
  • +
  • @@ -65,27 +66,33 @@ \ No newline at end of file diff --git a/Application/Home/Controller/PromoteController.class.php b/Application/Home/Controller/PromoteController.class.php index 8c92a6ad2..d532ed431 100644 --- a/Application/Home/Controller/PromoteController.class.php +++ b/Application/Home/Controller/PromoteController.class.php @@ -26,6 +26,8 @@ use Home\Model\PromoteModel; use Base\Service\PromoteService; use Base\Service\ApplyService; +use Org\RedisSDK\Redis; + /** * 前台首页控制器 * 主要获取首页聚合数据 @@ -222,14 +224,22 @@ class PromoteController extends BaseController $this->assign("rules", $rules); $this->assign("rules_count", count($rules)); - $currentTime = strtotime(date('Y-m-d')); - $weekArray = [7,1,2,3,4,5,6]; - $week = $weekArray[date("w")]; - $match_rules = M("document_pop_rules") - ->field('id') - ->where("(type = 1 and pop_time = {$currentTime}) or (type = 2 and pop_time = {$week})") - ->order("sort asc, id desc") - ->select(); + $redis = new \Org\RedisSDK\Redis(['host'=>'127.0.0.1','port'=>6379],[]); + $cacheKey = "pop:rule:set"; + if (!$redis->sIsMember($cacheKey, get_pid())) { + $currentTime = strtotime(date('Y-m-d')); + $weekArray = [7,1,2,3,4,5,6]; + $week = $weekArray[date("w")]; + $match_rules = M("document_pop_rules") + ->field('id') + ->where("(type = 1 and pop_time = {$currentTime}) or (type = 2 and pop_time = {$week})") + ->order("sort asc, id desc") + ->select(); + } else { + $match_rules = []; + } + + $this->assign("match_rules_id", $match_rules ? json_encode(array_column($match_rules, 'id')) : 'null'); $this->assign("user_count", $user_count); @@ -280,6 +290,19 @@ class PromoteController extends BaseController $this->display('pop_rule_detail'); } + public function popRuleFinish() + { + $redis = new \Org\RedisSDK\Redis(['host'=>'127.0.0.1','port'=>6379],[]); + $cacheKey = "pop:rule:set"; + if ($redis->exists($cacheKey)) { + $redis->sadd($cacheKey, get_pid()); + } else { + $redis->sadd($cacheKey, get_pid()); + $redis->exprieAt($cacheKey, strtotime(date('Y-m-d')) + 86400); + } + return $this->success("成功", [], true); + } + private function caculateSpend($pay_time, $condition, $create = [], $type = 0) { $map['promote_id'] = array('egt', 0); diff --git a/Application/Home/View/default/Promote/pop_rule_detail.html b/Application/Home/View/default/Promote/pop_rule_detail.html index ae07b7b33..5cb08a123 100644 --- a/Application/Home/View/default/Promote/pop_rule_detail.html +++ b/Application/Home/View/default/Promote/pop_rule_detail.html @@ -90,6 +90,8 @@