* @version : HUOSDK 8.0 */ namespace huo\model\log; use huo\model\common\CommonModel; class LogModel extends CommonModel { protected $table_date = ''; protected $table_prefix = ''; protected $partition_data = []; protected $partition_field = 'date'; protected $partition_rule = ['type' => 'month', 'expr' => 1]; /** * @param $data * @param bool $replace * @param bool $get_last_insert_id * * @return bool|int|string */ public function insertLog($data, $replace = false, $get_last_insert_id = true) { if ($_id = $this->computeTable($data['date'])->insert($data, $replace, $get_last_insert_id)) { return $_id; } else { return false; } } /** * 计算在哪张表 * * @param string $date * * @return \Think\Model */ public function computeTable($date = '') { $this->partition_data[$this->partition_field] = $date; $this->checkTable(); return $this->partition($this->partition_data, $this->partition_field, $this->partition_rule); } /** * 计算在哪张表 * * @param string $date * * @return \Think\Model */ public function computeTableTwo($date = '') { $this->partition_data[$this->partition_field] = $date; $_time = strtotime($date); $_time = !empty($_time) ? $_time : time(); $this->partition_data[$this->partition_field] = date('Y-m-d', $_time); $this->table = $this->getPartitionTableName( $this->partition_data, $this->partition_field, $this->partition_rule ); return $this->partition($this->partition_data, $this->partition_field, $this->partition_rule); } /** * 检查表是否处在 * * * @return bool */ function checkTable() { return true; } }