123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
-
-
- namespace app\api\controller;
-
- use think\Db;
-
- class Diyajax extends Base
- {
-
-
- public function _initialize() {
- parent::_initialize();
- }
-
-
-
- public function check_userinfo()
- {
- if (IS_AJAX) {
- \think\Session::pause();
- $ajaxLogic = new \app\api\logic\AjaxLogic;
- $result = $ajaxLogic->check_userinfo();
- if (!empty($result['data']['ey_is_login'])) {
- $assignData = [
- 'users' => $result['users'],
- ];
- $this->assign($assignData);
-
- $filename = './template/'.THEME_STYLE_PATH.'/'.'system/users_info.htm';
- if (file_exists($filename)) {
- $html = $this->fetch($filename);
- } else {
- $html = '缺少模板文件:'.ltrim($filename, '.');
- }
- $result['data']['html'] = $html;
- }
- respose(['code'=>1, 'msg'=>'请求成功', 'data'=>$result['data']]);
- }
- to_index("404");
- }
-
-
-
- public function downFile(){
-
- $id = request()->get('id',0);
-
-
- if((int)$id === 0){
- respose(['code'=>0, 'msg'=>'请求失败!', 'data'=>[]]);
- }
-
- $one = Db::name('users_down')->where(['id'=>$id])->find();
-
- if((int)$one['num'] >= 3){
- respose(['code'=>0, 'msg'=>'该链接请求下载次数不能超过3次,链接已失效!', 'data'=>[]]);
- }
-
- if((int)$one['expire_time'] < time()){
-
- respose(['code'=>0, 'msg'=>'下载链接已失效!', 'data'=>[]]);
- }
-
-
- $artData = Db::name('zczygz_content')->where('aid', $one['aid'])
- ->find();
- if(empty($artData) || empty($artData['down'])){
- respose(['code'=>0, 'msg'=>'文档不存在!', 'data'=>[]]);
- }
-
-
- $ext = explode('.',$artData['down']);
- $ext = end($ext);
- $filename = $one['title'].'.'.$ext;
- $file = $artData['down'].'?attname='.$filename;
-
-
-
-
-
- Db::name('users_down')->where(['id'=>$id])->setInc('num');
-
- header('location:'.$file);
-
-
- }
-
- public function downFileCurl($url, $file_name)
- {
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $file_name);
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }
- }
|