123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- class Appauth_model extends CI_Model
- {
- private $collection_name = 'app_auth';
- public function __construct()
- {
- parent::__construct();
- }
- private $model = array(
- 'app_id' => "",
- "secret" => "",
- "app_name" => "",
- "status" => "",
- "create_time" => ""
- );
- public function get_model(){
- return $this->model;
- }
- public function get_appauth_with_id($id)
- {
- return $this->mongo_db->where(array("app_id" => $id))->find_one($this->collection_name);
- }
- public function is_exists($field, $val, $old_val=null)
- {
- if ($old_val) {
- $appauth = $this->mongo_db->set_wheres(array('$and' => array(array($field => array('$ne' => $old_val)), array($field => $val))))->get($this->collection_name);
- } else {
- $appauth = $this->mongo_db->where(array($field => $val))->get($this->collection_name);
- }
- if ($appauth && count($appauth) > 0) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 列表接入授权
- */
- public function list_appauth($limit, $offset, $like = NULL, $where = NULL, $order = NULL)
- {
- if (!$order) {
- $order = array("create_time" => "ASC");
- }
- if ($like && $where) {
- return $this->mongo_db->like("app_name", $like)->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
- } else if ($like && !$where) {
- return $this->mongo_db->like("app_name", $like)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
- } else if (!$like && $where) {
- return $this->mongo_db->where($where)->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
- } else {
- return $this->mongo_db->order_by($order)->limit($limit)->offset($offset)->get($this->collection_name);
- }
- }
- /**
- * 获取接入授权数据条数
- */
- public function count_appauth($like = NULL, $where = NULL)
- {
- if ($like && $where) {
- return $this->mongo_db->like("app_name", $like)->where($where)->count($this->collection_name);
- } else if ($like && !$where) {
- return $this->mongo_db->like("app_name", $like)->count($this->collection_name);
- } else if (!$like && $where) {
- return $this->mongo_db->where($where)->count($this->collection_name);
- } else {
- return $this->mongo_db->count($this->collection_name);
- }
- }
- /**
- *新增接入授权
- */
- public function insert_appauth($app_auth)
- {
- return $this->mongo_db->insert($this->collection_name, $app_auth);
- }
- public function set_val($field, $wheres, $value = NULL)
- {
- if (is_array($field)) {
- return $this->mongo_db->set_wheres($wheres)->set($field)->update_all($this->collection_name);
- } else {
- return $this->mongo_db->set_wheres($wheres)->set($field, $value)->update_all($this->collection_name);
- }
- }
- /**
- *更新接入授权
- */
- public function update_appauth($app_auth)
- {
- $data['filter'] = array("app_id" => $app_auth['app_id']);
- $data['update'] = $app_auth;
- return $this->mongo_db->update($this->collection_name, $data);
- }
- /**
- * 删除接入授权
- */
- public function delete_appauth($app_id)
- {
- return $this->mongo_db->where(array("app_id" => $app_id))->delete($this->collection_name);
- }
- }
|