songxingwei 2 年之前
父節點
當前提交
7b03a4ef8d
共有 1 個文件被更改,包括 50 次插入0 次删除
  1. 50 0
      application/api/controller/Timedtask.php

+ 50 - 0
application/api/controller/Timedtask.php

@@ -156,4 +156,54 @@ class Timedtask
     }
 
 
+    /**
+     * @title 每天7-16点,没5秒造一次假数据
+     * @desc  每天7-16点,没5秒造一次假数据
+     * @author  Gavin
+     * @url /index.php/api/Timedtask/SetFake
+     * @method GET
+     */
+    public function SetFake2(){
+        $now_hour = date('H');
+        $min = date('i');
+        if (($now_hour>7 && $now_hour<10) || ($now_hour>14 && $now_hour<17)){
+            if ($now_hour==16 && $min>30){
+                die();
+            }
+            $all = Db::name('system_day')->where('date',date('Y-m-d'))->value('now_value');
+            if ($all>0){
+                $now_time = date('Y-m-d 07:00:00');
+                $end_time = date('Y-m-d 10:00:00');
+                $now_time1 = date('Y-m-d 14:00:00');
+                $end_time1 = date('Y-m-d 16:30:00');
+                $strto = (strtotime($end_time)-strtotime($now_time))+(strtotime($end_time1)-strtotime($now_time1));
+                $num = ceil($all/($strto/5));
+                $num_array =array();
+                for ($i=$num-2;$i<=$num+2;$i++){
+                    if ($i>0){
+                        array_push($num_array,$i);
+                    }
+                }
+
+                $kd = Db::name('system_day_fake')
+                    ->where('rate','gt',0)
+                    ->where('date',date('Y-m-d'))
+                    ->field('id,name,rate')
+                    ->select();
+                foreach ($kd as $key => $val) {
+                    $arr[$val['id']] = $val['rate'];//概率数组
+                }
+                $rid = get_rand($arr); //根据概率获取id
+
+                $value = $num_array[array_rand($num_array)];
+
+                Db::startTrans();
+                Db::name('system_day_fake')->where('id',$rid)->setInc('value',$value);
+                Db::name('system_day')->where('date',date('Y-m-d'))->setDec('now_value',$value);
+                Db::name('system_day_fake')->where('id',$rid)->setDec('rate',$value);
+                Db::commit();
+            }
+        }
+    }
+
 }