فهرست منبع

新增批次、发货

qiuenguang 1 سال پیش
والد
کامیت
38a32b6669

+ 535 - 0
application/admin/controller/Deliver.php

@@ -0,0 +1,535 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\model\QcodeLarge;
+use app\admin\model\QcodeSmall;
+use app\common\controller\Backend;
+use app\admin\model\QcodeProduct;
+use app\admin\model\QcodeCompany;
+use app\admin\model\QcodeBach;
+use app\admin\model\QcodeExport;
+use fast\Arr;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Exception;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+use app\admin\model\QcodeGoods;
+use think\Session;
+
+class Deliver extends Backend
+{
+    /**
+     * 首页
+     * @return string|\think\response\Json
+     * @throws \think\Exception
+     */
+    public function index()
+    {
+        return $this->view->fetch();
+    }
+
+    /**
+     * 大件发货列表
+     * @return string|\think\response\Json
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function lager()
+    {
+        $company = new QcodeCompany();
+        $product = new QcodeProduct();
+        $large = new QcodeLarge();
+        $bach = new QcodeBach();
+        $small = new QcodeSmall();
+        $this->request->filter(['strip_tags', 'trim']);
+        if (false === $this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        // 接收参数
+        $userInfo = Session::get('admin');
+        $where = [
+            'delete_time'=> ''
+        ];
+        $filter = input('filter');
+        $filter = json_decode($filter,true);
+        $whereList = [
+            'delete_time'=>'',
+        ];
+        //样品编号查询
+        if (isset($filter['matter_name'])){
+            $whereList['matter_no'] =$filter['matter_name'];
+        }
+        if (isset($filter['bach'])){
+            $whereList['bach_num'] = $filter['bach'];
+        }
+        if (isset($filter['manufacture_date'])){
+            $begin = substr($filter['manufacture_date'],0,19);
+            $end = substr($filter['manufacture_date'],22);
+            $begin = (int)date('ymd',strtotime($begin));
+            $end = (int)date('ymd',strtotime($end));
+            $whereList['manufacture_date'] = ['between',[$begin,$end]];
+        }
+
+        $bach_list = $bach->name($userInfo['company'].'_'.'qcode_bach')->where($whereList)->column('_id');
+        $bach_id = [];
+        foreach ($bach_list as $v){
+            $id = substr(json_encode($v),9,-2);
+            array_push($bach_id,$id);
+        }
+        $order = input('order');
+        $offset = input('offset');
+        $limit = input('limit');
+        $total = $large->name($userInfo['company'].'_'.'qcode_large')->where($where)->whereIn('bach_id',$bach_id)->count();
+        $large_list = $large->name($userInfo['company'].'_'.'qcode_large')
+            ->order('creat_time',$order)
+            ->where($where)
+            ->whereIn('bach_id',$bach_id)
+            ->skip($offset)
+            ->limit($limit)
+            ->select();
+        $list=[];
+        foreach ($large_list as $k=>$v) {
+            $bach_detail = $bach->name($userInfo['company'].'_'.'qcode_bach')->where('_id',$v['bach_id'])->find();
+            $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
+            $list[$k]['bach'] = $bach_detail['bach_num'];
+            $list[$k]['l_flow'] = $bach_detail['l_flow']+$k;
+            $list[$k]['matter_name'] = $bach_detail['matter_name'];
+            $list[$k]['manufacture_date'] = date('Y-m-d',strtotime('20'.$bach_detail['manufacture_date']));
+            $list[$k]['code'] = $v['code'];
+            $small_num = $small->name($userInfo['company'].'_'.'qcode_small')->where('large_id',substr(json_encode($v['_id']),9,-2))->count();
+            $list[$k]['small_num'] = $small_num;
+        }
+        $result = ['total'=>$total,'rows'=>$list];
+        return json($result);
+    }
+
+    /**
+     * 小件列表
+     * @return \think\response\Json
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function smallList()
+    {
+        $userinfo = Session::get('admin');
+        $lager = new QcodeLarge();
+        $small = new QcodeSmall();
+        if ($this->request->isAjax() === false){
+            $this->error('请求错误');
+        }
+        $lager_list = input('search');
+        $order = input('order');
+        $offset = input('offset');
+        $limit = input('limit');
+        $lagerList = explode(',',$lager_list);
+        $smallList = $small->name($userinfo['company'].'_'.'qcode_small')
+            ->whereIn('large_id',$lagerList)
+//            ->order('l_flow',$order)
+            ->skip($offset)
+            ->limit($limit)
+            ->select();
+        $total = $small->name($userinfo['company'].'_'.'qcode_small')->whereIn('large_id',$lagerList)->count();
+        $list = [];
+        foreach ($smallList as $k=>$v){
+            $list[$k] = [
+                'code' => $v['code'],
+                'l_flow' => $v['l_flow'],
+                'print_num' => $v['p_nums'],
+                'status' => $v['status'],
+            ];
+        }
+        return json(['total'=>$total,'rows'=>$list]);
+    }
+
+    /**
+     * 导出发货
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function print()
+    {
+        $userinfo = Session::get('admin');
+        $lager = new QcodeLarge();
+        $bach = new QcodeBach();
+        $small = new QcodeSmall();
+        $export = new QcodeExport();
+        if ($this->request->isAjax() === false){
+            $this->error('请求错误');
+        }
+        $lager_id = input('lager_id');
+        if ($lager_id === ''){
+            $this->error('请至少选择一个大件');
+        }
+        $lagerId = [];
+        if (strpos($lager_id,',') === false){
+            $lagerId[0] = $lager_id;
+        }else{
+            $lagerId = explode(',',$lager_id);
+        }
+        $lager_num = count($lagerId);
+        $bach_id = [];
+        foreach ($lagerId as $k=>$v){
+            $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$v)->find();
+            $bachList = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$lagerList['bach_id'])->find();
+            $bach_id[$k] = substr(json_encode($bachList['_id']),9,-2);
+        }
+        $bach_id = array_unique($bach_id);
+        $data = [];
+        foreach ($bach_id as $k=>$v){
+            $m = 1;$n =0;
+            $large_str = '';
+            foreach ($lagerId as $key=>$value){
+                $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$value)->find();
+                if($v === $lagerList['bach_id']){
+                    $m++;
+                    $large_str = $large_str.substr(json_encode($lagerList['_id']),9,-2).',';
+                }
+
+            }
+
+            $large_str = substr($large_str,0,strlen($large_str)-1);
+            foreach (explode(',',$large_str) as $kk=>$vv){
+                $n = $n + $small->name($userinfo['company'].'_'.'qcode_small')->where('large_id',$vv)->count();
+            }
+            $bachDetail = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
+            if ($bachDetail['box_num'] === 1){
+                $mater_type = 2;
+            }else{
+                $mater_type = 1;
+            }
+//            $file_dir = $this->exportExcel($v,$large_str,$userinfo['company'],$m,$n);
+            $data[$k] = [
+                'username'  => $bachDetail['supplier_name'],
+                'matter_name' => $bachDetail['matter_name'],
+                'matter_no' => $bachDetail['matter_no'],
+                'large_str' => $large_str,
+                'large_num' => $lager_num,
+                'small_num' => $n,
+                'status' => 0,
+                'num' => $bachDetail['s_weight'],
+                'bach_num' => $bachDetail['bach_num'],
+                'mater_type' => $mater_type,
+                'note' => '',
+                'user_id' => $userinfo['id'],
+                'create_time' => time(),
+                'file_dir' => '',
+                'company_id' => $userinfo['company'],
+            ];
+            $res = $export->save($data[$k]);
+        }
+        $this->success();
+    }
+
+    /**
+     * 生成excel
+     * @param $bach_id
+     * @param $large_str
+     * @param $company
+     * @param $large_num
+     * @param $small_num
+     * @return string
+     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function exportExcel($bach_id,$large_str,$company,$large_num,$small_num)
+    {
+        $bach = new QcodeBach();
+        $large = new QcodeLarge();
+        $small = new QcodeSmall();
+        $bachList = $bach->name($company . '_' . 'qcode_bach')->where('_id', $bach_id)->find();
+        $data = [
+            'supplier_name' => $bachList['supplier_name'],
+            'supplier_no' => $bachList['supplier_code'],
+            'matter_name' => $bachList['matter_name'],
+            'matter_no' => $bachList['matter_no'],
+            'manufacture_date' => $bachList['manufacture_date'],
+            'print_date' => $bachList['print_date'],
+            'box_num' => $large_num,
+            'tray_num' => $bachList['tray_num'],
+            'small_num' => $small_num,
+            'l_reservation' => $bachList['l_reservation'],
+            's_reservation' => $bachList['s_reservation'],
+            'l_flow' => $bachList['l_flow'],
+            's_flow' => $bachList['s_flow'],
+            'l_weight' => $bachList['l_weight'],
+            's_weight' => $bachList['s_weight'],
+            'code' => [],
+        ];
+        $large_id = explode(',', $large_str);
+        foreach ($large_id as $k => $v) {
+            $largeList = $large->name($company . '_' . 'qcode_large')->where('_id', $v)->find();
+            $small_list = $small->name($company . '_' . 'qcode_small')->where('large_id', $v)->select();
+
+            foreach ($small_list as $value) {
+                $code = [
+                    'large_code' => $largeList['code'],
+                    'small_code' => $value['code'],
+                ];
+                $data['code'][] = $code;
+            }
+        }
+        $objexcel = new Spreadsheet();
+        $sheet = $objexcel->getActiveSheet();
+        //设置全局单元格垂直居中
+//        $objexcel->getDefaultStyle()->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
+//        //设置全局单元格水平居中
+//        $objexcel->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
+//        //设置全局单元格自动换行
+//        $objexcel->getDefaultStyle()->getAlignment()->setWrapText(true);
+        //设置单元格宽度
+        $sheet->getDefaultColumnDimension()->setWidth(25);
+        //设置表头
+//        $sheet->setCellValue('A1', '文件流水号');
+//        $sheet->setCellValue('A2', '订单号');
+//        $sheet->setCellValue('A3', '供应商');
+//        $sheet->setCellValue('A4', '供应商代码');
+//        $sheet->setCellValue('A5', '物料名称');
+//        $sheet->setCellValue('A6', '物料代码');
+//        $sheet->setCellValue('A7', '生产日期');
+//        $sheet->setCellValue('A8', '打码日期');
+//        $sheet->setCellValue('A9', '大件数量');
+//        $sheet->setCellValue('A10', '托盘小件数量');
+//        $sheet->setCellValue('A11', '小件总数量');
+//        $sheet->setCellValue('C3', '大件预留码');
+//        $sheet->setCellValue('C5', '小件预留码');
+//        $sheet->setCellValue('C7', '大件开始流水号');
+//        $sheet->setCellValue('C9', '小件开始流水号');
+//        $sheet->setCellValue('C11', '大件重量(Kg)');
+//        $sheet->setCellValue('C13', '小件重量(Kg)');
+//        $sheet->setCellValue('A15', '大件二维码');
+//        $sheet->setCellValue('B15', '大件条码(预留)');
+//        $sheet->setCellValue('C15', '小件二维码');
+//        $sheet->setCellValue('D15', '小件条码(预留)');
+        //插入表格数据
+//        $sheet->getCell('B3')->setValue(isset($data['supplier_name'])?$data['supplier_name']:'');
+//        $sheet->getCell('B4')->setValue(isset($data['supplier_no'])?$data['supplier_no']:'');
+//        $sheet->getCell('B5')->setValue(isset($data['matter_name'])?$data['matter_name']:'');
+//        $sheet->getCell('B6')->setValue(isset($data['matter_no'])?$data['matter_no']:'');
+//        $sheet->getCell('B7')->setValue(isset($data['manufacture_date'])?$data['manufacture_date']:'');
+//        $sheet->getCell('B8')->setValue(isset($data['print_date'])?$data['print_date']:'');
+//        $sheet->getCell('B9')->setValue(isset($data['box_num'])?$data['box_num']:'');
+//        $sheet->getCell('B10')->setValue(isset($data['tray_num'])?$data['tray_num']:'');
+//        $sheet->getCell('B11')->setValue(isset($data['small_num'])?$data['small_num']:'');
+//        $sheet->getCell('C4')->setValue(isset($data['l_reservation'])?$data['l_reservation']:'');
+//        $sheet->getCell('C6')->setValue(isset($data['s_reservation'])?$data['s_reservation']:'');
+//        $sheet->getCell('C8')->setValue(isset($data['l_flow'])?$data['l_flow']:'');
+//        $sheet->getCell('C10')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
+//        $sheet->getCell('C12')->setValue(isset($data['l_weight'])?$data['l_weight']:'');
+//        $sheet->getCell('C14')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
+//        foreach ($data['code'] as $v){
+//            $sheet->getCell('A16')->setValue(isset($v['large_code'])?$v['large_code']:'');
+//            $sheet->getCell('B16')->setValue('');
+//            $sheet->getCell('C16')->setValue(isset($v['small_code'])?$v['small_code']:'');
+//            $sheet->getCell('D16')->setValue('');
+//        }
+        //文件另存
+        $filename = date('Ymd',time()).rand(100,999).'_'.$data['supplier_name'].'_'.$data['matter_name'].'_'.$data['small_num'].'.xlsx';
+//        $filename = iconv("utf-8","gb2312",$filename);
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="'.$filename.'"');
+        header('Cache-Control: max-age=0');
+        header("Content-Type:text/html;charset=utf-8");
+//        if(is_dir(ROOT_PATH.'public/uploads/export/') == null)
+//        {
+//            mkdir(ROOT_PATH.'public/uploads/export/',0777,true);
+//        }
+        $writer = new Xlsx($objexcel);
+//        $writer->save($filename);
+        $writer->save(ROOT_PATH.'public/uploads/export'.DS.$filename);
+        return 'public/uploads/export/'.$filename;
+    }
+    //批次发货审批
+    public function apply()
+    {
+        $export = new QcodeExport();
+        $this->request->filter(['strip_tags', 'trim']);
+        if (false === $this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        // 接收参数
+        $userInfo = Session::get('admin');
+        $where = [
+            'company_id' => $userInfo['company'],
+            'delete_time'=> ''
+        ];
+        $filter = input('filter');
+        $filter = json_decode($filter,true);
+        //样品编号查询
+        if (isset($filter['matter_name'])){
+            $where['matter_no'] =$filter['matter_name'];
+        }
+        if (isset($filter['username'])){
+            $where['username'] = $filter['username'];
+        }
+        if (isset($filter['status'])){
+            $where['status'] = (int)$filter['status'];
+        }
+        if (isset($filter['create_time'])){
+            $begin = substr($filter['create_time'],0,19);
+            $end = substr($filter['create_time'],22);
+            $begin = strtotime($begin);
+            $end = strtotime($end);
+            $where['create_time'] = ['between',[$begin,$end]];
+        }
+        $order = input('order');
+        $offset = input('offset');
+        $limit = input('limit');
+        $total = $export->where($where)->count();
+        $export_list = $export
+            ->order('_id',$order)
+            ->where($where)
+            ->whereIn('status',[0,1])
+            ->skip($offset)
+            ->limit($limit)
+            ->select();
+        $list=[];
+        foreach ($export_list as $k=>$v) {
+            $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
+            $list[$k]['matter_name'] = $v['matter_name'];
+            $list[$k]['matter_no'] = $v['matter_no'];
+            $list[$k]['username'] = $v['username'];
+            $list[$k]['large_num'] = $v['large_num'];
+            $list[$k]['small_num'] = $v['small_num'];
+            $list[$k]['create_time'] = $v['create_time'];
+            $list[$k]['file_dir'] = $v['file_dir'];
+            $list[$k]['status'] = $v['status'];
+        }
+        $result = ['total'=>$total,'rows'=>$list];
+        return json($result);
+    }
+    //批次发货申请删除
+    public function apply_del($ids)
+    {
+        $export = new QcodeExport();
+        if (empty($ids)){
+            $this->error('请求错误');
+        }
+        $res = $export->where('_id',$ids)->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
+        if ($res === false){
+            $this->error('删除失败');
+        }
+        $this->success('成功');
+    }
+    public function goods($ids)
+    {
+        $this->view->assign('ids',$ids);
+        return $this->view->fetch();
+    }
+    //批次发货提交
+    public function apply_add()
+    {
+        $goods = new QcodeGoods();
+        $export = new QcodeExport();
+        $userinfo = Session::get('admin');
+        if ($this->request->isAjax() === false){
+            $this->error('请求错误');
+        }
+        $ids = input('ids');
+        $order_number = input('order_number');
+        $deliveryman = input('deliveryman');
+        $shr_phone = input('shr_phone');
+        $plate_number = input('plate_number');
+        $note = input('note');
+        $id_list = [];
+        if (strpos($ids,',') === false){
+            $id_list[0] = $ids;
+        }else{
+            $id_list = explode(',',$ids);
+        }
+        $update_status = $export->where('company_id',$userinfo['company'])->whereIn('_id',$id_list)->update(['status'=>2]);
+        if ($update_status){
+            $export_list = $export->whereIn('_id',$id_list)->select();
+            $daterq = date('ymd',time());
+
+            $data = [
+                'shdh' => substr($daterq,2,2).' '.substr($daterq,2,6).mt_rand(1000,9999),
+                'order_number' => $order_number,
+                'deliveryman' => $deliveryman,
+                'shr_phone' => $shr_phone,
+                'plate_number' => $plate_number,
+                'shrq_date' => '',
+                'supplier_name' => $export_list[0]['username'],
+                'supplier_id' => $userinfo['id'],
+                'user_id' => $userinfo['id'],
+                'status' => 0,
+                'export_id' => $ids,
+                'create_time' => time(),
+                'note' => $note,
+                'company_id' => $userinfo['company'],
+            ];
+            $data['qrcode_add'] = $this->Qrcode($data['shdh']);
+            $res = $goods->save($data);
+            if ($res === false){
+                $this->error('失败');
+            }
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+    //生成二维码
+    public function Qrcode($url)
+    {
+        $level=2;
+        $size=5;
+        Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
+        $errorCorrectionLevel =intval($level) ;//容错级别
+        $matrixPointSize = intval($size);//生成图片大小
+        //生成二维码图片
+        $object = new \QRcode();
+        //打开缓冲区
+        ob_start();
+        $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
+        //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
+        $imageString = base64_encode(ob_get_contents());
+        //关闭缓冲区
+        ob_end_clean();
+        //把生成的base64字符串返回给前端
+        return 'data:image/png;base64,'.$imageString;
+    }
+    //发货单
+    public function dispatch()
+    {
+        return $this->view->fetch();
+    }
+
+    /**
+     * 获取辅料名称
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function matterName()
+    {
+        $userinfo = Session::get('admin');
+        $lager = new QcodeLarge();
+        $bach = new QcodeBach();
+        $bach_id = $lager->name($userinfo['company'].'_'.'qcode_large')->where('delete_time','')->column('bach_id');
+        $matter_name = [];
+        if (!empty($bach_id)){
+            foreach ($bach_id as $v){
+                $bach_list = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
+                $matter_name[$bach_list['matter_no']] = $bach_list['matter_name'];
+            }
+        }
+        $matter_name = array_unique($matter_name);
+        return json($matter_name);
+    }
+}

+ 308 - 0
application/admin/controller/QcodeAdd.php

@@ -0,0 +1,308 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\model\QcodeCompany;
+use app\admin\model\QcodeProduct;
+use app\common\controller\Backend;
+use app\admin\model\ResetFlow;
+use app\admin\model\QcodeLarge;
+use app\admin\model\QcodeBach;
+use app\admin\model\QcodeSmall;
+use app\admin\model\QcodeLiushui;
+use fast\Arr;
+use think\Session;
+
+class QcodeAdd extends Backend
+{
+    /**
+     * 首页展示
+     * @return string|\think\response\Json
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function index()
+    {
+        $company = new QcodeCompany();
+        $product = new QcodeProduct();
+        $userinfo = Session::get('admin');
+        $data = [
+            'nickname' => $userinfo['nickname'],
+            'postcode' => $userinfo['postcode'],
+            'mobile' => $userinfo['mobile'],
+            'company_address' => $userinfo['company_address']
+        ];
+        $product_id = $company->name((int)$userinfo['company'].'_'.'qcode_company')->where('delete_time','')->column('product_id');
+        $product_name = [];
+        foreach ($product_id as $v){
+            $list = $product->where('_id',$v)->where('delete_time','')->find();
+            $product_name[$list['product_code']] =  $list['product_name'];
+        }
+        $this->view->assign('row',$data);
+        $this->view->assign('product',$product_name);
+        return $this->view->fetch();
+    }
+
+    /**
+     * 获取产品信息
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function product(){
+        $QcodeProduct = new QcodeProduct();
+        $ResetFlow = new ResetFlow();
+        if ($this->request->isAjax() === false){
+            $this->error('请求错误');
+        }
+        $product_code = input('product_code');
+        if (empty($product_code)){
+            $this->error('参数错误');
+        }
+        $product = $QcodeProduct->where('product_code',$product_code)->find();
+        if (empty($product)){
+            $this->error('未找到该产品信息');
+        }
+        $flow = $ResetFlow->name((int)Session::get('admin')['company'].'_'."reset_flow")->where('product_id',substr(json_encode($product['_id']),9,-2))->find();
+        $row = [
+            'temple' => $product['temple'],
+            'flow' => '',
+            'bach' => '',
+        ];
+        if (!empty($flow)){
+            $row['flow'] = $flow['l_flow']+1;
+            $row['bach'] = $flow['bach_num']+1;
+        }
+
+        return json(['code'=>1,'data'=>$row]);
+    }
+
+    /**
+     * 增加新批次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function add()
+    {
+        $product = new QcodeProduct();
+        $bach = new QcodeBach();
+        $large = new QcodeLarge();
+        $small = new QcodeSmall();
+        $liushui = new QcodeLiushui();
+        if ($this->request->isAjax() === false){
+            $this->error('请求错误');
+        }
+        $rows = input('row');
+        if (empty($rows)){
+            $this->error('参数错误');
+        }
+        $rows = json_decode($rows);
+        $data = [];
+        foreach ($rows as $value){
+           foreach ($value as $k=>$v){
+               $data[$k] = $v;
+           }
+        }
+        if ($data['danwei'] == 1){
+            $num = $data['number'];
+            $tray_num = $data['tray_num'];
+            $box_number = $data['box_number'];
+        }else{
+            $num = 0;
+            $tray_num = 0;
+            $box_number = 0;
+        }
+        //插入批次信息
+        $userinfo = Session::get('admin');//获取用户信息
+        $productList = $product->where('product_code',$data['product_code'])->find();//获取材料信息
+        if (empty($productList)){
+            $this->error('未找到该产品数据');
+        }
+        $batchList = [
+            'supplier_name' => $data['company_name'],
+            'supplier_code' => '',
+            'supplier_id' => $userinfo['id'],
+            'matter_name' => $productList['product_name'],
+            'matter_no' => $productList['product_code'],
+            'matter_id' => substr(json_encode($productList['_id']),9,-2),
+            'matter_type' => $productList['temple'],
+            'num' => $num,
+            'larger_num' => $data['box_num'],
+            'small_num' => $data['small_num'],
+            'manufacture_date' => (int)date('ymd',strtotime($data['manufacture_date'])),
+            'print_date' => (int)date('ymd',strtotime($data['print_date'])),
+            'box_num' => $box_number,
+            'tray_num' => $tray_num,
+            'l_reservation' => '',
+            'l_flow' => $data['big_liushui'],
+            'l_weight' => $data['big_weight'],
+            's_flow' => $data['small_start_liushui'],
+            's_weight' => $data['small_weight'],
+            'bach_status' => 0,
+            'userid' => $userinfo['id'],
+            'bach_num' => $data['batch'],
+            'large_endnum' => $data['big_liushui'] + $data['box_num'] -1,
+        ];
+        $res = $bach->save($batchList);
+        $last_id = $bach->getLastInsID();
+        if ($res === false){
+            $this->error('添加失败');
+        }
+        //插入大小二维码数据
+        //二维码数据不变区域
+        $fixed_code = '';
+        $fixed_code.=$this->intTochar($batchList['matter_type'],2);//2位  辅料种类编码
+        $fixed_code.=$this->intTochar($batchList['supplier_code'],12);//12位  供应商编码
+        $fixed_code.=$this->intTochar($batchList['matter_no'],20);//20位  辅料编码
+        $fixed_code.=$batchList['manufacture_date'];//6位  生产日期
+
+        $print_code=$batchList['print_date'];//6位  打码日期
+        $small_liushui = [
+            'onlycode' => 'AB92'.$fixed_code.$print_code,
+            'last_num' => 0,
+            'user_id' => $userinfo['id'],
+            'stype' => 2,
+            'dateTime' => date('Y-m-d H:i:s',time()),
+        ];
+        $whereSmall = [
+            'onlycode' => $small_liushui['onlycode'],
+            'user_id' => $userinfo['id'],
+        ];
+        if ($liushui->name($userinfo['id'].'_'.'qcode_liushui')->where($whereSmall)->find()){
+            //小件二维码存在,更新小件二维码最后流水号
+            $lastNum = $liushui->name($userinfo['id'].'_'.'qcode_liushui')->where($whereSmall)->find();
+        }else{
+            //小件二维码不存在,新增记录
+            $liushui->save($small_liushui);
+        }
+        var_dump($lastNum);
+        //循环插入大件二维码数据
+        for ($i=0;$i<$batchList['box_num'];$i++){
+            $l_flow = $this->intTochar($batchList['l_flow']+$i,6);
+            $l_weight = $this->intTochar($batchList['l_weight']*100,6);
+            $l_reservation = $this->intTochar($batchList['bach_num'],10);
+            $l_reservation = $l_reservation.'0000000000';
+            $remainder = $batchList['small_num'] - $batchList['tray_num'] * $i;//最后一托盘小件数量
+            if ($remainder < $batchList['tray_num']){
+                $small_n = $this->intTochar($remainder,3);//3位小件数量,不足补0
+            }else{
+                $small_n = $this->intTochar($batchList['tray_num'],3);
+            }
+            $l_num = 0;
+            if ($data['danwei'] == 1){
+                //以箱为单位时
+                $l_num = $small_n * $batchList['box_num'];
+            }
+            //大件二维码数据
+            $code_data = $this->CodeData('AB92',$fixed_code,$small_n,$print_code,$l_flow,$l_weight,'2',$l_reservation);
+            //大码数据信息
+            $l_data = [
+                'bach_id' => $last_id,
+                'code' => $code_data['code'],
+                'code_cp1' => $code_data['code_cp1'],
+                'code_cp2' => $code_data['code_cp2'],
+                'print_date' => $print_code,
+                'create_time' => date('Y-m-d H:i:s',time()),
+                'p_nums' => 0,
+                'userid' =>$userinfo['id'],
+                'l_weight' =>$l_weight,
+                'l_num' =>$l_num,
+            ];
+            $l_res = $large->save($l_data);
+            $large_id = $large->getLastInsID();
+            if ($l_res === false){
+                $this->error('大件码插入失败');
+            }
+            //小件码循环插入
+            for ($j=0;$j<$tray_num and ($j+$i*$tray_num)<$batchList['small_num'];$j++){
+                $s_flow = $this->intTochar($batchList['s_flow']+$j+$i*$batchList['tray_num']+$lastNum['last_num'],6);//小件码序号从1开始
+                $s_weight = $this->intTochar($batchList['s_weight'],6);
+                $small_sign = '000';
+                $s_reservation = $this->intTochar($batchList['bach_num'],10);
+                $s_reservation = $s_reservation . '0000000000';
+                //生成小件码
+                $small_code_data = $this->CodeData('AB92',$fixed_code,$small_sign,$print_code,$s_flow,$s_weight,'1',$s_reservation);
+                //小码数据
+                $s_data = [
+                    'large_id'=>$large_id,
+                    'bach_id'=>$last_id,
+                    'code'=>$small_code_data['code'],
+                    'code_cp1'=>$small_code_data['code_cp1'],
+                    'code_cp2'=>$small_code_data['code_cp2'],
+                    'l_flow'=>$j+1,
+                    'print_date'=>$print_code,
+                    'create_time'=>date('Y-m-d H:i:s',time()),
+                    'p_nums'=>0,
+                    'userid'=>$userinfo['id'],//小码绑定用户id
+                    's_weight'=>$s_weight//单个小件重量
+                ];
+                $s_res = $small->save($s_data);
+                if ($s_res === false){
+                    $this->error('小件码插入失败');
+                }
+            }
+        }
+        $liushui_res = $liushui->name($userinfo['id'].'_'.'qcode_liushui')->where($whereSmall)->update(['last_num'=>$batchList['small_num']]);
+        if ($liushui_res === false){
+            $this->error('添加失败');
+        }
+        $this->success('添加成功');
+    }
+
+    /**
+     * 编码补位
+     * @param $num
+     * @param $len
+     * @return string
+     */
+    function intTochar($num=0,$len){
+        //规定的不足的时候自动补足零
+        $code=(string)$num;
+        $buwei='';
+        if(strlen($code)<$len){
+            for($i=strlen($code);$i<$len;$i++){
+                $buwei.='0';
+            }
+        }
+        return $buwei.$code;
+    }
+
+    /**
+     * 二维码编码生成
+     * @param $sign
+     * @param $fixed_code
+     * @param $small_num
+     * @param $print_date
+     * @param $flow
+     * @param $weight
+     * @param $large_sign
+     * @param $reservation
+     * @return array
+     */
+     function CodeData($sign,$fixed_code,$small_num,$print_date,$flow,$weight,$large_sign,$reservation){
+         $code=$sign;//4 位固定标志位
+         $code.=$fixed_code; // 固定字符串
+         $code.=$small_num;//3位 小件数量
+         $code.=$print_date;//6 位 日期
+         $code.=$flow;//6位打印流水号
+         $code.=$weight;//6位辅料重量
+         $code.=$large_sign;//大小件标示位
+
+         $code.=$reservation;//20 位 预留号
+
+         //大码数据信息
+         $data=[
+             'code'=>str_replace(" ","",$code),
+             'code_cp1'=>$print_date.$flow,
+             'code_cp2'=>$weight.$reservation,//20位补充
+             'print_date'=>time(),
+             'p_nums'=>0,
+         ];
+         return $data;
+     }
+}

