|
|
@@ -469,14 +469,15 @@ class Supplierservicescore extends Backend
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 某供应商某月参与评分的订单明细(开标/指定后按时间写入的评分记录)
|
|
|
- * 一单一行(多工序顿号间隔);按开标/指定时间倒序,不把整月汇总成一行
|
|
|
+ * 本月订单明细:已下发订单按「下发批次」(pick_time) 分行;
|
|
|
+ * 同一批次内多工序顿号合并,不同下发时间不合并。
|
|
|
+ * 仅返回已做质量评分且已完结的订单。
|
|
|
*
|
|
|
* @return array<int, array<string, mixed>>
|
|
|
*/
|
|
|
/**
|
|
|
- * 本月订单明细:已下发订单按「下发批次」(pick_time) 分行;
|
|
|
- * 同一批次内多工序顿号合并,不同下发时间不合并。
|
|
|
+ * 本月订单明细:与质量得分同源 —— 该供应商本月「质量评分」订单
|
|
|
+ * (不再依赖招标评分表,也不强制已完结;与 calcQualityScoreFromInbound 一致)
|
|
|
*
|
|
|
* @return array<int, array<string, mixed>>
|
|
|
*/
|
|
|
@@ -488,49 +489,127 @@ class Supplierservicescore extends Backend
|
|
|
return [];
|
|
|
}
|
|
|
ProcuremenSupplierScore::ensureSchema();
|
|
|
+
|
|
|
+ // 1) 与质量分同一来源:入库/质量评分表
|
|
|
try {
|
|
|
- $scoreRows = \think\Db::table(ProcuremenSupplierScore::TABLE_SCORE)
|
|
|
- ->where('ym', $ym)
|
|
|
+ $scoreRows = \think\Db::table('purchase_order_inbound_score')
|
|
|
->where('company_name', $companyName)
|
|
|
- ->field('ccydh,score,rank_no,quality_score,price_score,price_sum,lead_score,lead_days_sum,createtime')
|
|
|
- ->order('createtime', 'desc')
|
|
|
- ->order('ccydh', 'asc')
|
|
|
+ ->where(function ($q) use ($ym) {
|
|
|
+ $q->where('updatetime', 'like', $ym . '%')
|
|
|
+ ->whereOr('createtime', 'like', $ym . '%');
|
|
|
+ })
|
|
|
+ ->field('scydgy_id,ccydh,cyjmc,cgymc,result,delivery_status,customer_complaint,order_interrupt,remark,createtime,updatetime')
|
|
|
+ ->order('id', 'desc')
|
|
|
->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
- return [];
|
|
|
+ try {
|
|
|
+ $scoreRows = \think\Db::table('purchase_order_inbound_score')
|
|
|
+ ->where('company_name', $companyName)
|
|
|
+ ->where(function ($q) use ($ym) {
|
|
|
+ $q->where('updatetime', 'like', $ym . '%')
|
|
|
+ ->whereOr('createtime', 'like', $ym . '%');
|
|
|
+ })
|
|
|
+ ->field('scydgy_id,ccydh,cyjmc,cgymc,result,remark,createtime,updatetime')
|
|
|
+ ->order('id', 'desc')
|
|
|
+ ->select();
|
|
|
+ } catch (\Throwable $e2) {
|
|
|
+ $scoreRows = [];
|
|
|
+ }
|
|
|
}
|
|
|
if (!is_array($scoreRows) || $scoreRows === []) {
|
|
|
return [];
|
|
|
}
|
|
|
- $scoreByCcydh = [];
|
|
|
+
|
|
|
+ /** @var array<string, array<string, mixed>> $byCcydh */
|
|
|
+ $byCcydh = [];
|
|
|
+ $sidSet = [];
|
|
|
foreach ($scoreRows as $r) {
|
|
|
if (!is_array($r)) {
|
|
|
continue;
|
|
|
}
|
|
|
- $c = trim((string)($r['ccydh'] ?? ''));
|
|
|
- // 手工新增订单号 YW… 不进本月订单明细
|
|
|
- if ($c === '' || stripos($c, 'YW') === 0) {
|
|
|
+ $ccydh = trim((string)($r['ccydh'] ?? ''));
|
|
|
+ $result = trim((string)($r['result'] ?? ''));
|
|
|
+ if ($ccydh === '' || ($result !== '合格' && $result !== '不合格')) {
|
|
|
continue;
|
|
|
}
|
|
|
- // 同单可能有重复评分行时保留最新一条(已按 createtime desc)
|
|
|
- if (!isset($scoreByCcydh[$c])) {
|
|
|
- $scoreByCcydh[$c] = $r;
|
|
|
+ $sid = (int)($r['scydgy_id'] ?? 0);
|
|
|
+ if ($sid > 0) {
|
|
|
+ $sidSet[$sid] = true;
|
|
|
+ }
|
|
|
+ $scoreTime = trim((string)($r['updatetime'] ?? ''));
|
|
|
+ if ($scoreTime === '' || preg_match('/^0000-00-00/', $scoreTime)) {
|
|
|
+ $scoreTime = trim((string)($r['createtime'] ?? ''));
|
|
|
+ }
|
|
|
+ if (!isset($byCcydh[$ccydh])) {
|
|
|
+ $ds = trim((string)($r['delivery_status'] ?? ''));
|
|
|
+ if ($ds !== '准时' && $ds !== '滞后') {
|
|
|
+ $ds = '';
|
|
|
+ }
|
|
|
+ $byCcydh[$ccydh] = [
|
|
|
+ 'CCYDH' => $ccydh,
|
|
|
+ 'scydgy_id' => $sid > 0 ? $sid : 0,
|
|
|
+ 'scydgy_ids' => $sid > 0 ? [$sid] : [],
|
|
|
+ 'CYJMC' => trim((string)($r['cyjmc'] ?? '')),
|
|
|
+ 'CGYMC_list' => [],
|
|
|
+ 'inbound_result' => $result,
|
|
|
+ 'delivery_status' => $ds,
|
|
|
+ 'customer_complaint' => (int)($r['customer_complaint'] ?? 0) === 1 ? 1 : 0,
|
|
|
+ 'order_interrupt' => (int)($r['order_interrupt'] ?? 0) === 1 ? 1 : 0,
|
|
|
+ 'inbound_remark' => trim((string)($r['remark'] ?? '')),
|
|
|
+ 'score_time' => $scoreTime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $g = &$byCcydh[$ccydh];
|
|
|
+ // 任一工序不合格 → 整单不合格(与质量分统计一致)
|
|
|
+ if ($result === '不合格') {
|
|
|
+ $g['inbound_result'] = '不合格';
|
|
|
+ }
|
|
|
+ if ($sid > 0) {
|
|
|
+ if ($g['scydgy_id'] <= 0) {
|
|
|
+ $g['scydgy_id'] = $sid;
|
|
|
+ }
|
|
|
+ if (!in_array($sid, $g['scydgy_ids'], true)) {
|
|
|
+ $g['scydgy_ids'][] = $sid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $gymc = trim((string)($r['cgymc'] ?? ''));
|
|
|
+ if ($gymc !== '' && !in_array($gymc, $g['CGYMC_list'], true)) {
|
|
|
+ $g['CGYMC_list'][] = $gymc;
|
|
|
+ }
|
|
|
+ if ($g['CYJMC'] === '') {
|
|
|
+ $g['CYJMC'] = trim((string)($r['cyjmc'] ?? ''));
|
|
|
}
|
|
|
+ if ($g['inbound_remark'] === '') {
|
|
|
+ $g['inbound_remark'] = trim((string)($r['remark'] ?? ''));
|
|
|
+ }
|
|
|
+ if ($g['delivery_status'] === '') {
|
|
|
+ $ds = trim((string)($r['delivery_status'] ?? ''));
|
|
|
+ if ($ds === '准时' || $ds === '滞后') {
|
|
|
+ $g['delivery_status'] = $ds;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ((int)($r['customer_complaint'] ?? 0) === 1) {
|
|
|
+ $g['customer_complaint'] = 1;
|
|
|
+ }
|
|
|
+ if ((int)($r['order_interrupt'] ?? 0) === 1) {
|
|
|
+ $g['order_interrupt'] = 1;
|
|
|
+ }
|
|
|
+ if ($scoreTime !== '' && ($g['score_time'] === '' || strcmp($scoreTime, $g['score_time']) > 0)) {
|
|
|
+ $g['score_time'] = $scoreTime;
|
|
|
+ }
|
|
|
+ unset($g);
|
|
|
}
|
|
|
- if ($scoreByCcydh === []) {
|
|
|
+ if ($byCcydh === []) {
|
|
|
return [];
|
|
|
}
|
|
|
- $manualCcydh = [];
|
|
|
- /** @var array<string, array<string, array<string, mixed>>> $batchesByCcydh */
|
|
|
- $batchesByCcydh = [];
|
|
|
- /** @var array<int, array<string, mixed>> $issuedPoRows */
|
|
|
- $issuedPoRows = [];
|
|
|
- $sidList = [];
|
|
|
+
|
|
|
+ // 2) 补充采购单展示字段
|
|
|
+ $poByCcydh = [];
|
|
|
try {
|
|
|
$poRows = \think\Db::table('purchase_order')
|
|
|
- ->where('CCYDH', 'in', array_keys($scoreByCcydh))
|
|
|
+ ->where('CCYDH', 'in', array_keys($byCcydh))
|
|
|
->whereRaw('(mod_rq IS NULL OR TRIM(CAST(mod_rq AS CHAR(32))) = \'\' OR TRIM(CAST(mod_rq AS CHAR(32))) LIKE \'0000-00-00%\')')
|
|
|
- ->field('CCYDH,CYJMC,CGYMC,CCLBMMC,CDW,This_quantity,ceilingPrice,pick_company_name,wflow_status,status,pick_time,scydgy_id')
|
|
|
+ ->field('CCYDH,CYJMC,CGYMC,CCLBMMC,CDW,pick_company_name,wflow_status,status,pick_time,scydgy_id')
|
|
|
->order('id', 'asc')
|
|
|
->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
@@ -542,193 +621,158 @@ class Supplierservicescore extends Backend
|
|
|
continue;
|
|
|
}
|
|
|
$c = trim((string)($po['CCYDH'] ?? ''));
|
|
|
- if ($c === '' || !isset($scoreByCcydh[$c])) {
|
|
|
+ if ($c === '' || !isset($byCcydh[$c])) {
|
|
|
continue;
|
|
|
}
|
|
|
+ if (!isset($poByCcydh[$c])) {
|
|
|
+ $poByCcydh[$c] = [
|
|
|
+ 'CYJMC' => '',
|
|
|
+ 'CCLBMMC' => '',
|
|
|
+ 'CGYMC_list' => [],
|
|
|
+ 'CDW' => '',
|
|
|
+ 'pick_company_name' => '',
|
|
|
+ 'wflow_status' => '',
|
|
|
+ 'status' => '',
|
|
|
+ 'pick_time' => '',
|
|
|
+ 'completed' => false,
|
|
|
+ 'picked_match' => false,
|
|
|
+ 'scydgy_id' => 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $p = &$poByCcydh[$c];
|
|
|
$sid = (int)($po['scydgy_id'] ?? 0);
|
|
|
- if ($sid < 0) {
|
|
|
- $manualCcydh[$c] = true;
|
|
|
- continue;
|
|
|
+ if ($p['scydgy_id'] <= 0 && $sid > 0) {
|
|
|
+ $p['scydgy_id'] = $sid;
|
|
|
}
|
|
|
- if (isset($manualCcydh[$c])) {
|
|
|
- continue;
|
|
|
+ if ($p['CYJMC'] === '') {
|
|
|
+ $p['CYJMC'] = trim((string)($po['CYJMC'] ?? ''));
|
|
|
}
|
|
|
- $pickTime = trim((string)($po['pick_time'] ?? ''));
|
|
|
- if ($pickTime === '' || preg_match('/^0000-00-00/', $pickTime)) {
|
|
|
- continue;
|
|
|
+ if ($p['CCLBMMC'] === '') {
|
|
|
+ $p['CCLBMMC'] = trim((string)($po['CCLBMMC'] ?? ''));
|
|
|
}
|
|
|
- $issuedPoRows[] = $po;
|
|
|
- if ($sid > 0) {
|
|
|
- $sidList[$sid] = true;
|
|
|
+ if ($p['CDW'] === '') {
|
|
|
+ $p['CDW'] = trim((string)($po['CDW'] ?? ''));
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- // 按工序首次下发日志时间分批(避免整单 pick_time 被后次下发覆盖后合到一行)
|
|
|
- $firstIssueBySid = $this->loadFirstIssueTimeByScydgyIds(array_keys($sidList));
|
|
|
- foreach ($issuedPoRows as $po) {
|
|
|
- if (isset($manualCcydh[trim((string)($po['CCYDH'] ?? ''))])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $c = trim((string)($po['CCYDH'] ?? ''));
|
|
|
- $sid = (int)($po['scydgy_id'] ?? 0);
|
|
|
- $pickTime = trim((string)($po['pick_time'] ?? ''));
|
|
|
- $batchKey = '';
|
|
|
- if ($sid > 0 && isset($firstIssueBySid[$sid])) {
|
|
|
- $batchKey = $firstIssueBySid[$sid];
|
|
|
- }
|
|
|
- if ($batchKey === '') {
|
|
|
- $batchKey = $pickTime;
|
|
|
- }
|
|
|
- if ($batchKey === '' || preg_match('/^0000-00-00/', $batchKey)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 同一分钟内视为同一次下发(循环写入可能差 1 秒)
|
|
|
- $batchGroup = $batchKey;
|
|
|
- if (preg_match('/^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2})/', $batchKey, $m)) {
|
|
|
- $batchGroup = $m[1];
|
|
|
- }
|
|
|
- if (!isset($batchesByCcydh[$c])) {
|
|
|
- $batchesByCcydh[$c] = [];
|
|
|
- }
|
|
|
- if (!isset($batchesByCcydh[$c][$batchGroup])) {
|
|
|
- $batchesByCcydh[$c][$batchGroup] = [
|
|
|
- 'scydgy_id' => $sid > 0 ? $sid : 0,
|
|
|
- 'scydgy_ids' => [],
|
|
|
- 'CYJMC' => trim((string)($po['CYJMC'] ?? '')),
|
|
|
- 'CCLBMMC' => trim((string)($po['CCLBMMC'] ?? '')),
|
|
|
- 'CGYMC_list' => [],
|
|
|
- 'CDW' => trim((string)($po['CDW'] ?? '')),
|
|
|
- 'pick_company_name' => trim((string)($po['pick_company_name'] ?? '')),
|
|
|
- 'wflow_status' => trim((string)($po['wflow_status'] ?? '')),
|
|
|
- 'status' => trim((string)($po['status'] ?? '')),
|
|
|
- 'pick_time' => $batchKey,
|
|
|
- 'completed' => false,
|
|
|
- 'picked_match' => false,
|
|
|
- ];
|
|
|
- }
|
|
|
- $batch = &$batchesByCcydh[$c][$batchGroup];
|
|
|
- if ($batch['scydgy_id'] <= 0 && $sid > 0) {
|
|
|
- $batch['scydgy_id'] = $sid;
|
|
|
- }
|
|
|
- if ($sid > 0 && !in_array($sid, $batch['scydgy_ids'], true)) {
|
|
|
- $batch['scydgy_ids'][] = $sid;
|
|
|
- }
|
|
|
- // 展示时间取该批次内最早时间
|
|
|
- if ($batch['pick_time'] === '' || strcmp($batchKey, $batch['pick_time']) < 0) {
|
|
|
- $batch['pick_time'] = $batchKey;
|
|
|
- }
|
|
|
- if ($batch['CYJMC'] === '') {
|
|
|
- $batch['CYJMC'] = trim((string)($po['CYJMC'] ?? ''));
|
|
|
- }
|
|
|
- if ($batch['CCLBMMC'] === '') {
|
|
|
- $batch['CCLBMMC'] = trim((string)($po['CCLBMMC'] ?? ''));
|
|
|
- }
|
|
|
- $g = trim((string)($po['CGYMC'] ?? ''));
|
|
|
- if ($g !== '' && !in_array($g, $batch['CGYMC_list'], true)) {
|
|
|
- $batch['CGYMC_list'][] = $g;
|
|
|
- }
|
|
|
- $pn = trim((string)($po['pick_company_name'] ?? ''));
|
|
|
- if ($pn !== '') {
|
|
|
- if ($batch['pick_company_name'] === '') {
|
|
|
- $batch['pick_company_name'] = $pn;
|
|
|
- }
|
|
|
- if ($pn === $companyName) {
|
|
|
- $batch['picked_match'] = true;
|
|
|
+ $g = trim((string)($po['CGYMC'] ?? ''));
|
|
|
+ if ($g !== '' && !in_array($g, $p['CGYMC_list'], true)) {
|
|
|
+ $p['CGYMC_list'][] = $g;
|
|
|
}
|
|
|
- }
|
|
|
- if (\app\common\library\ProcuremenStatus::isPoCompleted($po['status'] ?? '')) {
|
|
|
- $batch['completed'] = true;
|
|
|
- $batch['status'] = \app\common\library\ProcuremenStatus::PO_COMPLETED;
|
|
|
- }
|
|
|
- if (\app\common\library\ProcuremenStatus::isWflowApproved($po['wflow_status'] ?? '')) {
|
|
|
- $batch['wflow_status'] = \app\common\library\ProcuremenStatus::WFLOW_APPROVED;
|
|
|
- } elseif ($batch['wflow_status'] === '' && trim((string)($po['wflow_status'] ?? '')) !== '') {
|
|
|
- $batch['wflow_status'] = trim((string)$po['wflow_status']);
|
|
|
- }
|
|
|
- unset($batch);
|
|
|
- }
|
|
|
-
|
|
|
- $out = [];
|
|
|
- $allSids = [];
|
|
|
- foreach ($batchesByCcydh as $ccydhBatches) {
|
|
|
- if (!is_array($ccydhBatches)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- foreach ($ccydhBatches as $batch) {
|
|
|
- if (!is_array($batch)) {
|
|
|
- continue;
|
|
|
+ $pn = trim((string)($po['pick_company_name'] ?? ''));
|
|
|
+ if ($pn !== '') {
|
|
|
+ if ($p['pick_company_name'] === '') {
|
|
|
+ $p['pick_company_name'] = $pn;
|
|
|
+ }
|
|
|
+ if ($pn === $companyName) {
|
|
|
+ $p['picked_match'] = true;
|
|
|
+ }
|
|
|
}
|
|
|
- foreach ((array)($batch['scydgy_ids'] ?? []) as $sidItem) {
|
|
|
- $sidItem = (int)$sidItem;
|
|
|
- if ($sidItem > 0) {
|
|
|
- $allSids[$sidItem] = true;
|
|
|
+ $pt = trim((string)($po['pick_time'] ?? ''));
|
|
|
+ if ($pt !== '' && !preg_match('/^0000-00-00/', $pt)) {
|
|
|
+ if ($p['pick_time'] === '' || strcmp($pt, $p['pick_time']) < 0) {
|
|
|
+ $p['pick_time'] = $pt;
|
|
|
}
|
|
|
}
|
|
|
- $one = (int)($batch['scydgy_id'] ?? 0);
|
|
|
- if ($one > 0) {
|
|
|
- $allSids[$one] = true;
|
|
|
+ if (\app\common\library\ProcuremenStatus::isPoCompleted($po['status'] ?? '')) {
|
|
|
+ $p['completed'] = true;
|
|
|
+ $p['status'] = \app\common\library\ProcuremenStatus::PO_COMPLETED;
|
|
|
+ } elseif ($p['status'] === '' && trim((string)($po['status'] ?? '')) !== '') {
|
|
|
+ $p['status'] = trim((string)$po['status']);
|
|
|
}
|
|
|
+ if (\app\common\library\ProcuremenStatus::isWflowApproved($po['wflow_status'] ?? '')) {
|
|
|
+ $p['wflow_status'] = \app\common\library\ProcuremenStatus::WFLOW_APPROVED;
|
|
|
+ } elseif ($p['wflow_status'] === '' && trim((string)($po['wflow_status'] ?? '')) !== '') {
|
|
|
+ $p['wflow_status'] = trim((string)$po['wflow_status']);
|
|
|
+ }
|
|
|
+ unset($p);
|
|
|
}
|
|
|
}
|
|
|
- $inboundBySid = $this->loadInboundResultByScydgyIds(array_keys($allSids));
|
|
|
|
|
|
- foreach ($scoreByCcydh as $ccydh => $r) {
|
|
|
- if (isset($manualCcydh[$ccydh]) || !isset($batchesByCcydh[$ccydh])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- foreach ($batchesByCcydh[$ccydh] as $batch) {
|
|
|
- if (!is_array($batch)) {
|
|
|
+ // 3) 可选:招标评分表补排名/分项(没有也不影响展示)
|
|
|
+ $bidByCcydh = [];
|
|
|
+ try {
|
|
|
+ $bidRows = \think\Db::table(ProcuremenSupplierScore::TABLE_SCORE)
|
|
|
+ ->where('ym', $ym)
|
|
|
+ ->where('company_name', $companyName)
|
|
|
+ ->where('ccydh', 'in', array_keys($byCcydh))
|
|
|
+ ->field('ccydh,score,rank_no,quality_score,price_score,price_sum,lead_score,lead_days_sum,createtime')
|
|
|
+ ->order('createtime', 'desc')
|
|
|
+ ->select();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ $bidRows = [];
|
|
|
+ }
|
|
|
+ if (is_array($bidRows)) {
|
|
|
+ foreach ($bidRows as $br) {
|
|
|
+ if (!is_array($br)) {
|
|
|
continue;
|
|
|
}
|
|
|
- $pickTimeRaw = trim((string)($batch['pick_time'] ?? ''));
|
|
|
- if ($pickTimeRaw === '') {
|
|
|
+ $c = trim((string)($br['ccydh'] ?? ''));
|
|
|
+ if ($c === '' || isset($bidByCcydh[$c])) {
|
|
|
continue;
|
|
|
}
|
|
|
- $gymcList = is_array($batch['CGYMC_list'] ?? null) ? $batch['CGYMC_list'] : [];
|
|
|
- // 与详情页一致:采购确认通过或已完结后才展示中标/未中标
|
|
|
- $showBid = !empty($batch['completed'])
|
|
|
- || \app\common\library\ProcuremenStatus::isPoCompleted($batch['status'] ?? '')
|
|
|
- || \app\common\library\ProcuremenStatus::isWflowApproved($batch['wflow_status'] ?? '');
|
|
|
- $isPicked = !empty($batch['picked_match']) ? 1 : 0;
|
|
|
- $inboundResult = '';
|
|
|
- $sidCandidates = is_array($batch['scydgy_ids'] ?? null) ? $batch['scydgy_ids'] : [];
|
|
|
- $mainSid = (int)($batch['scydgy_id'] ?? 0);
|
|
|
- if ($mainSid > 0 && !in_array($mainSid, $sidCandidates, true)) {
|
|
|
- $sidCandidates[] = $mainSid;
|
|
|
- }
|
|
|
- foreach ($sidCandidates as $sidItem) {
|
|
|
- $sidItem = (int)$sidItem;
|
|
|
- if ($sidItem > 0 && isset($inboundBySid[$sidItem]) && $inboundBySid[$sidItem] !== '') {
|
|
|
- $inboundResult = $inboundBySid[$sidItem];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- $out[] = [
|
|
|
- 'seq_no' => 0,
|
|
|
- 'scydgy_id' => (int)($batch['scydgy_id'] ?? 0),
|
|
|
- 'CCYDH' => $ccydh,
|
|
|
- 'CYJMC' => (string)($batch['CYJMC'] ?? ''),
|
|
|
- 'CCLBMMC' => (string)($batch['CCLBMMC'] ?? ''),
|
|
|
- 'CGYMC' => $gymcList !== [] ? implode('、', $gymcList) : '',
|
|
|
- 'CDW' => (string)($batch['CDW'] ?? ''),
|
|
|
- 'pick_company_name' => (string)($batch['pick_company_name'] ?? ''),
|
|
|
- 'wflow_status' => (string)($batch['wflow_status'] ?? ''),
|
|
|
- 'status' => (string)($batch['status'] ?? ''),
|
|
|
- 'progress_text' => $this->formatMonthOrderProgressText($batch),
|
|
|
- 'pick_time' => $pickTimeRaw,
|
|
|
- 'issue_time' => \app\common\library\ProcuremenTime::formatDisplayDateTime($pickTimeRaw),
|
|
|
- 'score' => $r['score'] ?? null,
|
|
|
- 'rank_no' => (int)($r['rank_no'] ?? 0),
|
|
|
- 'quality_score' => $r['quality_score'] ?? null,
|
|
|
- 'price_score' => $r['price_score'] ?? null,
|
|
|
- 'price_sum' => $r['price_sum'] ?? null,
|
|
|
- 'lead_score' => $r['lead_score'] ?? null,
|
|
|
- 'lead_days_sum' => $r['lead_days_sum'] ?? null,
|
|
|
- 'is_picked' => $isPicked,
|
|
|
- 'show_bid_result' => $showBid ? 1 : 0,
|
|
|
- 'inbound_result' => $inboundResult,
|
|
|
- ];
|
|
|
+ $bidByCcydh[$c] = $br;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $out = [];
|
|
|
+ foreach ($byCcydh as $ccydh => $g) {
|
|
|
+ $po = $poByCcydh[$ccydh] ?? [];
|
|
|
+ $bid = $bidByCcydh[$ccydh] ?? [];
|
|
|
+ $gymcList = is_array($g['CGYMC_list'] ?? null) ? $g['CGYMC_list'] : [];
|
|
|
+ if ($gymcList === [] && is_array($po['CGYMC_list'] ?? null)) {
|
|
|
+ $gymcList = $po['CGYMC_list'];
|
|
|
+ }
|
|
|
+ $batch = [
|
|
|
+ 'completed' => !empty($po['completed']),
|
|
|
+ 'status' => (string)($po['status'] ?? ''),
|
|
|
+ 'wflow_status' => (string)($po['wflow_status'] ?? ''),
|
|
|
+ ];
|
|
|
+ $progressText = $this->formatMonthOrderProgressText($batch);
|
|
|
+ // 已质量评分:进度优先显示已完结,否则显示实际流程
|
|
|
+ if ($progressText === '待入库评分') {
|
|
|
+ $progressText = \app\common\library\ProcuremenStatus::PO_COMPLETED;
|
|
|
+ }
|
|
|
+ $showBid = !empty($po['completed'])
|
|
|
+ || \app\common\library\ProcuremenStatus::isPoCompleted($po['status'] ?? '')
|
|
|
+ || \app\common\library\ProcuremenStatus::isWflowApproved($po['wflow_status'] ?? '');
|
|
|
+ $pickTimeRaw = trim((string)($po['pick_time'] ?? ''));
|
|
|
+ if ($pickTimeRaw === '') {
|
|
|
+ $pickTimeRaw = trim((string)($g['score_time'] ?? ''));
|
|
|
+ }
|
|
|
+ $sid = (int)($g['scydgy_id'] ?? 0);
|
|
|
+ if ($sid <= 0) {
|
|
|
+ $sid = (int)($po['scydgy_id'] ?? 0);
|
|
|
}
|
|
|
+ $out[] = [
|
|
|
+ 'seq_no' => 0,
|
|
|
+ 'scydgy_id' => $sid,
|
|
|
+ 'CCYDH' => $ccydh,
|
|
|
+ 'CYJMC' => (string)(($g['CYJMC'] ?? '') !== '' ? $g['CYJMC'] : ($po['CYJMC'] ?? '')),
|
|
|
+ 'CCLBMMC' => (string)($po['CCLBMMC'] ?? ''),
|
|
|
+ 'CGYMC' => $gymcList !== [] ? implode('、', $gymcList) : '',
|
|
|
+ 'CDW' => (string)($po['CDW'] ?? ''),
|
|
|
+ 'pick_company_name' => (string)(($po['pick_company_name'] ?? '') !== '' ? $po['pick_company_name'] : $companyName),
|
|
|
+ 'wflow_status' => (string)($po['wflow_status'] ?? ''),
|
|
|
+ 'status' => (string)($po['status'] ?? ''),
|
|
|
+ 'progress_text' => $progressText,
|
|
|
+ 'pick_time' => $pickTimeRaw,
|
|
|
+ 'issue_time' => $pickTimeRaw !== ''
|
|
|
+ ? \app\common\library\ProcuremenTime::formatDisplayDateTime($pickTimeRaw)
|
|
|
+ : '',
|
|
|
+ 'score' => $bid['score'] ?? null,
|
|
|
+ 'rank_no' => (int)($bid['rank_no'] ?? 0),
|
|
|
+ 'quality_score' => $bid['quality_score'] ?? null,
|
|
|
+ 'price_score' => $bid['price_score'] ?? null,
|
|
|
+ 'price_sum' => $bid['price_sum'] ?? null,
|
|
|
+ 'lead_score' => $bid['lead_score'] ?? null,
|
|
|
+ 'lead_days_sum' => $bid['lead_days_sum'] ?? null,
|
|
|
+ 'is_picked' => !empty($po['picked_match']) ? 1 : 1,
|
|
|
+ 'show_bid_result' => $showBid ? 1 : 0,
|
|
|
+ 'inbound_result' => (string)($g['inbound_result'] ?? ''),
|
|
|
+ 'delivery_status' => (string)($g['delivery_status'] ?? ''),
|
|
|
+ 'customer_complaint' => (int)($g['customer_complaint'] ?? 0),
|
|
|
+ 'order_interrupt' => (int)($g['order_interrupt'] ?? 0),
|
|
|
+ 'inbound_remark' => (string)($g['inbound_remark'] ?? ''),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
usort($out, static function ($a, $b) {
|
|
|
@@ -737,10 +781,8 @@ class Supplierservicescore extends Backend
|
|
|
if ($ta !== $tb) {
|
|
|
return strcmp($tb, $ta);
|
|
|
}
|
|
|
- $ca = (string)($a['CCYDH'] ?? '');
|
|
|
- $cb = (string)($b['CCYDH'] ?? '');
|
|
|
|
|
|
- return strcmp($ca, $cb);
|
|
|
+ return strcmp((string)($a['CCYDH'] ?? ''), (string)($b['CCYDH'] ?? ''));
|
|
|
});
|
|
|
$total = count($out);
|
|
|
$seq = $total;
|
|
|
@@ -840,10 +882,10 @@ class Supplierservicescore extends Backend
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量读取入库评分结果(合格/不合格)
|
|
|
+ * 批量读取质量评分明细(是否合格 / 交货情况 / 客户投诉 / 订单中断 / 备注)
|
|
|
*
|
|
|
* @param int[] $scydgyIds
|
|
|
- * @return array<int, string> scydgy_id => 合格|不合格
|
|
|
+ * @return array<int, array{result:string,delivery_status:string,customer_complaint:int,order_interrupt:int,remark:string}>
|
|
|
*/
|
|
|
protected function loadInboundResultByScydgyIds(array $scydgyIds): array
|
|
|
{
|
|
|
@@ -855,10 +897,25 @@ class Supplierservicescore extends Backend
|
|
|
try {
|
|
|
$rows = \think\Db::table('purchase_order_inbound_score')
|
|
|
->where('scydgy_id', 'in', $ids)
|
|
|
- ->field('scydgy_id,result')
|
|
|
+ ->field('scydgy_id,result,delivery_status,customer_complaint,order_interrupt,remark')
|
|
|
->select();
|
|
|
} catch (\Throwable $e) {
|
|
|
- return [];
|
|
|
+ // 兼容旧表无新列
|
|
|
+ try {
|
|
|
+ $rows = \think\Db::table('purchase_order_inbound_score')
|
|
|
+ ->where('scydgy_id', 'in', $ids)
|
|
|
+ ->field('scydgy_id,result,customer_complaint,order_interrupt,remark')
|
|
|
+ ->select();
|
|
|
+ } catch (\Throwable $e2) {
|
|
|
+ try {
|
|
|
+ $rows = \think\Db::table('purchase_order_inbound_score')
|
|
|
+ ->where('scydgy_id', 'in', $ids)
|
|
|
+ ->field('scydgy_id,result,remark')
|
|
|
+ ->select();
|
|
|
+ } catch (\Throwable $e3) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if (!is_array($rows)) {
|
|
|
return [];
|
|
|
@@ -872,7 +929,17 @@ class Supplierservicescore extends Backend
|
|
|
if ($sid <= 0 || ($result !== '合格' && $result !== '不合格')) {
|
|
|
continue;
|
|
|
}
|
|
|
- $out[$sid] = $result;
|
|
|
+ $ds = trim((string)($r['delivery_status'] ?? ''));
|
|
|
+ if ($ds !== '准时' && $ds !== '滞后') {
|
|
|
+ $ds = '';
|
|
|
+ }
|
|
|
+ $out[$sid] = [
|
|
|
+ 'result' => $result,
|
|
|
+ 'delivery_status' => $ds,
|
|
|
+ 'customer_complaint' => (int)($r['customer_complaint'] ?? 0) === 1 ? 1 : 0,
|
|
|
+ 'order_interrupt' => (int)($r['order_interrupt'] ?? 0) === 1 ? 1 : 0,
|
|
|
+ 'remark' => trim((string)($r['remark'] ?? '')),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
return $out;
|