where($where)->count(); $p = getpage($count,50); $list = $model->getList($where,$p); $this->assign('meta_title','条码大件打印'); $this->assign('list',$list); $this->assign('page', $p->show()); // 赋值分页输出 $this->assign('search',$search); $this->display('list'); } public function largeEdit(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $data = $_POST['data']; $return = $this->dispose($data); if($return){ $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']); }else{ $this->ajaxReturn(['status'=>0,'msg'=>'修改失败']); } }else { $id = $_GET['id']; $productList = D('BarProduct')->select(); $this->assign('productList', $productList); $model = D('BarLarge'); $list = $model->slectById($id); $url = "/index.php?s=/Admin/Bar/largeEdit.html"; $this->assign('url', $url); $this->assign('list', $list[0]); $this->display('add'); } } public function largeAdd(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $data = $_POST['data']; $return = $this->dispose($data); if($return){ $this->ajaxReturn(['status'=>1,'msg'=>'增加成功']); }else{ $this->ajaxReturn(['status'=>0,'msg'=>'增加失败']); } }else{ $productList = D('BarProduct')->select(); $this->assign('productList',$productList); $url = "/index.php?s=/Admin/Bar/largeAdd.html"; $this->assign('url',$url); $this->display('add'); } } public function LargeDel(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $id = $_POST['id']; $model = D('BarLarge'); $return = $model->delete($id); if($return){ $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']); }else{ $this->ajaxReturn(['status'=>0,'msg'=>'删除失败']); } }else{ $this->error('非法请求','/index',5); } } public function dispose($data){ $title = explode('|',$data['title']); $data['title'] = $title[0]; if(strstr($title[0],'_')){ $arr = explode('_',$title[0]); }else{ $arr = explode('-',$title[0]); } $data['name'] = $arr[0]; if(isset($data['mix_board'])){ $data['mix_board'] = 'Y'; $isMix = 1; }else{ $data['mix_board'] = 'N'; $isMix = 0; } $bach = substr($data['batch_number'],-5); $date = substr(preg_replace("/(-)/","",$data['time']),2); $board_no = $this->addZero($data['board_no'],3,'left'); $tray_no = $this->addZero($data['tray_no'],5,'left'); $data['sn'] = '(92)'.$data['custome_sn'].'01A'.'(11)'.$date.'(21)'.$bach.$board_no.$isMix.$tray_no; $data['time'] = strtotime($data['time']); $model = D('BarLarge'); $return = $model->save1($data); return $return; } public function addZero($a,$le,$pos='left'){ $str =$a; $len = substr($a); $cha = $le-$len; if($cha>0){ if($pos=='left'){ $str = str_pad($str,$le,"0",STR_PAD_LEFT); }else{ $str = str_pad($str,$le,"0",STR_PAD_RIGHT); } } return $str; } /**************************************************小件*******************************************************************/ /*大件模块*/ public function small(){ if(IS_POST){ $data = $_POST; $where = array(); $search = $_POST['search']; $where['name'] = array('like', '%'.$search.'%'); $where['title'] = array('like', '%'.$search.'%'); $where['no'] = array('like', '%'.$search.'%'); $where['batch_number'] = array('like', '%'.$search.'%'); $where['technics_number'] = array('like', '%'.$search.'%'); $where['quality_no'] = array('like', '%'.$search.'%'); $where['_logic'] = 'or'; }else{ $where = array(); } $model = D('BarSmall'); $count = $model->where($where)->count(); $p = getpage($count,100); $list = $model->getList($where,$p); $this->assign('meta_title','条码小件件打印'); $this->assign('list',$list); $this->assign('page', $p->show()); // 赋值分页输出 $this->assign('search',$search); $this->display('smalllist'); } public function smallAdd(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $data = $_POST['data']; $return = $this->disposeSmall($data); $return_arr = json_decode($return); $msg = '成功条数'.$return_arr[0].',失败条数'.($return_arr[1]-$return_arr[0]); $this->ajaxReturn(['msg'=>$msg]); }else{ $productList = D('BarProduct')->select(); $this->assign('productList',$productList); $url = "/index.php?s=/Admin/Bar/smallAdd.html"; $this->assign('url',$url); $this->display('smalladd'); } } public function smallEdit(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $data = $_POST['data']; $return = $this->disposeSmall($data); $return_arr = json_decode($return); if($return_arr[0]>0){ $msg = '编辑成功'; }else{ $msg = '编辑失败'; } $this->ajaxReturn(['msg'=>$msg]); }else { $id = $_GET['id']; $productList = D('BarProduct')->select(); $this->assign('productList', $productList); $model = D('BarSmall'); $list = $model->slectById($id); $list = $list[0]; $url = "/index.php?s=/Admin/Bar/smallEdit.html"; $this->assign('url', $url); $this->assign('list', $list); $this->display('smalladd'); } } public function smallDel(){ if(IS_POST){ header("Content-type: text/html; charset=utf-8"); $id = $_POST['id']; $model = D('BarSmall'); $return = $model->delete($id); if($return){ $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']); }else{ $this->ajaxReturn(['status'=>0,'msg'=>'删除失败']); } }else{ $this->error('非法请求','/index',5); } } public function disposeSmall($data){ $model = D('BarSmall'); $title = explode('|',$data['title']); $data['title'] = $title[0]; if(strstr($title[0],'_')){ $arr = explode('_',$title[0]); }else{ $arr = explode('-',$title[0]); } $data['name'] = $arr[0]; $data['num'] = $arr[1]; $date = substr(preg_replace("/(-)/","",$data['time']),2); $quality = $this->addZero($data['technics_number'],9,'right'); $border = $this->addZero($data['board_no'],3,'left'); $mix_board = $this->addZero($data['mix_board'],3,'left'); $success = 0; $i = (int)$data['start']; $step = (int)$data['step']; if($step==0){ $step = 1; } $end = $i+$step-1; for ($i;$i<=$end;$i++) { $new = array(); $new = $data; $new['time'] = time(); $new['board_no_serial'] = $i; $board_no_serial = $this->addZero($i,5,'left'); $new['sn'] = $data['custome_sn'].'01A'.$quality.$date.$border.$mix_board.$board_no_serial; unset($new['start']); unset($new['step']); unset($new['custome_sn']); $id = $model->save1($new); if($id){ $success = $success+1; } } return json_encode([$success,$step]); } /*****************************************************产品模块******************************************************************/ /*产品配置*/ public function product(){ // 搜索 $keyword = I('keyword', '', 'string'); $condition = array('like', '%' . $keyword . '%'); $map['code|title|code1|standard'] = array( $condition, $condition, $condition, $condition, '_multi' => true, ); $p = !empty($_GET["p"]) ? $_GET['p'] : 1; $product_object = D('BarProduct'); $data_list = $product_object ->page($p, 50) ->where($map) ->order('id asc') ->select(); $page = new Page( $product_object->where($map)->count(), 50 ); // 使用Builder快速建立列表页面。 $builder = new \Common\Builder\ListBuilder(); $builder->setMetaTitle('配置列表') // 设置页面标题 ->addTopButton('addnew',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductAdd')]) // 添加新增按钮 ->addTopButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductDel')]) // 添加删除按钮 ->setSearch( '请输入代码/自定义名称', U('product') ) ->addTableColumn('id', 'ID') ->addTableColumn('code', '代码') ->addTableColumn('code1', '客户产品编码') ->addTableColumn('standard', '产品规则') ->addTableColumn('title', '自定义') ->addTableColumn('right_button', '操作', 'btn') ->setTableDataList($data_list) // 数据列表 ->setTableDataPage($page->show()) // 数据列表分页 ->addRightButton('edit',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductEdit',array( 'id' => '__data_id__', ))]) // 添加编辑按钮 ->addRightButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductDel',array( 'id' => '__data_id__', ))]) // 添加删除按钮 ->display(); } /** * 产品新增配置 * */ public function barProductAdd() { if (IS_POST) { $bar_object = D('BarProduct'); $data = $bar_object->create(); if ($data) { if ($bar_object->add($data)) { $this->success('新增成功', U('product')); } else { $this->error('新增失败'); } } else { $this->error($bar_object->getError()); } } else { //使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('新增条形码产品配置') //设置页面标题 ->setPostUrl(U('barProductAdd')) //设置表单提交地址 ->addFormItem('code', 'text', '产品代码', '产品代码') ->addFormItem('code1','text', '客户产品编码', '客户产品编码') ->addFormItem('standard','text', '产品规则', '产品规则') ->addFormItem('title', 'text', '自定义名称', '自定义名称') ->display(); } } /*条形码产品删除*/ public function barProductDel(){ if(IS_POST){ if(empty($_POST)){ $this->error('请至少选择一个选项'); }else{ $bar = D('BarProduct'); $id = implode(',',$_POST['ids']); $return = $bar->DelQcodeProduct($id); if($return){ $this->success('删除成功', U('product')); }else{ $this->error('删除失败'); } } }else{ $id = $_GET['id']; $bar = D('BarProduct'); $return = $bar->DelQcodeProduct($id); if($return){ $this->success('删除成功', U('product')); }else{ $this->error('删除失败'); } } } /*条形码产品修改*/ public function barProductEdit(){ if (IS_POST) { $bar = D('BarProduct'); $data = $bar->create(); if ($data) { if ($bar->save($data)) { $this->success('更新成功', U('product')); } else { $this->error('更新失败'); } } else { $this->error($bar->getError()); } } else { $id = $_GET['id']; $bar = D('BarProduct'); if (!$id) { $this->error('参数错误'); } $data = $bar->where('id = ' . $id)->find(); if (!$data) { $this->error('参数错误'); } else { // 使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('编辑产品数据')// 设置页面标题 ->setPostUrl(U('barProductEdit'))// 设置表单提交地址 ->addFormItem('id', 'hidden', 'ID', 'ID') ->addFormItem('code', 'text', '产品代码', '产品代码') ->addFormItem('code1','text', '客户产品编码', '客户产品编码') ->addFormItem('standard','text', '产品规则', '产品规则') ->addFormItem('title', 'text', '自定义名称', '自定义名称') ->setFormData(D('BarProduct')->find($id)) ->display(); } } } /******************************************二维码********************************************************************************/ public function qrcode($url)//二维码生成类 { Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类 $level=3; $size=4; $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字符串返回给前端 /*$data = array( 'labelcode'=>$url, 'code'=>200, 'data'=>$imageString ); $this->ajaxReturn($data);*/ } public function getLargeDate(){ $id = $_POST['id']; $id_arr = explode(',',$id); /*查询相关的数据*/ $data = []; $Model = D('BarLarge'); $return = $Model->getById($id); $this->ajaxReturn($return); } public function getSmallDate(){ $id = $_POST['id']; /*查询相关的数据*/ $data = []; $Model = D('BarSmall'); $return = $Model->getById($id); $this->ajaxReturn($return); } }