|
|
@@ -2678,6 +2678,9 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $this->updatePurchaseOrderDetailStatusNameByIds($sid, $selectedIds, '已完成');
|
|
|
+ $this->updatePurchaseOrderDetailStatusNameByIds($sid, $unselectedIds, '未通过');
|
|
|
+
|
|
|
if ($manageTransaction) {
|
|
|
Db::commit();
|
|
|
}
|
|
|
@@ -2712,27 +2715,7 @@ class Procuremen extends Backend
|
|
|
$poIdFinal > 0 ? $poIdFinal : null
|
|
|
);
|
|
|
|
|
|
- $ccydh = '';
|
|
|
- $cyjmc = '';
|
|
|
- try {
|
|
|
- $po = Db::table('purchase_order')->where('scydgy_id', $sid)->find();
|
|
|
- if (is_array($po)) {
|
|
|
- $ccydh = trim((string)($po['CCYDH'] ?? ''));
|
|
|
- $cyjmc = trim((string)($po['CYJMC'] ?? ''));
|
|
|
- }
|
|
|
- } catch (\Throwable $e) {
|
|
|
- }
|
|
|
- if ($ccydh === '' || $cyjmc === '') {
|
|
|
- $any = $this->purchaseOrderDetai($sid, $selectedIds[0] ?? 0);
|
|
|
- if (is_array($any)) {
|
|
|
- if ($ccydh === '') {
|
|
|
- $ccydh = trim((string)($any['CCYDH'] ?? ''));
|
|
|
- }
|
|
|
- if ($cyjmc === '') {
|
|
|
- $cyjmc = trim((string)($any['CYJMC'] ?? ''));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $confirmNotifyVars = $this->buildPurchaseConfirmNotifyVars($sid, $selectedIds[0] ?? 0);
|
|
|
|
|
|
$sendSmsSafe = function ($phone, $content) {
|
|
|
$phone = trim((string)$phone);
|
|
|
@@ -2753,13 +2736,11 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
$cname = trim((string)($dr['company_name'] ?? ''));
|
|
|
$ph = trim((string)($dr['phone'] ?? ''));
|
|
|
- $sms = $this->renderNotifyTemplate('confirm_ok', [
|
|
|
+ $sms = $this->renderNotifyTemplate('confirm_ok', array_merge($confirmNotifyVars, [
|
|
|
'company_name' => $cname,
|
|
|
'contact_name' => $this->resolveCustomerContactName($ph, $cname),
|
|
|
'phone' => $ph,
|
|
|
- 'ccydh' => $ccydh,
|
|
|
- 'cyjmc' => $cyjmc,
|
|
|
- ]);
|
|
|
+ ]));
|
|
|
$sendSmsSafe((string)($dr['phone'] ?? ''), $sms);
|
|
|
}
|
|
|
foreach ($unselectedIds as $pid) {
|
|
|
@@ -2769,13 +2750,11 @@ class Procuremen extends Backend
|
|
|
}
|
|
|
$cname = trim((string)($dr['company_name'] ?? ''));
|
|
|
$ph = trim((string)($dr['phone'] ?? ''));
|
|
|
- $sms = $this->renderNotifyTemplate('confirm_fail', [
|
|
|
+ $sms = $this->renderNotifyTemplate('confirm_fail', array_merge($confirmNotifyVars, [
|
|
|
'company_name' => $cname,
|
|
|
'contact_name' => $this->resolveCustomerContactName($ph, $cname),
|
|
|
'phone' => $ph,
|
|
|
- 'ccydh' => $ccydh,
|
|
|
- 'cyjmc' => $cyjmc,
|
|
|
- ]);
|
|
|
+ ]));
|
|
|
$sendSmsSafe((string)($dr['phone'] ?? ''), $sms);
|
|
|
}
|
|
|
|
|
|
@@ -2803,6 +2782,68 @@ class Procuremen extends Backend
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量更新 purchase_order_detail.status_name(兼容 id / ID 列名)
|
|
|
+ *
|
|
|
+ * @param int[] $detailIds
|
|
|
+ */
|
|
|
+ protected function updatePurchaseOrderDetailStatusNameByIds(int $sid, array $detailIds, string $statusName): void
|
|
|
+ {
|
|
|
+ $detailIds = array_values(array_unique(array_filter(array_map('intval', $detailIds))));
|
|
|
+ if ($detailIds === []) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $payload = ['status_name' => $statusName];
|
|
|
+ try {
|
|
|
+ Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('id', 'in', $detailIds)->update($payload);
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ Db::table('purchase_order_detail')->where('scydgy_id', $sid)->where('ID', 'in', $detailIds)->update($payload);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批驳回后按是否已报价恢复 status_name(未提交 / 已提交)
|
|
|
+ */
|
|
|
+ protected function restorePurchaseOrderDetailStatusNamesAfterReject(int $sid): void
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $rows = Db::table('purchase_order_detail')->where('scydgy_id', $sid)->select();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!is_array($rows)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ foreach ($rows as $dr) {
|
|
|
+ if (!is_array($dr)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $id = (int)($dr['id'] ?? $dr['ID'] ?? 0);
|
|
|
+ if ($id <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $sn = $this->resolvePurchaseOrderDetailQuoteStatusName($dr);
|
|
|
+ $pk = isset($dr['id']) ? 'id' : (isset($dr['ID']) ? 'ID' : 'id');
|
|
|
+ try {
|
|
|
+ Db::table('purchase_order_detail')->where($pk, $id)->update(['status_name' => $sn]);
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array<string, mixed> $detailRow
|
|
|
+ */
|
|
|
+ protected function resolvePurchaseOrderDetailQuoteStatusName(array $detailRow): string
|
|
|
+ {
|
|
|
+ $am = $detailRow['amount'] ?? null;
|
|
|
+ $dv = isset($detailRow['delivery']) ? trim((string)$detailRow['delivery']) : '';
|
|
|
+ $amountFilled = !($am === null || $am === '' || (is_string($am) && trim($am) === ''));
|
|
|
+ $deliveryFilled = ($dv !== '' && !preg_match('/^0000-00-00/i', $dv));
|
|
|
+
|
|
|
+ return ($amountFilled || $deliveryFilled) ? '已提交' : '未提交';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return int[]
|
|
|
*/
|
|
|
@@ -4226,6 +4267,64 @@ class Procuremen extends Backend
|
|
|
return implode("\n", $lines);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 采购确认短信/邮件共用变量(含订单号、印件名称、工序明细)
|
|
|
+ *
|
|
|
+ * @return array<string, string>
|
|
|
+ */
|
|
|
+ protected function buildPurchaseConfirmNotifyVars(int $sid, int $fallbackDetailId = 0): array
|
|
|
+ {
|
|
|
+ $po = null;
|
|
|
+ try {
|
|
|
+ $po = Db::table('purchase_order')->where('scydgy_id', $sid)->find();
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ $po = null;
|
|
|
+ }
|
|
|
+ $ccydh = is_array($po) ? trim((string)($po['CCYDH'] ?? '')) : '';
|
|
|
+ $cyjmc = is_array($po) ? trim((string)($po['CYJMC'] ?? '')) : '';
|
|
|
+ if (($ccydh === '' || $cyjmc === '') && $fallbackDetailId > 0) {
|
|
|
+ $any = $this->purchaseOrderDetai($sid, $fallbackDetailId);
|
|
|
+ if (is_array($any)) {
|
|
|
+ if ($ccydh === '') {
|
|
|
+ $ccydh = trim((string)($any['CCYDH'] ?? ''));
|
|
|
+ }
|
|
|
+ if ($cyjmc === '') {
|
|
|
+ $cyjmc = trim((string)($any['CYJMC'] ?? ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $mergeRows = is_array($po) && $po !== [] ? [$po] : [];
|
|
|
+ $processPlain = $mergeRows !== [] ? $this->buildProcessLinesPlain($mergeRows) : '';
|
|
|
+ $processLines = $this->buildPurchaseConfirmProcessLinesText($ccydh, $cyjmc, $processPlain);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'ccydh' => $ccydh,
|
|
|
+ 'cyjmc' => $cyjmc,
|
|
|
+ 'cgymc' => is_array($po) ? trim((string)($po['CGYMC'] ?? '')) : '',
|
|
|
+ 'process_lines' => $processLines,
|
|
|
+ 'process_lines_html' => '',
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采购确认短信中的工序/订单信息块(模版常用 {process_lines})
|
|
|
+ */
|
|
|
+ protected function buildPurchaseConfirmProcessLinesText(string $ccydh, string $cyjmc, string $processPlain): string
|
|
|
+ {
|
|
|
+ $lines = [];
|
|
|
+ if ($ccydh !== '') {
|
|
|
+ $lines[] = '订单号:' . $ccydh;
|
|
|
+ }
|
|
|
+ if ($cyjmc !== '') {
|
|
|
+ $lines[] = '印件名称:' . $cyjmc;
|
|
|
+ }
|
|
|
+ if ($processPlain !== '') {
|
|
|
+ $lines[] = $processPlain;
|
|
|
+ }
|
|
|
+
|
|
|
+ return implode("\n", $lines);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 各工序手机端链接(纯文本,供短信模版 {platform_links})
|
|
|
*
|
|
|
@@ -6020,6 +6119,7 @@ class Procuremen extends Backend
|
|
|
'pick_company_name' => '',
|
|
|
]);
|
|
|
Db::table('purchase_order_detail')->where('scydgy_id', $sid)->update(['status' => 0]);
|
|
|
+ $this->restorePurchaseOrderDetailStatusNamesAfterReject($sid);
|
|
|
|
|
|
$poId = 0;
|
|
|
try {
|
|
|
@@ -6911,6 +7011,8 @@ class Procuremen extends Backend
|
|
|
foreach ($vars as $k => $v) {
|
|
|
$tpl = str_replace('{' . $k . '}', (string)$v, $tpl);
|
|
|
}
|
|
|
+ // 未传入的占位符置空,避免短信出现 {process_lines} 等原文
|
|
|
+ $tpl = preg_replace('/\{[a-zA-Z0-9_]+\}/', '', $tpl);
|
|
|
|
|
|
return $tpl;
|
|
|
}
|