+ 51 - 0
application/admin/model/QcodeExport.php

@@ -0,0 +1,51 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use traits\model\SoftDelete;
+class QcodeExport extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = 'qcode_export';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        $this->connection->command([
+            'createIndexes' => $this->table,
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+    protected static function init()
+    {
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', "qcode_export");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 51 - 0
application/admin/model/QcodeGoods.php

@@ -0,0 +1,51 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use traits\model\SoftDelete;
+class QcodeGoods extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = 'qcode_goods';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        $this->connection->command([
+            'createIndexes' => $this->table,
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+    protected static function init()
+    {
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', "qcode_goods");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 70 - 0
application/admin/model/QcodeLiushui.php

@@ -0,0 +1,70 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use \think\Session;
+
+use traits\model\SoftDelete;
+class QcodeLiushui extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = '';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        $this->connection->command([
+            'createIndexes' => $company_id.'_'."qcode_liushui",
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+
+    protected static function init()
+    {
+        self::event('before_insert', function ($model) {
+            //获取公司编码
+            $userInfo = Session::get('admin');
+            $company_id = (int)$userInfo['company'];
+
+            // 设置表名
+            $model->table($company_id.'_'."qcode_liushui");
+        });
+
+        //获取公司编码
+        $userInfo = Session::get('admin');
+        $company_id = (int)$userInfo['company'];
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', $company_id.'_'."qcode_liushui");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->create_time)){
+                $model->create_time="";
+            }
+            if (!isset($model->update_time)){
+                $model->update_time="";
+            }
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 22 - 0
application/admin/view/deliver/apply.html

@@ -0,0 +1,22 @@
+<div class="row" style="font-size: 12px;">
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="myTabContent" class="tab-content">
+                <div class="tab-pane fade active in row" 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>
+                            <a href="javascript:;" class="btn btn-success  btn-goods btn-disabled disabled {:$auth->check('deliver/goods')?'':'hide'}" title="发货" ><i class="glyphicon glyphicon-export"></i>发货</a>
+                        </div>
+                        <table id="table2" class="table table-striped table-bordered table-hover table-nowrap"
+                               data-operate-edit=""
+                               data-operate-del="{:$auth->check('deliver/apply_del')}"
+                               width="100%">
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+

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

@@ -0,0 +1,21 @@
+<div class="panel panel-default panel-intro">
+    <div class="panel-body">
+        <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>
+<!--                        <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>
+                    <table id="table3" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit=""
+                           data-operate-del="{:$auth->check('deliver/dispatch_del')}"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 39 - 0
application/admin/view/deliver/goods.html

@@ -0,0 +1,39 @@
+<form class="form-horizontal " id="apply"  method="" action>
+    <input type="hidden" value="{$ids}" name="ids" id="goods_id" >
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">输入订单号</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-order_number" class="form-control" data-rule="required" name="order_number" type="text" >
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">输入司机</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-deliveryman" class="form-control" data-rule="required" name="deliveryman" type="text" >
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">输入司机电话</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-shr_phone" class="form-control" data-rule="required" name="shr_phone" type="text" >
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">输入车牌号</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-plate_number" class="form-control" name="plate_number" type="text" >
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">备注</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-note" class="form-control" name="note" type="text" >
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-1"></label>
+        <div class="col-xs-12 col-sm-2">
+            <button type="submit" class="btn btn-success" id="apply_btn">提交</button>
+        </div>
+    </div>
+</form>

+ 25 - 0
application/admin/view/deliver/index.html

@@ -0,0 +1,25 @@
+<div class="panel-heading">
+    <ul id="myTab" class="nav nav-tabs">
+        <li class="active">
+            <a href="#iframe1" id="lager" data-toggle="tab">大件发货</a>
+        </li>
+        <li>
+            <a href="#iframe2" id="apply" data-toggle="tab">批次发货申请</a>
+        </li>
+        <li>
+            <a href="#iframe3" id="dispatch" data-toggle="tab">发货单</a>
+        </li>
+    </ul>
+</div>
+<div id="myTabContent" class="tab-content">
+    <div class="tab-pane fade in active" id="iframe1">
+        <iframe src="lager" allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%;height: 800px;"></iframe>
+    </div>
+    <div class="tab-pane fade" id="iframe2">
+        <iframe src="apply" allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%;height: 800px"></iframe>
+    </div>
+    <div class="tab-pane fade" id="iframe3">
+        <iframe src="dispatch" allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%;height: 800px"></iframe>
+    </div>
+
+</div>

+ 38 - 0
application/admin/view/deliver/lager.html

@@ -0,0 +1,38 @@
+<div class="row" style="font-size: 12px;">
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="myTabContent" class="tab-content">
+                <div class="tab-pane fade active in row" 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>
+                            <a href="javascript:;" class="btn btn-success  btn-print btn-disabled disabled {:$auth->check('deliver/print')?'':'hide'}" title="导出发货" ><i class="glyphicon glyphicon-export"></i>导出发货</a>
+                            <a href="javascript:;" class="btn btn-success  btn-disabled disabled {:$auth->check('')?'':'hide'}" title="新增大件" ><i class="fa fa-pencil"></i>新增大件</a>
+                        </div>
+                        <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                               width="100%">
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+    <input type="hidden" value="" id="lager_id">
+    <div class="panel panel-default panel-intro">
+        <div class="panel-body">
+            <div id="myTabContent1" class="tab-content">
+                <div class="tab-pane fade active in row" id="two">
+                    <div class="widget-body no-padding">
+                        <div id="toolbar1" class="toolbar">
+<!--                            <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>-->
+                        </div>
+                        <table id="small_table" class="table"
+                               width="100%">
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+

+ 169 - 0
application/admin/view/qcode_add/index.html

@@ -0,0 +1,169 @@
+<style>
+    table tr th,table tr td {border: thin #ddd dashed;padding: 5px }
+</style>
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+    <fieldset style="width: 1200px;margin:10px;padding: 10px;border:solid thin #c0c0c0">
+        <legend>生成厂商信息</legend>
+        <div class="form-group">
+            <label class="control-label col-xs-2 col-sm-1">生产厂商:</label>
+            <div class="col-xs-2 col-sm-3">
+                <input id="c-company_name" data-rule="required" disabled class="form-control" value="{$row['nickname']}" name="company_name" type="text">
+            </div>
+            <label class="control-label col-xs-2 col-sm-1">邮政编码:</label>
+            <div class="col-xs-2 col-sm-3">
+                <input id="c-postcode" data-rule="required" disabled class="form-control" value="{$row['postcode']}" name="postcode" type="text">
+            </div>
+            <label class="control-label col-xs-2 col-sm-1">电&nbsp;&nbsp;话:</label>
+            <div class="col-xs-2 col-sm-3">
+                <input id="c-mobile" data-rule="required;mobile" disabled class="form-control" value="{$row['mobile']}" name="mobile" type="text">
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label col-xs-2 col-sm-1">地&nbsp;&nbsp;&nbsp;&nbsp;址:</label>
+            <div class="col-xs-2 col-sm-7">
+                <input id="c-company_address" data-rule="required" disabled class="form-control" value="{$row['company_address']}" name="company_address" type="text">
+            </div>
+        </div>
+    </fieldset>
+    <fieldset style="width: 1200px;margin: 10px;padding:10px;border: solid thin #c0c0c0">
+        <legend>辅料信息</legend>
+        <div class="form-group">
+            <label class="control-label col-xs-2 col-sm-1">辅料名称</label>
+            <div class="col-xs-2 col-sm-4">
+                <select class="form-control" id="c-product_name" name="product_name">
+                    <option>==================>选择<===================</option>
+                    {volist name='product' id='vo' }
+                    <option value="{$key}">{$vo}</option>
+                    {/volist}
+                </select>
+            </div>
+            <label class="control-label col-xs-2 col-sm-1">辅料代码</label>
+            <div class="col-xs-2 col-sm-4">
+                <input type="text" disabled class="form-control" id="c-product_code" name="product_code">
+            </div>
+        </div>
+    </fieldset>
+    <fieldset style="width: 1200px;margin: 10px;padding:10px;border: solid thin #c0c0c0">
+        <legend>标记参数</legend>
+        <table style="width: 100%;border: thin #ddd dashed">
+            <caption>标签序列配置</caption>
+            <tr>
+                <th style="width: 40%">字段</th>
+                <th>值</th>
+            </tr>
+            <tr>
+                <td><span>请选择单位</span></td>
+                <td>
+                    <select id="danwei" name="danwei" style="width: 200px;padding: 5px;">
+                        <option value="1">箱</option>
+                        <option value="2">卷</option>
+                    </select>
+                </td>
+            </tr>
+            <tr class="xiang">
+                <td><span>总(张)数量(6位)</span></td>
+                <td><input type="text" name="number" id="c-number" data-rule="required"></td>
+            </tr>
+            <tr class="xiang">
+                <td><span>一箱(包)多少张(直接填比例分母)</span></td>
+                <td>
+                    <select name="box_number" id="box_number" style="width:200px;padding: 5px">
+                        <option value="1">========选择=========</option>
+                        <option value="25">========25========</option>
+                        <option value="50">========50========</option>
+                        <option value="250">========250张========</option>
+                        <option value="500">========500张========</option>
+                        <option value="1000">=======1000张========</option>
+                        <option value="2000">=======2000张========</option>
+                        <option value="2500">=======2500张========</option>
+                        <option value="3000">=======3000张========</option>
+                        <option value="4000">=======4000张========</option>
+                        <option value="5000">=======5000张========</option>
+                        <option value="8000">=======8000张========</option>
+                        <option value="10000">=======10000张========</option>
+                        <option value="24000">=======24000张========</option>
+                    </select>
+                </td>
+            </tr>
+            <tr class="xiang">
+                <td><span>一托盘多少箱(包)</span></td>
+                <td>
+                    <select name="tray_num" id="tray_num" style="width: 200px;padding: 5px;">
+                        <option value="1">========>选择<========</option>
+                        <option value="5">========>5层<========</option>
+                        <option value="24">========>24箱<========</option>
+                        <option value="28">========>28箱<========</option>
+                        <option value="32">========>32箱<========</option>
+                        <option value="40">========>40箱<========</option>
+                        <option value="42">========>42箱<========</option>
+                        <option value="48">========>48箱<========</option>
+                        <option value="60">========>60箱<========</option>
+                        <option value="64">========>64箱<========</option>
+                        <option value="72">========>72箱<========</option>
+                        <option value="80">========>80箱<========</option>
+                        <option value="96">========>96箱<========</option>
+                        <option value="105">========>105箱<========</option>
+                        <option value="108">========>108箱<========</option>
+                        <option value="144">========>144箱<========</option>
+                        <option value="180">========>180箱<========</option>
+                        <option value="240">========>240箱<========</option>
+                    </select>
+                </td>
+            </tr>
+            <tr>
+                <td><span>小件总数量(3位)</span></td>
+                <td><input type="text" id="c-small_num" name="small_num" data-rule="required"></td>
+            </tr>
+            <tr class="juan">
+                <td><span>一托盘多少卷(3位)</span></td>
+                <td><input type="text" id="c-volume_num" name="volume_num" data-rule="required"></td>
+            </tr>
+            <tr>
+                <td><span>大件数量</span></td>
+                <td><input type="text" id="c-box_num" name="box_num" data-rule="required"></td>
+            </tr>
+            <tr>
+                <td><span>生产日期</span></td>
+                <td>
+                    <input class="datetimepicker" id="c-manufacture_date" data-date-use-current="true" name="manufacture_date" data-date-format="YYYY-MM-DD">
+                </td>
+            </tr>
+            <tr>
+                <td><span>打码日期</span></td>
+                <td>
+                    <input class="datetimepicker" id="c-print_date" data-date-use-current="true" name="print_date" data-date-format="YYYY-MM-DD">
+                </td>
+            </tr>
+            <tr>
+                <td><span>生产批次号</span></td>
+                <td>
+                    <input type="text" name="batch" id="c-batch"  data-rule="required" readonly>
+                </td>
+            </tr>
+            <tr>
+                <td><span>大件开始流水号</span></td>
+                <td>
+                    <input type="text" name="big_liushui" id="c-big_liushui" data-rule="required" readonly>
+                </td>
+            </tr>
+            <tr>
+                <td><span>大件重量(单位千克数值)有小数时保留2位小数</span></td>
+                <td><input type="text" id="c-big_weight" name="big_weight"></td>
+            </tr>
+            <tr>
+                <td><span>小件开始流水号</span></td>
+                <td><input type="text" id="c-small_start_liushui" name="small_start_liushui" ></td>
+            </tr>
+            <tr>
+                <td><span>小件重量(单位克 数值)</span></td>
+                <td><input type="text" id="c-small_weight" name="small_weight"></td>
+            </tr>
+        </table>
+    </fieldset>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-5"></label>
+        <div class="col-xs-12 col-sm-5">
+            <button type="submit" id="submit" class="btn btn-primary btn-embossed">{:__('保存')}</button>
+        </div>
+    </div>
+</form>

+ 273 - 0
public/assets/js/backend/deliver.js

@@ -0,0 +1,273 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            $('#lager').click(function () {
+                $('#iframe1').contentWindow.location.reload('lager.html');
+            });
+            Controller.api.bindevent();
+        },
+        lager: function () {
+            // 初始化表格参数配置
+            Table.api.init();
+            this.table.first();
+            this.table.second();
+            Controller.api.bindevent();
+        },
+        table:{
+          first:function (){
+              var table = $("#table");
+              // 初始化表格
+              table.bootstrapTable({
+                  url: 'deliver/lager',
+                  pk: 'id',
+                  height:300,
+                  sortName: 'id',
+                  toolbar:'#toolbar',
+                  searchFormVisible:true,
+                  search:false,
+                  showToggle:false,
+                  showColumns:false,
+                  showExport:false,
+                  columns: [
+                      [
+                          {checkbox: true},
+                          {field: 'id', title: 'ID', visible:false,operate: false},
+                          {field: 'bach', title: __('批次号'),operate: "LIKE"},
+                          {field: 'l_flow', title: __('托盘号'), operate: false},
+                          {field: 'matter_name', title: __('辅料名称'), operate: 'LIKE',searchList: $.getJSON("deliver/matterName")},
+                          {field: 'manufacture_date', title: '生产日期', operate: 'RANGE', addclass: 'datetimerange',datetimeFormat:'YYYY-MM-DD', formatter: Table.api.formatter.datetime},
+                          {field: 'code', title: __('大件编码'), operate: false},
+                          {field: 'small_num', title: __('小件数'),operate: false},
+                      ]
+                  ]
+              });
+              //导出发货按钮
+              $('.btn-print').on('click',function () {
+                  var ids = Table.api.selectedids(table);
+                  if (ids.length === 0){
+                      alert('至少选择一个大件');
+                  }
+                  var lager = ids.toString();
+                  Fast.api.ajax({
+                      url:'deliver/print',
+                      data:{lager_id:lager},
+                  },function (data,res) {
+                      return false;
+                  },function (data) {
+                      return false;
+                  })
+              })
+              // 为表格绑定事件
+              Table.api.bindevent(table);
+              //去掉时间区间记忆
+              table.on('post-body.bs.table',function (e,settings,json,xhr) {
+                  $('.datetimerange').each(function () {
+                      $(this).attr('autocomplete','off');
+                  })
+              });
+
+              //复选框全选事件
+              table.on('check-all.bs.table',function (e,rows){
+                  var lagerlist = '';
+                  for (i=0;i<rows.length;i++){
+                      lagerlist = lagerlist + rows[i].id + ',';
+                  }
+                  $("#myTabContent1 .search input").val(lagerlist);
+                  $("#myTabContent1 .btn-refresh").trigger("click");
+              });
+              //复选框全反选
+              table.on('uncheck-all.bs.table',function (e,rows) {
+
+              });
+              //复选框单个选中
+              table.on('check.bs.table',function (e,rows){
+
+              });
+              //复选框单个反选
+              table.on('uncheck.bs.table',function (e,rows) {
+
+              });
+          }, second:function(){
+                //小件列表
+                var smallTable = $('#small_table');
+                smallTable.bootstrapTable({
+                    url:'deliver/smallList',
+                    height: 300,
+                    toolbar: '#toolbar1',
+                    searchText:'',
+                    commonSearch:false,
+                    showToggle:false,
+                    showColumns:false,
+                    showExport:false,
+                    columns: [
+                        [
+                            {field: 'code', title: __('小件标签代码'),operate: false},
+                            {field: 'l_flow', title: __('当前序号'),operate: false},
+                            {field: 'print_num', title: __('打印次数'),operate: false},
+                            {field: 'status', title: __('状态'),operate: false},
+                        ]
+                    ]
+                });
+                // 为表格绑定事件
+                Table.api.bindevent(smallTable);
+            }
+        },
+        apply: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'deliver/apply' + location.search,
+                    goods_url: 'deliver/goods',
+                    del_url:'deliver/apply_del',
+                    table:'deliver'
+                }
+            });
+
+            var table = $("#table2");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                height:500,
+                sortName: 'id',
+                searchFormVisible:true,
+                search:false,
+                showToggle:false,
+                showColumns:false,
+                showExport:false,
+                fixedColumns: true,
+                fixedRightNumber: 1,
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id'),visible:false,operate: false},
+                        {field: 'matter_name', title: '辅料名称', operate: 'LIKE',searchList: $.getJSON("deliver/matterName")},
+                        {field: 'matter_no', title: '辅料编码', operate: false},
+                        {field: 'username', title: '所属用户', operate: 'LIKE'},
+                        {field: 'large_num', title: '大件数量', operate: false},
+                        {field: 'small_num', title: '小件数量', operate: false},
+                        {field: 'create_time', title: '创建时间', operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
+                        {field: 'file_dir', title: '下载路径', operate: false},
+                        {field: 'status', title: '状态', operate: 'LIKE',searchList: {"0":'待发货',"1":'已删除'}, formatter: Table.api.formatter.status},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ],
+            });
+
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+            //发货按钮
+            $('.btn-goods').on('click',function () {
+                var ids = Table.api.selectedids(table);
+                if (ids.length === 0){
+                    alert('至少选择一个订单');
+                }
+                var id_str = ids.toString();
+                Fast.api.open('deliver/goods?ids='+id_str,'发货信息',{area:["60%","60%"]})
+            });
+            //去掉时间区间输入记忆
+            table.on('post-body.bs.table',function (e,settings,json,xhr) {
+                $('.datetimerange').each(function () {
+                    $(this).attr('autocomplete','off');
+                })
+            });
+
+            Controller.api.bindevent();
+        },
+        goods: function () {
+            $('#apply_btn').click(function () {
+               var ids = $('#goods_id').val();
+               var order_number = $('#c-order_number').val();
+               if (order_number == null || order_number === ''){
+                   layer.confirm('订单号不能为空');
+               }
+               var deliveryman = $('#c-deliveryman').val();
+               if (deliveryman == null || deliveryman === ''){
+                   layer.confirm('司机名称不能为空');
+               }
+               var shr_phone = $('#c-shr_phone').val();
+               if (shr_phone == null || shr_phone === ''){
+                   layer.confirm('手机号不能为空');
+               }
+               var plate_number = $('c-plate_number').val();
+               var note = $('c-note').val();
+               Fast.api.ajax({
+                   url:'deliver/apply_add',
+                   data:{
+                       ids:ids,
+                       order_number:order_number,
+                       deliveryman:deliveryman,
+                       shr_phone:shr_phone,
+                       plate_number:plate_number,
+                       note:note,
+                   }
+               },function (data,res) {
+                   parent.Toastr.success("成功");
+                   Fast.api.close();
+                   parent.Fast.api.refreshmenu();
+                   return false;
+               },function (data) {
+                   parent.Toastr.error('失败');
+                   Fast.api.close();
+                   return false;
+               })
+            });
+            Controller.api.bindevent();
+        },
+        dispatch: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'deliver/dispatch' + location.search,
+                    del_url:'deliver/dispatch_del',
+                    table:'deliver'
+                }
+            });
+
+            var table = $("#table3");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                height:500,
+                sortName: 'id',
+                searchFormVisible:true,
+                showToggle:false,
+                showColumns:false,
+                showExport:false,
+                fixedColumns: true,
+                fixedRightNumber: 1,
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id'),visible:false,operate: false},
+                        {field: 'matter_name', title: '辅料名称', operate: 'LIKE',},
+                        {field: 'matter_no', title: '辅料编码', operate: false},
+                        {field: 'username', title: '所属用户', operate: 'LIKE'},
+                        {field: 'large_num', title: '大件数量', operate: false},
+                        {field: 'small_num', title: '小件数量', operate: false},
+                        {field: 'create_time', title: '创建时间', operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
+                        {field: 'file_dir', title: '下载路径', operate: false},
+                        {field: 'status', title: '状态', operate: 'LIKE',searchList: {"0":'待发货',"1":'已删除'}, formatter: Table.api.formatter.status},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ],
+            });
+
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});

