|
|
@@ -15,14 +15,11 @@ use fast\Arr;
|
|
|
use think\Db;
|
|
|
use think\Session;
|
|
|
|
|
|
-class QcodeAdd extends Backend
|
|
|
-{
|
|
|
+class QcodeAdd extends Backend{
|
|
|
/**
|
|
|
* 首页展示
|
|
|
*/
|
|
|
- public function index()
|
|
|
- {
|
|
|
-
|
|
|
+ public function index(){
|
|
|
//获取登录账号信息【厂商信息】
|
|
|
$userinfo = Session::get('admin');
|
|
|
$data = [
|
|
|
@@ -60,71 +57,22 @@ class QcodeAdd extends Backend
|
|
|
echo "创建集合 {$tableName} 失败:" . $e->getMessage();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// //统计产品信息数据
|
|
|
-// $mongo = \think\Db::connect('mongodb');
|
|
|
-// // 获取成品入仓表数据
|
|
|
-// $mongo_products = $mongo
|
|
|
-// ->name('finished_products')
|
|
|
-// ->field('成品名称, jjcp_cpdh, 订单编号, jjcp_gdbh, jjcp_sl')
|
|
|
-// ->order('UniqId','desc')
|
|
|
-// ->where('jjcp_smb','末 板')
|
|
|
-// ->limit(1,50)
|
|
|
-// ->select();
|
|
|
-//
|
|
|
-// $grouped_products = [];
|
|
|
-// foreach ($mongo_products as $item) {
|
|
|
-// $group_key = $item['订单编号'] . '_' . $item['jjcp_gdbh'];
|
|
|
-// if (!isset($grouped_products[$group_key])) {
|
|
|
-// $grouped_products[$group_key] = [
|
|
|
-// 'order_ddbh' => $item['订单编号'],
|
|
|
-// 'gdbh' => $item['jjcp_gdbh'],
|
|
|
-// 'cpmc' => $item['成品名称'],
|
|
|
-//// 'cpdh' => $item['jjcp_cpdh'],
|
|
|
-// 'ruku_sl' => 0, // 入库数量
|
|
|
-// 'remain_stock' => 0, // 剩余库存
|
|
|
-// 'sl' => 0
|
|
|
-// ];
|
|
|
-// }
|
|
|
-// // 累加入库数量
|
|
|
-// $grouped_products[$group_key]['ruku_sl'] += (int)$item['jjcp_sl'];
|
|
|
-// }
|
|
|
-// // 查询库存表并计算
|
|
|
-// foreach ($grouped_products as $group_key => &$prod) {
|
|
|
-// $where = [
|
|
|
-// 'order_ddbh' => $prod['order_ddbh'],
|
|
|
-// 'gdbh' => $prod['gdbh'],
|
|
|
-// 'cpmc' => $prod['cpmc'],
|
|
|
-// ];
|
|
|
-//
|
|
|
-// $inventory = $mongo->name('inventory_summary')->where($where)->find();
|
|
|
-// $prod['remaining_quantity'] = $inventory ? (int)$inventory['remaining_quantity'] : 0;
|
|
|
-// $prod['sl'] = $prod['remaining_quantity'] > 0 ? $prod['remaining_quantity'] : $prod['ruku_sl'];
|
|
|
-// }
|
|
|
-// unset($prod);
|
|
|
-// $matched_products = array_values($grouped_products);
|
|
|
-// $this->view->assign('product', $matched_products);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取产品信息
|
|
|
- * 查询入仓表【finished_products】
|
|
|
*/
|
|
|
- public function product()
|
|
|
- {
|
|
|
+ public function product(){
|
|
|
$params = input('');
|
|
|
$page = max(1, (int)$params['page']);
|
|
|
$limit = max(1, (int)$params['limit']);
|
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 获取工单编号列表
|
|
|
$db3 = Db::connect(config('database.db3'));
|
|
|
$gdRows = $db3->query("SELECT DISTINCT `Gd_gdbh`, `Gd_客户代号`, `Gd_cpdh` FROM `工单_基本资料` WHERE `Gd_客户代号` = ?", ['J0031']);
|
|
|
-
|
|
|
$Gd_gdbhList = array_column($gdRows, 'Gd_gdbh');
|
|
|
$gdbhList = array_column($gdRows, 'Gd_cpdh');
|
|
|
if (empty($gdbhList)) {
|
|
|
@@ -137,9 +85,8 @@ class QcodeAdd extends Backend
|
|
|
// Mongo 查询
|
|
|
$mongo = \think\Db::connect('mongodb');
|
|
|
$where = ['jjcp_cpdh' => ['in', $gdbhList],'jjcp_gdbh' => ['in', $Gd_gdbhList], 'jjcp_smb' => '末 板'];
|
|
|
-
|
|
|
if (!empty($params['search'])) {
|
|
|
- $where['jjcp_cpdh|成品名称|jjcp_gdbh|订单编号'] = new \MongoDB\BSON\Regex($params['search'], 'i');
|
|
|
+ $where['成品编码|成品名称|jjcp_gdbh|订单编号'] = new \MongoDB\BSON\Regex($params['search'], 'i');
|
|
|
}
|
|
|
|
|
|
// 1. 查询所有符合条件的成品数据(不分页)
|
|
|
@@ -148,21 +95,39 @@ class QcodeAdd extends Backend
|
|
|
->order('UniqId', 'desc')
|
|
|
->select();
|
|
|
|
|
|
- // 2. 按订单编号 + 工单编号分组聚合
|
|
|
+ // 2. 按订单编号 + 工单编号分组聚合,并处理多个cpdh与成品编码
|
|
|
$grouped_products = [];
|
|
|
foreach ($all_products as $item) {
|
|
|
$group_key = $item['订单编号'] . '_' . $item['jjcp_gdbh'];
|
|
|
+
|
|
|
if (!isset($grouped_products[$group_key])) {
|
|
|
$grouped_products[$group_key] = [
|
|
|
'order_ddbh' => $item['订单编号'],
|
|
|
'gdbh' => $item['jjcp_gdbh'],
|
|
|
+ 'cpbm' => $item['成品编码'],
|
|
|
'cpmc' => $item['成品名称'],
|
|
|
- 'ruku_sl' => 0,
|
|
|
- 'remain_stock' => 0,
|
|
|
- 'sl' => 0
|
|
|
+ 'sl' => 0, // 库存总数
|
|
|
+ 'cpdh_list' => [],
|
|
|
+ 'cpbm_list' => []
|
|
|
];
|
|
|
}
|
|
|
- $grouped_products[$group_key]['sl'] += (int)$item['jjcp_sl'];
|
|
|
+ $grouped_products[$group_key]['sl'] += (int)$item['jjcp_sl']; // 累计库存数量
|
|
|
+
|
|
|
+ // 收集不同的cpdh和cpbm(成品编码)
|
|
|
+ if (!in_array($item['jjcp_cpdh'], $grouped_products[$group_key]['cpdh_list'])) {
|
|
|
+ $grouped_products[$group_key]['cpdh_list'][] = $item['jjcp_cpdh'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!in_array($item['成品编码'], $grouped_products[$group_key]['cpbm_list'])) {
|
|
|
+ $grouped_products[$group_key]['cpbm_list'][] = $item['成品编码'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化成用逗号连接的字符串
|
|
|
+ foreach ($grouped_products as &$group) {
|
|
|
+ $group['cpdh'] = implode(',', $group['cpdh_list']);
|
|
|
+ $group['cpbm'] = implode(',', $group['cpbm_list']);
|
|
|
+ unset($group['cpdh_list'], $group['cpbm_list']); // 清理临时字段
|
|
|
}
|
|
|
|
|
|
// 3. 将聚合后结果分页(稳定分页)
|
|
|
@@ -170,7 +135,7 @@ class QcodeAdd extends Backend
|
|
|
$total = count($all_grouped);
|
|
|
$paged_grouped = array_slice($all_grouped, $offset, $limit);
|
|
|
|
|
|
- // 4. 获取库存数据
|
|
|
+ // 4. 获取库存出货数据并计算剩余数
|
|
|
foreach ($paged_grouped as &$prod) {
|
|
|
$inventory = $mongo->name('inventory_summary')->where([
|
|
|
'order_ddbh' => $prod['order_ddbh'],
|
|
|
@@ -178,12 +143,14 @@ class QcodeAdd extends Backend
|
|
|
'cpmc' => $prod['cpmc'],
|
|
|
])->find();
|
|
|
|
|
|
-// $prod['remaining_quantity'] = $inventory ? (int)$inventory['remaining_quantity'] : 0;
|
|
|
-// $prod['sl'] = $prod['remaining_quantity'] > 0 ? $prod['remaining_quantity'] : $prod['ruku_sl'];
|
|
|
+ // 出货数量(若无数据则为 0)
|
|
|
+ $total_chu_quantity = isset($inventory['total_chu_quantity']) ? (int)$inventory['total_chu_quantity'] : 0;
|
|
|
+ $prod['total_chu_quantity'] = $total_chu_quantity;
|
|
|
|
|
|
+ // 计算剩余数 = sl - 出货数
|
|
|
+ $prod['remaining_quantity'] = $prod['sl'] - $total_chu_quantity;
|
|
|
}
|
|
|
unset($prod);
|
|
|
-
|
|
|
return json([
|
|
|
'code' => 1,
|
|
|
'data' => $paged_grouped,
|
|
|
@@ -193,135 +160,6 @@ class QcodeAdd extends Backend
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// public function product()
|
|
|
-// {
|
|
|
-//
|
|
|
-// $db3 = Db::connect(config('database.db3'));
|
|
|
-// $query = $db3->query("SELECT * FROM `工单_基本资料` WHERE `Gd_客户代号` = ?", ['J0031']);
|
|
|
-//
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($query);
|
|
|
-// echo "</pre>";
|
|
|
-// die;
|
|
|
-//
|
|
|
-// $params = input('');
|
|
|
-// $page = max(1, (int)$params['page']);
|
|
|
-// $limit = max(1, (int)$params['limit']);
|
|
|
-// $offset = ($page - 1) * $limit;
|
|
|
-//
|
|
|
-// $mongo = \think\Db::connect('mongodb');
|
|
|
-// $where = [];
|
|
|
-// if (!empty($params['search'])) {
|
|
|
-// // 使用正则表达式来实现模糊匹配,'i' 表示忽略大小写
|
|
|
-// $where['jjcp_cpdh|成品名称|jjcp_gdbh|订单编号'] = new \MongoDB\BSON\Regex($params['search'], 'i');
|
|
|
-// }
|
|
|
-//// if (!empty($where)) {
|
|
|
-//// $mongo_products = $mongo->name('finished_products')
|
|
|
-//// ->where($where)
|
|
|
-//// ->limit($offset, $limit)
|
|
|
-//// ->order('UniqId','desc')
|
|
|
-//// ->where('jjcp_smb','末 板')
|
|
|
-//// ->select();
|
|
|
-//// } else {
|
|
|
-//// // 如果没有条件,仍然执行查询,避免错误
|
|
|
-//// $mongo_products = $mongo->name('finished_products')
|
|
|
-//// ->limit(1, 10)
|
|
|
-//// ->order('UniqId','desc')
|
|
|
-//// ->where('jjcp_smb','末 板')
|
|
|
-//// ->select();
|
|
|
-//// }
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// $mongo_products = $mongo->name('finished_products')
|
|
|
-// ->where($where)
|
|
|
-// ->limit($offset, $limit)
|
|
|
-// ->order('UniqId','desc')
|
|
|
-// ->where('jjcp_smb','末 板')
|
|
|
-// ->select();
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($mongo_products);
|
|
|
-// echo "<pre>";die;
|
|
|
-//
|
|
|
-// //计算【订单编号】【jjcp_gdbh】相同的数据进行统计汇总累加入库数量【jjcp_sl】
|
|
|
-// $grouped_products = [];
|
|
|
-// foreach ($mongo_products as $item) {
|
|
|
-// $group_key = $item['订单编号'] . '_' . $item['jjcp_gdbh'];
|
|
|
-// if (!isset($grouped_products[$group_key])) {
|
|
|
-// $grouped_products[$group_key] = [
|
|
|
-// 'order_ddbh' => $item['订单编号'],
|
|
|
-// 'gdbh' => $item['jjcp_gdbh'],
|
|
|
-// 'cpmc' => $item['成品名称'],
|
|
|
-//// 'cpdh' => $item['jjcp_cpdh'],
|
|
|
-// 'ruku_sl' => 0, // 入库数量
|
|
|
-// 'remain_stock' => 0, // 剩余库存
|
|
|
-// 'sl' => 0
|
|
|
-// ];
|
|
|
-// }
|
|
|
-// $grouped_products[$group_key]['ruku_sl'] += (int)$item['jjcp_sl'];
|
|
|
-// }
|
|
|
-// // 查询库存表并计算
|
|
|
-// foreach ($grouped_products as $group_key => &$prod) {
|
|
|
-// $where = [
|
|
|
-// 'order_ddbh' => $prod['order_ddbh'],
|
|
|
-// 'gdbh' => $prod['gdbh'],
|
|
|
-// 'cpmc' => $prod['cpmc'],
|
|
|
-// ];
|
|
|
-// $inventory = $mongo->name('inventory_summary')->where($where)->find();
|
|
|
-// $prod['remaining_quantity'] = $inventory ? (int)$inventory['remaining_quantity'] : 0;
|
|
|
-// $prod['sl'] = $prod['remaining_quantity'] > 0 ? $prod['remaining_quantity'] : $prod['ruku_sl'];
|
|
|
-// }
|
|
|
-// unset($prod);
|
|
|
-// $matched_products = array_values($grouped_products);
|
|
|
-//
|
|
|
-// // 获取总数
|
|
|
-// $total = $mongo->name('finished_products')
|
|
|
-// ->where($where)
|
|
|
-// ->count();
|
|
|
-//
|
|
|
-// return json([
|
|
|
-// 'code' => 1,
|
|
|
-// 'data' => $matched_products,
|
|
|
-// 'total' => $total,
|
|
|
-// 'page' => $page,
|
|
|
-// 'limit' => $limit
|
|
|
-// ]);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// public function product(){
|
|
|
-// $QcodeProduct = new QcodeProduct();
|
|
|
-// $ResetFlow = new ResetFlow();
|
|
|
-// $userinfo = Session::get('admin');
|
|
|
-// 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($userinfo['company'].'_'."reset_flow")->where('product_id',substr(json_encode($product['_id']),9,-2))->find();
|
|
|
-// $row = [
|
|
|
-// 'temple' => $product['temple'],
|
|
|
-// 'flow' => isset($flow['l_flow'])?(int)$flow['l_flow']+1:'',
|
|
|
-// 'bach' => isset($flow['bach_num'])?(int)$flow['bach_num']+1:'',
|
|
|
-// ];
|
|
|
-// if (!empty($flow)){
|
|
|
-// $row['flow'] = $flow['l_flow']+1;
|
|
|
-// $row['bach'] = $flow['bach_num']+1;
|
|
|
-// }
|
|
|
-//
|
|
|
-// return json(['code'=>1,'data'=>$row]);
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 增加新批次
|
|
|
*/
|
|
|
@@ -350,47 +188,43 @@ class QcodeAdd extends Backend
|
|
|
$data[$k] = $v;
|
|
|
}
|
|
|
}
|
|
|
-// echo "接口获取";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($data);
|
|
|
-// echo "<pre>";die;
|
|
|
|
|
|
+ //打印信息
|
|
|
+
|
|
|
+// echo "接口获取";echo "<pre>";print_r($data);echo "<pre>";die;
|
|
|
|
|
|
|
|
|
+ //记录库存操作
|
|
|
$mongo = \think\Db::connect('mongodb');
|
|
|
- // 构建查询条件
|
|
|
$where = [
|
|
|
'gdbh' => $data['gdbh'],
|
|
|
'order_ddbh' => $data['order_ddbh'],
|
|
|
-// 'cpdh' => $data['cpdh'],
|
|
|
'cpmc' => $data['cpmc'],
|
|
|
];
|
|
|
- //插入字段
|
|
|
+ //插入字段[inventory_summaryk库存明细]
|
|
|
$insertData = [
|
|
|
'gdbh' => $data['gdbh'],
|
|
|
'order_ddbh' => $data['order_ddbh'],
|
|
|
-// 'cpdh' => $data['cpdh'],
|
|
|
+ 'cpbm' => $data['cpbm'],
|
|
|
'cpmc' => $data['cpmc'],
|
|
|
- 'total_ru_quantity' => $data['sl'],//入库数量
|
|
|
- 'total_chu_quantity' => $data['number'],//出库数量
|
|
|
- 'remaining_quantity' => $data['sl'] - $data['number'],//剩余结存数量
|
|
|
+ 'total_ru_quantity' => $data['sl'],//入库数
|
|
|
+ 'total_chu_quantity' => $data['number'],//出库数
|
|
|
+ 'remaining_quantity' => $data['remaining_quantity'] - $data['number'],//剩余数
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
'updated_at' => '',
|
|
|
'mod_rq' => '',
|
|
|
'company' => '',
|
|
|
];
|
|
|
-
|
|
|
- // 查询是否已存在记录
|
|
|
+ // 查询库存汇总表数据是否存在记录
|
|
|
$list = $mongo->name('inventory_summary')->where($where)->find();
|
|
|
if ($list) {
|
|
|
// 如果数据存在,更新库存汇总记录
|
|
|
- $ru = $list['total_ru_quantity'] + $data['sl'];//累计入库数量
|
|
|
- $chu = $list['total_chu_quantity'] + $data['sl'];//累计出库数量
|
|
|
- $jiecun = $data['sl'] - $data['number'];//剩余结存数量
|
|
|
+ $chu = $list['total_chu_quantity'] + $data['number'];//累计出库数量
|
|
|
+ $jiecun = $list['remaining_quantity'] - $data['number'];//剩余结存数量
|
|
|
$updateResult = $mongo->name('inventory_summary')
|
|
|
->where($where)
|
|
|
->update([
|
|
|
- 'total_ru_quantity' => $ru,
|
|
|
+ 'total_ru_quantity' => $data['sl'],
|
|
|
'total_chu_quantity' => $chu,
|
|
|
'remaining_quantity' => $jiecun,
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
@@ -402,32 +236,45 @@ class QcodeAdd extends Backend
|
|
|
//记录库存明细
|
|
|
$mongo->name('inventory_records')->insert($insertData);
|
|
|
|
|
|
-// // 调试输出(可删)
|
|
|
-// echo "<pre>"; print_r($list); echo "</pre>";
|
|
|
-// die;
|
|
|
-
|
|
|
-
|
|
|
+// // 调试输出
|
|
|
+// echo "<pre>"; print_r($list); echo "</pre>";die;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// if ($data['danwei'] == 1){
|
|
|
+// $num = $data['number'];
|
|
|
+// $tray_num = $data['tray_num'];
|
|
|
+// $box_number = $data['box_number'];
|
|
|
+// //$small_num = (int)ceil((int)总数量(张/个)/(int)张数);
|
|
|
+// $small_num = (int)ceil((int)$data['number']/(int)$data['box_number']);
|
|
|
+// $large_num = (int)ceil($small_num/$tray_num);
|
|
|
+// }else{
|
|
|
+// $num = 0;
|
|
|
+// $tray_num = $data['volume_num'];
|
|
|
+// $small_num = $data['small_num'];
|
|
|
+// $large_num = (int)ceil($small_num/$tray_num);
|
|
|
+// $box_number = 1;
|
|
|
+// $tray_num1 = 1;
|
|
|
+// }
|
|
|
|
|
|
- if ($data['danwei'] == 1){
|
|
|
- $num = $data['number'];
|
|
|
- $tray_num = $data['tray_num'];
|
|
|
- $tray_num1 = $data['tray_num'];
|
|
|
- $box_number = $data['box_number'];
|
|
|
- //$small_num = (int)ceil((int)总数量(张/个)/(int)张数);
|
|
|
- $small_num = (int)ceil((int)$data['number']/(int)$data['box_number']);
|
|
|
- $large_num = (int)ceil($small_num/$tray_num);
|
|
|
- }else{
|
|
|
- $num = 0;
|
|
|
- $tray_num = $data['volume_num'];
|
|
|
- $small_num = $data['small_num'];
|
|
|
- $large_num = (int)ceil($small_num/$tray_num);
|
|
|
- $box_number = 1;
|
|
|
- $tray_num1 = 1;
|
|
|
+ switch ($data['danwei']) {
|
|
|
+ case 1:
|
|
|
+ $danwei = '个';
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $danwei = '套';
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $danwei = '张';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $danwei = '';
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
$userinfo = Session::get('admin');//获取用户信息
|
|
|
$arr = [
|
|
|
- 'batch' => $data['batch'],
|
|
|
+ 'batch' => $data['gdbh'],
|
|
|
'create_time' => time(),
|
|
|
'delect_time' => '',
|
|
|
'sync_flag' => 0,
|
|
|
@@ -439,92 +286,73 @@ class QcodeAdd extends Backend
|
|
|
|
|
|
|
|
|
$batchList = [
|
|
|
- 'userid' => $userinfo['id'],
|
|
|
- 'supplier_id' => $userinfo['id'],
|
|
|
+ 'userid' => $userinfo['id'],//登录用户id
|
|
|
+ 'supplier_id' => $userinfo['id'],//登录用户id
|
|
|
'supplier_code' => $userinfo['printer_code'],
|
|
|
|
|
|
'supplier_name' => $data['company_name'],//公司名称
|
|
|
- 'matter_name' => $data['cpmc'],//产品名称
|
|
|
- 'matter_no' => $data['batch'],//生产批次号
|
|
|
+ 'cpbm' => $data['cpbm'],//成品编码
|
|
|
+ 'matter_name' => $data['cpmc'],//成品名称
|
|
|
+ 'matter_no' => $data['gdbh'],//生产批次号-工单编号
|
|
|
'order_ddbh' => $data['order_ddbh'],//销售订单号
|
|
|
- 'matter_id' => $data['batch'],
|
|
|
-// 'matter_type' => $data['temple'],
|
|
|
+ 'matter_id' => $data['gdbh'],
|
|
|
'matter_type' => '01',
|
|
|
'manufacture_date' => (int)date('ymd',strtotime($data['manufacture_date'])),//生产日期
|
|
|
'print_date' => (int)date('ymd',strtotime($data['print_date'])),//打码日期
|
|
|
|
|
|
- 'danwei' => $data['danwei'],//单位
|
|
|
- 'num' => $num,//总数量(张/个)
|
|
|
- 'tray_num' => $tray_num1,//每层箱数
|
|
|
- 'box_num' => $box_number,//每托层数
|
|
|
- 'total_boxes' => $data['total_boxes'],//每托盘箱数
|
|
|
- 'small_num' => $small_num,//每托盘箱数
|
|
|
+ 'num_danwei' => $data['danwei'],//单位
|
|
|
+ 'danwei' => $danwei,//单位
|
|
|
+ 'num' => $data['number'],//总数量(张/个)
|
|
|
+ 'small_num' => $data['box_number'],//每一箱数量
|
|
|
+ 'tray_num' => $data['tray_num'],//每层箱数【箱/层】
|
|
|
+ 'box_num' => $data['tray_number'],//每托层数【 层/托】
|
|
|
+ 'total_boxes' => $data['total_boxes'],//每托盘箱数【箱/托】
|
|
|
+ 'large_num' => $data['box_num'],//本次打包托盘数
|
|
|
+ 'larger_num' => $data['small_num'],//总箱数
|
|
|
'pallet_height' => $data['pallet_height'],//每托高度
|
|
|
'pallet_length' => $data['pallet_length'],//托盘规格
|
|
|
'pallet_width' => $data['pallet_width'],//托盘规格
|
|
|
- 'larger_num' => $large_num,//大件(总托数)
|
|
|
|
|
|
'l_reservation' => '',
|
|
|
- 'l_flow' => $data['big_liushui'],
|
|
|
+ // 处理可能为空的流水/重量字段
|
|
|
+ 'l_flow' => $data['big_liushui'],//大件流水
|
|
|
'l_weight' => $data['big_weight'],//大件重量
|
|
|
- 's_flow' => $data['small_start_liushui'],
|
|
|
+ 's_flow' => $data['small_start_liushui'],//小件流水
|
|
|
's_weight' => $data['small_weight'],//小件重量
|
|
|
's_reservation' => '',
|
|
|
'bach_status' => 0,
|
|
|
- 'bach_num' => $data['batch'],
|
|
|
+ 'bach_num' => $data['gdbh'],//生产批次号-工单编号
|
|
|
'large_endnum' => $data['big_liushui'] + $data['box_num'] -1,
|
|
|
'create_time' => time(),//新增时间
|
|
|
+ 'delect_time' => '',//删除时间
|
|
|
];
|
|
|
+
|
|
|
$res = $bach->save($batchList);
|
|
|
if ($res === 0){
|
|
|
$this->error('添加失败');
|
|
|
}
|
|
|
|
|
|
$flow = [
|
|
|
- 'l_flow' => (int)$batchList['large_endnum'],
|
|
|
- 'bach_num' => $batchList['bach_num'],
|
|
|
+ 'l_flow' => (int)$batchList['large_num'],
|
|
|
+ 'bach_num' => $batchList['matter_no'],
|
|
|
];
|
|
|
-
|
|
|
- if ($resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_id'])->find()){
|
|
|
- $resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_id'])->update($flow);
|
|
|
+ if ($resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_no'])->find()){
|
|
|
+ $resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_no'])->update($flow);
|
|
|
}else{
|
|
|
- $flow['product_id'] = $batchList['matter_id'];
|
|
|
+ $flow['product_id'] = $batchList['matter_no'];
|
|
|
$resetFlow->save($flow);
|
|
|
}
|
|
|
|
|
|
$last_id = $bach->getLastInsID();
|
|
|
-
|
|
|
if ($last_id){
|
|
|
- //插入大小二维码数据
|
|
|
- //二维码数据不变区域
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList);
|
|
|
-// echo "<pre>";
|
|
|
-// die;
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList['matter_type']);
|
|
|
-// echo "<pre>";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList['supplier_code']);
|
|
|
-// echo "<pre>";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r('9');
|
|
|
-// echo "<pre>";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList['matter_no']);
|
|
|
-// echo "<pre>";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList['manufacture_date']);
|
|
|
-// echo "<pre>";
|
|
|
-// echo "<pre>";
|
|
|
-// print_r($batchList['print_date']);
|
|
|
-// echo "<pre>";die;
|
|
|
+ //插入大小二维码数据 二维码数据不变区域
|
|
|
+// echo "<pre>";print_r($batchList);echo "<pre>";die;
|
|
|
+
|
|
|
$fixed_code = '';
|
|
|
$fixed_code.=$this->intTochar($batchList['matter_type'],2);//2位 辅料种类编码
|
|
|
-// $fixed_code .= substr($this->intTochar($batchList['supplier_code'], 12), 1);//12位 供应商编码 // 去掉第一位0
|
|
|
$fixed_code .= $this->intTochar($batchList['supplier_code'], 21);//21位 供应商编码
|
|
|
$fixed_code .= '9'; // 补0一位
|
|
|
- $fixed_code.=$this->intTochar($batchList['matter_no'],10);//10位 辅料编码
|
|
|
+ $fixed_code.=$this->intTochar($batchList['cpbm'],10);//10位 辅料编码
|
|
|
$fixed_code.=$batchList['manufacture_date'];//6位 生产日期
|
|
|
$print_code=$batchList['print_date'];//6位 打码日期
|
|
|
|
|
|
@@ -551,25 +379,27 @@ class QcodeAdd extends Backend
|
|
|
}
|
|
|
|
|
|
//循环插入大件二维码数据
|
|
|
- for ($i=0;$i<$batchList['larger_num'];$i++){
|
|
|
+ for ($i=0;$i<$data['box_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 = $this->intTochar($batchList['matter_no'],10);
|
|
|
$l_reservation = $l_reservation.'0000000000';
|
|
|
- $remainder = $batchList['small_num'] - $batchList['tray_num'] * $i;//最后一托盘小件数量
|
|
|
+ $remainder = $batchList['num'] - $batchList['total_boxes'] * $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 = $small_n * $batchList['box_num'];
|
|
|
$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,
|
|
|
@@ -585,6 +415,7 @@ class QcodeAdd extends Backend
|
|
|
'l_status' => 0,
|
|
|
'l_print' => 0
|
|
|
];
|
|
|
+
|
|
|
$l_res = $large->save($l_data);
|
|
|
if ($l_res === 0){
|
|
|
$this->error('大件码插入失败');
|
|
|
@@ -592,9 +423,9 @@ class QcodeAdd extends Backend
|
|
|
$large_id = $large->getLastInsID();
|
|
|
if ($large_id){
|
|
|
// //小件码循环插入
|
|
|
- for ($j=0;$j<$tray_num and ($j+$i*$tray_num)<$batchList['small_num'];$j++){
|
|
|
+ for ($j=0;$j<$data['tray_num'] and ($j+$i*$data['tray_num'])<$batchList['small_num'];$j++){
|
|
|
$small = new QcodeSmall();
|
|
|
- $s_flow = $this->intTochar($batchList['s_flow']+$j+$i*$tray_num+$lastNum['last_num'],6);//小件码序号从1开始
|
|
|
+ $s_flow = $this->intTochar($batchList['s_flow']+$j+$i*$data['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);
|
|
|
@@ -631,7 +462,8 @@ class QcodeAdd extends Backend
|
|
|
if ($liushui_res === false){
|
|
|
$this->error('添加失败');
|
|
|
}
|
|
|
- $this->success('成功');
|
|
|
+ return json(['code' => 1, 'msg' => '成功', 'data' => '']);
|
|
|
+// $this->success('成功');
|
|
|
}
|
|
|
|
|
|
/**
|