shish vor 5 Jahren
Ursprung
Commit
3dfb19f5f4

+ 59 - 1
biz-ghs/order/classes/OrderClass.php

@@ -23,9 +23,11 @@ use common\components\dict;
 use common\components\httpUtil;
 use common\components\imgUtil;
 use common\components\orderSn;
+use common\components\printUtil;
 use common\components\stringUtil;
 use common\components\util;
 use bizGhs\base\classes\BaseClass;
+use Yii;
 
 class OrderClass extends BaseClass
 {
@@ -163,7 +165,7 @@ class OrderClass extends BaseClass
             //减库存
             $cgStyle = $data['cgStyle'] ?? 1;
 
-            $checkStock = $cgStyle == dict::getDict('cgStyle','hd') ? true : false;
+            $checkStock = $cgStyle == dict::getDict('cgStyle', 'hd') ? true : false;
             $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock);
             //记录库存流水
             $recordData = [];
@@ -413,6 +415,62 @@ class OrderClass extends BaseClass
         return $list;
     }
 
+    //云打印 shish 20210709
+    public static function onlinePrint($orderInfo, $debtAmount, $showItem)
+    {
+        $respond = self::getPrintData($orderInfo, $debtAmount, $showItem);
+        $content = '<B>' . $respond['sendNum'] . '</B><BR>';
+        $content .= '--------------------------------<BR>';
+        $content .= '<B>' . $respond['custom']['fullAddress'] . '</B><BR>';
+        $content .= '<B>' . $respond['custom']['customName'] . '</B><BR>';
+        $content .= '<B>' . $respond['custom']['customMobile'] . '</B><BR>';
+        if (isset($respond['remark']) && !empty($respond['remark'])) {
+            $content .= '备注:<BR>';
+            $content .= '<CB>' . $respond['remark'] . '</CB><BR>';
+        }
+        //--------------------------------------
+
+        $content .= '花材         数量    金额<BR>';
+        $content .= '--------------------------------<BR>';
+
+//        $content .= '饭       10.0   10  100.0<BR>';
+//        $content .= '炒饭      10.0   10  100.0<BR>';
+//        $content .= '蛋炒饭     10.0   10  100.0<BR>';
+//        $content .= '鸡蛋炒饭    10.0   10  100.0<BR>';
+//        $content .= '西红柿炒饭   10.0   10  100.0<BR>';
+//        $content .= '西红柿蛋炒饭  10.0   10  100.0<BR>';
+//        $content .= '西红柿鸡蛋炒饭 10.0   10  100.0<BR>';
+
+        if (isset($respond['product']) && !empty($respond['product'])) {
+            foreach ($respond['product'] as $current) {
+                $content .= $current['name'] . " " . $current['num'] . ' ' . $current['price'] . '<BR>';
+            }
+        }
+        $content .= '--------------------------------<BR>';
+        $content .= '总金额:' . $respond['prePrice'] . '<BR>';
+        $content .= '应付金额:' . $respond['realPrice'] . '<BR>';
+        if (isset($respond['debt']) && $respond['debt'] == 1) {
+            $content .= '实付金额:0.00<BR>';
+        } else {
+            $content .= '实付金额:' . $respond['realPrice'] . '<BR>';
+        }
+        if (isset($respond['discountAmount']) && $respond['discountAmount'] > 0) {
+            $content .= '累计欠款:' . $respond['discountAmount'] . '<BR>';
+        }
+        $i = self::getById($orderInfo['id']);
+        $content .= '--------------------------------<BR>';
+        $content .= '订单日期:' . $i['addTime'] . '<BR>';
+        $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
+        $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);
+    }
+
     //打印数据 shish 20210702
     public static function getPrintData($val, $debtAmount, $showItem)
     {

+ 4 - 28
biz-ghs/order/services/OrderService.php

@@ -572,34 +572,10 @@ class OrderService extends BaseService
             }
         }
 
