| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- /**
- * 外发采购 — 历史存证档案查询(已完结工序 + 操作记录详情)
- *
- * @icon fa fa-archive
- */
- class Procuremenarchive extends Backend
- {
- protected $searchFields = 'CCYDH,CYJMC,CGYMC';
- /** purchase_order.status 为已完结(兼容 varchar / 数字 / 首尾空格) */
- protected function applyPurchaseOrderCompletedWhere($query): void
- {
- $query->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();
- }
- }
|