Ejemplo n.º 1
0
 public function actionList()
 {
     if (isset($_GET['ajax'])) {
         $page = isset($_POST['page']) ? $_POST['page'] : 1;
         $rows = isset($_POST['rows']) ? $_POST['rows'] : 10;
         $api_obj = new \app\models\Api();
         $data = $api_obj->get_list([], 0, 0);
         if (!$data) {
             echo '查询失败';
             exit;
         }
         // 查询最多的次数
         $apply_info = $this->get_secret_key($data['rows']);
         foreach ($data['rows'] as $dk => $dv) {
             $all_num = 0;
             if (!empty($apply_info)) {
                 foreach ($apply_info as $ak => $av) {
                     if ($av['aid'] == $dv['id']) {
                         $all_num = $all_num + $av['access_num'];
                     }
                 }
             }
             $data['rows'][$dk]['all_num'] = $all_num;
         }
         echo json_encode($data);
     } else {
         return $this->render('list');
     }
 }
Ejemplo n.º 2
0
 public function actionAdd()
 {
     if (isset($_POST["sub"])) {
         $api_name = !empty($_POST['api_name']) ? $_POST['api_name'] : '';
         $api_url = !empty($_POST['api_url']) ? $_POST['api_url'] : '';
         $type = !empty($_POST['type']) ? $_POST['type'] : '';
         $rate_limit = !empty($_POST['rate_limit']) ? $_POST['rate_limit'] : '';
         if (empty($api_name)) {
             echo json_encode(array('code' => 10001, 'message' => '接口名称为空'));
             exit;
         }
         if (empty($api_url)) {
             echo json_encode(array('code' => 10002, 'message' => '接口地址为空'));
             exit;
         }
         if (empty($type)) {
             echo json_encode(array('code' => 10003, 'message' => '接口类型为空'));
             exit;
         }
         if (empty($rate_limit)) {
             echo json_encode(array('code' => 10004, 'message' => '速率限制为空'));
             exit;
         }
         // 判断是否存在
         $api_obj = new \app\models\Api();
         if ($api_obj->get_field('api_name', $api_name)) {
             echo json_encode(array('code' => 10005, 'message' => '接口已存在'));
             exit;
         }
         $api_info = ['api_name' => $api_name, 'api_url' => $api_url, 'type' => $type, 'rate_limit' => $rate_limit];
         $re = $api_obj->save_api($api_info);
         if (!$re) {
             echo json_encode(array('code' => 10006, 'message' => '添加失败'));
         } else {
             echo json_encode(array('code' => 10000, 'message' => '添加成功'));
         }
     } else {
         echo json_encode(array('code' => 10009, 'message' => '非法提交'));
     }
 }