whereRaw( "(TRIM(CAST(`status` AS CHAR)) = '1' OR CAST(`status` AS UNSIGNED) = 1)" ); } public function index() { $this->relationSearch = false; $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $ccydhKw = trim((string)$this->request->get('ccydh', '')); $query = Db::table('purchase_order'); $this->applyPurchaseOrderCompletedWhere($query); if ($ccydhKw !== '') { $query->where('CCYDH', 'like', '%' . $ccydhKw . '%'); } if (is_callable($where)) { $query->where($where); } $total = (clone $query)->count(); $sortField = preg_match('/^[a-zA-Z0-9_]+$/', (string)$sort) ? $sort : 'id'; $orderDir = strtoupper((string)$order) === 'ASC' ? 'ASC' : 'DESC'; $rows = $query ->field('id,scydgy_id,CCYDH,CYJMC,CGYMC,createtime,dStamp') ->order($sortField, $orderDir) ->limit($offset, $limit) ->select(); if (!is_array($rows)) { $rows = []; } $out = []; foreach ($rows as $r) { if (!is_array($r)) { continue; } $sid = (int)($r['scydgy_id'] ?? 0); $doneText = ''; $ct = $r['createtime'] ?? null; if (is_numeric($ct) && (int)$ct > 946684800) { $doneText = date('Y-m-d H:i:s', (int)$ct); } elseif (is_string($ct) && trim($ct) !== '' && stripos(trim($ct), '0000-00-00') !== 0) { $doneText = trim($ct); } elseif (!empty($r['dStamp']) && stripos((string)$r['dStamp'], '0000-00-00') !== 0) { $doneText = trim((string)$r['dStamp']); } $out[] = [ 'id' => (int)($r['id'] ?? 0), 'scydgy_id' => $sid, 'CCYDH' => trim((string)($r['CCYDH'] ?? '')), 'CYJMC' => trim((string)($r['CYJMC'] ?? '')), 'CGYMC' => trim((string)($r['CGYMC'] ?? '')), 'createtime_text' => $doneText, ]; } return json(['total' => $total, 'rows' => $out]); } return $this->view->fetch(); } }