123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * LogModel.php UTF-8
- * 分表Log基类
- *
- * @date : 2018/6/1 18:23
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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;
- }
- }
|