songxingwei 2 yıl önce
ebeveyn
işleme
32492e5486
1 değiştirilmiş dosya ile 14 ekleme ve 15 silme
  1. 14 15
      application/api/controller/Timedtask.php

+ 14 - 15
application/api/controller/Timedtask.php

@@ -127,23 +127,22 @@ class Timedtask
                         array_push($num_array,$i);
                     }
                 }
-                $kd = Db::name('system_kd')->column('name');
-                $kd_rand = $kd[array_rand($kd)];
+
+                $kd = Db::name('system_day_fake')
+                    ->where('rate','neq',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();
-                    $in = Db::name('system_day_fake')->where('name',$kd_rand)->where('date',date('Y-m-d'))->find();
-                    if ($in){
-                        Db::name('system_day_fake')->where('id',$in['id'])->setInc('value',$value);
-                    }else{
-                        Db::name('system_day_fake')->insert(
-                            [
-                                'name'=>$kd_rand,
-                                'date'=>date('Y-m-d'),
-                                'value'=>$value
-                            ]
-                        );
-                    }
-                    Db::name('system_day')->where('date',date('Y-m-d'))->setDec('now_value',$value);
+                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();
             }
         }