|
|
@@ -51,6 +51,7 @@ class QcodeBach extends Backend
|
|
|
|
|
|
/**
|
|
|
* 主表查询
|
|
|
+ * search搜索
|
|
|
*/
|
|
|
public function bach()
|
|
|
{
|
|
|
@@ -72,6 +73,43 @@ class QcodeBach extends Backend
|
|
|
// 获取前端传参
|
|
|
$req = input();
|
|
|
|
|
|
+ // 顶部快速搜索(Bootstrap Table 传 search,与 buildparams 一致)
|
|
|
+ $quickSearch = trim((string)($req['search'] ?? $req['searchText'] ?? ''));
|
|
|
+ if ($quickSearch !== '') {
|
|
|
+ $pattern = '.*' . preg_quote($quickSearch, '/') . '.*';
|
|
|
+ $where['matter_name|supplier_name|bach_num|print_date'] = new \MongoDB\BSON\Regex($pattern, 'i');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通用搜索:filter + op(FastAdmin 表单提交 JSON)
|
|
|
+ $filter = isset($req['filter']) ? json_decode($req['filter'], true) : [];
|
|
|
+ $op = isset($req['op']) ? json_decode($req['op'], true) : [];
|
|
|
+ if (!is_array($filter)) {
|
|
|
+ $filter = [];
|
|
|
+ }
|
|
|
+ if (!is_array($op)) {
|
|
|
+ $op = [];
|
|
|
+ }
|
|
|
+ $allowedFilterFields = ['matter_name', 'supplier_name', 'bach_num', 'print_date', 'matter_no'];
|
|
|
+ foreach ($filter as $field => $val) {
|
|
|
+ if (!in_array($field, $allowedFilterFields, true)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($val === '' || $val === null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $sym = strtoupper((string)($op[$field] ?? 'LIKE'));
|
|
|
+ if ($sym === '=') {
|
|
|
+ $where[$field] = is_string($val) ? trim($val) : $val;
|
|
|
+ } elseif (strpos($sym, 'NOT LIKE') === 0) {
|
|
|
+ // 通用搜索暂不支持 NOT LIKE
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ // LIKE / LIKE %...% 等按包含匹配(MongoDB 正则)
|
|
|
+ $pattern = '.*' . preg_quote(trim((string)$val), '/') . '.*';
|
|
|
+ $where[$field] = new \MongoDB\BSON\Regex($pattern, 'i');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 安全处理排序字段和排序方式
|
|
|
$sort = $req['sort'] ?? 'id';
|
|
|
$sort = $sort == 'id' ? '_id' : $sort;
|
|
|
@@ -151,6 +189,109 @@ class QcodeBach extends Backend
|
|
|
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+// /**
|
|
|
+// * 主表查询
|
|
|
+// * search搜索
|
|
|
+// */
|
|
|
+// public function bach()
|
|
|
+// {
|
|
|
+// $this->relationSearch = false;
|
|
|
+// $this->request->filter(['strip_tags', 'trim']);
|
|
|
+//
|
|
|
+// if ($this->request->isAjax()) {
|
|
|
+// // 如果是 Selectpage 请求则跳转
|
|
|
+// if ($this->request->request('keyField')) {
|
|
|
+// return $this->selectpage();
|
|
|
+// }
|
|
|
+//
|
|
|
+// $userInfo = Session::get('admin');
|
|
|
+// $company_id = (int)$userInfo['company'];
|
|
|
+//
|
|
|
+// // 默认条件:未删除
|
|
|
+// $where = ['delete_time' => ''];
|
|
|
+//
|
|
|
+// // 获取前端传参
|
|
|
+// $req = input();
|
|
|
+//
|
|
|
+// // 安全处理排序字段和排序方式
|
|
|
+// $sort = $req['sort'] ?? 'id';
|
|
|
+// $sort = $sort == 'id' ? '_id' : $sort;
|
|
|
+//
|
|
|
+// // 定义允许排序的字段,防止注入
|
|
|
+// $allowedSortFields = ['_id', 'create_time', 'update_time', 'name']; // 按实际情况添加
|
|
|
+// if (!in_array($sort, $allowedSortFields)) {
|
|
|
+// $sort = '_id';
|
|
|
+// }
|
|
|
+//
|
|
|
+// $orderStr = strtolower($req['order'] ?? 'desc');
|
|
|
+// $order = $orderStr === 'asc' ? 1 : -1; // MongoDB 排序必须是 1 或 -1
|
|
|
+//
|
|
|
+// $offset = $req['offset'] ?? 0;
|
|
|
+// $limit = $req['limit'] ?? 20;
|
|
|
+//
|
|
|
+// // 解析 filter 筛选条件
|
|
|
+//// $filter = json_decode($req['filter'], true);
|
|
|
+//// if (is_array($filter)) {
|
|
|
+//// foreach ($filter as $k => $v) {
|
|
|
+//// $where[$k] = new \MongoDB\BSON\Regex($v);
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//
|
|
|
+// $list = [];
|
|
|
+//
|
|
|
+// // 超级管理员:查询所有公司
|
|
|
+// if (isSuperAdmin()) {
|
|
|
+// $companies = Db::name('admin')
|
|
|
+// ->field('company')
|
|
|
+// ->where('company', '<>', '')
|
|
|
+// ->where('kes', '<>', '')
|
|
|
+// ->distinct(true)
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// foreach ($companies as $row) {
|
|
|
+// $cid = $row['company'];
|
|
|
+// $rows = $this->model->name($cid . '_qcode_bach')
|
|
|
+// ->where($where)
|
|
|
+// ->select(); // 不分页,后续统一处理
|
|
|
+//
|
|
|
+// foreach ($rows as &$item) {
|
|
|
+// $oid = $item['_id']->jsonSerialize();
|
|
|
+// $item['id'] = $oid['$oid'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $list = array_merge($list, $rows);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 全局排序(按 create_time 排序)
|
|
|
+// usort($list, function ($a, $b) use ($sort, $order) {
|
|
|
+// $valA = $a[$sort] ?? 0;
|
|
|
+// $valB = $b[$sort] ?? 0;
|
|
|
+// return $order === 1 ? ($valA <=> $valB) : ($valB <=> $valA);
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 总数与分页
|
|
|
+// $total = count($list);
|
|
|
+// $list = array_slice($list, $offset, $limit);
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// // 普通用户:只查本公司
|
|
|
+// $total = $this->model->name($company_id . '_qcode_bach')->where($where)->count();
|
|
|
+// $list = $this->model->name($company_id . '_qcode_bach')->where($where)
|
|
|
+// ->order([$sort => $order])
|
|
|
+// ->limit($limit)
|
|
|
+// ->skip($offset)
|
|
|
+// ->select();
|
|
|
+// foreach ($list as &$item) {
|
|
|
+// $oid = $item['_id']->jsonSerialize();
|
|
|
+// $item['id'] = $oid['$oid'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return json(["total" => $total, "rows" => $list]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// return $this->view->fetch();
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 大件列表
|