+ 265 - 0
public/assets/js/backend/qcode_add.js

@@ -0,0 +1,265 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            //选择产品获取产品编码、单位
+            $('#c-product_name').change(function () {
+               var product_code = $('#c-product_name').val();
+               $('#c-product_code').val(product_code);
+               Fast.api.ajax({
+                   url:'qcode_add/product',
+                   data:{product_code:product_code},
+               },function (data) {
+                   if (data.temple === '07'){
+                       $('#danwei').val(1);
+                       $('.juan').hide();
+                       $('.xiang').show();
+                   }else {
+                       $('#danwei').val(2);
+                       $('.xiang').hide();
+                       $('.juan').show();
+                   }
+                   if (data.flow === ''){
+                       $('#c-big_liushui').val(1)
+                   }else {
+                       $('#c-big_liushui').val(data.flow);
+                   }
+                   if (data.bach === ''){
+                       $('#c-batch').val(201800000);
+                   }else {
+                       $('#c-batch').val(data.bach);
+                   }
+                   return false;
+               },function () {
+                   return false;
+               });
+            });
+            //进入页面根据单位判断显示字段
+            $(document).ready(function () {
+                var status = $('#danwei').val();
+                if (status == '1'){
+                    $('.xiang').show();
+                    $('.juan').hide();
+                }else {
+                    $('.xiang').hide();
+                    $('.juan').show();
+                }
+            });
+            //选择单位时触发,显示隐藏对饮字段
+            $('#danwei').change(function (){
+                var status = $('#danwei').val();
+                console.log(status);
+                if (status == '1'){
+                    $('.xiang').show();
+                    $('.juan').hide();
+                }else {
+                    $('.xiang').hide();
+                    $('.juan').show();
+                }
+            });
+            //计算大件、小件数量
+            //总数变化
+            $('#c-number').change(function (){
+                if ($('#danwei').val() === '1'){
+                    xiangcal();
+                }
+            });
+            //一箱多少张数量变化
+            $('#box_number').change(function () {
+                if ($('#danwei').val() === '1'){
+                    xiangcal();
+                }
+            });
+            //一托盘多少箱数量变化
+            $('#tray_num').change(function () {
+                if ($('#danwei').val() === '1'){
+                    xiangcal();
+                }
+            });
+            //小件数量变化时
+            $('#c-small_num').change(function () {
+                if ($('#danwei').val() == 2){
+                    juancal();
+                }
+            });
+            //一托盘多少卷数量变化时
+            $('#c-volume_num').change(function () {
+                if ($('#danwei').val() == 2){
+                    juancal();
+                }
+            });
+
+            //单位为箱时计算大小件数量
+            function xiangcal() {
+                var number = $('#c-number').val();
+                var box_number = $('#box_number').val();
+                var tray_num = $('#tray_num').val();
+                var small_num  = 0;
+                var box_num = 0;
+                if (box_number !== 0 && tray_num !== 0){
+                    small_num = Math.ceil(number / box_number) ;
+                    $('#c-small_num').val(small_num);
+                    box_num = Math.ceil(small_num / tray_num);
+                    $('#c-box_num').val(box_num);
+                }
+            }
+            //单位为卷时计算大小件数量
+            function juancal() {
+                var small_num = $('#c-small_num').val();
+                var volume_num = $('#c-volume_num').val();
+                console.log(small_num);
+                var box_num = 0;
+                if (small_num !== 0 && volume_num !== 0){
+                    box_num = Math.ceil(small_num / volume_num);
+                    $('#c-box_num').val(box_num);
+                }
+            }
+            //点击保存按钮,上传表单信息
+            $('#submit').click(function () {
+                //表单验证
+                //生产厂商
+                var rows = $.makeArray();
+                var company_name = $('#c-company_name').val();
+                if (company_name == null || company_name === ''){
+                    layer.confirm('生产厂商不能为空');
+                }
+                rows.push({'company_name':company_name});
+                //邮政编码
+                var postcode = $('#c-postcode').val();
+                if (postcode == null || postcode === ''){
+                    layer.confirm('邮政编码不能为空');
+                }
+                rows.push({'postcode':postcode});
+                //电话
+                var mobile = $('#c-mobile').val();
+                if (mobile == null || mobile === ''){
+                    layer.confirm('电话不能为空');
+                }
+                rows.push({'mobile':mobile});
+                //公司地址
+                var company_address = $('#c-company_address').val();
+                if (company_address == null || company_address === ''){
+                    layer.confirm('公司地址不能为空');
+                }
+                rows.push({'company_address':company_address});
+                //辅料名称
+                var product_name = $('#c-product_name').val();
+                if (product_name == null || product_name === ''){
+                    layer.confirm('辅料名称不能为空');
+                }
+                rows.push({'product_name':product_name});
+                //辅料代码
+                var product_code = $('#c-product_code').val();
+                if (product_code == null || product_code === ''){
+                    layer.confirm('辅料代码不能为空');
+                }
+                rows.push({'product_code':product_code});
+                //单位
+                var danwei = $('#danwei').val();
+                if (danwei == null || danwei === ''){
+                    layer.confirm('单位不能为空');
+                }
+                rows.push({'danwei':danwei});
+                //小件总数量
+                var small_num = $('#c-small_num').val();
+                if (small_num == null || small_num === ''){
+                    layer.confirm('小件总数量不能为空');
+                }
+                rows.push({'small_num':small_num});
+                //大件数量
+                var box_num = $('#c-box_num').val();
+                if (box_num == null || box_num ===''){
+                    layer.confirm('大件数量不能为空');
+                }
+                rows.push({'box_num':box_num});
+                //生产日期
+                var manufacture_date = $('#c-manufacture_date').val();
+                if (manufacture_date == null || manufacture_date === ''){
+                    layer.confirm('生产日期不能为空');
+                }
+                rows.push({'manufacture_date':manufacture_date});
+                //打码日期
+                var print_date = $('#c-print_date').val();
+                if (print_date == null || print_date === ''){
+                    layer.confirm('打码日期不能为空');
+                }
+                rows.push({'print_date':print_date});
+                //生产批次号
+                var batch = $('#c-batch').val();
+                if (batch == null || batch === ''){
+                    layer.confirm('生产批次号不能为空');
+                }
+                rows.push({'batch':batch});
+                //大件流水号
+                var big_liushui = $('#c-big_liushui').val();
+                if (big_liushui == null || big_liushui === ''){
+                    layer.confirm('大件流水号不能为空');
+                }
+                rows.push({'big_liushui':big_liushui});
+                //大件重量
+                var big_weight = $('#c-big_weight').val();
+                if (big_weight == null || big_weight === ''){
+                    layer.confirm('大件重量不能为空');
+                }
+                rows.push({'big_weight':big_weight});
+                //小件流水号
+                var small_start_liushui = $('#c-small_start_liushui').val();
+                if (small_start_liushui == null || small_start_liushui === ''){
+                    layer.confirm('小件流水号不能为空');
+                }
+                rows.push({'small_start_liushui':small_start_liushui});
+                //小件重量
+                var small_weight = $('#c-small_weight').val();
+                if (small_weight == null || small_weight === ''){
+                    layer.confirm('小件重量不能为空');
+                }
+                rows.push({'small_weight':small_weight});
+                if (danwei === '1'){
+                    //总张数
+                    var number = $('#c-number').val();
+                    if (number == null || number === ''){
+                        layer.confirm('总张数不能为空');
+                    }
+                    rows.push({'number':number});
+                    //一托盘多少箱
+                    var tray_num =  $('#tray_num').val();
+                    if (tray_num == null || tray_num === ''){
+                        layer.confirm('一托盘多少箱不能为空');
+                    }
+                    rows.push({'tray_num':tray_num});
+                    //一箱多少张
+                    var box_number = $('#box_number').val();
+                    if (box_number == null || box_number === ''){
+                        layer.confirm('一箱多少张不能为空');
+                    }
+                    rows.push({'box_number':box_number});
+                }else {
+                    //一托盘多少卷
+                    var volume_num = $('#c-volume_num').val();
+                    if (volume_num == null || volume_num === ''){
+                        layer.confirm('一坨多少卷不能为空');
+                    }
+                    rows.push({'volume_num':volume_num});
+                }
+                console.log(rows);
+                console.log(JSON.stringify({rows}));
+                Fast.api.ajax({
+                    url:'qcode_add/add',
+                    type:'POST',
+                    data:{row:JSON.stringify(rows)},
+                },function (data) {
+                    return false;
+                },function () {
+                    return false;
+                })
+            });
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});