pengchanglu 3 år sedan
förälder
incheckning
17709c8d70

+ 28 - 0
application/admin/controller/pig/Codecreate.php

@@ -105,4 +105,32 @@ class Codecreate extends Backend
         }
         return $this->view->fetch();
     }
+
+    /**
+     * 下载
+     */
+    public function download()
+    {
+        $co_id = $params = $this->request->request("co_id");
+        if (!$co_id) {
+            $this->error('co_id为空!');
+        }
+        $list = $this->model->where('co_id', $co_id)->column('id')->select();
+
+        set_time_limit(0);
+        ini_set('memory_limit', '512M');
+
+        //导出csv格式
+        header("Content-Type:text/csv");
+        header("Content-Disposition:attachment;filename=" . $co_id ."-code-" . date("Y-m-d") . ".csv");
+        ob_end_clean();
+
+        echo 'ID,URL\n';
+
+        foreach ($list as $k => $v) {
+            echo $k+1,','.encrypt($v).'\n';
+            // code...
+        }
+        exit;
+    }
 }

+ 2 - 2
application/index/controller/Index.php

@@ -27,10 +27,10 @@ class Index extends Frontend
             $this->error("CODE为空,非法访问!");
             exit;
         }
-        //$id = decrypt($code);
+        $id = decrypt($code);
         $id = 1;
         $code = new Code();
-        $codeinfo = $code->find($id)->toArray();
+        $codeinfo = $code->find($id);
         if (!$codeinfo) {
             $this->error("参数错误!");
             exit;