model = new \app\admin\model\QcodeBach(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = false; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); return $this->view->fetch(); } /** * 主表查询 */ public function bach() { //当前是否为关联查询 $this->relationSearch = false; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $where = [ 'delete_time'=> '' ]; $req = input(); $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort']; $order = $req['order']; $offset = $req['offset']; $limit = $req['limit']; // 构造模糊查询条件 // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i'); // $filter = ['field' => $regex]; $filter = json_decode($req['filter'], true); foreach ($filter as $k => $v){ $where[$k] = new \MongoDB\BSON\Regex($v); } $userinfo = Session::get('admin'); if (empty($userinfo) || !isset($userinfo['company'])) { $this->error('获取用户信息失败,请重新登录'); } $mongo = \think\Db::connect('mongodb'); $qcode_bach = $userinfo['company'] . '_qcode_bach'; $bachdetails = $userinfo['company'] . '_qcode_bachdetails'; $bachsummary = $userinfo['company'] . '_qcode_bachsummary'; // 查询发货单数据,admin用户可以查看所有,普通用户只能查看自己的数据 $query = $mongo->name('qcode_goods')->where('delete_time',''); if ($userinfo['username'] !== 'admin') { $query = $query->where('user_id', $userinfo['id']); } $goodsList = $query->select(); // 获取所有相关的bach_ids $bachIds = []; foreach ($goodsList as $v) { $summary = $mongo->name($bachsummary)->where('_id', $v['qcode_bachsummary_id']) ->where('delete_time','') ->find(); if ($summary && !empty($summary['bach_ids'])) { $bachIds[] = $summary['bach_ids']; } } // 如果有有效的bach_ids,则添加到查询条件中 if (!empty($bachIds)) { $total = $this->model->name($qcode_bach)->where($where)->count(); $list = $this->model->name($qcode_bach)->where($where) ->order($sort,$order) ->limit($limit) ->skip($offset) ->select(); foreach ($list as $k=>$v) { $oid = $v['_id']->jsonSerialize(); $list[$k]['id'] = $oid['$oid']; } $result = array("total" => $total, "rows" => $list); } else { $result = array("total" => 0, "rows" => ''); } return json($result); } return $this->view->fetch(); } /** * 大件列表 */ public function large() { //当前是否为关联查询 $this->relationSearch = false; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $req = input(); if($req['filter']=='{}'){ $result = array("total" => 0, "rows" => []); return json($result); } $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort']; $filter = json_decode($req['filter'], true); foreach ($filter as $k => $v){ $where[$k] = new \MongoDB\BSON\Regex($v); } $mongo = \think\Db::connect('mongodb'); $collection = $userInfo['company'] . '_qcode_bach'; $bachdetails = $userInfo['company'] . '_qcode_bachdetails'; $bach = $mongo->name($collection)->where('_id',$filter['bach_id'])->find(); $total = $mongo->name($bachdetails)->where('bach_ids',$bach['bach_ids'])->count(); $list = $mongo->name($bachdetails)->where('bach_ids',$bach['bach_ids']) ->select(); // $qcodeSmall = new QcodeSmall(); // foreach ($list as $k=>$v) { // // $bach_detail = $this->model // ->name($company_id . '_qcode_bach') // ->where('_id', $filter['bach_id']) // ->find(); // // $num = (float)$bach_detail['num']; // $small_num = (float)$bach_detail['small_num']; // $boxes_per_pallet = (float)$bach_detail['total_boxes']; // // $larger_num = $num / $small_num; // $full_pallets = floor($larger_num / $boxes_per_pallet); // $last_pallet_boxes = fmod($larger_num, $boxes_per_pallet); // 真正浮点取余 // // // $total_pallets = $full_pallets + ($last_pallet_boxes > 0 ? 1 : 0); // // // 当前是第几托(code中解析) // $current_flow_str = substr($v['code'], 53, 6); // $current_flow = (int) ltrim($current_flow_str, '0'); // $total_pallets = (int) $total_pallets; // // // 是否是最后一托 // $is_last = ($current_flow === $total_pallets) ? 1 : 0; // // // 修正箱数 // $total_boxes = $boxes_per_pallet; // if ($is_last && $last_pallet_boxes > 0) { // // 精准保留1位小数,不做四舍五入 // $total_boxes = number_format($last_pallet_boxes, 1, '.', ''); // } // // $oid = $v['_id']->jsonSerialize(); // $list[$k]['id'] = $oid['$oid']; // //设置当前托盘号 // $list[$k]['l_flow'] = ltrim(substr($v['code'],53,6),'0'); // //查询小件数量 // $small_num = $qcodeSmall->name($company_id.'_'."qcode_small") // ->where('large_id',$oid['$oid']) // ->count(); // $list[$k]['small_num'] = $small_num; // $list[$k]['tray_num'] = $bach_detail['tray_num']; // $list[$k]['total_boxes'] = $total_boxes; // //设置当前大件重量 // $list[$k]['l_weight'] = floatval($v['l_weight'])/100; // // } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 小件列表 */ public function small() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); $req = $this->request->param(); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $where = [ 'delete_time'=> '', 'large_id'=> $req['large_id'] ]; $req = input(); $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort']; $order = $req['order']; $offset = $req['offset']; $limit = $req['limit']; // 构造模糊查询条件 // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i'); // $filter = ['field' => $regex]; $filter = json_decode($req['filter'], true); foreach ($filter as $k => $v){ $where[$k] = new \MongoDB\BSON\Regex($v); } $qcodeSmall = new QcodeSmall(); $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count(); $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where) ->order($sort,$order) ->limit($limit) ->skip($offset) ->select(); foreach ($list as $k=>$v) { $oid = $v['_id']->jsonSerialize(); $list[$k]['id'] = $oid['$oid']; $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow']; } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 小件导出状态修改 */ public function small_status() { $req = $this->request->param(); $ids = $req['ids']; $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $qcodeSmall = new QcodeSmall(); $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status'); if ($status === 0) { $newStatus = 1; } elseif ($status === 1) { $newStatus = 0; } else { // 处理其他情况,如果有需要 } $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids']) ->update(['status' => $newStatus]); if ($bool){ $this->success("切换成功", null, ['id' => $ids]); }else{ $this->error("切换失败", null, ['id' => $ids]); } } /** * 自动打码(大件) */ public function print_l() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); $req = $this->request->param(); $ids = $req['ids']; $type = $req['type']; $numn = $req['numn']; $userinfo = Session::get('admin'); if (empty($userinfo) || !isset($userinfo['company'])) { $this->error('获取用户信息失败,请重新登录'); } $mongo = \think\Db::connect('mongodb'); $collection = $userinfo['company'] . '_qcode_bach'; $bachdetails = $userinfo['company'] . '_qcode_bachdetails'; $bachsummary = $userinfo['company'] . '_qcode_bachsummary'; // 初始化数组存储所有查询结果 $allRows = []; $alls = []; foreach ($req['ids'] as $index => $v){ // 先从bachdetails集合获取原始数据 $detailData = $mongo->name($bachdetails)->where('_id', $v)->find(); if ($detailData) { // 从collection集合获取cpmc字段 $bachData = $mongo->name($collection)->where('bach_ids', $detailData['bach_ids'])->find(); $bachsummaryData = $mongo->name($bachsummary)->where('bach_ids', $detailData['bach_ids'])->find(); // 获取ObjectId的字符串表示 $bachsummaryId = (string)$bachsummaryData['_id']; $goods = $mongo->name("qcode_goods")->where('qcode_bachsummary_id', $bachsummaryId)->find(); $goodsData['order_number'] = $goods['order_number']; $detailData['cpmc'] = $bachData['cpmc']; $detailData['unit'] = $bachData['unit']; $detailData['tray_num'] = $bachData['tray_num']; $detailData['small_num'] = $bachData['small_num']; $detailData['total_boxes'] = $bachData['total_boxes']; $detailData['order_ddbh'] = $bachData['order_ddbh']; $detailData['riqi'] = date('Y-m-d'); // 将更新后的数据添加到结果数组 $allRows[$index] = $detailData; $alls[$index] = $goodsData; } } // 处理kes值,去掉前四位 if (isset($userinfo['kes'])) { $userinfo['kes'] = substr($userinfo['kes'], 4); } // 构建返回数据 $data = [ 'order_number' => $alls, 'userinfo' => $userinfo, 'type' => $type, 'numn' => $numn, 'rows' => $allRows, 'ids' => $ids, 'count' => count($allRows) ]; $this->success('成功获取打印数据', '', $data); } /** * 自动打码(小件) */ public function print_s() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); $req = $this->request->param(); if ($this->request->isAjax()) { $ids = $req['ids']; $type = $req['type']; $numn = $req['numn']; $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $qcodeLarge = new QcodeLarge(); $qcodeSmall = new QcodeSmall(); $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find(); $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find(); $company_name = json_decode($bach,true)['supplier_name']; $product_name = json_decode($bach,true)['matter_name']; //获取全部小件id $rows = []; $key = 0; foreach ($ids as $value){ $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find(); $large = json_decode($large,true); $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id'); //查询打印大件码所需数据 foreach ($arr as $v){ $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find(); $small = json_decode($small,true); $code = $small['code']; $rows[$key]['company_name'] = $company_name; $rows[$key]['product_name'] = $product_name; $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0); $rows[$key]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow']; $rows[$key]['qrcode'] = $code; // $rows[$key]['pCode'] = $this->qrcode($code); //批次号特殊情况判断 if (substr($code,76,10)=='0000000000'){ $rows[$key]['batch'] = ltrim(substr($code,66,10),'0'); }else{ $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0'); } $key++; } } $data = [ 'type'=>$type, 'numn'=>$numn, 'rows'=>$rows, 'ids'=>$ids, ]; $this->success('成功','',$data); } $this->view->assign('ids',$req['ids']); return $this->view->fetch(); } /** * 手动打码(小件) */ public function print_ls() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); $req = $this->request->param(); if ($this->request->isAjax()) { $ids = $req['ids']; $type = $req['type']; $numn = $req['numn']; $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $qcodeLarge = new QcodeLarge(); $qcodeSmall = new QcodeSmall(); $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->find(); $small = json_decode($small,true); $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find(); $large = json_decode($large,true); $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find(); $company_name = json_decode($bach,true)['supplier_name']; $product_name = json_decode($bach,true)['matter_name']; //获取全部小件id $rows = []; $code = $small['code']; $rows[0]['company_name'] = $company_name; $rows[0]['product_name'] = $product_name; $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0); $rows[0]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow']; $rows[0]['qrcode'] = $code; // $rows[0]['pCode'] = $this->qrcode($code); //批次号特殊情况判断 if (substr($code,76,10)=='0000000000'){ $rows[0]['batch'] = ltrim(substr($code,66,10),'0'); }else{ $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0'); } $data = [ 'type'=>$type, 'numn'=>$numn, 'rows'=>$rows, 'ids'=>$ids, ]; $this->success('成功','',$data); } $this->view->assign('ids',$req['ids']); return $this->view->fetch(); } /** * 打印数量设置 */ public function set_num() { $req = $this->request->param(); //获取数据 $status = $req['status']; $num = (int)$req['num']; $ids = $req['ids']; //获取company_id $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; //自动打印大件 if($status==1){ $qcodeLarge = new QcodeLarge(); foreach ($ids as $v){ $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setInc('p_nums',$num); $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setField('l_print','1'); } }elseif($status==2){ $qcodeSmall = new QcodeSmall(); foreach ($ids as $v){ $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$v)->setInc('p_nums',$num); } }elseif($status==3){ $qcodeSmall = new QcodeSmall(); $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->setInc('p_nums',$num); } } /** * 导出excel跳转 */ public function exp() { //获取产品配置菜单id $bool = db('auth_rule')->field('id')->where('title','发货管理')->find(); if ($bool){ $this->success('成功','',$bool); }else{ $this->error('未获取到菜单','',$bool); } } /** * 修改大件重量数量 */ public function edit($ids = NULL) { $req = $this->request->param(); if ($this->request->isAjax()){ parse_str($req['data'],$req); if(!isset($req['row']['type']) || empty($req['row']['type'])){ $this->error('请选择修改类型'); } if(!isset($req['row']['numn']) || empty($req['row']['numn'])){ $this->error('请填写修改数量'); } $ids = explode(',',$req['row']['ids']); $data = [ 'update_time'=>time(), 'sync_flag'=>0 ]; $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $qcodeLarge = new QcodeLarge(); if($req['row']['type']==1){//修改大件重量 $data['l_weight'] = intval($req['row']['numn']*100); foreach($ids as $val){ //查询code $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('code')->where('_id',$val)->find(); $code = json_decode($large,true)['code']; if($code){ $code1 = substr($code,0,59); $code2 = substr($code,65,85); $data['code'] = $code1.str_pad(intval($req['row']['numn'])*100,6, '0', STR_PAD_LEFT).$code2; //修改code和大件重量 $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data); } } $this->success('修改成功'); } if($req['row']['type']==2){//修改大件总张数 $data['l_num'] = intval($req['row']['numn']); foreach($ids as $val){ //查询l_num, 判断是否可以修改总张数 $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('l_num')->where('_id',$val)->find(); $l_num = json_decode($large,true)['l_num']; if($l_num > 0 || $l_num==null){ //可以修改 $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data); }else{ $this->error('该产品不能修改大件数量'); } } $this->success('修改成功'); } } $this->view->assign('ids',$req['ids']); return $this->view->fetch(); } /** * 删除批次 */ public function del($ids = NULL) { $userInfo = Session::get('admin'); $company_id = (int)$userInfo['company']; $qcodeLarge = new QcodeLarge(); $qcodeSmall = new QcodeSmall(); $qcode_bach_list = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->find(); // echo "
";
// print_r($qcode_bach_list);
// echo "";
$mongo = \think\Db::connect('mongodb');
$where = [
'gdbh' => $qcode_bach_list['matter_no'],
'order_ddbh' => $qcode_bach_list['order_ddbh'],
'cpbm' => $qcode_bach_list['cpbm'],
'cpmc' => $qcode_bach_list['matter_name'],
];
$inventory_summary = $mongo->name('inventory_summary')
->where($where)
->find();
$updateResult = $mongo->name('inventory_summary')
->where($where)
->update([
'total_ru_quantity' => $inventory_summary['total_ru_quantity'] - $qcode_bach_list['num'],
'total_chu_quantity' => $inventory_summary['total_chu_quantity'] - $qcode_bach_list['num'],
'remaining_quantity' => $inventory_summary['remaining_quantity'] + $qcode_bach_list['num'],
'updated_at' => date('Y-m-d H:i:s'),
]);
$where = [
'gdbh' => $qcode_bach_list['matter_no'],
'order_ddbh' => $qcode_bach_list['order_ddbh'],
'cpbm' => $qcode_bach_list['cpbm'],
'cpmc' => $qcode_bach_list['matter_name'],
'total_chu_quantity' => $qcode_bach_list['num'],
];
$inventory_records_updateResult = $mongo->name('inventory_records')
->where($where)
->update([
'mod_rq' => date('Y-m-d H:i:s')
]);
$data = [
'delete_time'=>time(),
];
$bool1 = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->update($data);
$bool2 = $qcodeLarge->name($company_id.'_'."qcode_large")->where('bach_id',$ids)->update($data);
$bool3 = $qcodeSmall->name($company_id.'_'."qcode_small")->where('bach_id',$ids)->update($data);
if($bool1!==false && $bool2!==false && $bool3!==false){
$this->success('删除成功');
}else{
$this->error('删除失败');
}
}
/**
* 补打标签
*/
public function reprint()
{
if ($this->request->isAjax()) {
$data = $this->request->param();
parse_str($data['data'],$req);
if(!isset($req['row']['nickname']) || empty($req['row']['nickname'])){
$this->error('请填写公司名称');
}
if((!isset($req['row']['product_name']) || empty($req['row']['product_name'])) && (!isset($req['row']['product_code']) || empty($req['row']['product_code']))){
$this->error('请填写辅料名称或辅料编号');
}
if(!isset($req['row']['sqrcd']) || empty($req['row']['sqrcd'])){
$this->error('请填写配盘数');
}
if(!isset($req['row']['num']) || empty($req['row']['num'])){
$this->error('请填写数量');
}
//查询公司信息
$qcodeGsmc = new QcodeGsmc();
$print_code = $qcodeGsmc
->field('id, nickname, print_code')
->where('nickname',$req['row']['nickname'])
->find();
if (!$print_code) $this->error('未查到公司信息');
$print_code = json_decode($print_code,true);
//查询产品信息
$qcodeProduct = new QcodeProduct();
if(!empty($req['row']['product_code'])){
$sel = $qcodeProduct
->field('id, product_name, product_code, temple')
->where('product_code',$req['row']['product_code'])
->find();
}else{
$sel = $qcodeProduct
->field('id, product_name, product_code, temple')
->where('product_name',$req['row']['product_name'])
->find();
}
if (!$sel) $this->error('未查到辅料信息');
$sel = json_decode($sel,true);
$data = [
'company_name'=>$req['row']['nickname'],
'product_name'=>$sel['product_name'],
'sqrcd'=>$req['row']['sqrcd'],
'num'=>$req['row']['num'],
'main_unit'=>'盘',
'sec_unit'=>'万米',
'date'=>date('Y-m-d'),
'batch'=>substr(date('Ymd'),2,6),
'l_flow'=>1,
];
$num = str_pad($req['row']['num'], 3, '0', STR_PAD_LEFT);
$qrcode = 'AB'.'92'.$sel['temple'].'0'.$print_code['print_code'].('000'.$sel['product_code']).$data['batch'].$num.$data['batch'].'000001'.'000000'.'2'.'0000'.$data['batch'].'0000000000';
$data['pCode'] = $this->qrcode($qrcode);
$data['qrcode'] = $qrcode;
$this->success('成功','',$data);
}
return $this->view->fetch();
}
/**
* 公司名称搜索
*/
public function sel_n()
{
$name = $this->request->param()['q_word'][0];
$where = [
'nickname'=>new \MongoDB\BSON\Regex($name),
'delete_time'=>'',
];
$qcodeGsmc = new QcodeGsmc();
$sel = $qcodeGsmc
->field('nickname')
->where($where)
->limit(0,10)
->select();
return json(['list' => $sel, 'total' => count($sel)]);
}
/**
* 辅料名称搜索
*/
public function sel_p()
{
$name = $this->request->param()['q_word'][0];
$where = [
'product_name'=>new \MongoDB\BSON\Regex($name),
'delete_time'=>'',
];
$qcodeProduct = new QcodeProduct();
$sel = $qcodeProduct
->field('product_name, product_code')
->where($where)
->limit(0,10)
->select();
foreach ($sel as $k=>$v) {
$oid = $v['_id']->jsonSerialize();
$sel[$k]['id'] = $oid['$oid'];
}
return json(['list' => $sel, 'total' => count($sel)]);
}
/**
* 辅料编码搜索
*/
public function sel_c()
{
$name = $this->request->param()['q_word'][0];
$where = [
'product_code'=>new \MongoDB\BSON\Regex($name),
'delete_time'=>'',
];
$qcodeProduct = new QcodeProduct();
$sel = $qcodeProduct
->field('id, product_name, product_code')
->where($where)
->limit(0,10)
->select();
foreach ($sel as $k=>$v) {
$oid = $v['_id']->jsonSerialize();
$sel[$k]['id'] = $oid['$oid'];
}
return json(['list' => $sel, 'total' => count($sel)]);
}
/**
* 二维码生成类
*/
public function qrcode($url)//二维码生成类
{
$url=$url;
$level=3;
$size=6;
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字符串返回给前端
// $data = array(
// 'labelcode'=>$url,
// 'code'=>200,
// 'data'=>$imageString,
// 'product_code'=>$url
// );
return 'data:image/png;base64,'.$imageString;
}
}