/** * 功能统计总次数增加1 * @param string $key 功能对应的tag字符值 * @param string $map 备注 */ public function increase($key, $map) { $now = date('Y-m-d', time()); try { $this->sql->beginTransaction(); //检查表结构 $sqlStm = "DESC `{$this->tag}` `{$key}`"; //若无$key列则修改表结构 $result = $this->sql->query($sqlStm); if ($result == null || count($result->fetchAll(\PDO::FETCH_ASSOC)) == 0) { $this->appendCol($key, $map); } //更新数据 $sqlStm = "UPDATE `{$this->tag}` SET `{$key}` = `{$key}`+1 WHERE `date` = '{$now}'"; //更新数据失败,则添加新的行 if ($this->sql->exec($sqlStm) == 0) { $this->appendRow($key, $map, $now); } //检查数据是否需要更新备注 $sqlStm = "SELECT `{$key}` FROM `{$this->tag}` WHERE `date` = '{$now}'"; $result = $this->sql->query($sqlStm)->fetchAll(\PDO::FETCH_ASSOC); if (count($result) > 0 && intval($result[0][$key]) == 1) { $this->updateCol($key, $map); } $this->sql->commit(); } catch (\PDOException $e) { $this->sql->rollBack(); Log::e($e); } }
private function cleanRetry() { $max = MAX_CACHE; try { $result = $this->db->query("SELECT `priority` FROM `{$this->tableRetry}` ORDER BY `priority` DESC LIMIT {$max}, 1"); $result = $result->fetchAll(\PDO::FETCH_ASSOC); if (count($result) == 0) { return; } $maxTime = $result[0]['priority']; $this->db->exec("DELETE FROM `{$this->tableRetry}` WHERE `priority` <= {$maxTime}"); return true; } catch (\PDOException $e) { Log::e($e); return false; } }