[328] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class Smstemplate_model extends MY_Model
|
---|
| 4 | {
|
---|
| 5 |
|
---|
| 6 | protected $table_name = 'tblsmstemplate';
|
---|
[404] | 7 | protected $id_name = 'sms_id';
|
---|
[328] | 8 |
|
---|
| 9 | function __construct()
|
---|
| 10 | {
|
---|
| 11 | parent::__construct();
|
---|
| 12 | }
|
---|
[404] | 13 | function getSmstemplates($data) {
|
---|
| 14 | $sql = "SELECT * FROM " . $this->table_name;
|
---|
| 15 | if ($data['keyword']) {
|
---|
| 16 | if ($data['search_field'] == "cellphone") {
|
---|
| 17 | $sql.=" WHERE (service_id LIKE '%" . $data['keyword'] . "%')";
|
---|
| 18 | } else {
|
---|
| 19 | $sql.=" WHERE (sms_content LIKE '%" . $data['keyword'] . "%' OR sms_reply LIKE '%" . $data['keyword'] . "%') ";
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | $order = "";
|
---|
| 24 | if ($data['sorting_order'] != "sorting") {
|
---|
| 25 | if ($data['sorting_field'] != "money") {
|
---|
| 26 | $sort = "DESC";
|
---|
| 27 | if ($data['sorting_order'] == "sorting_asc")
|
---|
| 28 | $sort = "ASC";
|
---|
| 29 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 | $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
| 33 |
|
---|
| 34 | return $this->db->query($sql)->result_array();
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | function isExist($data) {
|
---|
| 38 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'";
|
---|
| 39 | if (isset($data['id']))
|
---|
| 40 | {
|
---|
| 41 | $id=$data['id'];
|
---|
| 42 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
| 43 | }
|
---|
| 44 | $result = $this->db->query($sql)->row_array();
|
---|
| 45 | if ($result['total'] == 1) {
|
---|
| 46 | return true;
|
---|
| 47 | } else {
|
---|
| 48 | return false;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | function countSmstemplate($data) {
|
---|
| 53 | $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name;
|
---|
| 54 | if ($data['keyword']) {
|
---|
| 55 | if ($data['search_field'] == "cellphone") {
|
---|
| 56 | $sql.=" WHERE (service_id LIKE '%" . $data['keyword'] . "%')";
|
---|
| 57 | } else {
|
---|
| 58 | $sql.=" WHERE (sms_content LIKE '%" . $data['keyword'] . "%' OR sms_reply LIKE '%" . $data['keyword'] . "%') ";
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | $result = $this->db->query($sql)->row_array();
|
---|
| 62 | return $result['total'];
|
---|
| 63 | }
|
---|
| 64 | function getSmstemplate($id)
|
---|
| 65 | {
|
---|
| 66 | $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1";
|
---|
| 67 | $result = $this->db->query($sql)->row_array();
|
---|
| 68 | return $result;
|
---|
| 69 | }
|
---|
[328] | 70 | } |
---|