From 15221ea7797b4dd117f2016ca2c7f2b836b32c95 Mon Sep 17 00:00:00 2001 From: "lmr@hainatravel.com" <59361885@qq.com> Date: Fri, 15 Dec 2017 14:42:26 +0800 Subject: [PATCH] update --- application/models/infoTemplate_model.php | 122 ++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 application/models/infoTemplate_model.php diff --git a/application/models/infoTemplate_model.php b/application/models/infoTemplate_model.php new file mode 100644 index 00000000..6f6e2208 --- /dev/null +++ b/application/models/infoTemplate_model.php @@ -0,0 +1,122 @@ +HT = $this->load->database('HT', TRUE); + } + + /** + * 增加标签 + */ + function add_tag() + { + if ($this->it_title) + { + //查看是否已存在标签 + $sql = "SELECT TOP 1 * from infoTags WHERE it_title = N?"; + $check = $this->HT->query($sql, array($this->it_title)); + + //添加标签 + if ($check->num_rows() === 0) + { + $sql = "INSERT INTO infoTags (it_title, it_memo) VALUES (N?, N?)"; + $query = $this->HT->query($sql, array($this->it_title, $this->it_memo)); + return $this->HT->insert_id(); + } + else + { + $row = $check->row(); + return $row->it_id; + } + + } + return FALSE; + } + + /** + * 删除标签 + */ + function remove_tag() + { + if ($this->it_title) + { + $sql = "DELETE FROM infoTags WHERE it_title = N?"; + $query = $this->HT->query($sql, array($this->it_title)); + return 'success'; + } + return 'fail'; + } + + /** + * 标签列表 + */ + function list_tag() + { + if ($this->ic_id) + { + //展示信息的标签 + $sql = "SELECT * FROM infoContentToTag INNER JOIN infoTags ON icit_it_id = it_id WHERE icit_ic_id = ?"; + $query = $this->HT->query($sql, array($this->ic_id)); + return $query->result(); + } + else + { + //全部展示 + $sql = "SELECT * FROM infoTags ORDER BY it_title ASC, it_date DESC"; + $query = $this->HT->query($sql); + return $query->result(); + } + return 'fail'; + } + + /** + * 添加信息与标签的关联 + */ + function add_tag_to_content() + { + if ($this->ic_id && $this->it_id) + { + //查看是否已存在关联 + $sql = "SELECT TOP 1 * from infoContentToTag WHERE icit_ic_id = ? AND icit_it_id = ?"; + $check = $this->HT->query($sql, array($this->ic_id, $this->it_id)); + + //添加关联 + if ($check->num_rows() === 0) + { + $sql = "INSERT INTO infoContentToTag (icit_ic_id, icit_it_id) VALUES (?, ?)"; + $query = $this->HT->query($sql, array($this->ic_id, $this->it_id)); + } + else + { + return 'exist'; + } + return 'success'; + } + return 'fail'; + } + + /** + * 解除信息与标签的关联 + */ + function remove_tag_to_content() + { + if ($this->ic_id && $this->it_id) + { + $sql = "DELETE FROM infoContentToTag WHERE icit_ic_id = ? and icit_it_id = ?"; + $query = $this->HT->query($sql, array($this->ic_id, $this->it_id)); + return 'success'; + } + return 'fail'; + } + +}