shish před 5 roky
rodič
revize
3096a87167

+ 30 - 0
app-ghs/controllers/ShopExtController.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace ghs\controllers;
+
+use common\components\printUtil;
+use common\components\util;
+use Yii;
+
+class ShopExtController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    //添加打印机 shish 20210712
+    public function actionAddPrint()
+    {
+        $get = Yii::$app->request->get();
+        $sn = $get['sn'] ?? '';
+        $key = $get['key'] ?? '';
+        $print = new printUtil();
+        $shop = $this->shop;
+        $shopName = $shop['shopName'] ?? '';
+        $return = $print->addPrint($sn, $key, $shopName);
+        if ($return) {
+            util::complete();
+        }
+        util::fail();
+    }
+
+}

+ 12 - 6
biz-ghs/order/classes/OrderClass.php

@@ -4,6 +4,7 @@ namespace bizGhs\order\classes;
 
 use biz\shop\classes\ShopAdminClass;
 use biz\shop\classes\ShopClass;
+use biz\shop\classes\ShopExtClass;
 use biz\shop\models\Shop;
 use bizGhs\custom\models\Custom;
 use bizGhs\express\services\DadaExpressServices;
@@ -462,7 +463,7 @@ class OrderClass extends BaseClass
             $content .= '实付金额:' . $respond['realPrice'] . '<BR>';
         }
         if ($debtAmount > 0) {
-            $content .= '累计欠款:' . $debtAmount. '<BR>';
+            $content .= '累计欠款:' . $debtAmount . '<BR>';
         }
         $i = self::getById($orderInfo['id']);
         $content .= '--------------------------------<BR>';
@@ -471,11 +472,16 @@ class OrderClass extends BaseClass
         $content .= '门店名称:纯彩花艺<BR>';
         $content .= '门店地址:' . $respond['address'] . '<BR>';
         $content .= "<BR>";
-        $content .= "<C>扫码采购</C><BR>";
-        $url = Yii::$app->params['ghsDomain'] . '/#/pagesPurchase/ghsProduct';
-        $content .= '<QR>' . $url . '</QR>';//把二维码字符串用标签套上即可自动生成二维码
-        $p = new printUtil('530501507');
-        $p->printMsg($content);
+        //$content .= "<C>扫码采购</C><BR>";
+        //$url = Yii::$app->params['ghsDomain'] . '/#/pagesPurchase/ghsProduct';
+        //$content .= '<QR>' . $url . '</QR>';//把二维码字符串用标签套上即可自动生成二维码
+        $shopId = $orderInfo['shopId'] ?? 0;
+        $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
+        $printSn = $ext['printSn'] ?? '';
+        if(!empty($printSn)){
+            $p = new printUtil($printSn);
+            $p->printMsg($content);
+        }
     }
 
     //打印数据 shish 20210702

+ 21 - 0
common/components/printUtil.php

@@ -54,4 +54,25 @@ class printUtil
         return sha1($this->user . $this->uKey . $time);//公共参数,请求公钥
     }
 
+    //批量添加打印机 shish 20210712
+    public function addPrint($sn, $key, $shopName)
+    {
+        $printerContent = "sn{$sn}#{$key}#{$shopName}";
+        $time = time();         //请求时间
+        $msgInfo = array(
+            'user' => $this->user,
+            'stime' => $time,
+            'sig' => $this->signature($time),
+            'apiname' => 'Open_printerAddlist',
+            'printerContent' => $printerContent
+        );
+        $client = new \HttpClient(self::IP, self::PORT);
+        if (!$client->post(self::PATH, $msgInfo)) {
+            return false;
+        } else {
+            $client->getContent();
+            return true;
+        }
+    }
+
 }