load->model("appauth_model"); $this->load->library('MY_pagination'); $this->load->helper(array('url', 'form', 'date')); $this->assign("appauth_status", $this->appauth_status); } /** * 应用授权列表页 */ public function index() { $url = site_url("appauth/index?"); $wheres = array(); $order_info = array(); $keyword = $this->input->get("keyword", TRUE); $status = $this->input->get("status", TRUE); $order = $this->input->get("order", TRUE); $page_num = $this->input->get("per_page", TRUE); $page_size = $this->input->get("page_size", TRUE); if ($keyword) { $url .= "&keyword=" . $keyword; } if ($status) { $wheres['status'] = $status; $url .= "&status=" . $status; } if ($order) { $orders = explode(" ", $order); if (count($orders) == 2) { $order_info[$orders[0]] = $orders[1]; $url .= "&order=" . $order; } } if ($page_size) { $this->page_size = $page_size; $url .= "&page_size=" . $page_size; } $count = $this->appauth_model->count_appauth($keyword, $wheres); $this->assign("count", $count); $config = $this->page_config($count, $this->page_size, $url); $this->my_pagination->initialize($config); if ($page_num && $page_num > 1) { $offset = (intval($page_num) - 1) * $this->page_size; } else { $offset = 0; } $appauth_list = $this->appauth_model->list_appauth($this->page_size, $offset, $keyword, $wheres, $order_info); $this->assign("keyword", $keyword); $this->assign("status", $status); $this->assign("order", $order); $this->assign("page_size", $this->page_size); $this->assign("page", $this->my_pagination->create_pages()); $this->assign("appauth_list", $appauth_list); $this->display("appauth/index.html"); } /** * 查看应用授权信息 * @param $app_id APPID */ public function view($app_id) { $message = ""; $appauth = $this->appauth_model->get_appauth_with_id($app_id); if($appauth){ $this->assign("appauth",$appauth); }else{ $this->assign("appauth",$this->appauth_model->get_model()); $message = "应用授权信息不存在或者已经被删除"; } $this->assign("message",$message); $this->display("appauth/view.html"); } /** * 增加应用授权 */ public function add() { $app_id = md5(uniqid(md5(microtime(true)), true)); $secret = md5(uniqid(md5(microtime(true)), true)); $this->assign("app_id", $app_id); $this->assign("secret", $secret); $this->display("appauth/add.html"); } /** * 保存应用授权信息 */ public function save() { $msg = array(); $data = array(); $msg['code'] = 1; $msg['icon'] = 2; $data['app_id'] = $app_id = $this->input->post("app_id", true); $data['app_name'] = $app_name = $this->input->post("app_name", true); $data['secret'] = $secret = $this->input->post("secret", true); if (!$app_name) { $msg['code'] = 0; $msg['msg'] = "应用名称不能为空!"; } elseif ($this->appauth_model->is_exists("app_name", $app_name) && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "应用名称已存在!"; } if (!$app_id && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "APPID不能为空!"; } elseif ($this->appauth_model->is_exists("app_id", $app_id) && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "APPID已存在!请刷新后重试!"; } if (!$secret && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "SECRET不能为空!"; } if ($msg['code']) { $data['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000); $data['status'] = "10"; $this->appauth_model->insert_appauth($data); $msg['icon'] = 1; $msg['msg'] = "应用授权信息保存成功!"; } $this->response($msg); } /** * 更新应用授权信息 */ public function update() { $msg = array(); $data = array(); $msg['code'] = 1; $msg['icon'] = 2; $msg = array(); $data = array(); $msg['code'] = 1; $msg['icon'] = 2; $data['app_id']= $app_id = $this->input->post("app_id", true); $old_appauth = $this->appauth_model->get_appauth_with_id($app_id); $data['app_name'] = $app_name = $this->input->post("app_name", true); $data['secret'] = $secret = $this->input->post("secret", true); if (!$app_name) { $msg['code'] = 0; $msg['msg'] = "应用名称不能为空!"; } elseif ($this->appauth_model->is_exists("app_name", $app_name,$old_appauth['app_name']) && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "应用名称已存在!"; } if (!$secret && $msg['code']) { $msg['code'] = 0; $msg['msg'] = "SECRET不能为空!"; } if ($msg['code']) { $this->appauth_model->update_appauth($data); $msg['icon'] = 1; $msg['msg'] = "应用授权信息保存成功!"; } $this->response($msg); } /** * 删除应用授权 * @param $app_id */ public function delete($app_id) { $data['icon'] = 1; if ($app_id) { $appauth = $this->appauth_model->get_appauth_with_id($app_id); if ($appauth) { $this->appauth_model->delete_appauth($app_id); $data['msg'] = "应用授权信息删除成功!"; } else { $data['icon'] = 2; $data['msg'] = "应用授权信息不存在或者已经被删除!"; } } else { $data['icon'] = 2; $data['msg'] = "参数错误请刷新后重试!"; } $this->response($data); } /** * 禁用应用授权 * @param $app_id */ public function stopuse($app_id) { $data['icon'] = 1; if ($app_id) { $appauth = $this->appauth_model->get_appauth_with_id($app_id); if ($appauth) { $appauth['status'] = "40"; $this->appauth_model->update_appauth($appauth); $data['msg'] = "应用授权信息停用成功!"; } else { $data['icon'] = 2; $data['msg'] = "应用授权信息不存在或者已经被删除!"; } } else { $data['icon'] = 2; $data['msg'] = "参数错误请刷新后重试!"; } $this->response($data); } /** * 启用应用授权 * @param $app_id */ public function restore($app_id) { $data['icon'] = 1; if ($app_id) { $appauth = $this->appauth_model->get_appauth_with_id($app_id); if ($appauth) { $appauth['status'] = "10"; $this->appauth_model->update_appauth($appauth); $data['msg'] = "应用授权恢复成功!"; } else { $data['icon'] = 2; $data['msg'] = "应用授权信息不存在或者已经被删除!"; } } else { $data['icon'] = 2; $data['msg'] = "参数错误请刷新后重试!"; } $this->response($data); } /** * 批量禁用应用授权 */ public function disable_all(){ $ids = rtrim($this->input->post("ids",true),","); $ids = explode(",",$ids); if(count($ids)<1){ $data['icon'] = 2; $data['msg'] = "参数错误请刷新后重试!"; }else{ $wheres = array('app_id'=>array('$in'=>$ids)); $this->appauth_model->set_val("status",$wheres,"40"); $data['icon'] = 1; $data['msg'] = "批量禁用应用授权成功!"; } $this->response($data); } /** * 批量启用应用授权 */ public function enable_all(){ $ids = rtrim($this->input->post("ids",true),","); $ids = explode(",",$ids); if(count($ids)<1){ $data['icon'] = 2; $data['msg'] = "参数错误请刷新后重试!"; }else{ $wheres = array('app_id'=>array('$in'=>$ids)); $this->appauth_model->set_val("status",$wheres,"10"); $data['icon'] = 1; $data['msg'] = "批量启用应用授权成功!"; } $this->response($data); } }