Procuremenarchive.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 外发采购 — 历史存证档案查询(已完结工序 + 操作记录详情)
  7. *
  8. * @icon fa fa-archive
  9. */
  10. class Procuremenarchive extends Backend
  11. {
  12. protected $searchFields = 'CCYDH,CYJMC,CGYMC';
  13. /** purchase_order.status 为已完结(兼容 varchar / 数字 / 首尾空格) */
  14. protected function applyPurchaseOrderCompletedWhere($query): void
  15. {
  16. $query->whereRaw(
  17. "(TRIM(CAST(`status` AS CHAR)) = '1' OR CAST(`status` AS UNSIGNED) = 1)"
  18. );
  19. }
  20. public function index()
  21. {
  22. $this->relationSearch = false;
  23. $this->request->filter(['strip_tags', 'trim']);
  24. if ($this->request->isAjax()) {
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. $ccydhKw = trim((string)$this->request->get('ccydh', ''));
  27. $query = Db::table('purchase_order');
  28. $this->applyPurchaseOrderCompletedWhere($query);
  29. if ($ccydhKw !== '') {
  30. $query->where('CCYDH', 'like', '%' . $ccydhKw . '%');
  31. }
  32. if (is_callable($where)) {
  33. $query->where($where);
  34. }
  35. $total = (clone $query)->count();
  36. $sortField = preg_match('/^[a-zA-Z0-9_]+$/', (string)$sort) ? $sort : 'id';
  37. $orderDir = strtoupper((string)$order) === 'ASC' ? 'ASC' : 'DESC';
  38. $rows = $query
  39. ->field('id,scydgy_id,CCYDH,CYJMC,CGYMC,createtime,dStamp')
  40. ->order($sortField, $orderDir)
  41. ->limit($offset, $limit)
  42. ->select();
  43. if (!is_array($rows)) {
  44. $rows = [];
  45. }
  46. $out = [];
  47. foreach ($rows as $r) {
  48. if (!is_array($r)) {
  49. continue;
  50. }
  51. $sid = (int)($r['scydgy_id'] ?? 0);
  52. $doneText = '';
  53. $ct = $r['createtime'] ?? null;
  54. if (is_numeric($ct) && (int)$ct > 946684800) {
  55. $doneText = date('Y-m-d H:i:s', (int)$ct);
  56. } elseif (is_string($ct) && trim($ct) !== '' && stripos(trim($ct), '0000-00-00') !== 0) {
  57. $doneText = trim($ct);
  58. } elseif (!empty($r['dStamp']) && stripos((string)$r['dStamp'], '0000-00-00') !== 0) {
  59. $doneText = trim((string)$r['dStamp']);
  60. }
  61. $out[] = [
  62. 'id' => (int)($r['id'] ?? 0),
  63. 'scydgy_id' => $sid,
  64. 'CCYDH' => trim((string)($r['CCYDH'] ?? '')),
  65. 'CYJMC' => trim((string)($r['CYJMC'] ?? '')),
  66. 'CGYMC' => trim((string)($r['CGYMC'] ?? '')),
  67. 'createtime_text' => $doneText,
  68. ];
  69. }
  70. return json(['total' => $total, 'rows' => $out]);
  71. }
  72. return $this->view->fetch();
  73. }
  74. }