public function searchSeeds() { $keywords = explode(' ', $this->search_text); array_walk($keywords, function (&$value) { $value = strtolower($value); }); $qr = Seed::find()->select('seed_id')->where(['like', 'lower(full_name)', $keywords])->andWhere("coefs_stack[1][1] BETWEEN {$this->upcoe_min} AND {$this->upcoe_max}")->andWhere("coefs_stack[1][2] BETWEEN {$this->downcoe_min} AND {$this->downcoe_max}")->andWhere("pub_time >= 'today'::date - '{$this->date_after} days'::interval"); $cond = []; foreach ($this->type_subtype_assoc as $type => $sub_type) { $tmpc = " (\"type_id\"='{$type}' "; if (!empty($sub_type)) { $tmpc .= " AND \"sub_type_id\"='{$sub_type}') "; } else { $tmpc .= ")"; } $cond[] = $tmpc; } if (!empty($cond)) { $qr->andWhere(implode('OR', $cond)); } foreach ($this->order_by as $idx => $by) { $type = strtolower($this->order_type[$idx]) == 'asc' ? SORT_ASC : SORT_DESC; $qr->addOrderBy([$by => $type]); } if ($this->nodead) { $qr->andWhere(['between', 'seeder_count', 1, 100000]); } Yii::info($qr->where); return $qr->limit($this->limit)->offset($this->offset)->all(); }
public function actionMaintainCoef() { $now = time(); $seeds = Seed::find()->where("coefs_stack[1][3] < {$now}")->andWhere('coefs_stack[1][3] != 0')->all(); foreach ($seeds as $seed) { $arr = $seed->getCoefArray(); var_dump($arr); array_shift($arr); //无后备选项 if (empty($arr)) { $arr[] = [100, 100, 0]; } $seed->setCoefArray($arr); echo '新系数\\n'; var_dump($seed->getCoefArray()); $seed->save(); } var_dump(count($seeds)); return; }