123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- 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];
-
- 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;
- }
- }
-
- 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);
- }
-
- 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);
- }
-
- function checkTable() {
- return true;
- }
- }
|