isAjax()) { $condition = array( ['site_id', '=', $this->site_id], ['app_type', '=', 'foreign'], ); $app_model = new AppModel(); $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $list = $app_model->getAppApiList($condition, $page, $page_size, '*', 'create_time desc,id desc'); return $list; } $this->forthMenu(); return $this->fetch("appapi/lists"); } /*** * 添加应用 * @return array|mixed */ public function apiadd() { if (request()->isAjax()) { $push_url = input('push_url', ''); $data = [ 'app_name' => input('app_name', ''), 'push_url' => $push_url, 'is_push' => input('is_push', 0), 'remark' => input('remark', ''), ]; $data['site_id'] = $this->site_id; $app_model = new AppModel(); if(!empty($push_url)){ $domainRegex = '/^([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9\-]{0,61}[a-z0-9]$/i'; if ((strpos($push_url, "https://") !== 0) || preg_match($domainRegex, $push_url)) return error(-1, '请输入正确的推送地址https://开头'); $info = model('supply_app')->getInfo(['site_id' => $this->site_id, 'push_url' => $push_url], 'id'); if (!empty($info)) return error('', '该推送地址已存在'); } $Snowflake = new Snowflake($this->site_id); $data['app_type'] = 'foreign'; $data['create_time'] = time(); $data['app_id'] = $Snowflake->generateId(); $data['app_secret'] = md5(uniqid(md5(microtime(true)), true)); $res = $app_model->addAppApi($data); return $res; } return $this->fetch("appapi/apiadd"); } /*** * 编辑应用 * @return array|mixed */ public function apiedit() { $app_model = new AppModel(); if (request()->isAjax()) { $push_url = input('push_url', ''); $data = [ 'app_name' => input('app_name', ''), 'push_url' => $push_url, 'remark' => input('remark', ''), 'is_push' => input('is_push', 0), ]; $data['site_id'] = $this->site_id; $domainRegex = '/^([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9\-]{0,61}[a-z0-9]$/i'; if ((strpos($push_url, "https://") !== 0) || preg_match($domainRegex, $push_url)) return error(-1, '请输入正确的推送地址https://开头'); $info = model('supply_app')->getInfo(['site_id' => $this->site_id, 'push_url' => $push_url], 'id'); if (!empty($info)&&$info['id'] != input('id')) return error('', '该推送地址已存在'); $condition = [ ['id', '=', input('id')], ['site_id', '=', $this->site_id] ]; $res = $app_model->editAppApi($data, $condition); return $res; } $info = $app_model->getAppApiInfo([['id', '=', input('id')], ['site_id', '=', $this->site_id]]); $this->assign('info', $info['data']); return $this->fetch("appapi/apiedit"); } /** * 删除应用 * @return array|void */ public function apidel() { if (request()->isAjax()) { $app_model = new AppModel(); $condition = [ ['id', '=', input('id')], ['site_id', '=', $this->site_id] ]; $type = input('type', ''); if ($type != 'access') { $info = model('supply_app')->getInfo($condition, 'usable_price'); if ($info['usable_price'] > 0) return error(-1, '可用余额未使用完无法删除'); } $res = $app_model->delAppApi($condition); return $res; } } /*** * 第三方应用列表 * @return array|mixed */ public function threelists() { if (request()->isAjax()) { $condition = array( ['site_id', '=', $this->site_id], ['app_type', '=', 'access'], ); $app_model = new AppModel(); $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $list = $app_model->getAppApiList($condition, $page, $page_size, '*', 'create_time desc,id desc'); return $list; } $this->forthMenu(); return $this->fetch("appapi/access_lists"); } /*** * 添加第三方应用 * @return array|mixed */ public function threeapiadd() { if (request()->isAjax()) { $push_url = input('push_url', ''); $domainRegex = '/^([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9\-]{0,61}[a-z0-9]$/i'; if ((strpos($push_url, "https://") !== 0) || preg_match($domainRegex, $push_url)) return error(-1, '请输入正确的推送地址https://开头'); $info = model('supply_app')->getInfo(['site_id' => $this->site_id, 'push_url' => $push_url], 'id'); if (!empty($info)) return error('', '该网关地址已存在'); $app_model = new AppModel(); $data = request()->post(); $data['site_id'] = $this->site_id; $data['app_type'] = 'access'; $data['create_time'] = time(); $res = $app_model->addAppApi($data); return $res; } return $this->fetch("appapi/threeadd"); } /** * 编辑应用 * @return array|mixed */ public function threeapiedit() { $app_model = new AppModel(); if (request()->isAjax()) { $push_url = input('push_url', ''); $data = request()->post(); $domainRegex = '/^([a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9\-]{0,61}[a-z0-9]$/i'; if ((strpos($push_url, "https://") !== 0) || preg_match($domainRegex, $push_url)) return error(-1, '请输入正确的推送地址https://开头'); $condition = [ ['id', '=', input('id')], ['site_id', '=', $this->site_id] ]; $res = $app_model->editAppApi($data, $condition); return $res; } $info = $app_model->getAppApiInfo([['id', '=', input('id')], ['site_id', '=', $this->site_id]]); $this->assign('info', $info['data']); return $this->fetch("appapi/threeedit"); } /** * 扣费记录 * @return array|mixed */ public function deduction() { if (request()->isAjax()) { $condition = array( ['site_id', '=', $this->site_id], ['account_type', '=', 'usable_price'], ); $keyword = input('keyword', ''); if ($keyword) { $condition[] = ['relate_tag', 'like', '%' . $keyword . '%']; } $app_model = new SupplyAccount(); $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $list = $app_model->getAccountPageList($condition, $page, $page_size); return $list; } } /** * 充值 * @return array|mixed */ public function recharge() { if (request()->isAjax()) { $id = input('id'); $money = input('money'); $pay = new OrderCreate(); $return = $pay->rechargeOrderCreate($money, $this->site_id, $this->uid, $id); $qrcode = qrcode($return['data']['data']['qrcode'], 'upload/qrcode/pay/', $return['data']['out_trade_no'], 16); $return = [ 'qrcode' => 'data:image/png;base64,' . base64_encode(file_get_contents($qrcode)), 'out_trade_no' => $return['data']['out_trade_no'], ]; return $return; } } /** * 详情 * @return array|mixed */ public function detail() { if (request()->isAjax()) { $app_model = new AppModel(); $info = $app_model->getAppApiInfo([['id', '=', input('id')], ['site_id', '=', $this->site_id]]); return $info; } } }