-        header("Content-type: text/html; charset=utf-8");
-        include 'HttpClient.class.php';
-
-        $fei = Yii::getAlias("@vendor/feie");
-        require_once($fei . '/HttpClient.class.php');
-        $content = '<CB>测试打印</CB><BR>';
-        $content .= '名称      单价  数量 金额<BR>';
-        $content .= '--------------------------------<BR>';
-        $content .= '饭       10.0   10  100.0<BR>';
-        $content .= '炒饭      10.0   10  100.0<BR>';
-        $content .= '蛋炒饭     10.0   10  100.0<BR>';
-        $content .= '鸡蛋炒饭    10.0   10  100.0<BR>';
-        $content .= '西红柿炒饭   10.0   10  100.0<BR>';
-        $content .= '西红柿蛋炒饭  10.0   10  100.0<BR>';
-        $content .= '西红柿鸡蛋炒饭 10.0   10  100.0<BR>';
-        $content .= '--------------------------------<BR>';
-        $content .= '备注:加辣<BR>';
-        $content .= '合计:xx.0元<BR>';
-        $content .= '送货地点:广州市南沙区xx路xx号<BR>';
-        $content .= '联系电话:13888888888888<BR>';
-        $content .= '订餐时间:2014-08-08 08:08:08<BR>';
-        $content .= '<QR>http://www.feieyun.com</QR>';
-
-        //提示:
-        $sn = '530501507';
-        //打开注释可测试
-        printMsg($sn,$content,1);//该接口只能是小票机使用,如购买的是标签机请使用下面方法3,调用打印
-
+        //在线打印
+        $debtAmount = $custom->debtAmount;
+        $showItem = OrderClass::getShowItem(true, $order);
+        OrderClass::onlinePrint($order, $debtAmount, $showItem);
 
     }
 

+ 57 - 0
common/components/printUtil.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace common\components;
+
+use Yii;
+use yii\helpers\Json;
+use linslin\yii2\curl;
+
+/**
+ * 微信和微信开放平台交互接口
+ */
+class printUtil
+{
+    public $access_token;
+
+    public $user = 'shish@zhhinc.com', $uKey = 'Du4uwgvtAVmcEzbP', $sn, $times = 1;
+
+    const IP = 'api.feieyun.cn';      //接口IP或域名
+    const PORT = 80;            //接口IP端口
+    const PATH = '/Api/Open/';    //接口路径
+
+    public function __construct($sn)
+    {
+        header("Content-type: text/html; charset=utf-8");
+        $fei = Yii::getAlias("@vendor/feie");
+        require_once($fei . '/HttpClient.class.php');
+        $this->sn = $sn;
+    }
+
+    public function printMsg($content)
+    {
+        $time = time();         //请求时间
+        $msgInfo = array(
+            'user' => $this->user,
+            'stime' => $time,
+            'sig' => $this->signature($time),
+            'apiname' => 'Open_printMsg',
+            'sn' => $this->sn,
+            'content' => $content,
+            'times' => $this->times//打印次数
+        );
+        $client = new \HttpClient(self::IP, self::PORT);
+        if (!$client->post(self::PATH, $msgInfo)) {
+            //echo 'error';
+        } else {
+            //服务器返回的JSON字符串,建议要当做日志记录起来
+            $result = $client->getContent();
+            //echo $result;
+        }
+    }
+
+    public function signature($time)
+    {
+        return sha1($this->user . $this->uKey . $time);//公共参数,请求公钥
+    }
+
+}

+ 2 - 2
vendor/feie/API_PHP_DEMO.php

@@ -210,11 +210,11 @@
     );
     $client = new HttpClient(IP,PORT);
     if(!$client->post(PATH,$msgInfo)){
-      //echo 'error';
+      echo 'error';
     }else{
       //服务器返回的JSON字符串,建议要当做日志记录起来
       $result = $client->getContent();
-      //echo $result;
+      echo $result;
     }
   }