public static function doAdvises($ids) { if (strpos($ids, ',') !== false) { $condition = "id in ({$ids})"; } else { $condition = "id={$ids}"; } $advise = new self(); return $advise->getDb()->update($advise->getSource(), array('status'), array(self::STATUS_DO), $condition); }
/** * Allows to perform a summatory group for a column in the collection * * @param string $field * @param array|null $conditions * @param string|null $finalize * @return array|null * @throws Exception */ public static function summatory($field, $conditions = null, $finalize = null) { if (is_string($field) === false) { throw new Exception('Invalid field name for group'); } if (is_array($conditions) === false && is_null($conditions) === false) { throw new Exception('Invalid parameter type.'); } if (is_string($finalize) === false && is_null($finalize) === false) { throw new Exception('Invalid parameter type.'); } $model = new self(); $connection = $model->getConnection(); $source = $model->getSource(); if (empty($source) === true) { throw new Exception('Method getSource() returns empty string'); } $collection = $connection->selectCollection($source); /* * Uses a javascript hash to group the results, however this is slow with larger * datasets */ $group = $collection->group(array(), array('summatory' => array()), "function (curr, result) { if (typeof result.summatory[curr." . $field . "] === \"undefined\") { result.summatory[curr." . $field . "] = 1; } else { result.summatory[curr." . $field . "]++; } }"); if (isset($group['retval']) === true) { if (isset($group['retval'][0]) === true) { $firstRetval = $group['retval'][0]; if (isset($firstRetval['summatory']) === true) { return $firstRetval['summatory']; } return $firstRetval; } return $group['retval']; } }
/** * 设置返回值 * @param $id * @param $response */ public static function setResponse($id, $response) { $model = new self(); $sql = 'UPDATE ' . $model->getSource() . ' SET resp_content = :resp, resp_time = NOW() WHERE id = :id'; $model->getWriteConnection()->execute($sql, ['id' => $id, 'resp' => $response]); }