Your Name 10 months ago
parent
commit
c6fe71ff81

+ 27
- 7
application/api/controller/Ajax.php View File

@@ -2344,14 +2344,29 @@ class Ajax extends Base
2344 2344
             ->where('add_time','> time',$formatted_time)
2345 2345
             ->where(['users_id'=>$users_id,'aid' => $aid])->count();
2346 2346
         if(!empty($down_log) && $down_log >= 1){
2347
-            $this->error('不允许频繁下载,请等待一分钟后重试!', '', []);
2348
-        }
2349
-        
2350
-        
2347
+            $this->error('不允许频繁下载,点击下载后请等待一分钟再重试!', '', []);
2348
+        }else{
2349
+            $lc_time = date("Y-m-d 00:00:01", time());
2350
+            //可以再限制 每天只能下载几次
2351
+            $down_log = Db::name('users_down')
2352
+                ->where('add_time','> time',$lc_time)
2353
+                ->where(['users_id'=>$users_id,'aid' => $aid])->count();
2354
+            if(!empty($down_log) && $down_log >= 10){
2355
+                $this->error('同一文件今日最多下载10次!', '', []);
2356
+            }
2357
+        }
2358
+
2359
+        /*
2360
+         * 执行下载记录 生成 每条记录有效时间 1小时
2361
+         * 过后得重新 点击下载 生成新的下载链接
2362
+         * 每天 同一文档 最多下载10次
2363
+         * 每条下载记录 最多下载3次 就无效
2364
+         */
2351 2365
         // 启动事务
2352 2366
         $run = 0;
2353 2367
         Db::startTrans();
2354 2368
         try{
2369
+            $expire_time = strtotime("+60 minutes");
2355 2370
             //记录下载数,二次下载也记录
2356 2371
             $inser_log = [
2357 2372
                     'users_id' => $users_id,
@@ -2361,9 +2376,13 @@ class Ajax extends Base
2361 2376
                     'title' => $art['title'],
2362 2377
                     'add_time' => time(),
2363 2378
                     'update_time' => time(),
2379
+                    'expire_time' => $expire_time,
2380
+                    'num' => 0
2364 2381
                 ];
2365
-            $log_id = Db::name('users_down')->insert($inser_log);
2366
-            if((int)$log_id !== 1){
2382
+            $log_id = Db::name('users_down')->insertGetId($inser_log);
2383
+            if((int)$log_id > 0){
2384
+                //正常得到ID
2385
+            }else{
2367 2386
                 $run = 1;
2368 2387
             }
2369 2388
             
@@ -2391,7 +2410,8 @@ class Ajax extends Base
2391 2410
         }else{
2392 2411
             //
2393 2412
             $result = [
2394
-                    'down' => $artData['down']
2413
+                    //'down' => $artData['down']
2414
+                    'down' => 'https://www.zc10000.com/api/diyajax/downfile?id='.$log_id
2395 2415
                 ];
2396 2416
             $this->success('下载请求成功', null, $result);
2397 2417
         }

+ 51
- 0
application/api/controller/Diyajax.php View File

@@ -51,4 +51,55 @@ class Diyajax extends Base
51 51
         }
52 52
         to_index("404");
53 53
     }
54
+
55
+    /*
56
+     * 下载文件
57
+     * https://www.zc10000.com/api/diyajax/downfile
58
+     */
59
+    public function downFile(){
60
+
61
+        $id = request()->get('id',0);
62
+        //var_dump((int)$id);
63
+        //非法
64
+        if((int)$id === 0){
65
+            respose(['code'=>0, 'msg'=>'请求失败!', 'data'=>[]]);
66
+        }
67
+        //查找记录
68
+        $one = Db::name('users_down')->where(['id'=>$id])->find();
69
+
70
+        if((int)$one['num'] >= 3){
71
+            respose(['code'=>0, 'msg'=>'该链接请求下载次数不能超过3次,链接已失效!', 'data'=>[]]);
72
+        }
73
+
74
+        if((int)$one['expire_time'] < time()){
75
+            //已过期
76
+            respose(['code'=>0, 'msg'=>'下载链接已失效!', 'data'=>[]]);
77
+        }
78
+
79
+        //查找下载地址
80
+        $artData = Db::name('zczygz_content')->where('aid', $one['aid'])
81
+            ->find();
82
+        if(empty($artData) || empty($artData['down'])){
83
+            respose(['code'=>0, 'msg'=>'文档不存在!', 'data'=>[]]);
84
+        }
85
+
86
+        //php
87
+        $filename = $one['title'];
88
+        $file = $artData['down'];
89
+        //$filename = basename($file);
90
+        //echo $file;
91
+        if(!empty($file)){
92
+            header("Content-type:application/octet-stream");
93
+            header("Content-Disposition:attachment;filename = ".$filename);
94
+            header("Accept-ranges:bytes");
95
+            header("Accept-length:".filesize($file));
96
+            readfile($file);
97
+
98
+            //记录下载次数
99
+            Db::name('users_down')->where(['id'=>$id])->setInc('num');
100
+
101
+        }else{
102
+            respose(['code'=>0, 'msg'=>'文件下载地址不存在!', 'data'=>[]]);
103
+        }
104
+    }
54 105
 }

