| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- <?php
- namespace Admin\Controller;
- use Think\Page;
- class BarController extends AddonController{
- /*****************************************************大件模块*******************************************************************8888*/
- public function Large(){
- 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['board_no'] = array('like', '%'.$search.'%');
- $where['mix_board'] = array('like', '%'.$search.'%');
- $where['quality_no'] = array('like', '%'.$search.'%');
- $where['batch_number'] = array('like', '%'.$search.'%');
- $where['tray_no'] = array('like', '%'.$search.'%');
- $where['inspector'] = array('like', '%'.$search.'%');
- $where['_logic'] = 'or';
- }else{
- $where = array();
- }
- $model = D('BarLarge');
- $count = $model->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);
- }
- }
|