12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- class Branch_model extends CI_Model
- {
- private $collection_name = 'branch';
- public function __construct()
- {
- parent::__construct();
- }
- private $model = array(
- 'branch_type' => "",
- "branch_id" => "",
- "branch_name" => "",
- "device" => array(
- "device_id" => "",
- "device_type" => ""
- )
- );
- public function get_model()
- {
- return $this->model;
- }
- public function select_branch()
- {
- $order = array("create_time" => "ASC");
- return $this->mongo_db->order_by($order)->get($this->collection_name);
- }
- public function get_branch_by_id($branch_id)
- {
- return $this->mongo_db->where(array("branch_id" => $branch_id))->find_one($this->collection_name);
- }
- public function save_branch($branch)
- {
- if ($this->get_branch_by_id($branch['branch_id'])) {
- return $this->update_branch($branch);
- } else {
- return $this->insert_branch($branch);
- }
- }
- public function insert_branch($branch)
- {
- return $this->mongo_db->insert($this->collection_name, $branch);
- }
- public function update_branch($branch)
- {
- $data['filter'] = array("branch_id" => $branch['branch_id']);
- $data['update'] = $branch;
- return $this->mongo_db->update($this->collection_name, $data);
- }
- }
|