|
|
@@ -112,10 +112,14 @@ class QcodeAdd extends Backend
|
|
|
$num = $data['number'];
|
|
|
$tray_num = $data['tray_num'];
|
|
|
$box_number = $data['box_number'];
|
|
|
+ $small_num = (int)ceil((int)$data['number']/(int)$data['box_number']);
|
|
|
+ $large_num = (int)ceil($small_num/$tray_num);
|
|
|
}else{
|
|
|
$num = 0;
|
|
|
- $tray_num = 0;
|
|
|
- $box_number = 0;
|
|
|
+ $tray_num = $data['volume_num'];
|
|
|
+ $small_num = $data['small_num'];
|
|
|
+ $large_num = (int)ceil($small_num/$tray_num);
|
|
|
+ $box_number = 1;
|
|
|
}
|
|
|
//插入批次信息
|
|
|
$userinfo = Session::get('admin');//获取用户信息
|
|
|
@@ -132,8 +136,8 @@ class QcodeAdd extends Backend
|
|
|
'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'],
|
|
|
+ 'larger_num' => $large_num,
|
|
|
+ 'small_num' => $small_num,
|
|
|
'manufacture_date' => (int)date('ymd',strtotime($data['manufacture_date'])),
|
|
|
'print_date' => (int)date('ymd',strtotime($data['print_date'])),
|
|
|
'box_num' => $box_number,
|
|
|
@@ -143,115 +147,130 @@ class QcodeAdd extends Backend
|
|
|
'l_weight' => $data['big_weight'],
|
|
|
's_flow' => $data['small_start_liushui'],
|
|
|
's_weight' => $data['small_weight'],
|
|
|
+ 's_reservation' => '',
|
|
|
'bach_status' => 0,
|
|
|
'userid' => $userinfo['id'],
|
|
|
'bach_num' => $data['batch'],
|
|
|
'large_endnum' => $data['big_liushui'] + $data['box_num'] -1,
|
|
|
+ 'create_time' => time(),
|
|
|
];
|
|
|
$res = $bach->save($batchList);
|
|
|
- $last_id = $bach->getLastInsID();
|
|
|
- if ($res === false){
|
|
|
+ if ($res === 0){
|
|
|
$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位 生产日期
|
|
|
+ $last_id = $bach->getLastInsID();
|
|
|
+ if ($last_id){
|
|
|
+ //插入大小二维码数据
|
|
|
+ //二维码数据不变区域
|
|
|
+ $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,
|
|
|
+ $print_code=$batchList['print_date'];//6位 打码日期
|
|
|
+ $small_liushui = [
|
|
|
+ 'onlycode' => 'AB92'.$fixed_code.$print_code,
|
|
|
+ 'last_num' => 0,
|
|
|
+ 'user_id' => $userinfo['id'],
|
|
|
+ 'stype' => 2,
|
|
|
+ 'dateTime' => time(),
|
|
|
+ ];
|
|
|
+ $whereSmall = [
|
|
|
+ 'onlycode' => $small_liushui['onlycode'],
|
|
|
+ 'user_id' => $userinfo['id'],
|
|
|
];
|
|
|
- $l_res = $large->save($l_data);
|
|
|
- $large_id = $large->getLastInsID();
|
|
|
- if ($l_res === false){
|
|
|
- $this->error('大件码插入失败');
|
|
|
+ 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);
|
|
|
+ $lastNum['last_num'] = 1;
|
|
|
}
|
|
|
- //小件码循环插入
|
|
|
- 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//单个小件重量
|
|
|
+
|
|
|
+ //循环插入大件二维码数据
|
|
|
+ for ($i=0;$i<$batchList['larger_num'];$i++){
|
|
|
+ $large = new QcodeLarge();
|
|
|
+ $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' => time(),
|
|
|
+ 'p_nums' => 0,
|
|
|
+ 'userid' =>$userinfo['id'],
|
|
|
+ 'l_weight' =>$l_weight,
|
|
|
+ 'l_num' =>$l_num,
|
|
|
+ 'l_status' => 0,
|
|
|
+ 'l_print' => 0
|
|
|
];
|
|
|
- $s_res = $small->save($s_data);
|
|
|
- if ($s_res === false){
|
|
|
- $this->error('小件码插入失败');
|
|
|
+ $l_res = $large->save($l_data);
|
|
|
+ if ($l_res === 0){
|
|
|
+ $this->error('大件码插入失败');
|
|
|
}
|
|
|
+ $large_id = $large->getLastInsID();
|
|
|
+ if ($large_id){
|
|
|
+// //小件码循环插入
|
|
|
+ for ($j=0;$j<$tray_num and ($j+$i*$tray_num)<$batchList['small_num'];$j++){
|
|
|
+ $small = new QcodeSmall();
|
|
|
+ $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'=>time(),
|
|
|
+ 'p_nums'=>0,
|
|
|
+ 'userid'=>$userinfo['id'],//小码绑定用户id
|
|
|
+ 's_weight'=>$s_weight,//单个小件重量
|
|
|
+ 'status' => 0,
|
|
|
+ ];
|
|
|
+ $s_res = $small->save($s_data);
|
|
|
+ if ($s_res === 0){
|
|
|
+ $this->error('小件码插入失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $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('添加成功');
|
|
|
+ $this->success('成功');
|
|
|
}
|
|
|
|
|
|
/**
|