shish 1 день назад
Родитель
Сommit
ed084b0413
2 измененных файлов с 52 добавлено и 1 удалено
  1. 49 0
      app-ghs/controllers/OrderController.php
  2. 3 1
      biz-hd/purchase/classes/PurchaseClass.php

+ 49 - 0
app-ghs/controllers/OrderController.php

@@ -2974,6 +2974,55 @@ class OrderController extends BaseController
         }
     }
 
+    /**
+     * 修改订单发货日期:同时写 xhGhsOrder.sendTimeWant 与 xhCg.sendTimeWant。
+     * ghsApp 订单详情「发货时间-修改」调用;允许补录过去日期。关键词 sync_send_time_want
+     */
+    public function actionModifySendTimeWant()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $date = $get['date'] ?? '';
+        $date = str_replace('/', '-', trim($date));
+        if (empty($date) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
+            util::fail('请选择日期');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $order = OrderClass::getById($id, true);
+            if (empty($order)) {
+                util::fail('没有找到订单');
+            }
+            if ($order->mainId != $this->mainId) {
+                util::fail('不是你的订单');
+            }
+            $oldDate = substr((string)$order->sendTimeWant, 0, 10);
+            if ($oldDate === $date) {
+                util::fail('日期没变');
+            }
+            $cgId = $order->purchaseId ?? 0;
+            $cg = PurchaseClass::getById($cgId, true);
+            if (empty($cg)) {
+                util::fail('没有找到订单信息');
+            }
+            // 销售单、采购单发货日期必须一致,否则花店侧看到的要求发货日会对不上
+            $order->sendTimeWant = $date;
+            if (!$order->save()) {
+                util::fail('修改失败');
+            }
+            $cg->sendTimeWant = $date;
+            if (!$cg->save()) {
+                util::fail('修改失败');
+            }
+            $transaction->commit();
+            util::complete('修改成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('修改失败');
+        }
+    }
+
     /**
      * 应收统计:按支付日汇总。
      * originAmount=未扣隔天;nextDayAmount=跨天售后;amount=已扣隔天(净额)。

+ 3 - 1
biz-hd/purchase/classes/PurchaseClass.php

@@ -999,7 +999,9 @@ class PurchaseClass extends BaseClass
         $prePrice = 0;
         $live = $ghs['live'] ?? 1;
         $sendTimeWant = !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
-        if ($sendTimeWant < date("Y-m-d")) {
+        // 花店自下单仍禁止过去发货日;供货商开单允许补录历史发货日期,xhCg.sendTimeWant 与销售单保持一致。关键词 sync_send_time_want
+        $cgStyle = $data['cgStyle'] ?? 0;
+        if ($sendTimeWant < date("Y-m-d") && $cgStyle != dict::getDict('cgStyle', 'ghs')) {
             util::fail('您选了过去时间');
         }
         $data['sendTimeWant'] = $sendTimeWant;