123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- /**
- * Class 应用授权管理类
- */
- class Appauth extends MY_Controller
- {
- function __construct()
- {
- parent::__construct();
- $this->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);
- }
- }
|