|
|
@@ -12,6 +12,7 @@ use app\admin\model\QcodeBach;
|
|
|
use app\admin\model\QcodeSmall;
|
|
|
use app\admin\model\QcodeLiushui;
|
|
|
use fast\Arr;
|
|
|
+use MongoDB\BSON\ObjectId;
|
|
|
use think\Db;
|
|
|
use think\Session;
|
|
|
|
|
|
@@ -73,47 +74,63 @@ class QcodeAdd extends Backend{
|
|
|
// 获取工单编号列表
|
|
|
$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)) {
|
|
|
$this->assign([
|
|
|
'data' => '',
|
|
|
- 'total' =>'',
|
|
|
+ 'total' => '',
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
// Mongo 查询
|
|
|
$mongo = \think\Db::connect('mongodb');
|
|
|
- $where = ['jjcp_cpdh' => ['in', $gdbhList],'jjcp_gdbh' => ['in', $Gd_gdbhList], 'jjcp_smb' => '末 板'];
|
|
|
+ $where = ['成品编码' => ['in', $gdbhList],'jjcp_gdbh' => ['in', $Gd_gdbhList], 'jjcp_smb' => '末 板'];
|
|
|
+ // $where = ['成品编码' => ['in', $gdbhList], 'jjcp_smb' => '末 板'];
|
|
|
if (!empty($params['search'])) {
|
|
|
$where['成品编码|成品名称|jjcp_gdbh|订单编号'] = new \MongoDB\BSON\Regex($params['search'], 'i');
|
|
|
}
|
|
|
|
|
|
- // 1. 查询所有符合条件的成品数据(不分页)
|
|
|
- $all_products = $mongo->name('finished_products')
|
|
|
+ // 查询符合条件的成品数据
|
|
|
+ $al_products = $mongo->name('finished_products')
|
|
|
->where($where)
|
|
|
- ->order('UniqId', 'desc')
|
|
|
+ ->order('Sys_rq', 'desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 查询 texts = 新增产品 的数据
|
|
|
+ $xz_products = $mongo->name('finished_products')
|
|
|
+ ->where('texts', '新增产品')
|
|
|
+ ->order('Sys_rq', 'desc')
|
|
|
->select();
|
|
|
|
|
|
- // 2. 按订单编号 + 工单编号分组聚合,并处理多个cpdh与成品编码
|
|
|
+ // 合并数据
|
|
|
+ $all_products = array_merge($al_products, $xz_products);
|
|
|
+
|
|
|
+ // 分组聚合处理
|
|
|
$grouped_products = [];
|
|
|
foreach ($all_products as $item) {
|
|
|
+ // 转换日期格式(如果是 d/m/Y H:i:s)
|
|
|
+ $date = \DateTime::createFromFormat('d/m/Y H:i:s', $item['Sys_rq']);
|
|
|
+ $item['Sys_rq'] = $date ? $date->format('Y-m-d H:i:s') : $item['Sys_rq'];
|
|
|
+
|
|
|
$group_key = $item['订单编号'] . '_' . $item['jjcp_gdbh'];
|
|
|
|
|
|
if (!isset($grouped_products[$group_key])) {
|
|
|
$grouped_products[$group_key] = [
|
|
|
+ 'Sys_rq' => $item['Sys_rq'],
|
|
|
'order_ddbh' => $item['订单编号'],
|
|
|
'gdbh' => $item['jjcp_gdbh'],
|
|
|
'cpbm' => $item['成品编码'],
|
|
|
'cpmc' => $item['成品名称'],
|
|
|
- 'sl' => 0, // 库存总数
|
|
|
+ 'sl' => 0,
|
|
|
'cpdh_list' => [],
|
|
|
'cpbm_list' => []
|
|
|
];
|
|
|
}
|
|
|
- $grouped_products[$group_key]['sl'] += (int)$item['jjcp_sl']; // 累计库存数量
|
|
|
|
|
|
- // 收集不同的cpdh和cpbm(成品编码)
|
|
|
+ $grouped_products[$group_key]['sl'] += (int)$item['jjcp_sl'];
|
|
|
+
|
|
|
if (!in_array($item['jjcp_cpdh'], $grouped_products[$group_key]['cpdh_list'])) {
|
|
|
$grouped_products[$group_key]['cpdh_list'][] = $item['jjcp_cpdh'];
|
|
|
}
|
|
|
@@ -123,19 +140,26 @@ class QcodeAdd extends Backend{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 格式化成用逗号连接的字符串
|
|
|
+ // 格式化列表字符串
|
|
|
foreach ($grouped_products as &$group) {
|
|
|
$group['cpdh'] = implode(',', $group['cpdh_list']);
|
|
|
$group['cpbm'] = implode(',', $group['cpbm_list']);
|
|
|
- unset($group['cpdh_list'], $group['cpbm_list']); // 清理临时字段
|
|
|
+ unset($group['cpdh_list'], $group['cpbm_list']);
|
|
|
}
|
|
|
|
|
|
- // 3. 将聚合后结果分页(稳定分页)
|
|
|
+ // 聚合结果排序(按时间降序)
|
|
|
$all_grouped = array_values($grouped_products);
|
|
|
+ usort($all_grouped, function ($a, $b) {
|
|
|
+ $timeA = strtotime($a['Sys_rq']) ?: 0;
|
|
|
+ $timeB = strtotime($b['Sys_rq']) ?: 0;
|
|
|
+ return $timeB <=> $timeA;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 再分页
|
|
|
$total = count($all_grouped);
|
|
|
$paged_grouped = array_slice($all_grouped, $offset, $limit);
|
|
|
|
|
|
- // 4. 获取库存出货数据并计算剩余数
|
|
|
+ // 查询库存并计算剩余数
|
|
|
foreach ($paged_grouped as &$prod) {
|
|
|
$inventory = $mongo->name('inventory_summary')->where([
|
|
|
'order_ddbh' => $prod['order_ddbh'],
|
|
|
@@ -143,14 +167,12 @@ class QcodeAdd extends Backend{
|
|
|
'cpmc' => $prod['cpmc'],
|
|
|
])->find();
|
|
|
|
|
|
- // 出货数量(若无数据则为 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,
|
|
|
@@ -160,6 +182,518 @@ class QcodeAdd extends Backend{
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function add_bach()
|
|
|
+ {
|
|
|
+ if (!$this->request->isAjax()) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = input('row');
|
|
|
+ if (empty($data)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = json_decode($data, true);
|
|
|
+
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+ $this->error('JSON解析错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($data['products'])) {
|
|
|
+ $this->error('产品数据不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ $userinfo = Session::get('admin');
|
|
|
+ if (empty($userinfo) || !isset($userinfo['company'])) {
|
|
|
+ $this->error('用户信息获取失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $mongo = \think\Db::connect('mongodb');
|
|
|
+ $collection = $userinfo['company'] . '_qcode_bach';
|
|
|
+ $bachsummary = $userinfo['company'] . '_qcode_bachsummary';
|
|
|
+
|
|
|
+ $insertData = [];
|
|
|
+ $currentday = date('Y-m-d');
|
|
|
+ $currentTime = date('Y-m-d H:i:s');
|
|
|
+ $timestamp = time();
|
|
|
+ $bachNum = 'BACH' . date('YmdHis') . mt_rand(1000, 9999);
|
|
|
+
|
|
|
+ $totalQuantity = 0;
|
|
|
+ $totalBoxes = 0;
|
|
|
+ $totalPallets = 0;
|
|
|
+ $palletSequence = 1; // 全局托盘序号计数器
|
|
|
+
|
|
|
+ foreach ($data['products'] as $product) {
|
|
|
+ $small_num = 20;
|
|
|
+ $tray_num = 6;
|
|
|
+ $box_num = 3;
|
|
|
+ $total_boxes = $tray_num * $box_num;
|
|
|
+
|
|
|
+ $remaining_quantity = (int)$product['remaining_quantity'];
|
|
|
+ $larger_num = ceil($remaining_quantity / $small_num);
|
|
|
+ $large_num = ceil($larger_num / $total_boxes);
|
|
|
+
|
|
|
+ $totalQuantity += $remaining_quantity;
|
|
|
+ $totalBoxes += $larger_num;
|
|
|
+ $totalPallets += $large_num;
|
|
|
+
|
|
|
+ // 计算完整托盘数和剩余箱数
|
|
|
+ $full_pallets = floor($larger_num / $total_boxes);
|
|
|
+ $remaining_boxes = $larger_num % $total_boxes;
|
|
|
+
|
|
|
+ // 为每个托盘创建记录
|
|
|
+ for ($i = 1; $i <= $large_num; $i++) {
|
|
|
+ $is_full_pallet = ($i <= $full_pallets) || ($i == $full_pallets + 1 && $remaining_boxes == $total_boxes);
|
|
|
+ $boxes_in_pallet = $is_full_pallet ? $total_boxes : ($i == $full_pallets + 1 ? $remaining_boxes : 0);
|
|
|
+
|
|
|
+ $insertData[] = [
|
|
|
+ // 用户信息相关字段
|
|
|
+ 'userid' => $userinfo['id'], // 用户ID
|
|
|
+ 'supplier_id' => $userinfo['id'], // 供应商ID (同用户ID)
|
|
|
+ 'supplier_code' => $userinfo['printer_code'], // 供应商编码/打印机编码
|
|
|
+ 'supplier_name' => $data['company_name'], // 供应商名称/公司名称
|
|
|
+
|
|
|
+ // 托盘信息相关字段
|
|
|
+ 'pallet' => $palletSequence, // 托盘编号 (全局唯一序号)
|
|
|
+ 'pallet_sequence' => $palletSequence, // 托盘序号 (同pallet字段,冗余设计)
|
|
|
+ 'pallet_type' => $is_full_pallet ? 'full' : 'partial', // 托盘类型: full-整托/partial-部分托
|
|
|
+
|
|
|
+ // 产品基本信息
|
|
|
+ 'matter_no' => $product['gdbh'], // 产品编号/工单编号
|
|
|
+ 'matter_id' => $product['gdbh'], // 产品ID (同工单编号)
|
|
|
+ 'matter_type' => '01', // 产品类型 (固定值01)
|
|
|
+ 'order_ddbh' => $product['order_ddbh'], // 订单编号
|
|
|
+ 'cpbm' => $product['cpbm'], // 产品编码
|
|
|
+ 'matter_name' => $product['cpmc'], // 产品名称
|
|
|
+ 'remark' => $product['remark'], // 备注信息
|
|
|
+
|
|
|
+ // 数量单位信息
|
|
|
+ 'num_danwei' => '2', // 数量单位类型 (固定值2)
|
|
|
+ 'danwei' => '套', // 单位名称 (套)
|
|
|
+
|
|
|
+ // 数量计算相关字段
|
|
|
+ 'num' => $i <= $full_pallets ? $small_num * $total_boxes : ($i == $full_pallets + 1 ? $small_num * $remaining_boxes : 0), // 本托盘实际产品数量
|
|
|
+ 'small_num' => $small_num, // 每箱产品数量 (固定20)
|
|
|
+ 'tray_num' => $tray_num, // 每层箱数 (固定6)
|
|
|
+ 'box_num' => $box_num, // 每托盘层数 (固定3)
|
|
|
+ 'total_boxes' => $total_boxes, // 每托盘总箱数 (tray_num * box_num)
|
|
|
+ 'boxes_in_pallet' => $boxes_in_pallet, // 本托盘实际箱数 (full时为18,partial时为余数)
|
|
|
+
|
|
|
+ // 托盘汇总信息
|
|
|
+ 'large_num' => $large_num, // 本产品总托盘数
|
|
|
+ 'larger_num' => $larger_num, // 本产品总箱数
|
|
|
+
|
|
|
+ // 托盘尺寸规格
|
|
|
+ 'pallet_height' => '1.05', // 托盘高度(米)
|
|
|
+ 'pallet_length' => '0.9', // 托盘长度(米)
|
|
|
+ 'pallet_width' => '1.2', // 托盘宽度(米)
|
|
|
+
|
|
|
+ // 物流相关字段 (当前为空)
|
|
|
+ 'l_reservation' => '', // 物流预留字段
|
|
|
+ 'l_flow' => '1', // 物流流向 (固定值1)
|
|
|
+ 'l_weight' => '', // 物流重量
|
|
|
+ 's_flow' => '', // 备用流向字段
|
|
|
+ 's_weight' => '', // 备用重量字段
|
|
|
+ 's_reservation' => '', // 备用预留字段
|
|
|
+
|
|
|
+ // 状态信息
|
|
|
+ 'bach_status' => 0, // 批次状态 (0-初始状态)
|
|
|
+ 'bach_ids' => $bachNum, // 批次编号 (唯一标识)
|
|
|
+ 'large_endnum' => $large_num, // 本产品结束托盘号 (同large_num)
|
|
|
+
|
|
|
+ // 日期相关字段
|
|
|
+ 'manufacture_date' => '', // 生产日期 (空)
|
|
|
+ 'print_date' => '', // 打印日期 (空)
|
|
|
+ 'sys_rq' => $currentday, // 系统日期 (YYYY-MM-DD)
|
|
|
+ 'created_at' => $currentTime, // 创建时间 (YYYY-MM-DD HH:MM:SS)
|
|
|
+ 'create_time' => $timestamp, // 创建时间戳 (Unix timestamp)
|
|
|
+ 'updated_at' => '', // 更新时间 (空)
|
|
|
+
|
|
|
+ // 系统标志字段
|
|
|
+ 'sync_flag' => '0', // 同步标志 (0-未同步)
|
|
|
+
|
|
|
+ // 删除相关字段
|
|
|
+ 'delete_time' => '', // 删除时间 (空)
|
|
|
+ 'delect_time' => '' // 删除时间 (拼写错误,同delete_time)
|
|
|
+ ];
|
|
|
+
|
|
|
+ $palletSequence++; // 递增全局托盘序号
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $insertData_bachsummary = [
|
|
|
+ 'bach_ids' => $bachNum,
|
|
|
+ 'userid' => $userinfo['id'],
|
|
|
+ 'supplier_id' => $userinfo['id'],
|
|
|
+ 'supplier_code' => $userinfo['printer_code'],
|
|
|
+ 'supplier_name' => $data['company_name'],
|
|
|
+ 'total_quantity' => $totalQuantity,
|
|
|
+ 'total_boxes' => $totalBoxes,
|
|
|
+ 'total_pallets' => $totalPallets,
|
|
|
+ 'full_pallets' => $totalPallets - count(array_filter($insertData, function($item) { return $item['pallet_type'] === 'partial'; })),
|
|
|
+ 'partial_pallets' => count(array_filter($insertData, function($item) { return $item['pallet_type'] === 'partial'; })),
|
|
|
+ 'product_count' => count($data['products']),
|
|
|
+ 'bach_status' => 0,
|
|
|
+ 'sys_rq' => $currentday,
|
|
|
+ 'created_at' => $currentTime,
|
|
|
+ 'create_time' => $timestamp,
|
|
|
+ 'updated_at' => '',
|
|
|
+ 'delete_time' => ''
|
|
|
+ ];
|
|
|
+//echo "<pre>";
|
|
|
+//print_r($insertData);
|
|
|
+//echo "<pre>";die;
|
|
|
+ // 插入数据
|
|
|
+ $mongo->name($collection)->insertAll($insertData);
|
|
|
+ $mongo->name($bachsummary)->insert($insertData_bachsummary);
|
|
|
+//die;
|
|
|
+ // 更新库存信息
|
|
|
+ foreach ($data['products'] as $product) {
|
|
|
+ $where = [
|
|
|
+ 'gdbh' => $product['gdbh'],
|
|
|
+ 'order_ddbh' => $product['order_ddbh'],
|
|
|
+ 'cpmc' => $product['cpmc'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $actual_quantity = isset($product['actual_quantity']) ? (int)$product['actual_quantity'] : 0;
|
|
|
+ $remaining_quantity = isset($product['remaining_quantity']) ? (int)$product['remaining_quantity'] : 0;
|
|
|
+
|
|
|
+ $insertData = [
|
|
|
+ 'gdbh' => $product['gdbh'],
|
|
|
+ 'order_ddbh' => $product['order_ddbh'],
|
|
|
+ 'cpbm' => $product['cpbm'],
|
|
|
+ 'cpmc' => $product['cpmc'],
|
|
|
+ 'total_ru_quantity' => $remaining_quantity,
|
|
|
+ 'total_chu_quantity' => $actual_quantity,
|
|
|
+ 'remaining_quantity' => $remaining_quantity - $actual_quantity,
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => '',
|
|
|
+ 'mod_rq' => '',
|
|
|
+ 'company' => $data['company_name'] ?? '',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $existing = $mongo->name('inventory_summary')->where($where)->find();
|
|
|
+
|
|
|
+ if ($existing) {
|
|
|
+ $new_chu = (int)$existing['total_chu_quantity'] + $actual_quantity;
|
|
|
+ $new_remaining = (int)$existing['remaining_quantity'] - $actual_quantity;
|
|
|
+
|
|
|
+ $mongo->name('inventory_summary')
|
|
|
+ ->where($where)
|
|
|
+ ->update([
|
|
|
+ 'total_ru_quantity' => (int)$existing['total_ru_quantity'],
|
|
|
+ 'total_chu_quantity' => $new_chu,
|
|
|
+ 'remaining_quantity' => $new_remaining,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $mongo->name('inventory_summary')->insert($insertData);
|
|
|
+ }
|
|
|
+
|
|
|
+ $mongo->name('inventory_records')->insert($insertData);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('添加成功');
|
|
|
+ }
|
|
|
+// public function add_bach()
|
|
|
+// {
|
|
|
+// if (!$this->request->isAjax()) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $data = input('row');
|
|
|
+// if (empty($data)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $data = json_decode($data, true);
|
|
|
+//
|
|
|
+// if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+// $this->error('JSON解析错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (empty($data['products'])) {
|
|
|
+// $this->error('产品数据不能为空');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $userinfo = Session::get('admin');
|
|
|
+// if (empty($userinfo) || !isset($userinfo['company'])) {
|
|
|
+// $this->error('用户信息获取失败');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $mongo = \think\Db::connect('mongodb');
|
|
|
+// $collection = $userinfo['company'] . '_qcode_bach';
|
|
|
+// $bachsummary = $userinfo['company'] . '_qcode_bachsummary';
|
|
|
+//
|
|
|
+// $insertData = [];
|
|
|
+// $currentday = date('Y-m-d');
|
|
|
+// $currentTime = date('Y-m-d H:i:s');
|
|
|
+// $timestamp = time();
|
|
|
+// $bachNum = 'BACH' . date('YmdHis') . mt_rand(1000, 9999);
|
|
|
+//
|
|
|
+// $totalQuantity = 0;
|
|
|
+// $totalBoxes = 0;
|
|
|
+// $totalPallets = 0;
|
|
|
+//
|
|
|
+// foreach ($data['products'] as $product) {
|
|
|
+// $small_num = 20;
|
|
|
+// $tray_num = 6;
|
|
|
+// $box_num = 3;
|
|
|
+// $total_boxes = $tray_num * $box_num;
|
|
|
+//
|
|
|
+// $remaining_quantity = (int)$product['remaining_quantity'];
|
|
|
+// $larger_num = ceil($remaining_quantity / $small_num);
|
|
|
+// $large_num = ceil($larger_num / $total_boxes);
|
|
|
+//
|
|
|
+// $totalQuantity += $remaining_quantity;
|
|
|
+// $totalBoxes += $larger_num;
|
|
|
+// $totalPallets += $large_num;
|
|
|
+//
|
|
|
+// $palletRange = '1-' . $large_num;
|
|
|
+//
|
|
|
+// $insertData[] = [
|
|
|
+// 'userid' => $userinfo['id'],
|
|
|
+// 'supplier_id' => $userinfo['id'],
|
|
|
+// 'supplier_code' => $userinfo['printer_code'],
|
|
|
+// 'supplier_name' => $data['company_name'],
|
|
|
+// 'pallet' => $palletRange,
|
|
|
+// 'matter_no' => $product['gdbh'],
|
|
|
+// 'matter_id' => $product['gdbh'],
|
|
|
+// 'matter_type' => '01',
|
|
|
+// 'order_ddbh' => $product['order_ddbh'],
|
|
|
+// 'cpbm' => $product['cpbm'],
|
|
|
+// 'matter_name' => $product['cpmc'],
|
|
|
+// 'remark' => $product['remark'],
|
|
|
+// 'num_danwei' => '2',
|
|
|
+// 'danwei' => '套',
|
|
|
+// 'num' => $remaining_quantity,
|
|
|
+// 'small_num' => $small_num,
|
|
|
+// 'tray_num' => $tray_num,
|
|
|
+// 'box_num' => $box_num,
|
|
|
+// 'total_boxes' => $total_boxes,
|
|
|
+// 'large_num' => $large_num,
|
|
|
+// 'larger_num' => $larger_num,
|
|
|
+// 'pallet_height' => '1.05',
|
|
|
+// 'pallet_length' => '0.9',
|
|
|
+// 'pallet_width' => '1.2',
|
|
|
+// 'l_reservation' => '',
|
|
|
+// 'l_flow' => '1',
|
|
|
+// 'l_weight' => '',
|
|
|
+// 's_flow' => '',
|
|
|
+// 's_weight' => '',
|
|
|
+// 's_reservation' => '',
|
|
|
+// 'bach_status' => 0,
|
|
|
+// 'bach_ids' => $bachNum,
|
|
|
+// 'large_endnum' => $large_num,
|
|
|
+// 'manufacture_date' => '',
|
|
|
+// 'print_date' => '',
|
|
|
+// 'sys_rq' => $currentday,
|
|
|
+// 'created_at' => $currentTime,
|
|
|
+// 'create_time' => $timestamp,
|
|
|
+// 'updated_at' => '',
|
|
|
+// 'sync_flag' => '0',
|
|
|
+// 'delete_time' => '',
|
|
|
+// 'delect_time' => ''
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $insertData_bachsummary = [
|
|
|
+// 'bach_ids' => $bachNum,
|
|
|
+// 'userid' => $userinfo['id'],
|
|
|
+// 'supplier_id' => $userinfo['id'],
|
|
|
+// 'supplier_code' => $userinfo['printer_code'],
|
|
|
+// 'supplier_name' => $data['company_name'],
|
|
|
+// 'total_quantity' => $totalQuantity,
|
|
|
+// 'total_boxes' => $totalBoxes,
|
|
|
+// 'total_pallets' => $totalPallets,
|
|
|
+// 'product_count' => count($data['products']),
|
|
|
+// 'bach_status' => 0,
|
|
|
+// 'sys_rq' => $currentday,
|
|
|
+// 'created_at' => $currentTime,
|
|
|
+// 'create_time' => $timestamp,
|
|
|
+// 'updated_at' => '',
|
|
|
+// 'delete_time' => ''
|
|
|
+// ];
|
|
|
+//
|
|
|
+//echo "<pre>";
|
|
|
+//print_r($insertData);
|
|
|
+//echo "<pre>";die;
|
|
|
+// $mongo->name($collection)->insertAll($insertData);
|
|
|
+// $mongo->name($bachsummary)->insert($insertData_bachsummary);
|
|
|
+//
|
|
|
+//
|
|
|
+// foreach ($data['products'] as $product) {
|
|
|
+// $where = [
|
|
|
+// 'gdbh' => $product['gdbh'],
|
|
|
+// 'order_ddbh' => $product['order_ddbh'],
|
|
|
+// 'cpmc' => $product['cpmc'],
|
|
|
+// ];
|
|
|
+//
|
|
|
+// // 实际出库数量
|
|
|
+// $actual_quantity = isset($product['actual_quantity']) ? (int)$product['actual_quantity'] : 0;
|
|
|
+// $remaining_quantity = isset($product['remaining_quantity']) ? (int)$product['remaining_quantity'] : 0;
|
|
|
+//
|
|
|
+// // 插入/更新字段
|
|
|
+// $insertData = [
|
|
|
+// 'gdbh' => $product['gdbh'],
|
|
|
+// 'order_ddbh' => $product['order_ddbh'],
|
|
|
+// 'cpbm' => $product['cpbm'],
|
|
|
+// 'cpmc' => $product['cpmc'],
|
|
|
+// 'total_ru_quantity' => $remaining_quantity, // 入库数来自当前剩余
|
|
|
+// 'total_chu_quantity' => $actual_quantity, // 本次出库数
|
|
|
+// 'remaining_quantity' => $remaining_quantity - $actual_quantity, // 计算结存
|
|
|
+// 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+// 'updated_at' => '',
|
|
|
+// 'mod_rq' => '',
|
|
|
+// 'company' => $data['company_name'] ?? '',
|
|
|
+// ];
|
|
|
+//
|
|
|
+// // 查询是否已存在
|
|
|
+// $existing = $mongo->name('inventory_summary')->where($where)->find();
|
|
|
+//
|
|
|
+// if ($existing) {
|
|
|
+// // 累加更新
|
|
|
+// $new_chu = (int)$existing['total_chu_quantity'] + $actual_quantity;
|
|
|
+// $new_remaining = (int)$existing['remaining_quantity'] - $actual_quantity;
|
|
|
+//
|
|
|
+// $mongo->name('inventory_summary')
|
|
|
+// ->where($where)
|
|
|
+// ->update([
|
|
|
+// 'total_ru_quantity' => (int)$existing['total_ru_quantity'], // 保持不变或你可定义逻辑
|
|
|
+// 'total_chu_quantity' => $new_chu,
|
|
|
+// 'remaining_quantity' => $new_remaining,
|
|
|
+// 'updated_at' => date('Y-m-d H:i:s'),
|
|
|
+// ]);
|
|
|
+// } else {
|
|
|
+// // 插入新记录
|
|
|
+// $mongo->name('inventory_summary')->insert($insertData);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 插入库存明细记录
|
|
|
+// $mongo->name('inventory_records')->insert($insertData);
|
|
|
+// }
|
|
|
+// $this->success('添加成功');
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+// public function add_bach()
|
|
|
+// {
|
|
|
+// if ($this->request->isAjax() === false) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $data = input('row');
|
|
|
+// if (empty($data)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $data = json_decode($data, true); // 解码为关联数组
|
|
|
+//
|
|
|
+// if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
+// $this->error('JSON解析错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!isset($data['products']) || empty($data['products'])) {
|
|
|
+// $this->error('产品数据不能为空');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $userinfo = Session::get('admin'); // 获取用户信息
|
|
|
+// if (empty($userinfo) || !isset($userinfo['company'])) {
|
|
|
+// $this->error('用户信息获取失败');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $mongo = \think\Db::connect('mongodb');
|
|
|
+// $collection = $userinfo['company'] . '_qcode_bach';
|
|
|
+// $bachsummary = $userinfo['company'] . '_qcode_bachsummary';
|
|
|
+//
|
|
|
+// $insertData = [];
|
|
|
+// $currentday = date('Y-m-d');
|
|
|
+// $currentTime = date('Y-m-d H:i:s');
|
|
|
+//
|
|
|
+// foreach ($data['products'] as $product) {
|
|
|
+//
|
|
|
+// // 计算相关数量
|
|
|
+// $small_num = 20; // 每一箱数量
|
|
|
+// $tray_num = 6; // 每层箱数【箱/层】
|
|
|
+// $box_num = 3; // 每托层数【层/托】
|
|
|
+// $total_boxes = $tray_num * $box_num; // 每托盘箱数【箱/托】= 6*3=18
|
|
|
+//
|
|
|
+// // 计算总箱数和托盘数
|
|
|
+// $remaining_quantity = (int)$product['remaining_quantity'];
|
|
|
+// $larger_num = ceil($remaining_quantity / $small_num); // 总箱数 = 剩余数量/每箱数量(向上取整)
|
|
|
+// $large_num = ceil($larger_num / $total_boxes); // 本次打包托盘数 = 总箱数/每托盘箱数(向上取整)
|
|
|
+//
|
|
|
+// $insertData[] = [
|
|
|
+// //登录用户字段信息
|
|
|
+// 'userid' => $userinfo['id'],//用户id
|
|
|
+// 'supplier_id' => $userinfo['id'],//用户id
|
|
|
+// 'supplier_code' => $userinfo['printer_code'],//供应商编码
|
|
|
+// 'supplier_name' => $data['company_name'],//公司名称
|
|
|
+//
|
|
|
+// // 产品字段信息
|
|
|
+// 'pallet' => '1-'.$large_num,//托盘序号
|
|
|
+// 'matter_no' => $product['gdbh'],//生产批次号-工单编号
|
|
|
+// 'matter_id' => $product['gdbh'],
|
|
|
+// 'matter_type' => '01',
|
|
|
+// 'order_ddbh' => $product['order_ddbh'],//销售订单号
|
|
|
+// 'cpbm' => $product['cpbm'],//成品编码
|
|
|
+// 'matter_name' => $product['cpmc'],//成品名称
|
|
|
+// 'remark' => $product['remark'],
|
|
|
+//
|
|
|
+// 'num_danwei' => '2',//单位
|
|
|
+// 'danwei' => '套',//单位
|
|
|
+// 'num' => $remaining_quantity,//总数量(张/个)
|
|
|
+// 'small_num' => $small_num,//每一箱数量
|
|
|
+// 'tray_num' => $tray_num,//每层箱数【箱/层】
|
|
|
+// 'box_num' => $box_num,//每托层数【 层/托】
|
|
|
+// 'total_boxes' => $total_boxes,//每托盘箱数【箱/托】
|
|
|
+// 'large_num' => $large_num,//本次打包托盘数
|
|
|
+// 'larger_num' => $larger_num,//总箱数
|
|
|
+// 'pallet_height' => '1.05',//每托高度
|
|
|
+// 'pallet_length' => '0.9',//托盘规格
|
|
|
+// 'pallet_width' => '1.2',//托盘规格
|
|
|
+//
|
|
|
+// 'l_reservation' => '',
|
|
|
+// 'l_flow' => '1',//大件流水
|
|
|
+// 'l_weight' => '',//大件重量
|
|
|
+// 's_flow' => '',//小件流水
|
|
|
+// 's_weight' => '',//小件重量
|
|
|
+// 's_reservation' => '',
|
|
|
+// 'bach_status' => 0,
|
|
|
+// 'bach_num' => $product['gdbh'],//生产批次号-工单编号
|
|
|
+// 'large_endnum' => $large_num,
|
|
|
+//
|
|
|
+// // 其他字段信息
|
|
|
+// 'manufacture_date' => '',//生产日期
|
|
|
+// 'print_date' => '',//打码日期
|
|
|
+// 'sys_rq' => $currentday,//新增日期
|
|
|
+// 'created_at' => $currentTime,//新增时间
|
|
|
+// 'create_time' => time(),//新增时间
|
|
|
+// 'updated_at' => '',
|
|
|
+// 'sync_flag' => '0',
|
|
|
+// 'delete_time' => '',
|
|
|
+// 'delect_time' => ''//删除时间
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//echo "<pre>";
|
|
|
+//print_r($insertData_bachsummary);
|
|
|
+//echo "<pre>";die;
|
|
|
+//
|
|
|
+//
|
|
|
+// if (!empty($insertData)) {
|
|
|
+// //汇总数据
|
|
|
+// $mongo->name($bachsummary)->insertAll($insertData_bachsummary);
|
|
|
+// //明细数据
|
|
|
+// $mongo->name($collection)->insertAll($insertData);
|
|
|
+// $this->success('添加成功');
|
|
|
+// } else {
|
|
|
+// $this->error('没有有效数据可添加');
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 增加新批次
|
|
|
*/
|
|
|
@@ -184,11 +718,12 @@ class QcodeAdd extends Backend{
|
|
|
|
|
|
$data = [];
|
|
|
foreach ($rows as $value){
|
|
|
- foreach ($value as $k=>$v){
|
|
|
- $data[$k] = $v;
|
|
|
- }
|
|
|
+ foreach ($value as $k=>$v){
|
|
|
+ $data[$k] = $v;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//打印信息
|
|
|
|
|
|
// echo "接口获取";echo "<pre>";print_r($data);echo "<pre>";die;
|
|
|
@@ -423,7 +958,8 @@ class QcodeAdd extends Backend{
|
|
|
$large_id = $large->getLastInsID();
|
|
|
if ($large_id){
|
|
|
// //小件码循环插入
|
|
|
- for ($j=0;$j<$data['tray_num'] and ($j+$i*$data['tray_num'])<$batchList['small_num'];$j++){
|
|
|
+// for ($j=0;$j<$data['tray_num'] and ($j+$i*$data['tray_num'])<$batchList['small_num'];$j++){
|
|
|
+ for ($j=0;$j<$data['total_boxes'] and ($j+$i*$data['total_boxes'])<$batchList['total_boxes'];$j++){
|
|
|
$small = new QcodeSmall();
|
|
|
$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);
|
|
|
@@ -496,25 +1032,25 @@ class QcodeAdd extends Backend{
|
|
|
* @param $reservation
|
|
|
* @return array
|
|
|
*/
|
|
|
- function CodeData($sign,$fixed_code,$small_num,$print_date,$flow,$weight,$large_sign,$reservation){
|
|
|
- $code=$sign;//4 位固定标志位
|
|
|
- $code.=$fixed_code; // 固定字符串
|
|
|
- $code.=$small_num;//3位 小件数量
|
|
|
- $code.=$print_date;//6 位 日期
|
|
|
- $code.=$flow;//6位打印流水号
|
|
|
- $code.=$weight;//6位辅料重量
|
|
|
- $code.=$large_sign;//大小件标示位
|
|
|
-
|
|
|
- $code.=$reservation;//20 位 预留号
|
|
|
-
|
|
|
- //大码数据信息
|
|
|
- $data=[
|
|
|
- 'code'=>str_replace(" ","",$code),
|
|
|
- 'code_cp1'=>$print_date.$flow,
|
|
|
- 'code_cp2'=>$weight.$reservation,//20位补充
|
|
|
- 'print_date'=>time(),
|
|
|
- 'p_nums'=>0,
|
|
|
- ];
|
|
|
- return $data;
|
|
|
- }
|
|
|
+ function CodeData($sign,$fixed_code,$small_num,$print_date,$flow,$weight,$large_sign,$reservation){
|
|
|
+ $code=$sign;//4 位固定标志位
|
|
|
+ $code.=$fixed_code; // 固定字符串
|
|
|
+ $code.=$small_num;//3位 小件数量
|
|
|
+ $code.=$print_date;//6 位 日期
|
|
|
+ $code.=$flow;//6位打印流水号
|
|
|
+ $code.=$weight;//6位辅料重量
|
|
|
+ $code.=$large_sign;//大小件标示位
|
|
|
+
|
|
|
+ $code.=$reservation;//20 位 预留号
|
|
|
+
|
|
|
+ //大码数据信息
|
|
|
+ $data=[
|
|
|
+ 'code'=>str_replace(" ","",$code),
|
|
|
+ 'code_cp1'=>$print_date.$flow,
|
|
|
+ 'code_cp2'=>$weight.$reservation,//20位补充
|
|
|
+ 'print_date'=>time(),
|
|
|
+ 'p_nums'=>0,
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
}
|