Explorar o código

定期删除爆币日志,提升爆币统计速度

lizhen_gitee hai 1 ano
pai
achega
4c153cd7bb

+ 2 - 1
application/api/controller/Party.php

@@ -2157,7 +2157,8 @@ class Party extends Api
         $today_end   = time();
         $map = [
             //'user_id' => $user_id,
-            'createtime' => ['BETWEEN',[$today_start,$today_end]],
+//            'createtime' => ['BETWEEN',[$today_start,$today_end]],
+        //因为有了自动删除计划任务,这里不在需要时间限制,gift_id加索引提升速度
             'gift_id' => $gift_id,
         ];
         $today_data = Db::name('gift_baobi_log')->field('IFNULL(sum(pay_total),0) as today_pay_total,IFNULL(sum(baobi_total),0) as today_baobi_total')->where($map)->find();

+ 9 - 1
application/index/controller/Plantask.php

@@ -13,7 +13,15 @@ class Plantask extends Controller
     //只有 public 方法,auto_开头的才是计划任务,其他private 方法都是工具方法
 
 ////////////////////////////////////////下面都是计划任务方法///////////////////////////////////////////////////////////////
-
+    //自动删除3天前的爆币日志,提升统计速度
+    public function auto_del_baobi_log(){
+        $today_start = strtotime(date('Y-m-d')) - (86400 * 3);
+
+        $map = [
+            'createtime' => ['lt',$today_start],
+        ];
+        Db::name('gift_baobi_log')->where($map)->delete();
+    }
 
     //送礼物(api/party/giveGiftToYou)拆分出来的异步用户升级方法,