diff --git a/app/common/service/ApprovalRecordsService.php b/app/common/service/ApprovalRecordsService.php index f0e33b1..6af6a56 100644 --- a/app/common/service/ApprovalRecordsService.php +++ b/app/common/service/ApprovalRecordsService.php @@ -4,6 +4,7 @@ namespace app\common\service; use app\common\model\User; use app\common\model\UserGroupMembers; +use support\Db; use app\common\validate\ApprovalRecordsValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\ApprovalRecords; @@ -118,6 +119,31 @@ class ApprovalRecordsService $config['where']['status'] = ['!=', 'pending']; } + // 业务筛选:pi_no 精确到PI号;keyword 匹配 单号/PI号(历史页原有搜索框此前后端未实现) + // 两个条件同时传时取交集 + $bizIdFilter = null; + if (!empty($p['pi_no'])) { + $ids = Db::table('stock_orders') + ->where('pi_no', 'like', '%' . trim((string)$p['pi_no']) . '%') + ->pluck('id')->toArray(); + $bizIdFilter = $ids ?: [0]; + } + if (!empty($p['keyword'])) { + $kw = '%' . trim((string)$p['keyword']) . '%'; + $ids = Db::table('stock_orders') + ->where(function ($q) use ($kw) { + $q->where('order_no', 'like', $kw) + ->orWhere('pi_no', 'like', $kw) + ->orWhere('customer_snapshot', 'like', $kw); + }) + ->pluck('id')->toArray(); + $ids = $ids ?: [0]; + $bizIdFilter = $bizIdFilter === null ? $ids : array_values(array_intersect($bizIdFilter, $ids)); + } + if ($bizIdFilter !== null) { + $config['where']['instance.biz_id'] = ['in', $bizIdFilter]; + } + $config['order']['id'] = 'desc'; $config['with'] = [