Branch_model.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class Branch_model extends CI_Model
  3. {
  4. private $collection_name = 'branch';
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. private $model = array(
  10. 'branch_type' => "",
  11. "branch_id" => "",
  12. "branch_name" => "",
  13. "device" => array(
  14. "device_id" => "",
  15. "device_type" => ""
  16. )
  17. );
  18. public function get_model()
  19. {
  20. return $this->model;
  21. }
  22. public function select_branch()
  23. {
  24. $order = array("create_time" => "ASC");
  25. return $this->mongo_db->order_by($order)->get($this->collection_name);
  26. }
  27. public function get_branch_by_id($branch_id)
  28. {
  29. return $this->mongo_db->where(array("branch_id" => $branch_id))->find_one($this->collection_name);
  30. }
  31. public function save_branch($branch)
  32. {
  33. if ($this->get_branch_by_id($branch['branch_id'])) {
  34. return $this->update_branch($branch);
  35. } else {
  36. return $this->insert_branch($branch);
  37. }
  38. }
  39. public function insert_branch($branch)
  40. {
  41. return $this->mongo_db->insert($this->collection_name, $branch);
  42. }
  43. public function update_branch($branch)
  44. {
  45. $data['filter'] = array("branch_id" => $branch['branch_id']);
  46. $data['update'] = $branch;
  47. return $this->mongo_db->update($this->collection_name, $data);
  48. }
  49. }