Appauth_model.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. class Appauth_model extends CI_Model
  3. {
  4. private $collection_name = 'app_auth';
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. private $model = array(
  10. 'app_id' => "",
  11. "secret" => "",
  12. "app_name" => "",
  13. "status" => "",
  14. "create_time" => ""
  15. );
  16. public function get_model(){
  17. return $this->model;
  18. }
  19. public function get_appauth_with_id($id)
  20. {
  21. return $this->mongo_db->where(array("app_id" => $id))->find_one($this->collection_name);
  22. }
  23. public function is_exists($field, $val, $old_val=null)
  24. {
  25. if ($old_val) {
  26. $appauth = $this->mongo_db->set_wheres(array('$and' => array(array($field => array('$ne' => $old_val)), array($field => $val))))->get($this->collection_name);
  27. } else {
  28. $appauth = $this->mongo_db->where(array($field => $val))->get($this->collection_name);
  29. }
  30. if ($appauth && count($appauth) > 0) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }
  36. /**
  37. * 列表接入授权
  38. */
  39. public function list_appauth($limit, $offset, $like = NULL, $where = NULL, $order = NULL)
  40. {
  41. if (!$order) {
  42. $order = array("create_time" => "ASC");
  43. }
  44. if ($like && $where) {
  45. return $this->mongo_db->like("app_name", $like)->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  46. } else if ($like && !$where) {
  47. return $this->mongo_db->like("app_name", $like)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  48. } else if (!$like && $where) {
  49. return $this->mongo_db->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  50. } else {
  51. return $this->mongo_db->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
  52. }
  53. }
  54. /**
  55. * 获取接入授权数据条数
  56. */
  57. public function count_appauth($like = NULL, $where = NULL)
  58. {
  59. if ($like && $where) {
  60. return $this->mongo_db->like("app_name", $like)->where($where)->count($this->collection_name);
  61. } else if ($like && !$where) {
  62. return $this->mongo_db->like("app_name", $like)->count($this->collection_name);
  63. } else if (!$like && $where) {
  64. return $this->mongo_db->where($where)->count($this->collection_name);
  65. } else {
  66. return $this->mongo_db->count($this->collection_name);
  67. }
  68. }
  69. /**
  70. *新增接入授权
  71. */
  72. public function insert_appauth($app_auth)
  73. {
  74. return $this->mongo_db->insert($this->collection_name, $app_auth);
  75. }
  76. public function set_val($field, $wheres, $value = NULL)
  77. {
  78. if (is_array($field)) {
  79. return $this->mongo_db->set_wheres($wheres)->set($field)->update_all($this->collection_name);
  80. } else {
  81. return $this->mongo_db->set_wheres($wheres)->set($field, $value)->update_all($this->collection_name);
  82. }
  83. }
  84. /**
  85. *更新接入授权
  86. */
  87. public function update_appauth($app_auth)
  88. {
  89. $data['filter'] = array("app_id" => $app_auth['app_id']);
  90. $data['update'] = $app_auth;
  91. return $this->mongo_db->update($this->collection_name, $data);
  92. }
  93. /**
  94. * 删除接入授权
  95. */
  96. public function delete_appauth($app_id)
  97. {
  98. return $this->mongo_db->where(array("app_id" => $app_id))->delete($this->collection_name);
  99. }
  100. }