|
|
@@ -243,6 +243,106 @@ class QcodeBach extends Backend
|
|
|
/**
|
|
|
* 小件列表
|
|
|
*/
|
|
|
+// 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'];
|
|
|
+//
|
|
|
+// $filter = json_decode($req['filter'], true);
|
|
|
+// foreach ($filter as $k => $v){
|
|
|
+// $where[$k] = new \MongoDB\BSON\Regex($v);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $list = [];
|
|
|
+// $total = 0;
|
|
|
+//
|
|
|
+// $qcodeSmall = new QcodeSmall();
|
|
|
+//
|
|
|
+// // 超级管理员查询所有公司
|
|
|
+// if (isSuperAdmin()) {
|
|
|
+// $companies = Db::name('admin')
|
|
|
+// ->field('company')
|
|
|
+// ->where('company', '<>', '')
|
|
|
+// ->where('kes', '<>', '')
|
|
|
+// ->distinct(true)
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+//
|
|
|
+// foreach ($companies as $row) {
|
|
|
+// $cid = $row['company'];
|
|
|
+// $table = $cid . '_qcode_small';
|
|
|
+//
|
|
|
+// // 获取数据(不分页,后面统一分页)
|
|
|
+// $rows = $qcodeSmall->name($table)->where($where)->select();
|
|
|
+//
|
|
|
+// foreach ($rows as &$v) {
|
|
|
+// $oid = $v['_id']->jsonSerialize();
|
|
|
+// $v['id'] = $oid['$oid'];
|
|
|
+// $v['l_flow'] = ($req['l_flow'] ?? '') . '-' . $v['l_flow'];
|
|
|
+// if (strpos($v['l_flow'], '-') !== false) {
|
|
|
+// $parts = explode('-', $v['l_flow']);
|
|
|
+// $v['l_flows'] = end($parts);
|
|
|
+// } else {
|
|
|
+// $v['l_flows'] = '';
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $list = array_merge($list, $rows);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 全部公司数据合并后,统一排序
|
|
|
+// usort($list, function ($a, $b) use ($sort, $order) {
|
|
|
+// $valA = $a[$sort] ?? '';
|
|
|
+// $valB = $b[$sort] ?? '';
|
|
|
+// return $order === 'asc' ? ($valA <=> $valB) : ($valB <=> $valA);
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 总条数
|
|
|
+// $total = count($list);
|
|
|
+// // 分页截取
|
|
|
+// $list = array_slice($list, $offset, $limit);
|
|
|
+// } else {
|
|
|
+// // 普通用户仅查本公司
|
|
|
+// $table = $company_id . '_qcode_small';
|
|
|
+//
|
|
|
+// $total = $qcodeSmall->name($table)->where($where)->count();
|
|
|
+//
|
|
|
+// $list = $qcodeSmall->name($table)->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'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return json(["total" => $total, "rows" => $list]);
|
|
|
+// }
|
|
|
+// return $this->view->fetch();
|
|
|
+// }
|
|
|
+
|
|
|
public function small()
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
@@ -275,79 +375,33 @@ class QcodeBach extends Backend
|
|
|
$where[$k] = new \MongoDB\BSON\Regex($v);
|
|
|
}
|
|
|
|
|
|
- $list = [];
|
|
|
- $total = 0;
|
|
|
-
|
|
|
$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();
|
|
|
|
|
|
- // 超级管理员查询所有公司
|
|
|
- if (isSuperAdmin()) {
|
|
|
- $companies = Db::name('admin')
|
|
|
- ->field('company')
|
|
|
- ->where('company', '<>', '')
|
|
|
- ->where('kes', '<>', '')
|
|
|
- ->distinct(true)
|
|
|
- ->select();
|
|
|
-
|
|
|
- foreach ($companies as $row) {
|
|
|
- $cid = $row['company'];
|
|
|
- $table = $cid . '_qcode_small';
|
|
|
-
|
|
|
- // 获取数据(不分页,后面统一分页)
|
|
|
- $rows = $qcodeSmall->name($table)->where($where)->select();
|
|
|
-
|
|
|
- foreach ($rows as &$v) {
|
|
|
- $oid = $v['_id']->jsonSerialize();
|
|
|
- $v['id'] = $oid['$oid'];
|
|
|
- $v['l_flow'] = ($req['l_flow'] ?? '') . '-' . $v['l_flow'];
|
|
|
- if (strpos($v['l_flow'], '-') !== false) {
|
|
|
- $parts = explode('-', $v['l_flow']);
|
|
|
- $v['l_flows'] = end($parts);
|
|
|
- } else {
|
|
|
- $v['l_flows'] = '';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $list = array_merge($list, $rows);
|
|
|
- }
|
|
|
-
|
|
|
- // 全部公司数据合并后,统一排序
|
|
|
- usort($list, function ($a, $b) use ($sort, $order) {
|
|
|
- $valA = $a[$sort] ?? '';
|
|
|
- $valB = $b[$sort] ?? '';
|
|
|
- return $order === 'asc' ? ($valA <=> $valB) : ($valB <=> $valA);
|
|
|
- });
|
|
|
-
|
|
|
- // 总条数
|
|
|
- $total = count($list);
|
|
|
-
|
|
|
- // 分页截取
|
|
|
- $list = array_slice($list, $offset, $limit);
|
|
|
- } else {
|
|
|
- // 普通用户仅查本公司
|
|
|
- $table = $company_id . '_qcode_small';
|
|
|
-
|
|
|
- $total = $qcodeSmall->name($table)->where($where)->count();
|
|
|
-
|
|
|
- $list = $qcodeSmall->name($table)->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'];
|
|
|
+ foreach ($list as $k=>$v) {
|
|
|
+ $oid = $v['_id']->jsonSerialize();
|
|
|
+ $list[$k]['id'] = $oid['$oid'];
|
|
|
+ $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
|
|
|
+ if (strpos($v['l_flow'], '-') !== false) {
|
|
|
+ $parts = explode('-', $v['l_flow']);
|
|
|
+ $v['l_flows'] = end($parts);
|
|
|
+ } else {
|
|
|
+ $v['l_flows'] = '';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return json(["total" => $total, "rows" => $list]);
|
|
|
+ $result = array("total" => $total, "rows" => $list);
|
|
|
+
|
|
|
+ return json($result);
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 小件导出状态修改(支持超级管理员操作单个公司表)
|
|
|
* 支持处理单个ID和多个ID(逗号分隔)的情况
|
|
|
@@ -568,7 +622,7 @@ class QcodeBach extends Backend
|
|
|
if ($rowData['l_num'] === null) {
|
|
|
$rows[$key]['num'] = $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : '';
|
|
|
} elseif ($rowData['l_num'] == 0) {
|
|
|
- $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] : (
|
|
|
+ $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] /100 : (
|
|
|
$proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : ''
|
|
|
);
|
|
|
} else {
|
|
|
@@ -629,7 +683,7 @@ class QcodeBach extends Backend
|
|
|
if ($rowData['l_num'] === null) {
|
|
|
$rows[$key]['num'] = $proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : '';
|
|
|
} elseif ($rowData['l_num'] == 0) {
|
|
|
- $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] : (
|
|
|
+ $rows[$key]['num'] = ($main_unit == '公斤') ? $rowData['l_weight'] /100 : (
|
|
|
$proportion ? floor($rows[$key]['sqrcd'] * $proportion * 100) / 100 : ''
|
|
|
);
|
|
|
} else {
|
|
|
@@ -1209,4 +1263,161 @@ class QcodeBach extends Backend
|
|
|
return 'data:image/png;base64,'.$imageString;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// public function bacch(){
|
|
|
+// $mongo = \think\Db::connect('mongodb');
|
|
|
+//
|
|
|
+// // 表1数据
|
|
|
+// $qcode_product = $mongo->name('qcode_product')->select();
|
|
|
+// // 表2数据
|
|
|
+// $qr_qcode_product_copy = $mongo->name('qr_qcode_product_copy')->select();
|
|
|
+//
|
|
|
+// // 把表2按 product_name 索引
|
|
|
+// $map2 = [];
|
|
|
+// foreach ($qr_qcode_product_copy as $row) {
|
|
|
+// $map2[$row['product_name']] = $row['product_code'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $same = []; // 相同 product_name 的记录
|
|
|
+// $diff = []; // 不相同的记录
|
|
|
+//
|
|
|
+// // 先处理表1,找出匹配和不匹配
|
|
|
+// foreach ($qcode_product as $row1) {
|
|
|
+// if (isset($map2[$row1['product_name']])) {
|
|
|
+// $same[] = [
|
|
|
+// 'product_code_1' => $row1['product_code'],
|
|
|
+// 'product_code_2' => $map2[$row1['product_name']],
|
|
|
+// 'product_name' => $row1['product_name']
|
|
|
+// ];
|
|
|
+// unset($map2[$row1['product_name']]); // 已匹配,避免后面重复
|
|
|
+// } else {
|
|
|
+// $diff[] = [
|
|
|
+// 'product_code' => $row1['product_code'],
|
|
|
+// 'product_name' => $row1['product_name']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 剩下 map2 中的就是表2中独有的
|
|
|
+// foreach ($map2 as $name => $code) {
|
|
|
+// $diff[] = [
|
|
|
+// 'product_code' => $code,
|
|
|
+// 'product_name' => $name
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+//// // 存到新表
|
|
|
+// $mongo->name('same_products')->insertAll($same);
|
|
|
+// $mongo->name('diff_products')->insertAll($diff);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// public function bacch() {
|
|
|
+// $mongo = \think\Db::connect('mongodb');
|
|
|
+//
|
|
|
+// // 获取三个表的数据
|
|
|
+// $table1 = $mongo->name('qcode_product')->select();
|
|
|
+// $table2 = $mongo->name('qr_qcode_product_copy')->select();
|
|
|
+//
|
|
|
+// // 预加载qr_qcode_unit_copy表数据并建立索引
|
|
|
+// $unitData = $mongo->name('qr_qcode_unit_copy')->select();
|
|
|
+// $unitIndex = [];
|
|
|
+// foreach ($unitData as $unit) {
|
|
|
+// $unitIndex[$unit['code']] = [
|
|
|
+// 'main_unit' => $unit['main_unit'] ?? null,
|
|
|
+// 'sec_unit' => $unit['sec_unit'] ?? null,
|
|
|
+// 'proportion' => $unit['proportion'] ?? null
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 索引表2数据,包含product_name和temple
|
|
|
+// $table2Index = [];
|
|
|
+// foreach ($table2 as $row) {
|
|
|
+// $table2Index[$row['product_name']] = [
|
|
|
+// 'product_code' => $row['product_code'],
|
|
|
+// 'temple' => $row['temple'] ?? null
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $differences = [];
|
|
|
+//
|
|
|
+// // 处理表1中的记录
|
|
|
+// foreach ($table1 as $row) {
|
|
|
+// if (!isset($table2Index[$row['product_name']]) &&
|
|
|
+// strpos($row['product_code'], 'AB') !== 0) {
|
|
|
+//
|
|
|
+// // 获取单位信息
|
|
|
+// $unitInfo = $unitIndex[$row['product_code']] ?? [
|
|
|
+// 'main_unit' => null,
|
|
|
+// 'sec_unit' => null,
|
|
|
+// 'proportion' => null
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $differences[] = [
|
|
|
+// 'product_code' => $row['product_code'],
|
|
|
+// 'product_name' => $row['product_name'],
|
|
|
+// 'temple' => null,
|
|
|
+// 'main_unit' => $unitInfo['main_unit'],
|
|
|
+// 'sec_unit' => $unitInfo['sec_unit'],
|
|
|
+// 'proportion' => $unitInfo['proportion']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 处理表2中的记录
|
|
|
+// foreach ($table2Index as $name => $data) {
|
|
|
+// $existsInTable1 = false;
|
|
|
+// foreach ($table1 as $row) {
|
|
|
+// if ($row['product_name'] === $name) {
|
|
|
+// $existsInTable1 = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!$existsInTable1 && strpos($data['product_code'], 'AB') !== 0) {
|
|
|
+// // 获取单位信息
|
|
|
+// $unitInfo = $unitIndex[$data['product_code']] ?? [
|
|
|
+// 'main_unit' => null,
|
|
|
+// 'sec_unit' => null,
|
|
|
+// 'proportion' => null
|
|
|
+// ];
|
|
|
+//
|
|
|
+// $differences[] = [
|
|
|
+// 'product_name' => $name,
|
|
|
+// 'product_code' => $data['product_code'],
|
|
|
+// 'temple' => $data['temple'],
|
|
|
+// 'main_unit' => $unitInfo['main_unit'],
|
|
|
+// 'sec_unit' => $unitInfo['sec_unit'],
|
|
|
+// 'proportion' => $unitInfo['proportion'],
|
|
|
+// 'delete_time' => '',
|
|
|
+// 'sync_flag' => 0,
|
|
|
+// 'code' => substr($data['product_code'], 0, 4)
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 获取当前最大的oid_id值
|
|
|
+// $maxOid = $mongo->name('qcode_product')->order('oid_id','desc')->find();
|
|
|
+//
|
|
|
+// $nextOid = $maxOid['oid_id'] ? $maxOid['oid_id'] + 1 : 1; // 如果没有记录则从1开始
|
|
|
+// // 插入数据到qcode_product表
|
|
|
+// foreach ($differences as $diff) {
|
|
|
+// $insertData = [
|
|
|
+// 'oid_id' => $nextOid++,
|
|
|
+// 'product_code' => $diff['product_code'],
|
|
|
+// 'product_name' => $diff['product_name'],
|
|
|
+// 'temple' => $diff['temple'],
|
|
|
+// 'main_unit' => $diff['main_unit'],
|
|
|
+// 'sec_unit' => $diff['sec_unit'],
|
|
|
+// 'proportion' => $diff['proportion'],
|
|
|
+// 'delete_time' => $diff['delete_time'] ?? '',
|
|
|
+// 'sync_flag' => $diff['sync_flag'] ?? 0,
|
|
|
+// 'code' => $diff['code'] ?? substr($diff['product_code'], 0, 4)
|
|
|
+// ];
|
|
|
+// $mongo->name('qcode_product')->insert($insertData);
|
|
|
+// }
|
|
|
+//
|
|
|
+// echo "成功插入 " . count($differences) . " 条记录";
|
|
|
+// }
|
|
|
+
|
|
|
}
|