|
|
@@ -151,16 +151,35 @@ class Course extends Api
|
|
|
if (!empty($param['order'])) {
|
|
|
$where['a.Gd_cpdh|a.成品代号'] = ['like', $param['order'] . '%'];
|
|
|
}
|
|
|
- if (!empty($param['search'])) {
|
|
|
- $where['a.Gd_gdbh|a.Gd_cpmc|a.成品名称'] = ['like', '%' . $param['search'] . '%'];
|
|
|
- }
|
|
|
- $list = \db('工单_基本资料')
|
|
|
+ $listQuery = \db('工单_基本资料')
|
|
|
->alias('a')
|
|
|
->join('工单_印件资料 b', 'a.Gd_gdbh = b.Yj_Gdbh')
|
|
|
->field('b.Yj_Gdbh as 工单编号,b.yj_Yjno,b.yj_Yjdh as 印件代号,b.yj_yjmc as 印件名称,b.yj_ls as 联数,a.投料大箱 as 投料大箱,b.yj_平张投料 as 计划投料')
|
|
|
->where($where)
|
|
|
->where('a.gd_statu', '2-生产中')
|
|
|
- ->where('a.Gd_gdbh', 'like', 'Y%')
|
|
|
+ ->where('a.Gd_gdbh', 'like', 'Y%');
|
|
|
+ $workOrderNo = trim((string)($param['工单编号'] ?? ''));
|
|
|
+ if ($workOrderNo !== '') {
|
|
|
+ $listQuery->where('a.Gd_gdbh', 'like', '%' . $this->courseLikeKeyword($workOrderNo) . '%');
|
|
|
+ }
|
|
|
+ $productName = trim((string)($param['产品名称'] ?? ''));
|
|
|
+ if ($productName !== '') {
|
|
|
+ $nameLike = '%' . $this->courseLikeKeyword($productName) . '%';
|
|
|
+ $listQuery->where(function ($query) use ($nameLike) {
|
|
|
+ $query->where('a.成品名称', 'like', $nameLike)
|
|
|
+ ->whereOr('a.Gd_cpmc', 'like', $nameLike)
|
|
|
+ ->whereOr('b.yj_yjmc', 'like', $nameLike);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $salesOrderNo = trim((string)($param['销售订单号'] ?? ''));
|
|
|
+ if ($salesOrderNo !== '') {
|
|
|
+ $listQuery->where('a.销售订单号', 'like', '%' . $this->courseLikeKeyword($salesOrderNo) . '%');
|
|
|
+ }
|
|
|
+ $this->applyCourseRange($listQuery, 'a.投料大箱', $param['投料大箱起'] ?? '', $param['投料大箱止'] ?? '');
|
|
|
+ $this->applyCourseRange($listQuery, 'a.接单日期', $param['接单日期起'] ?? '', $param['接单日期止'] ?? '', true);
|
|
|
+ $this->applyCourseRange($listQuery, 'a.交货日期', $param['交货日期起'] ?? '', $param['交货日期止'] ?? '', true);
|
|
|
+ $this->applyCourseRange($listQuery, 'b.yj_平张投料', $param['计划投料起'] ?? '', $param['计划投料止'] ?? '');
|
|
|
+ $list = $listQuery
|
|
|
->group('b.Yj_Gdbh,b.yj_Yjno')
|
|
|
->select();
|
|
|
if (empty($list)) {
|
|
|
@@ -224,4 +243,27 @@ class Course extends Api
|
|
|
}
|
|
|
$this->success('成功', $list);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 范围条件只在传入起或止时生效,日期止取到当天结束
|
|
|
+ */
|
|
|
+ private function applyCourseRange($query, $field, $from, $to, $isDate = false)
|
|
|
+ {
|
|
|
+ $from = trim((string)$from);
|
|
|
+ $to = trim((string)$to);
|
|
|
+ if ($from !== '') {
|
|
|
+ $query->where($field, '>=', $from);
|
|
|
+ }
|
|
|
+ if ($to !== '') {
|
|
|
+ if ($isDate && preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
|
|
|
+ $to .= ' 23:59:59';
|
|
|
+ }
|
|
|
+ $query->where($field, '<=', $to);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function courseLikeKeyword($keyword)
|
|
|
+ {
|
|
|
+ return addcslashes((string)$keyword, '%_\\');
|
|
|
+ }
|
|
|
}
|