Kaynağa Gözat

first commit

liuhairui 6 ay önce
ebeveyn
işleme
bdb3569012

+ 14 - 26
application/admin/controller/QcodeAdd.php

@@ -166,6 +166,7 @@ class QcodeAdd extends Backend
         $batchList = [
             'supplier_name' => $data['company_name'],
             'supplier_code' => $userinfo['printer_code'],
+            'kes' => $userinfo['kes'],
             'supplier_id' => $userinfo['id'],
             'matter_name' => $productList['product_name'],
             'matter_no' => $productList['product_code'],
@@ -210,38 +211,19 @@ class QcodeAdd extends Backend
             //插入大小二维码数据
             //二维码数据不变区域
 //            echo "<pre>";
-//            print_r($batchList['matter_type']);
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r($batchList['supplier_code']);
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r('9');
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r($batchList['matter_no']);
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r($batchList['manufacture_date']);
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r($batchList['print_date']);
+//            print_r($batchList);
 //            echo "<pre>";
             $fixed_code = '';
             $fixed_code.=$this->intTochar($batchList['matter_type'],2);//2位  辅料种类编码
-//            $fixed_code .= substr($this->intTochar($batchList['supplier_code'], 12), 1);//12位  供应商编码 // 去掉第一位0
-            $fixed_code .= $this->intTochar($batchList['supplier_code'], 21);//21位  供应商编码
-            $fixed_code .= '9'; // 补0一位
+//            $fixed_code .= $this->intTochar($batchList['supplier_code'], 21);//21位  供应商编码
+            $fixed_code .= $this->intTochar($batchList['kes'], 12);//12位  供应商编码
+//            $fixed_code .= '9'; // 补0一位
+            $fixed_code .= '0000000000'; // 补0一位
             $fixed_code.=$this->intTochar($batchList['matter_no'],10);//10位  辅料编码
             $fixed_code.=$batchList['manufacture_date'];//6位  生产日期
             $print_code=$batchList['print_date'];//6位  打码日期
 
-//            echo "<pre>";
-//            print_r($fixed_code);
-//            echo "<pre>";
-//            echo "<pre>";
-//            print_r($print_code);
-//            echo "<pre>";
+
             $small_liushui = [
                 'onlycode' => 'AB92'.$fixed_code.$print_code,
                 'last_num' => 0,
@@ -256,7 +238,7 @@ class QcodeAdd extends Backend
             ];
 //echo "<pre>";
 //print_r($whereSmall);
-//echo "<pre>";die;
+//echo "<pre>";
             if ($liushui->name($userinfo['company'].'_'.'qcode_liushui')->where($whereSmall)->find()){
                 //小件二维码存在,更新小件二维码最后流水号
                 $lastNum = $liushui->name($userinfo['company'].'_'.'qcode_liushui')->where($whereSmall)->find();
@@ -286,6 +268,9 @@ class QcodeAdd extends Backend
                 }
                 //大件二维码数据
                 $code_data = $this->CodeData('AB92',$fixed_code,$small_n,$print_code,$l_flow,$l_weight,'2',$l_reservation);
+//                echo "<pre>";
+//                print_r($code_data);
+//                echo "<pre>";
                 //大码数据信息
                 $l_data = [
                     'bach_id' => $last_id,
@@ -301,6 +286,9 @@ class QcodeAdd extends Backend
                     'l_status' => 0,
                     'l_print' => 0
                 ];
+//                echo "<pre>";
+//                print_r($l_data);
+//                echo "<pre>";die;
                 $l_res = $large->save($l_data);
                 if ($l_res === 0){
                     $this->error('大件码插入失败');

+ 666 - 263
application/admin/controller/QcodeBach.php

@@ -10,11 +10,10 @@ use app\admin\model\QcodeSmall;
 use app\common\controller\Backend;
 use \think\Session;
 use think\Db;
+use MongoDB\BSON\ObjectId;
 
 /**
- *
- *
- * @icon fa fa-circle-o
+ * 批次列表
  */
 class QcodeBach extends Backend
 {
@@ -32,13 +31,12 @@ class QcodeBach extends Backend
         $this->model = new \app\admin\model\QcodeBach();
     }
 
-
-
     /**
      * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
      * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
      * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
      */
+
     /**
      * 查看
      */
@@ -56,120 +54,179 @@ class QcodeBach extends Backend
      */
     public function bach()
     {
-        //当前是否为关联查询
         $this->relationSearch = false;
-        //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
+
         if ($this->request->isAjax()) {
-            //如果发送的来源是Selectpage,则转发到Selectpage
+            // 如果是 Selectpage 请求则跳转
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
+
             $userInfo = Session::get('admin');
             $company_id = (int)$userInfo['company'];
-            $where = [
-                'delete_time'=> ''
-            ];
 
-            $req = input();
-            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
-            $order = $req['order'];
-            $offset = $req['offset'];
-            $limit = $req['limit'];
+            // 默认条件:未删除
+            $where = ['delete_time' => ''];
 
-            // 构造模糊查询条件
-//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
-//            $filter = ['field' => $regex];
+            // 获取前端传参
+            $req = input();
+            $sort = $req['sort'] == 'id' ? '_id' : $req['sort'];
+            $order = $req['order'] ?? 'desc';
+            $offset = $req['offset'] ?? 0;
+            $limit = $req['limit'] ?? 20;
 
+            // 解析 filter 筛选条件
             $filter = json_decode($req['filter'], true);
-            foreach ($filter as $k => $v){
-                $where[$k] = new \MongoDB\BSON\Regex($v);
+            if (is_array($filter)) {
+                foreach ($filter as $k => $v) {
+                    $where[$k] = new \MongoDB\BSON\Regex($v);
+                }
             }
 
-            $total = $this->model->name($company_id.'_'."qcode_bach")->where($where)->count();
-            $list = $this->model->name($company_id.'_'."qcode_bach")->where($where)
-                ->order($sort,$order)
-                ->limit($limit)
-                ->skip($offset)
-                ->select();
-            foreach ($list as $k=>$v) {
-                $oid = $v['_id']->jsonSerialize();
-                $list[$k]['id'] = $oid['$oid'];
-            }
+            $list = [];
+
+            // 超级管理员:查询所有公司
+            if (isSuperAdmin()) {
+                $companies = Db::name('admin')
+                    ->field('company')
+                    ->where('company', '<>', '')
+                    ->where('kes', '<>', '')
+                    ->distinct(true)
+                    ->select();
+
+                foreach ($companies as $row) {
+                    $cid = $row['company'];
+                    $rows = $this->model->name($cid . '_qcode_bach')
+                        ->where($where)
+                        ->select(); // 不分页,后面统一处理
+
+                    foreach ($rows as &$item) {
+                        $oid = $item['_id']->jsonSerialize();
+                        $item['id'] = $oid['$oid'];
+                    }
+
+                    $list = array_merge($list, $rows);
+                }
 
-            $result = array("total" => $total, "rows" => $list);
+                // 全局排序(按 create_time 排序)
+                usort($list, function ($a, $b) use ($sort, $order) {
+                    $valA = $a[$sort] ?? 0;
+                    $valB = $b[$sort] ?? 0;
+                    return $order === 'asc' ? ($valA <=> $valB) : ($valB <=> $valA);
+                });
+
+                // 总数与分页
+                $total = count($list);
+                $list = array_slice($list, $offset, $limit);
+            } else {
+                // 普通用户:只查本公司
+                $model = $this->model->name($company_id . '_qcode_bach');
+                $total = $model->where($where)->count();
+
+                $list = $model->where($where)
+                    ->order([$sort => $order])
+                    ->limit($limit)
+                    ->skip($offset)
+                    ->select();
+
+                foreach ($list as &$item) {
+                    $oid = $item['_id']->jsonSerialize();
+                    $item['id'] = $oid['$oid'];
+                }
+            }
 
-            return json($result);
+            return json(["total" => $total, "rows" => $list]);
         }
+
         return $this->view->fetch();
     }
 
+    /**
+     * 大件列表
+     */
     /**
      * 大件列表
      */
     public function large()
     {
-        //当前是否为关联查询
         $this->relationSearch = false;
-        //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
+
         if ($this->request->isAjax()) {
-            //如果发送的来源是Selectpage,则转发到Selectpage
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
+
             $userInfo = Session::get('admin');
             $company_id = (int)$userInfo['company'];
-            $where = [
-//                'company_id'=>(int)$userInfo['company'],
-                'delete_time'=> ''
-            ];
 
+            $where = ['delete_time' => ''];
             $req = input();
-            if($req['filter']=='{}'){
-                $result = array("total" => 0, "rows" => []);
-                return json($result);
+
+            if ($req['filter'] == '{}') {
+                return json(["total" => 0, "rows" => []]);
             }
-            $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
-            $order = $req['order'];
-//            $offset = $req['offset'];
-//            $limit = $req['limit'];
 
-            // 构造模糊查询条件
-//            $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
-//            $filter = ['field' => $regex];
+            $sort = ($req['sort'] == 'id') ? '_id' : $req['sort'];
+            $order = $req['order'];
 
             $filter = json_decode($req['filter'], true);
-            foreach ($filter as $k => $v){
-                $where[$k] = new \MongoDB\BSON\Regex($v);
+            if (is_array($filter)) {
+                foreach ($filter as $k => $v) {
+                    $where[$k] = new \MongoDB\BSON\Regex($v);
+                }
             }
 
+            $list = [];
+            $total = 0;
             $db = new QcodeLarge();
-            $total = $db->name($company_id.'_'."qcode_large")->where($where)->count();
-            $list = $db->name($company_id.'_'."qcode_large")->where($where)
-                ->order($sort,$order)
-//                ->limit($limit)
-//                ->skip($offset)
-                ->select();
             $qcodeSmall = new QcodeSmall();
-            foreach ($list as $k=>$v) {
-                $oid = $v['_id']->jsonSerialize();
-                $list[$k]['id'] = $oid['$oid'];
-                //设置当前托盘号
-                $list[$k]['l_flow'] = ltrim(substr($v['code'],53,6),'0');
-                //查询小件数量
-                $small_num = $qcodeSmall->name($company_id.'_'."qcode_small")
-                    ->where('large_id',$oid['$oid'])
-                    ->count();
-                $list[$k]['small_num'] = $small_num;
-                //设置当前大件重量
-                $list[$k]['l_weight'] = floatval($v['l_weight'])/100;
-
-            }
-
-            $result = array("total" => $total, "rows" => $list);
-            return json($result);
+
+            // 超级管理员查询所有公司数据
+            if (isSuperAdmin()) {
+                $companies = Db::name('admin')
+                    ->field('company')
+                    ->where('company', '<>', '')
+                    ->where('kes', '<>', '')
+                    ->distinct(true)
+                    ->select();
+
+                foreach ($companies as $row) {
+                    $cid = $row['company'];
+                    $table = $cid . '_qcode_large';
+
+                    $rows = $db->name($table)->where($where)->order($sort, $order)->select();
+                    $total += count($rows);
+
+                    foreach ($rows as $k => $v) {
+                        $oid = $v['_id']->jsonSerialize();
+                        $v['id'] = $oid['$oid'];
+                        $v['l_flow'] = ltrim(substr($v['code'], 53, 6), '0');
+                        $v['small_num'] = $qcodeSmall->name($cid . '_qcode_small')->where('large_id', $oid['$oid'])->count();
+                        $v['l_weight'] = floatval($v['l_weight']) / 100;
+                        $list[] = $v;
+                    }
+                }
+            } else {
+                // 普通用户只查自己公司表
+                $table = $company_id . '_qcode_large';
+
+                $list = $db->name($table)->where($where)->order($sort, $order)->select();
+                $total = count($list);
+
+                foreach ($list as $k => $v) {
+                    $oid = $v['_id']->jsonSerialize();
+                    $list[$k]['id'] = $oid['$oid'];
+                    $list[$k]['l_flow'] = ltrim(substr($v['code'], 53, 6), '0');
+                    $list[$k]['small_num'] = $qcodeSmall->name($company_id . '_qcode_small')->where('large_id', $oid['$oid'])->count();
+                    $list[$k]['l_weight'] = floatval($v['l_weight']) / 100;
+                }
+            }
+
+            return json(["total" => $total, "rows" => $list]);
         }
+
         return $this->view->fetch();
     }
 
@@ -208,54 +265,217 @@ class QcodeBach extends Backend
                 $where[$k] = new \MongoDB\BSON\Regex($v);
             }
 
+            $list = [];
+            $total = 0;
+
             $qcodeSmall = new QcodeSmall();
-            $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count();
-            $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
-                ->order($sort,$order)
-                ->limit($limit)
-                ->skip($offset)
-                ->select();
 
-            foreach ($list as $k=>$v) {
-                $oid = $v['_id']->jsonSerialize();
-                $list[$k]['id'] = $oid['$oid'];
-                $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
-            }
+            // 超级管理员查询所有公司
+            if (isSuperAdmin()) {
+                $companies = Db::name('admin')
+                    ->field('company')
+                    ->where('company', '<>', '')
+                    ->where('kes', '<>', '')
+                    ->distinct(true)
+                    ->select();
+
+                foreach ($companies as $row) {
+                    $cid = $row['company'];
+                    $table = $cid . '_qcode_small';
+
+                    // 获取数据(不分页,后面统一分页)
+                    $rows = $qcodeSmall->name($table)->where($where)->select();
+
+                    foreach ($rows as &$v) {
+                        $oid = $v['_id']->jsonSerialize();
+                        $v['id'] = $oid['$oid'];
+                        $v['l_flow'] = ($req['l_flow'] ?? '') . '-' . $v['l_flow'];
+                        if (strpos($v['l_flow'], '-') !== false) {
+                            $parts = explode('-', $v['l_flow']);
+                            $v['l_flows'] = end($parts);
+                        } else {
+                            $v['l_flows'] = '';
+                        }
+                    }
 
-            $result = array("total" => $total, "rows" => $list);
+                    $list = array_merge($list, $rows);
+                }
 
-            return json($result);
+                // 全部公司数据合并后,统一排序
+                usort($list, function ($a, $b) use ($sort, $order) {
+                    $valA = $a[$sort] ?? '';
+                    $valB = $b[$sort] ?? '';
+                    return $order === 'asc' ? ($valA <=> $valB) : ($valB <=> $valA);
+                });
+
+                // 总条数
+                $total = count($list);
+
+                // 分页截取
+                $list = array_slice($list, $offset, $limit);
+            } else {
+                // 普通用户仅查本公司
+                $table = $company_id . '_qcode_small';
+
+                $total = $qcodeSmall->name($table)->where($where)->count();
+
+                $list = $qcodeSmall->name($table)->where($where)
+                    ->order([$sort => $order])
+                    ->limit($limit)
+                    ->skip($offset)
+                    ->select();
+
+                foreach ($list as $k => $v) {
+                    $oid = $v['_id']->jsonSerialize();
+                    $list[$k]['id'] = $oid['$oid'];
+                    $list[$k]['l_flow'] = ($req['l_flow'] ?? '') . '-' . $v['l_flow'];
+                }
+            }
+
+            return json(["total" => $total, "rows" => $list]);
         }
         return $this->view->fetch();
     }
 
+
     /**
-     * 小件导出状态修改
+     * 小件导出状态修改(支持超级管理员操作单个公司表)
+     * 支持处理单个ID和多个ID(逗号分隔)的情况
      */
     public function small_status()
     {
         $req = $this->request->param();
         $ids = $req['ids'];
-        $userInfo = Session::get('admin');
-        $company_id = (int)$userInfo['company'];
+
+        // 统一处理ids参数,转换为数组
+        if (!is_array($ids)) {
+            $ids = explode(',', $ids);
+        }
+
+        // 过滤空值
+        $ids = array_filter($ids);
+        if (empty($ids)) {
+            $this->error("参数错误:ids不能为空");
+        }
+
+        // 判断是否是超级管理员
+        if (isSuperAdmin()) {
+            $this->handleSuperAdminMode($ids);
+        } else {
+            $this->handleNormalUserMode($ids);
+        }
+    }
+
+    /**
+     * 超级管理员处理模式
+     */
+    protected function handleSuperAdminMode($ids)
+    {
         $qcodeSmall = new QcodeSmall();
+        $companyTables = Db::name('admin')
+            ->field('company')
+            ->where('company', '<>', '')
+            ->where('kes', '<>', '')
+            ->distinct(true)
+            ->select();
 
-        $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status');
+        $found = false;
+        $successIds = [];
+        $failedIds = [];
+
+        foreach ($companyTables as $row) {
+            $cid = $row['company'];
+            $tableName = $cid . '_qcode_small';
+
+            try {
+                // 查询该表中存在的记录
+                $records = $qcodeSmall->name($tableName)
+                    ->whereIn('_id', $ids)
+                    ->select();
+
+                if (!empty($records)) {
+                    $found = true;
+
+                    // 批量更新状态
+                    foreach ($records as $record) {
+                        $newStatus = ($record['status'] == 0) ? 1 : 0;
+                        $result = $qcodeSmall->name($tableName)
+                            ->where('_id', $record['_id'])
+                            ->update(['status' => $newStatus]);
+
+                        if ($result) {
+                            $successIds[] = $record['_id'];
+                        } else {
+                            $failedIds[] = $record['_id'];
+                        }
+                    }
+                }
+            } catch (\Exception $e) {
+                continue; // 表不存在,跳过
+            }
+        }
 
-        if ($status === 0) {
-            $newStatus = 1;
-        } elseif ($status === 1) {
-            $newStatus = 0;
+        if ($found) {
+            $message = "超级管理员批量切换完成";
+            if (!empty($successIds)) {
+                $message .= ",成功:";
+            }
+            if (!empty($failedIds)) {
+                $message .= ",失败:";
+            }
+            $this->success($message);
         } else {
-            // 处理其他情况,如果有需要
+            $this->error("在所有公司中未找到这些记录:" . implode(',', $ids));
         }
+    }
 
-        $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids'])
-            ->update(['status' => $newStatus]);
-        if ($bool){
-            $this->success("切换成功", null, ['id' => $ids]);
-        }else{
-            $this->error("切换失败", null, ['id' => $ids]);
+    /**
+     * 普通用户处理模式
+     */
+    protected function handleNormalUserMode($ids)
+    {
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+        $qcodeSmall = new QcodeSmall();
+        $tableName = $company_id . '_qcode_small';
+
+        $successIds = [];
+        $failedIds = [];
+
+        try {
+            // 查询存在的记录
+            $records = $qcodeSmall->name($tableName)
+                ->whereIn('_id', $ids)
+                ->select();
+
+            if (empty($records)) {
+                $this->error("未找到符合条件的记录");
+            }
+
+            // 批量更新状态
+            foreach ($records as $record) {
+                $newStatus = ($record['status'] == 0) ? 1 : 0;
+                $result = $qcodeSmall->name($tableName)
+                    ->where('_id', $record['_id'])
+                    ->update(['status' => $newStatus]);
+
+                if ($result) {
+                    $successIds[] = $record['_id'];
+                } else {
+                    $failedIds[] = $record['_id'];
+                }
+            }
+
+            $message = "批量切换完成";
+            if (!empty($successIds)) {
+                $message .= ",成功:" ;
+            }
+            if (!empty($failedIds)) {
+                $message .= ",失败:" ;
+            }
+            $this->success($message);
+        } catch (\Exception $e) {
+            $this->error("操作失败:" . $e->getMessage());
         }
     }
 
@@ -264,94 +484,159 @@ class QcodeBach extends Backend
      */
     public function print_l()
     {
-        //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
         $req = $this->request->param();
-        if ($this->request->isAjax()) {
 
-            $ids = $req['ids'];
-            $type = $req['type'];
-            $numn = $req['numn'];
+        if (!$this->request->isAjax()) {
+            $this->view->assign('ids', $req['ids']);
+            return $this->view->fetch();
+        }
 
-            $userInfo = Session::get('admin');
-            $company_id = (int)$userInfo['company'];
-            $qcodeLarge = new QcodeLarge();
-            $qcodeSmall = new QcodeSmall();
-            $qcodeProduct = new QcodeProduct();
-            $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
-            $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
-            $row = $qcodeProduct->where('product_code',json_decode($bach,true)['matter_no'])->find();
-
-            $company_name = json_decode($bach,true)['supplier_name'];
-            $product_name = json_decode($bach,true)['matter_name'];
-//            $date = json_decode($bach,true)['manufacture_date'];
-//            $batch = json_decode($bach,true)['bach_num'];
-            $main_unit = json_decode($row,true)['main_unit'];
-            $sec_unit = json_decode($row,true)['sec_unit'];
-            $proportion = json_decode($row,true)['proportion'];
-
-            $rows = [];
-            //查询打印大件码所需数据
-            foreach ($ids as $key=>$value){
-                $row = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
-                $row = json_decode($row,true);
-                $code = $row['code'];
-                $rows[$key]['company_name'] = $company_name;
-                $rows[$key]['product_name'] = $product_name;
-                $rows[$key]['sqrcd'] = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->count();
-                $rows[$key]['main_unit'] = $main_unit;
-                $rows[$key]['sec_unit'] = $sec_unit;
-                $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
-                $rows[$key]['l_flow'] =  ltrim(substr($code,53,6),'0');
-                $rows[$key]['qrcode'] = $code;
-                $rows[$key]['pCode'] = $this->qrcode($code);
-
-                //批次号特殊情况判断
-                if (substr($code,76,10)=='0000000000'){
-                    $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
-                }else{
-                    $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
-                }
+        $ids = $req['ids'];
+        $type = $req['type'];
+        $numn = $req['numn'];
 
-                //转换关系判断
-                if($row['l_num']===null){
-                    //走转换关系
-                    if ($proportion){
-                        $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
-                        $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
-                    }else{
-                        $rows[$key]['num'] = '';
-                    }
-                }else if($row['l_num']==0){
-                    //判断是否是公斤
-                    if($main_unit=='公斤'){
-                        //公斤使用l_weight
-                        $rows[$key]['num'] = $row['l_weight'];
-                    }else{
-                        //不是公斤走转换关系
-                        if ($proportion){
-                            $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
-                            $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
-                        }else{
-                            $rows[$key]['num'] = '';
+        $qcodeLarge = new QcodeLarge();
+        $qcodeSmall = new QcodeSmall();
+        $qcodeProduct = new QcodeProduct();
+
+        $rows = [];
+
+        // 超级管理员逻辑:遍历所有公司表查找匹配ID
+        if (isSuperAdmin()) {
+            $companyList = Db::name('admin')
+                ->field('company')
+                ->where('company', '<>', '')
+                ->where('kes', '<>', '')
+                ->distinct(true)
+                ->select();
+
+            foreach ($companyList as $company) {
+                $cid = $company['company'];
+                $tableLarge = $cid . '_qcode_large';
+                $tableBach = $cid . '_qcode_bach';
+                $tableSmall = $cid . '_qcode_small';
+
+                // 检查是否有匹配的大件ID
+                try {
+                    $large = $qcodeLarge->name($tableLarge)->where('_id', $ids[0])->find();
+                    if (empty($large)) continue;
+
+                    $largeArr = json_decode($large, true);
+                    $bach = $this->model->name($tableBach)->where('_id', $largeArr['bach_id'])->find();
+                    $bachArr = json_decode($bach, true);
+                    $row = $qcodeProduct->where('product_code', $bachArr['matter_no'])->find();
+                    $rowArr = json_decode($row, true);
+
+                    $company_name = $bachArr['supplier_name'];
+                    $product_name = $bachArr['matter_name'];
+                    $main_unit = $rowArr['main_unit'];
+                    $sec_unit = $rowArr['sec_unit'];
+                    $proportion = $rowArr['proportion'];
+
+                    foreach ($ids as $key => $value) {
+                        $rowData = $qcodeLarge->name($tableLarge)->where('_id', $value)->find();
+                        $rowData = json_decode($rowData, true);
+                        $code = $rowData['code'];
+
+                        $rows[$key] = [
+                            'company_name' => $company_name,
+                            'product_name' => $product_name,
+                            'sqrcd' => $qcodeSmall->name($tableSmall)->where('large_id', $value)->count(),
+                            'main_unit' => $main_unit,
+                            'sec_unit' => $sec_unit,
+                            'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                            'l_flow' => ltrim(substr($code, 53, 6), '0'),
+                            'qrcode' => $code,
+                            'pCode' => $this->qrcode($code),
+                            'batch' => (substr($code, 76, 10) == '0000000000') ?
+                                ltrim(substr($code, 66, 10), '0') :
+                                ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0')
+                        ];
+
+                        // 数量处理
+                        if ($rowData['l_num'] === null) {
+                            $rows[$key]['num'] = $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : '';
+                        } elseif ($rowData['l_num'] == 0) {
+                            $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] : (
+                            $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : ''
+                            );
+                        } else {
+                            $rows[$key]['num'] = $rowData['l_num'];
                         }
                     }
-                }else{
-                    //箱, 使用l_num
-                    $rows[$key]['num'] = $row['l_num'];
+
+                    // 查到就停止遍历
+                    break;
+
+                } catch (\Exception $e) {
+                    continue;
                 }
+            }
+
+        } else {
+            // 普通用户逻辑,只能查看所属公司数据
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
 
+            $tableLarge = $company_id . '_qcode_large';
+            $tableBach = $company_id . '_qcode_bach';
+            $tableSmall = $company_id . '_qcode_small';
+
+            $large = $qcodeLarge->name($tableLarge)->where('_id', $ids[0])->find();
+            $largeArr = json_decode($large, true);
+            $bach = $this->model->name($tableBach)->where('_id', $largeArr['bach_id'])->find();
+            $bachArr = json_decode($bach, true);
+            $row = $qcodeProduct->where('product_code', $bachArr['matter_no'])->find();
+            $rowArr = json_decode($row, true);
+
+            $company_name = $bachArr['supplier_name'];
+            $product_name = $bachArr['matter_name'];
+            $main_unit = $rowArr['main_unit'];
+            $sec_unit = $rowArr['sec_unit'];
+            $proportion = $rowArr['proportion'];
+
+            foreach ($ids as $key => $value) {
+                $rowData = $qcodeLarge->name($tableLarge)->where('_id', $value)->find();
+                $rowData = json_decode($rowData, true);
+                $code = $rowData['code'];
+
+                $rows[$key] = [
+                    'company_name' => $company_name,
+                    'product_name' => $product_name,
+                    'sqrcd' => $qcodeSmall->name($tableSmall)->where('large_id', $value)->count(),
+                    'main_unit' => $main_unit,
+                    'sec_unit' => $sec_unit,
+                    'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                    'l_flow' => ltrim(substr($code, 53, 6), '0'),
+                    'qrcode' => $code,
+                    'pCode' => $this->qrcode($code),
+                    'batch' => (substr($code, 76, 10) == '0000000000') ?
+                        ltrim(substr($code, 66, 10), '0') :
+                        ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0')
+                ];
+
+                if ($rowData['l_num'] === null) {
+                    $rows[$key]['num'] = $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : '';
+                } elseif ($rowData['l_num'] == 0) {
+                    $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] : (
+                    $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : ''
+                    );
+                } else {
+                    $rows[$key]['num'] = $rowData['l_num'];
+                }
             }
-            $data = [
-                'type'=>$type,
-                'numn'=>$numn,
-                'rows'=>$rows,
-                'ids'=>$ids,
-            ];
-            $this->success('成功','',$data);
         }
-        $this->view->assign('ids',$req['ids']);
-        return $this->view->fetch();
+
+        // 最终返回数据
+        $data = [
+            'type' => $type,
+            'numn' => $numn,
+            'rows' => $rows,
+            'ids' => $ids,
+        ];
+
+        $this->success('成功', '', $data);
     }
 
     /**
@@ -359,67 +644,134 @@ class QcodeBach extends Backend
      */
     public function print_s()
     {
-        //设置过滤方法
+        // 过滤请求参数
         $this->request->filter(['strip_tags', 'trim']);
         $req = $this->request->param();
-        if ($this->request->isAjax()) {
 
-            $ids = $req['ids'];
-            $type = $req['type'];
-            $numn = $req['numn'];
+        if (!$this->request->isAjax()) {
+            $this->view->assign('ids', $req['ids']);
+            return $this->view->fetch();
+        }
+
+        $ids = $req['ids'];
+        $type = $req['type'];
+        $numn = $req['numn'];
 
+        $qcodeLarge = new QcodeLarge();
+        $qcodeSmall = new QcodeSmall();
+        $rows = [];
+        $key = 0;
+
+        // 超级管理员逻辑
+        if (isSuperAdmin()) {
+            $companyList = Db::name('admin')
+                ->field('company')
+                ->where('company', '<>', '')
+                ->where('kes', '<>', '')
+                ->distinct(true)
+                ->select();
+
+            foreach ($companyList as $company) {
+                $cid = $company['company'];
+                $tableLarge = $cid . '_qcode_large';
+                $tableSmall = $cid . '_qcode_small';
+                $tableBach = $cid . '_qcode_bach';
+
+                try {
+                    $large = $qcodeLarge->name($tableLarge)->where('_id', $ids[0])->find();
+                    if (empty($large)) continue;
+
+                    $largeArr = json_decode($large, true);
+                    $bach = $this->model->name($tableBach)->where('_id', $largeArr['bach_id'])->find();
+                    $bachArr = json_decode($bach, true);
+
+                    $company_name = $bachArr['supplier_name'];
+                    $product_name = $bachArr['matter_name'];
+
+                    foreach ($ids as $value) {
+                        $large = $qcodeLarge->name($tableLarge)->where('_id', $value)->find();
+                        $large = json_decode($large, true);
+
+                        $arr = $qcodeSmall->name($tableSmall)->where('large_id', $value)->column('_id');
+
+                        foreach ($arr as $v) {
+                            $oid = is_object($v) ? $v->jsonSerialize()['$oid'] : $v;
+                            $small = $qcodeSmall->name($tableSmall)->where('_id', $oid)->find();
+                            $small = json_decode($small, true);
+                            $code = $small['code'];
+
+                            $rows[$key] = [
+                                'company_name' => $company_name,
+                                'product_name' => $product_name,
+                                'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                                'l_flow' => ltrim(substr($large['code'], 53, 6), '0') . '-' . $small['l_flow'],
+                                'qrcode' => $code,
+//                          'pCode' => $this->qrcode($code), // 如需启用二维码图像,取消注释
+                                'batch' => (substr($code, 76, 10) == '0000000000') ?
+                                    ltrim(substr($code, 66, 10), '0') :
+                                    ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0'),
+                            ];
+                            $key++;
+                        }
+                    }
+
+                    break; // 找到数据即跳出公司循环
+
+                } catch (\Exception $e) {
+                    continue;
+                }
+            }
+
+        } else {
+            // 普通管理员逻辑
             $userInfo = Session::get('admin');
             $company_id = (int)$userInfo['company'];
-            $qcodeLarge = new QcodeLarge();
-            $qcodeSmall = new QcodeSmall();
-            $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
-            $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
 
-            $company_name = json_decode($bach,true)['supplier_name'];
-            $product_name = json_decode($bach,true)['matter_name'];
+            $tableLarge = $company_id . '_qcode_large';
+            $tableSmall = $company_id . '_qcode_small';
+            $tableBach = $company_id . '_qcode_bach';
 
-            //获取全部小件id
-            $rows = [];
-            $key = 0;
-            foreach ($ids as $value){
-                $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
-                $large = json_decode($large,true);
+            $large = $qcodeLarge->name($tableLarge)->where('_id', $ids[0])->find();
+            $bach = $this->model->name($tableBach)->where('_id', json_decode($large, true)['bach_id'])->find();
 
-                $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id');
-                //查询打印大件码所需数据
-                foreach ($arr as $v){
+            $company_name = json_decode($bach, true)['supplier_name'];
+            $product_name = json_decode($bach, true)['matter_name'];
 
-                    $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find();
-                    $small = json_decode($small,true);
-                    $code = $small['code'];
+            foreach ($ids as $value) {
+                $large = $qcodeLarge->name($tableLarge)->where('_id', $value)->find();
+                $large = json_decode($large, true);
 
-                    $rows[$key]['company_name'] = $company_name;
-                    $rows[$key]['product_name'] = $product_name;
-                    $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
-                    $rows[$key]['l_flow'] =  ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
-                    $rows[$key]['qrcode'] = $code;
-//                    $rows[$key]['pCode'] = $this->qrcode($code);
+                $arr = $qcodeSmall->name($tableSmall)->where('large_id', $value)->column('_id');
 
-                    //批次号特殊情况判断
-                    if (substr($code,76,10)=='0000000000'){
-                        $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
-                    }else{
-                        $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
-                    }
+                foreach ($arr as $v) {
+                    $oid = is_object($v) ? $v->jsonSerialize()['$oid'] : $v;
+                    $small = $qcodeSmall->name($tableSmall)->where('_id', $oid)->find();
+                    $small = json_decode($small, true);
+                    $code = $small['code'];
+
+                    $rows[$key] = [
+                        'company_name' => $company_name,
+                        'product_name' => $product_name,
+                        'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                        'l_flow' => ltrim(substr($large['code'], 53, 6), '0') . '-' . $small['l_flow'],
+                        'qrcode' => $code,
+//                  'pCode' => $this->qrcode($code),
+                        'batch' => (substr($code, 76, 10) == '0000000000') ?
+                            ltrim(substr($code, 66, 10), '0') :
+                            ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0'),
+                    ];
                     $key++;
                 }
             }
-
-            $data = [
-                'type'=>$type,
-                'numn'=>$numn,
-                'rows'=>$rows,
-                'ids'=>$ids,
-            ];
-            $this->success('成功','',$data);
         }
-        $this->view->assign('ids',$req['ids']);
-        return $this->view->fetch();
+
+        $data = [
+            'type' => $type,
+            'numn' => $numn,
+            'rows' => $rows,
+            'ids' => $ids,
+        ];
+        $this->success('成功', '', $data);
     }
 
     /**
@@ -427,58 +779,109 @@ class QcodeBach extends Backend
      */
     public function print_ls()
     {
-        //设置过滤方法
+        // 设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
         $req = $this->request->param();
-        if ($this->request->isAjax()) {
 
-            $ids = $req['ids'];
-            $type = $req['type'];
-            $numn = $req['numn'];
+        if (!$this->request->isAjax()) {
+            $this->view->assign('ids', $req['ids']);
+            return $this->view->fetch();
+        }
 
-            $userInfo = Session::get('admin');
-            $company_id = (int)$userInfo['company'];
+        $ids = $req['ids'];
+        $type = $req['type'];
+        $numn = $req['numn'];
 
-            $qcodeLarge = new QcodeLarge();
-            $qcodeSmall = new QcodeSmall();
-            $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->find();
-            $small = json_decode($small,true);
+        $qcodeLarge = new QcodeLarge();
+        $qcodeSmall = new QcodeSmall();
 
-            $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find();
-            $large = json_decode($large,true);
-            $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find();
+        $rows = [];
 
-            $company_name = json_decode($bach,true)['supplier_name'];
-            $product_name = json_decode($bach,true)['matter_name'];
+        // 超级管理员逻辑
+        if (isSuperAdmin()) {
+            $companyList = Db::name('admin')
+                ->field('company')
+                ->where('company', '<>', '')
+                ->where('kes', '<>', '')
+                ->distinct(true)
+                ->select();
 
-            //获取全部小件id
-            $rows = [];
-            $code = $small['code'];
+            foreach ($companyList as $company) {
+                $cid = $company['company'];
+                $tableSmall = $cid . '_qcode_small';
+                $tableLarge = $cid . '_qcode_large';
+                $tableBach = $cid . '_qcode_bach';
 
-            $rows[0]['company_name'] = $company_name;
-            $rows[0]['product_name'] = $product_name;
-            $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
-            $rows[0]['l_flow'] =  ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
-            $rows[0]['qrcode'] = $code;
-//            $rows[0]['pCode'] = $this->qrcode($code);
+                try {
+                    $small = $qcodeSmall->name($tableSmall)->where('_id', $ids)->find();
+                    if (empty($small)) continue;
+                    $small = json_decode($small, true);
 
-            //批次号特殊情况判断
-            if (substr($code,76,10)=='0000000000'){
-                $rows[0]['batch'] = ltrim(substr($code,66,10),'0');
-            }else{
-                $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
+                    $large = $qcodeLarge->name($tableLarge)->where('_id', $small['large_id'])->find();
+                    $large = json_decode($large, true);
+
+                    $bach = $this->model->name($tableBach)->where('_id', $small['bach_id'])->find();
+                    $bach = json_decode($bach, true);
+
+                    $code = $small['code'];
+                    $rows[0] = [
+                        'company_name' => $bach['supplier_name'],
+                        'product_name' => $bach['matter_name'],
+                        'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                        'l_flow' => ltrim(substr($large['code'], 53, 6), '0') . '-' . $small['l_flow'],
+                        'qrcode' => $code,
+                        // 'pCode' => $this->qrcode($code),
+                        'batch' => (substr($code, 76, 10) == '0000000000') ?
+                            ltrim(substr($code, 66, 10), '0') :
+                            ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0'),
+                    ];
+
+                    break; // 查到就退出循环
+                } catch (\Exception $e) {
+                    continue;
+                }
             }
 
-            $data = [
-                'type'=>$type,
-                'numn'=>$numn,
-                'rows'=>$rows,
-                'ids'=>$ids,
+        } else {
+            // 普通管理员逻辑
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            $tableSmall = $company_id . '_qcode_small';
+            $tableLarge = $company_id . '_qcode_large';
+            $tableBach = $company_id . '_qcode_bach';
+
+            $small = $qcodeSmall->name($tableSmall)->where('_id', $ids)->find();
+            $small = json_decode($small, true);
+
+            $large = $qcodeLarge->name($tableLarge)->where('_id', $small['large_id'])->find();
+            $large = json_decode($large, true);
+
+            $bach = $this->model->name($tableBach)->where('_id', $small['bach_id'])->find();
+            $bach = json_decode($bach, true);
+
+            $code = $small['code'];
+            $rows[0] = [
+                'company_name' => $bach['supplier_name'],
+                'product_name' => $bach['matter_name'],
+                'date' => substr_replace(substr_replace('20' . substr($code, 38, 6), '-', 4, 0), '-', 7, 0),
+                'l_flow' => ltrim(substr($large['code'], 53, 6), '0') . '-' . $small['l_flow'],
+                'qrcode' => $code,
+                // 'pCode' => $this->qrcode($code),
+                'batch' => (substr($code, 76, 10) == '0000000000') ?
+                    ltrim(substr($code, 66, 10), '0') :
+                    ltrim(substr($code, 66, 10), '0') . '、' . ltrim(substr($code, 76, 10), '0'),
             ];
-            $this->success('成功','',$data);
         }
-        $this->view->assign('ids',$req['ids']);
-        return $this->view->fetch();
+
+        $data = [
+            'type' => $type,
+            'numn' => $numn,
+            'rows' => $rows,
+            'ids' => $ids,
+        ];
+
+        $this->success('成功', '', $data);
     }
 
     /**

+ 3 - 1
application/admin/view/common/menu.html

@@ -3,7 +3,9 @@
     <!-- 管理员信息 -->
     <div class="user-panel hidden-xs">
         <div class="pull-left image">
-            <a href="general/profile" class="addtabsit"><img src="{$admin.avatar|cdnurl|htmlentities}" class="img-circle" /></a>
+            <a href="general/profile" class="addtabsit">
+                <img src="{$admin.avatar|cdnurl|htmlentities}" class="img-circle" />
+            </a>
         </div>
         <div class="pull-left info">
             <p>{$admin.nickname|htmlentities}</p>

+ 21 - 2
application/admin/view/deliver/dispatch.html

@@ -9,10 +9,29 @@
         <div id="myTabContent" class="tab-content">
             <div class="tab-pane fade active in" id="one">
                 <div class="widget-body no-padding">
-                    <div id="toolbar" class="toolbar">
-                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                    <div id="toolbar" class="toolbar clearfix">
+                        <div class="pull-left">
+                            <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}">
+                                <i class="fa fa-refresh"></i>
+                            </a>
 <!--                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('samplecompany/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
 <!--                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('samplecompany/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
+
+                            <!-- 其他按钮可继续放这里 -->
+                        </div>
+
+                        <div class="pull-left" style="margin-left: 15px; display: flex; align-items: center;">
+                            <label for="customer-select" style="margin: 0 8px 0 0;width: 142px">选择客户名称:</label>
+                            <select id="customer-select" class="form-control selectpicker" data-live-search="true" name="customer_name" style="min-width: 320px;">
+                                <option value="河南中烟工业有限责任公司黄金叶生产制造中心">河南中烟工业有限责任公司黄金叶生产制造中心</option>
+                                <option value="河南中烟工业有限责任公司南阳卷烟厂">河南中烟工业有限责任公司南阳卷烟厂</option>
+                                <option value="河南中烟工业有限责任公司驻马店卷烟厂">河南中烟工业有限责任公司驻马店卷烟厂</option>
+                                <option value="河南中烟工业有限责任公司洛阳卷烟厂">河南中烟工业有限责任公司洛阳卷烟厂</option>
+                                <option value="河南中烟工业有限责任公司许昌卷烟厂">河南中烟工业有限责任公司许昌卷烟厂</option>
+                                <option value="河南中烟工业有限责任公司漯河卷烟厂">河南中烟工业有限责任公司漯河卷烟厂</option>
+                                <option value="河南中烟工业有限责任公司安阳卷烟厂">河南中烟工业有限责任公司安阳卷烟厂</option>
+                            </select>
+                        </div>
                     </div>
                     <table id="table3" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit=""

+ 2 - 2
application/admin/view/index/login.html

@@ -94,10 +94,10 @@
         <div class="login-screen">
             <div class="well">
                 <div class="login-head">
-                    <img src="__CDN__/uploads/bg.png" style="width:100%;"/>
+                    <img src="__CDN__/uploads/login.png" style="width:100%;"/>
                 </div>
                 <div class="login-form">
-                    <img id="profile-img" class="profile-img-card" src="__CDN__/assets/img/avatar.png"/>
+<!--                    <img id="profile-img" class="profile-img-card" src="__CDN__/assets/img/avatar.png"/>-->
                     <p id="profile-name" class="profile-name-card"></p>
 
                     <form action="" method="post" id="login-form">

+ 10 - 1
application/admin/view/qcode_bach/small.html

@@ -21,7 +21,16 @@
         <div id="myTabContent" class="tab-content">
             <div class="tab-pane fade active in" id="one">
                 <div class="widget-body no-padding">
-                    <div id="toolbar" class="toolbar"></div>
+                    <div id="toolbar" class="toolbar">
+                        批量选中:
+                        从:
+                        <input name="small_start" value="" type="text" style="width:10%;" id="small_start">
+                        到
+                        <input name="small_end" value="" type="text" style="width:10%;" id="small_end">
+                        <button type="reset" class="btn btn-defaults btn-embossed" id="btn_yes">导出</button>
+                        <button type="reset" class="btn btn-defaults btn-embossed" id="btn_no">不导出</button>
+                    </div>
+
                     <table id="table" class="table table-striped table-bordered table-hover"
                            data-operate-edit=""
                            data-operate-del=""

+ 14 - 0
application/extra/global.php

@@ -0,0 +1,14 @@
+<?php
+
+use think\Session;
+
+/**
+ * 判断是否为超级管理员(admin 或 zzhjysy)
+ * @return bool
+ */
+function isSuperAdmin()
+{
+    $userInfo = Session::get('admin');
+    $username = $userInfo['username'] ?? '';
+    return in_array($username, ['admin', 'zzhjysy']);
+}

+ 0 - 0
public/assets/img/avatar.png → public/assets/img/avatars.png


+ 74 - 20
public/assets/js/backend/deliver.js

@@ -248,6 +248,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             });
 
             var table = $("#table3");
+            // 定义客户与地址映射表
+            var addressMap = {
+                "河南中烟工业有限责任公司黄金叶生产制造中心": "河南省郑州市经开区第三大街9号",
+                "河南中烟工业有限责任公司南阳卷烟厂": "河南省南阳市宛城区新华东路6号",
+                "河南中烟工业有限责任公司驻马店卷烟厂": "河南省驻马店市驿城区南海路1号",
+                "河南中烟工业有限责任公司洛阳卷烟厂": "河南省洛阳市洛龙区玉林路266号",
+                "河南中烟工业有限责任公司许昌卷烟厂": "河南省许昌市建安区魏武大道,明礼街",
+                "河南中烟工业有限责任公司漯河卷烟厂": "河南省漯河市召陵区漓江路与庐山路交叉口东北280米",
+                "河南中烟工业有限责任公司安阳卷烟厂": "河南省安阳市龙安区烟厂路与彩安路交叉口北100路西"
+            };
+            var selectedCustomerName = '';
+            var selectedAddress = '';
+
+            // 客户下拉选择绑定事件(放在这里确保页面加载后再绑定)
+            $(document).on('change', '#customer-select', function () {
+                selectedCustomerName = $(this).val();
+                selectedAddress = addressMap[selectedCustomerName];
+                console.log(selectedCustomerName)
+                console.log(selectedAddress)
+            });
 
             // 初始化表格
             table.bootstrapTable({
@@ -288,6 +308,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     // confirm: '确认发送',
                                     success: function (data,res) {
                                         if (res.code === 1){
+                                            // 定义默认值
+                                            var defaultCustomerName = "河南中烟工业有限责任公司黄金叶生产制造中心";
+                                            var defaultAddress = "河南省郑州市经开区第三大街9号";
+                                            var printCustomerName = selectedCustomerName || defaultCustomerName;
+                                            var printAddress = selectedAddress || defaultAddress;
+                                            console.log(printCustomerName);
+                                            console.log(printAddress);
+
                                             var arr = res.data.data;
                                             var note='';
                                             var html = '<div style="width: 1100px;height: 100px;position: relative;">\n' +
@@ -301,23 +329,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                                 '              </div>\n' +
                                                 '              <table class="tg1" style="margin-top: 3px;border-collapse:collapse;border-spacing:0;font-weight:500;width:1186px">\n' +
                                                 '                   <tr class="info">\n' +
-                                                '                       <td colspan="6" style="border:none">客户名称:河南中烟工业有限责任公司黄金叶生产制造中心</td>\n' +
+                                                '                       <td colspan="6" style="border:none">客户名称:' + printCustomerName + '</td>\n' +
                                                 '                       <td colspan="4" style="border:none">送货单号:<span style="font-size: 16px;" id="shdh">'+res.data.shdh+'</span></td>\n' +
                                                 '                   </tr>\n' +
                                                 '                   <tr class="info">\n' +
-                                                '                       <td colspan="6" style="border:none">送货地址:河南省郑州市经开区第三大街9号</td>\n' +
+                                                '                       <td colspan="6" style="border:none">送货地址:' + printAddress + '</td>\n' +
                                                 '                       <td colspan="4" style="border:none">送货日期:<span style="font-size: 16px;"  id="shrq_date">'+res.data.shrq_date+'</span></td>\n' +
                                                 '                   </tr>\n' +
                                                 '               </table>\n' +
                                                 '               <br>\n' +
-                                                '               <table class="tg1" style="table-layout:fixed;width: 1186px;border-collapse:collapse;border-spacing:0;font-weight:500; position: relative;" id="table">'+
-                                                '                   <tr><th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;;width: 170px;">物料名称</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;;width: 150px;">生产批号</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 100px;">大件</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 100px;">小件</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 100px;">单位</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 150px;">实发数量</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 150px;">备注</th>' +
+                                                '               <table class="tg1" style="table-layout:fixed;width: 1100px;border-collapse:collapse;border-spacing:0;font-weight:500; position: relative;" id="table">'+
+                                                '                   <tr><th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 140px;">物料名称</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;;width: 140px;">生产批号</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">大件</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">小件</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">单位</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 130px;">实发数量</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 140px;">备注</th>' +
                                                 '                   <th id="explain" rowspan="'+(res.data.count+1)+'" width="7%" style="border: none"><span style="writing-mode: tb-rl;height: 300px;font-size:16px;text-align: center;">' +
                                                 '                   蓝联(回):业务 黄联(回):运输 '+'<br>'+'白联:存根 红联:财务 绿联:客户</span></th></tr>';
                                                                 for (var i=0;i < arr.length;i++){
@@ -400,7 +428,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             });
 
             var table = $("#table");
+            // 定义客户与地址映射表
+            var addressMap = {
+                "河南中烟工业有限责任公司黄金叶生产制造中心": "河南省郑州市经开区第三大街9号",
+                "河南中烟工业有限责任公司南阳卷烟厂": "河南省南阳市宛城区新华东路6号",
+                "河南中烟工业有限责任公司驻马店卷烟厂": "河南省驻马店市驿城区南海路1号",
+                "河南中烟工业有限责任公司洛阳卷烟厂": "河南省洛阳市洛龙区玉林路266号",
+                "河南中烟工业有限责任公司许昌卷烟厂": "河南省许昌市建安区魏武大道,明礼街",
+                "河南中烟工业有限责任公司漯河卷烟厂": "河南省漯河市召陵区漓江路与庐山路交叉口东北280米",
+                "河南中烟工业有限责任公司安阳卷烟厂": "河南省安阳市龙安区烟厂路与彩安路交叉口北100路西"
+            };
+            var selectedCustomerName = '';
+            var selectedAddress = '';
 
+            // 客户下拉选择绑定事件(放在这里确保页面加载后再绑定)
+            $(document).on('change', '#customer-select', function () {
+                selectedCustomerName = $(this).val();
+                selectedAddress = addressMap[selectedCustomerName];
+                console.log(selectedCustomerName)
+                console.log(selectedAddress)
+            });
             // 初始化表格
             table.bootstrapTable({
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
@@ -439,6 +486,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     // confirm: '确认发送',
                                     success: function (data,res) {
                                         if (res.code === 1){
+                                            // 定义默认值
+                                            var defaultCustomerName = "河南中烟工业有限责任公司黄金叶生产制造中心";
+                                            var defaultAddress = "河南省郑州市经开区第三大街9号";
+                                            var printCustomerName = selectedCustomerName || defaultCustomerName;
+                                            var printAddress = selectedAddress || defaultAddress;
+                                            console.log(printCustomerName);
+                                            console.log(printAddress);
                                             var arr = res.data.data;
                                             var note='';
                                             var html = '<div style="width: 1100px;height: 100px;position: relative;">\n' +
@@ -452,23 +506,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                                 '              </div>\n' +
                                                 '              <table class="tg1" style="margin-top: 3px;border-collapse:collapse;border-spacing:0;font-weight:500;width:1186px">\n' +
                                                 '                   <tr class="info">\n' +
-                                                '                       <td colspan="6" style="border:none">客户名称:河南中烟工业有限责任公司黄金叶生产制造中心</td>\n' +
+                                                '                       <td colspan="6" style="border:none">客户名称:' + printCustomerName + '</td>\n' +
                                                 '                       <td colspan="4" style="border:none">送货单号:<span style="font-size: 16px;" id="shdh">'+res.data.shdh+'</span></td>\n' +
                                                 '                   </tr>\n' +
                                                 '                   <tr class="info">\n' +
-                                                '                       <td colspan="6" style="border:none">送货地址:河南省郑州市经开区第三大街9号</td>\n' +
+                                                '                       <td colspan="6" style="border:none">送货地址:' + printAddress + '</td>\n' +
                                                 '                       <td colspan="4" style="border:none">送货日期:<span style="font-size: 16px;"  id="shrq_date">'+res.data.shrq_date+'</span></td>\n' +
                                                 '                   </tr>\n' +
                                                 '               </table>\n' +
                                                 '               <br>\n' +
-                                                '               <table class="tg1" style="table-layout:fixed;width: 1186px;border-collapse:collapse;border-spacing:0;font-weight:500; position: relative;" id="table">'+
-                                                '                   <tr><th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">物料名称</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">生产批号</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">大件</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">小件</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">单位</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">实发数量</th>' +
-                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;">备注</th>' +
+                                                '               <table class="tg1" style="table-layout:fixed;width: 1100px;border-collapse:collapse;border-spacing:0;font-weight:500; position: relative;" id="table">'+
+                                                '                   <tr><th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 140px;">物料名称</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 140px;">生产批号</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">大件</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">小件</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 90px;">单位</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 130px;">实发数量</th>' +
+                                                '                   <th class="tg-s6z2" style="font-family:Arial, sans-serif;font-size:20px;text-align:center;font-weight:500;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;width: 140px;">备注</th>' +
                                                 '                   <th id="explain" rowspan="'+(res.data.count+1)+'" width="7%" style="border: none"><span style="writing-mode: tb-rl;height: 300px;font-size:16px;text-align: center;">' +
                                                 '                   蓝联(回):业务 黄联(回):运输 '+'<br>'+'白联:存根 红联:财务 绿联:客户</span></th></tr>';
                                             for (var i=0;i < arr.length;i++){

+ 6 - 1
public/assets/js/backend/qcode_add.js

@@ -26,9 +26,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                        $('#c-big_liushui').val(data.flow);
                    }
                    if (data.bach === ''){
-                       $('#c-batch').val(201800000);
+                       // $('#c-batch').val(201800000);
+                       var currentYear = new Date().getFullYear();
+                       var newValue = currentYear + '000000';
+                       $('#c-batch').removeAttr('disabled').val(newValue);
                    }else {
+                       // $('#c-batch').val(data.bach);
                        $('#c-batch').val(data.bach);
+                       $('#c-batch').attr('disabled', true);
                    }
                    return false;
                },function () {

+ 58 - 1
public/assets/js/backend/qcode_bach.js

@@ -813,6 +813,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'LodopFuncs'], functi
                 columns: [
                     [
                         // {checkbox: true},
+                        {field: 'l_flows', title: __('序号'), width:80, operate: false},
                         {field: 'code', title: __('Code'), cellStyle: function () {return {css: {"max-width": "200px","overflow":"hidden",}}}, operate: 'LIKE'},
                         {field: 'l_flow', title: __('Flow'), width:80, operate: false},
                         {field: 'p_nums', title: __('P_nums'), width:80, operate: false},
@@ -823,7 +824,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'LodopFuncs'], functi
                                     return '<span style="color: green">正常</span>';
                                 }
                             }, operate: false},
-                        {field: 'buttons', width: "120px", title: __('按钮组'), table: table, operate: false, events: Table.api.events.operate,
+                        {field: 'buttons', width: "120px", title: __('是否导出'), table: table, operate: false, events: Table.api.events.operate,
                             buttons: [
                                 {
                                     name: 'click',
@@ -991,6 +992,62 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'LodopFuncs'], functi
             });
 
 
+// 导出按钮:范围内保持正常,范围外设为已删除
+            $('#btn_yes').on('click', function () {
+                const start = parseInt($('#small_start').val());
+                const end = parseInt($('#small_end').val());
+                batchUpdateLabels(start, end, 'export');
+            });
+
+// 不导出按钮:范围内设为已删除,范围外保持正常
+            $('#btn_no').on('click', function () {
+                const start = parseInt($('#small_start').val());
+                const end = parseInt($('#small_end').val());
+                batchUpdateLabels(start, end, 'noexport');
+            });
+
+// 批量状态更新函数
+            function batchUpdateLabels(start, end, mode) {
+                if (isNaN(start) || isNaN(end)) {
+                    alert("请输入正确的序号范围");
+                    return;
+                }
+
+                const table = $('#table');
+                const rows = table.bootstrapTable('getData');
+                const idsToToggle = [];
+
+                rows.forEach(function (row) {
+                    const seq = row.l_flows; // 确保这是序号列
+                    const inRange = (seq >= start && seq <= end);
+
+                    if (mode === 'export') {
+                        // 如果在范围内且当前状态是已删除,加入待更新列表
+                        if (inRange && row.status === 1) { // 假设状态1是已删除
+                            idsToToggle.push(row.id);
+                        }
+                    } else if (mode === 'noexport') {
+                        // 如果在范围内且当前状态是正常,加入待更新列表
+                        if (inRange && row.status === 0) { // 假设状态0是正常
+                            idsToToggle.push(row.id);
+                        }
+                    }
+                });
+
+                // 批量发送请求
+                if (idsToToggle.length > 0) {
+                    $.get('qcode_bach/small_status', { ids: idsToToggle.join(',') }, function (res) {
+                        if (res.code == 1) {
+                            Toastr.success(res.msg);
+                            table.bootstrapTable('refresh');
+                        }
+                    });
+                } else {
+                    Toastr.info("没有需要更新的行");
+                }
+            }
+
+
             $(document).ready(function() {
                 // 自动触发搜索按钮的点击事件
                 $('.btn-default').click();