Browse Source

app-ghs 新增API: 打印拆散订单

shizhongqi 4 months ago
parent
commit
ba902aaef2
1 changed files with 67 additions and 0 deletions
  1. 67 0
      app-ghs/controllers/PartController.php

+ 67 - 0
app-ghs/controllers/PartController.php

@@ -7,6 +7,7 @@ use bizGhs\part\classes\PartItemClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\printUtil;
 use common\components\util;
 use Yii;
 
@@ -110,4 +111,70 @@ class PartController extends BaseController
         }
     }
 
+    //打印拆散订单
+    public function actionPrintOrder()
+    {
+        $get = Yii::$app->request->get();
+        $orderSn = $get['orderSn'] ?? '';
+        if (empty($orderSn)) {
+            util::fail('参数错误');
+        }
+
+        $info = PartClass::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($info)) {
+            util::fail('没有找到拆散单');
+        }
+        if ($info->mainId != $this->mainId) {
+            util::fail('没有权限');
+        }
+
+        $itemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
+        if (empty($itemList)) {
+            util::fail('没有花材需要打印');
+        }
+
+        $ext = $this->shopExt;
+        $printSn = is_array($ext) ? ($ext['printSn'] ?? '') : ($ext->printSn ?? '');
+        $printKey = is_array($ext) ? ($ext['printKey'] ?? '') : ($ext->printKey ?? '');
+        if (empty($printSn) || empty($printKey)) {
+            util::success(['hasNoPrint' => 1]);
+        }
+
+        $shop = $this->shop;
+        $sj = $this->sj;
+        $sjName = $sj->name ?? '';
+        $shopName = $shop->shopName ?? '';
+        $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
+
+        $kindNum = 0;
+        $totalNum = 0;
+        $content = "<CB>{$currentName}</CB><BR>";
+        $content .= "<CB>拆散单</CB><BR>";
+        $content .= '商品             数量 <BR>';
+        $content .= '--------------------------------<BR>';
+        foreach ($itemList as $current) {
+            $name = $current['name'] ?? '';
+            $num = $current['itemNum'] ?? 0;
+            $content .= '<B>' . $name . '    ' . floatval($num) . '扎' . "</B><BR>";
+            $content .= '--------------------------------<BR>';
+            $kindNum = bcadd($kindNum, 1);
+            $totalNum = bcadd($totalNum, $current['itemNum']);
+        }
+        if (!empty($info->remark)) {
+            $content .= '备注:' . $info->remark . '<BR>';
+        }
+        $content .= '<BR>';
+        $content .= '********************************<BR>';
+        $content .= "<CB>共{$kindNum}种,{$totalNum}扎";
+        $content .= "</CB>";
+        $content .= '********************************<BR>';
+        $content .= '<BR>';
+        $content .= "订单编号:{$orderSn}<BR>";
+        $content .= '拆散人员:' . ($info->shopAdminName ?? '') . '<BR>';
+
+        $p = new printUtil($printSn);
+        $p->printMsg($content, $shop, $orderSn);
+
+        util::complete('打印成功');
+    }
 }