pengchanglu il y a 3 ans
Parent
commit
d908f2b7c2

+ 10 - 8
application/admin/controller/pig/Codecreate.php

@@ -63,6 +63,7 @@ class Codecreate extends Backend
                     //pengchanglu
                     $params['orderid'] = 'c'. date("YmdHis") . mt_rand(100, 999);
                     $result = $this->model->allowField(true)->save($params);
+                    $last_id = $this->model->getLastInsID();
                     //生成码
                     /*
                     $code_temp = [];
@@ -76,9 +77,9 @@ class Codecreate extends Backend
                     Db::table('pi_p_code')->insertAll($code_temp);
                     */
 
-                    $sql = 'INSERT INTO `pig`.`pi_p_code` (`admin_id`, `createtime`) VALUES ';
+                    $sql = 'INSERT INTO `pig`.`pi_p_code` (`admin_id`,`co_id`,`createtime`) VALUES ';
                     for ($i=0; $i < $params['num']; $i++) {
-                        $sql .= ' ('.$params['admin_id'].','.time().'),';
+                        $sql .= ' ('.$params['admin_id'].','.$last_id.','.time().'),';
                     }
                     $sql = rtrim($sql, ',');
                     $sql .= ' ;';
@@ -112,25 +113,26 @@ class Codecreate extends Backend
     public function download()
     {
         $url = 'http://pig.viicb.com/index/index/code.html?code=';
-        $co_id = $params = $this->request->request("co_id");
-        if (!$co_id) {
-            $this->error('co_id为空!');
+        $ids = $params = $this->request->request("ids");
+        if (!$ids) {
+            $this->error('ids');
         }
+        $ids_arr = explode(',', $ids);
         $model = new \app\admin\model\pig\Code;
-        $list = $model->where('co_id', $co_id)->column('id');
+        $list = $model->where('co_id', 'in', $ids_arr)->column('id');
 
         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");
+        header("Content-Disposition:attachment;filename=code-" . date("Y-m-d") . ".csv");
         ob_end_clean();
 
         echo 'ID,URL'."\n";
 
         foreach ($list as $k => $v) {
-            echo $k+1,','.$url.encrypt(str_pad($v, 8, '0', STR_PAD_LEFT))."\n";
+            echo $k+1,','.$url.encrypt(str_pad($v, 10, '0', STR_PAD_LEFT))."\n";
             // code...
         }
         exit;

+ 1 - 0
application/admin/view/pig/codecreate/index.html

@@ -31,6 +31,7 @@
                         </div>
 
                         <a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('pig/codecreate/recyclebin')?'':'hide'}" href="pig/codecreate/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>
+                        <a class="btn btn-danger bg-yellow btn-code-download btn-disabled disabled{:$auth->check('pig/codecreate/download')?'':'hide'}" href="javascript:;" title="下载"><i class="fa fa-plus"></i>下载码</a>
                     </div>
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('pig/codecreate/edit')}"

+ 6 - 0
public/assets/js/backend/pig/codecreate.js

@@ -40,6 +40,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 
             // 为表格绑定事件
             Table.api.bindevent(table);
+            //下载
+            $(document).on("click", ".btn-code-download", function () {
+                var ids = Table.api.selectedids(table);
+                //Fast.api.open("shop/shop/cost?ids="+ids);
+                window.open("codecreate/download?ids="+ids, '下载码');
+            });
         },
         recyclebin: function () {
             // 初始化表格参数配置