+ 1
- 1
application/function.php View File

@@ -982,7 +982,7 @@ if (!function_exists('respose')) {
982 982
         if (true === $is_jsonp) {
983 983
             exit(input('callback') . "(" . json_encode($res) . ")");
984 984
         } else {
985
-            exit(json_encode($res));
985
+            exit(json_encode($res,JSON_UNESCAPED_UNICODE));
986 986
         }
987 987
     }
988 988
 }

+ 2
- 2
template/pc/common/include/footer.htm View File

@@ -67,11 +67,11 @@
67 67
         <div class="nav-item-t"><i class="iconfont icon-shouye"></i></div>
68 68
         <div class="nav-item-b">首页</div>
69 69
     </a>
70
-    <a href="https://www.zc10000.com/zc" class="nav-item" {eyou:if condition='($page=="zhengce")'}style="color:red;{/eyou:if}">
70
+    <a href="https://www.zc10000.com/zc" class="nav-item" {eyou:if condition='($page=="zhengce" || $page=="zc_detail")'}style="color:red;{/eyou:if}">
71 71
         <div class="nav-item-t"><i class="iconfont icon-huiyuanshengji"></i></div>
72 72
         <div class="nav-item-b">政策</div>
73 73
     </a>
74
-    <a href="https://www.zc10000.com/cl" class="nav-item" {eyou:if condition='($page=="cailiao")'}style="color:red;{/eyou:if}">
74
+    <a href="https://www.zc10000.com/cl" class="nav-item" {eyou:if condition='($page=="cailiao" || $page=="cl_detail")'}style="color:red;{/eyou:if}">
75 75
         <div class="nav-item-t"><i class="iconfont icon-dingdan2"></i></div> <!--shopping-cart-full-->
76 76
         <div class="nav-item-b">材料</div>
77 77
     </a>

+ 6
- 4
template/pc/js/common.js View File

@@ -60,10 +60,12 @@ layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate'
60 60
                     //window.location.reload();
61 61
                     //window.location.href = data.data.down;
62 62
                     /*启动下载*/
63
-                    downFile(title,data.data.down);
63
+                    //downFile(title,data.data.down);
64
+                    //window.location.href = data.data.down;
65
+                    window.open(data.data.down,"_blank");
64 66
                 }else{
65 67
                     //layer.alert(data.msg, {icon: 5});
66
-                    layer.confirm(data.msg, {icon: 3}, function(){
68
+                    layer.confirm(data.msg, {icon: 3,title:false}, function(){
67 69
                         if(data.url != ''){
68 70
                             window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
69 71
                         }else{
@@ -95,7 +97,7 @@ layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate'
95 97
             success: function (data) {
96 98
                 layer.closeAll();
97 99
                 if(parseInt(data.code) == 1){
98
-                    layer.msg(data.msg, {icon: 1});
100
+                    layer.msg(data.msg, {icon: 1,title:false});
99 101
                     //window.location.reload();
100 102
                     //window.location.href = data.data.down;
101 103
                     /*增加点赞数*/
@@ -143,7 +145,7 @@ layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate'
143 145
             success: function (data) {
144 146
                 layer.closeAll();
145 147
                 if(parseInt(data.code) == 1){
146
-                    layer.msg(data.msg, {icon: 1});
148
+                    layer.msg(data.msg, {icon: 1,title:false});
147 149
                     //window.location.reload();
148 150
                     //window.location.href = data.data.down;
149 151
                     /*增加点赞数*/

Loading…
Cancel
Save