dever 3 years ago
parent
commit
b4c64c6913
6 changed files with 338 additions and 648 deletions
  1. 129 108
      app/mshop/lib/Feieyun.php
  2. 0 460
      app/mshop/lib/Feieyun1.php
  3. 108 0
      app/mshop/src/Buy.php
  4. 43 36
      app/mshop/src/Data.php
  5. 29 21
      app/mshop/src/Goods.php
  6. 29 23
      app/mshop/src/Out.php

+ 129 - 108
app/mshop/lib/Feieyun.php

@@ -14,7 +14,10 @@ class Feieyun
         'ukey' => 'pMsXhZWu5F65MYyV',
         //host地址
         'host' => 'http://api.feieyun.cn:80/Api/Open/',
+        //可打印的长度
+        'length' => 32,
     );
+    private $text = '';
     # 生成参数
     public function param($api, $send = array())
     {
@@ -135,115 +138,133 @@ class Feieyun
 		return $result;
     }
 
-    # 打印商品排版 商品列表,名称长度,数量长度,单价长度
-    public function goods($name, $goods, $A = 14, $B = 4, $C = 12)
-    {
-    	$orderInfo = '';
-    	$orderInfo .= '--------------------------------<BR>';
-    	if ($name) {
-    		$orderInfo .= '<C>'.$name.'</C><BR>';
-    	}
-		$orderInfo .= '名称               数量   单价 <BR>';
-		
-		foreach ($goods as $k5 => $v5) {
-			$name = $v5['title'];
-			$price = $v5['price'];
-			$num = $v5['num'];
-			$kw3 = '';
-			$kw1 = '';
-			$kw2 = '';
-			$kw4 = '';
-			$str = $name;
-			$blankNum = $A;//名称控制为14个字节
-			$lan = mb_strlen($str,'utf-8');
-			$m = 0;
-			$j=1;
-			$blankNum++;
-			$result = array();
-
-      if (strlen($num) < $B) {
-        $k2 = $B - strlen($num);
-        for ($q=0; $q<$k2; $q++) {
-          $kw2 .= ' ';
+    public function getText()
+    {
+        return $this->text;
+    }
+
+    public function text($text = '', $align = '', $br = 1)
+    {
+        if ($align) {
+        	$text = '<'.$align.'>'.$text.'</'.$align.'>';
+        }
+        $this->text .= $text;
+        if ($br > 0) {
+        	$this->br($br);
+        }
+        return $this;
+    }
+
+    public function left($text)
+    {
+        $this->text($text);
+        return $this;
+    }
+
+    public function right($text)
+    {
+        $this->text($text, 'RIGHT');
+        return $this;
+    }
+
+    public function center($text)
+    {
+        $this->text($text, 'C');
+        return $this;
+    }
+
+    public function hr($str = '-', $name = '')
+    {
+        $text = str_pad($name, $this->config['length'], $str, STR_PAD_BOTH);
+        $this->text($text);
+        return $this;
+    }
+
+    public function br($num = 1)
+    {
+        for ($i = 0; $i < $num; $i++) {
+            $this->text .= '<BR>';
+        }
+        return $this;
+    }
+
+    # 左右结构
+    public function lr($s1, $s2)
+    {
+    	$l1 = strlen(Dever::convert($s1));
+        $n = '';
+        $max = $this->config['length'] - 6;
+        if ($l1 > $max) {
+            $max = $max/2;
+            $t = mb_substr($s1, 0, $max, 'utf-8');
+            $n = mb_substr($s1, $max, $l1, 'utf-8');
+            $s1 = $t;
+            $l1 = strlen(Dever::convert($s1));
+        }
+
+        $l2 = strlen(Dever::convert($s2));
+        $l = $this->config['length'] - ($l1+$l2);
+        $k = '';
+        for($i = 0; $i < $l; $i++) {
+            $k .= ' ';
+        }
+        $text = $s1 . $k . $s2;
+        $this->text($text);
+        return $n;
+    }
+
+    # 左中右结构
+    public function lcr($s1, $s2, $s3, $s1_s2 = 80, $s2_s3 = 20)
+    {
+        $s1_s2 = round(($s1_s2/100)*$this->config['length']);
+        $s2_s3 = round(($s2_s3/100)*$this->config['length']);
+
+        $l1 = strlen(Dever::convert($s1));
+        $n = '';
+        $max = $s1_s2 - ($s1_s2 - $s2_s3)/2;
+        if ($l1 > $max) {
+            $max = $max/2;
+            $t = mb_substr($s1, 0, $max, 'utf-8');
+            $n = mb_substr($s1, $max, $l1, 'utf-8');
+            $s1 = $t;
+            $l1 = strlen(Dever::convert($s1));
+        }
+
+        $l2 = strlen(Dever::convert($s2));
+        $l3 = strlen(Dever::convert($s3));
+        $l = $s1_s2 - ($l1+$l2);
+        $k = '';
+        for($i = 0; $i < $l; $i++) {
+            $k .= ' ';
+        }
+        $text = $s1 . $k . $s2;
+        
+        $l = $s2_s3 - $l3;
+        $k = '';
+        for($i = 0; $i < $l; $i++) {
+            $k .= ' ';
         }
-        $num = $num.$kw2;
-      }
-
-			if (strlen($price) < $C) {
-				$k1 = $C - strlen($price);
-				for ($q=0; $q<$k1; $q++) {
-					$kw1 .= ' ';
-				}
-				$price = $price.$kw1;
-			}
-			
-			for ($i=0;$i<$lan;$i++) {
-				$new = mb_substr($str,$m,$j,'utf-8');
-				$j++;
-				if (mb_strwidth($new,'utf-8')<$blankNum)  {
-					if ($m+$j>$lan) {
-						$m = $m+$j;
-						$tail = $new;
-						$lenght = Dever::convert($new);
-						$k = $A - strlen($lenght);
-						for ($q=0;$q<$k;$q++) {
-							$kw3 .= ' ';
-						}
-						if ($m==$j) {
-							$tail .= $kw3.' '.$num.' '.$price;
-						} else {
-							$tail .= $kw3.'<BR>';
-						}
-						break;
-					} else {
-						$next_new = mb_substr($str,$m,$j,'utf-8');
-						if (mb_strwidth($next_new,'utf-8')<$blankNum) {
-							continue;
-						} else{
-							$m = $i+1;
-							$result[] = $new;
-							$j=1;
-						}
-					}
-				}
-			}
-			$head = '';
-			foreach ($result as $key=>$value) {
-				if ($key < 1)  {
-					$v_lenght = Dever::convert($value);
-					$v_lenght = strlen($v_lenght);
-					if($v_lenght == 13) $value = $value." ";
-					$head .= $value.' '.$num.' '.$price;
-				} else {
-					$head .= $value.'<BR>';
-				}
-			}
-			$orderInfo .= $head.$tail.'<BR>';
-		}
-
-		$orderInfo .= '--------------------------------<BR>';
-
-		return $orderInfo;
-    }
-
-    /**
-     * 参考例子 3
-     * [统计字符串字节数补空格,实现左右排版对齐]
-     * @param  [string] $str_left    [左边字符串]
-     * @param  [string] $str_right   [右边字符串]
-     * @param  [int]    $length      [输入当前纸张规格一行所支持的最大字母数量]
-     *                               58mm的机器,一行打印16个汉字,32个字母;76mm的机器,一行打印22个汉字,33个字母,80mm的机器,一行打印24个汉字,48个字母
-     *                               标签机宽度50mm,一行32个字母,宽度40mm,一行26个字母
-     * @return [string]              [返回处理结果字符串]
-     */
-    public function lr($str_left,$str_right,$length = 32){
-        $kw = '';
-        $str_left_lenght = strlen(Dever::convert($str_left));
-        $str_right_lenght = strlen(Dever::convert($str_right));
-        $k = $length - ($str_left_lenght+$str_right_lenght);
-        for($q=0;$q<$k;$q++){
-            $kw .= ' ';
+        $text .= $k . $s3;
+        $this->text($text);
+        return $n;
+    }
+
+    # 表格
+    public function table($head, $body, $name, $method = 'lcr')
+    {
+        $this->hr();
+        if ($name) {
+            $this->center($name);
         }
-        return $str_left.$kw.$str_right;
+        call_user_func_array(array($this, $method), $head);
+        $next = '';
+        foreach ($body as $k => $v) {
+            $next = call_user_func_array(array($this, $method), $v);
+            if ($next) {
+                $this->left($next);
+            }
+        }
+
+        $this->hr();
     }
 }

+ 0 - 460
app/mshop/lib/Feieyun1.php

@@ -1,460 +0,0 @@
-<?php
-
-namespace Mshop\Lib;
-
-use Dever;
-
-class Feieyun
-{
-    private $config = array
-    (
-        //飞鹅云后台注册账号
-        'user' => 'liuxuemei@zsma.com.cn',
-        //飞鹅云后台注册账号后生成的UKEY
-        'ukey' => 'pMsXhZWu5F65MYyV',
-        //打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
-        'sn' => '',
-        //host地址
-        'host' => 'http://api.feieyun.cn:80/Api/Open/',
-    );
-    # 生成参数
-    public function param(&$param)
-    {
-        $time = time();
-        $param['user'] = $this->config['user'];
-        $param['stime'] = $time;
-        $param['sig'] = sha1($this->config['user'] . $this->config['ukey'] . $time);
-    }
-
-    # 发送
-    public function send()
-    {
-        $url = $this->config['host'];
-        $param = $this->param($param);
-        return Dever::curl($url, $param, 'post');
-    }
-
-    # 添加打印机
-    public function add()
-    {
-          $msgInfo = array(
-          'user'=>USER,
-          'stime'=>$time,
-          'sig'=>signature($time),
-          'apiname'=>'Open_printerAddlist',
-          'printerContent'=>$printerContent
-        );
-        $client = new HttpClient(IP,PORT);
-        if(!$client->post(PATH,$msgInfo)){
-          echo 'error';
-        }else{
-          $result = $client->getContent();
-          echo $result;
-        }
-    }
-
-    <?php
-  header("Content-type: text/html; charset=utf-8");
-  include 'HttpClient.class.php';
-
-  define('USER', 'xxxxxxxxxxxxxxxxx');  //*必填*:飞鹅云后台注册账号
-  define('UKEY', 'xxxxxxxxxxxxxxxxx');  //*必填*: 飞鹅云后台注册账号后生成的UKEY 【备注:这不是填打印机的KEY】
-  define('SN', 'xxxxxxxxxxxxxxxxx');      //*必填*:打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
-
-  //以下参数不需要修改
-  define('IP','api.feieyun.cn');      //接口IP或域名
-  define('PORT',80);            //接口IP端口
-  define('PATH','/Api/Open/');    //接口路径
-
-
-  //*************************************方法1 批量添加打印机接口*************************************************
-  //***接口返回值说明***
-  //正确例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#remark#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999  (错误:识别码不正确)"]},"serverExecutedTime":3}
-  //错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
-
-  //提示:
-  //$printerConten => 打印机编号sn(必填) # 打印机识别码key(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100台。
-  //打开注释可测试
-  //$printerContent = "sn1#key1#remark1#carnum1\nsn2#key2#remark2#carnum2";
-  //printerAddlist($printerContent);
-
-
-
-  //****************************************方法2 小票机打印订单接口****************************************************
-  //***接口返回值说明***
-  //正确例子:{"msg":"ok","ret":0,"data":"123456789_20160823165104_1853029628","serverExecutedTime":6}
-  //错误例子:{"msg":"错误信息.","ret":非零错误码,"data":null,"serverExecutedTime":5}
-
-  //标签说明:
-  //单标签:
-    //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
-    //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
-  //成对标签:
-    //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
-    //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
-
-    //拼凑订单内容时可参考如下格式
-  //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
-  $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 => 打印机编号
-  //$content => 打印内容,不能超过5000字节
-  //$times => 打印次数,默认为1。
-  //打开注释可测试
-  // printMsg(SN,$content,1);//该接口只能是小票机使用,如购买的是标签机请使用下面方法3,调用打印
-
-
-  //****************************************方法3 标签机专用打印订单接口****************************************************
-  //***接口返回值说明***
-  //正确例子:{"msg":"ok","ret":0,"data":"123456789_20160823165104_1853029628","serverExecutedTime":6}
-  //错误例子:{"msg":"错误信息.","ret":非零错误码,"data":null,"serverExecutedTime":5}
-
-  //标签说明:
-  $content = "<DIRECTION>1</DIRECTION>";//设定打印时出纸和打印字体的方向,n 0 或 1,每次设备重启后都会初始化为 0 值设置,1:正向出纸,0:反向出纸,
-  $content .= "<TEXT x='9' y='10' font='12' w='1' h='2' r='0'>#001       五号桌      1/3</TEXT><TEXT x='80' y='80' font='12' w='2' h='2' r='0'>可乐鸡翅</TEXT><TEXT x='9' y='180' font='12' w='1' h='1' r='0'>张三先生       13800138000</TEXT>";//40mm宽度标签纸打印例子,打开注释调用标签打印接口打印
-  
-  //提示:
-  //SN => 打印机编号
-  //$content => 打印内容,不能超过5000字节
-  //$times => 打印次数,默认为1。
-  //打开注释可测试
-  // printLabelMsg(SN,$content,1);//打开注释调用标签机打印接口进行打印,该接口只能是标签机使用,其它型号打印机请勿使用该接口
-
-
-  //**************************************方法4 批量删除打印机**************************************************
-  //***接口返回值说明***
-  //成功:{"msg":"ok","ret":0,"data":{"ok":["123456789成功"],"no":[]},"serverExecutedTime":5}
-  //错误:{"msg":"ok","ret":0,"data":{"ok":[],"no":["12345678打印机不存在"]},"serverExecutedTime":2}
-  //错误:{"msg":"ok","ret":0,"data":{"ok":[],"no":["123456789用户UID不匹配"]},"serverExecutedTime":3}
-  //提示:
-  //$snlist => 打印机编号,多台打印机请用减号"-"连接起来。
-  //打开注释可测试
-  // $snlist = "123456789";
-  // printerDelList($snlist);
-
-
-
-  //************************************方法5 修改打印机信息接口************************************************
-  //***接口返回值说明***
-  //成功:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":5}
-  //错误:{"msg":"参数错误 : 参数值不能传空字符,\"\"、\"null\"、\"undefined\".","ret":-2,"data":null,"serverExecutedTime":1}
-  //提示:
-  //SN => 打印机编号
-  //$name => 打印机备注名称
-  //$phonenum => 打印机流量卡号码
-  //打开注释可测试
-  //$name = "飞鹅云打印机";
-  //$phonenum = "01234567891011121314";
-  // printerEdit(SN,$name,$phonenum);
-
-
-
-  //************************************方法6 清空待打印订单接口************************************************
-  //***接口返回值说明***
-  //成功:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":4}
-  //错误:{"msg":"验证失败 : 打印机编号和用户不匹配.","ret":1002,"data":null,"serverExecutedTime":3}
-  //错误:{"msg":"参数错误 : 参数值不能传空字符,\"\"、\"null\"、\"undefined\".","ret":-2,"data":null,"serverExecutedTime":2}
-  //提示:
-  //SN => 打印机编号
-  //打开注释可测试
-  // delPrinterSqs(SN);
-
-
-  //*********************************方法7 查询订单是否打印成功接口*********************************************
-  //***接口返回值说明***
-  //正确例子:
-  //已打印:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":6}
-  //未打印:{"msg":"ok","ret":0,"data":false,"serverExecutedTime":6}
-
-  //提示:
-  //$orderid => 订单ID,由方法1接口Open_printMsg返回。
-  //打开注释可测试
-  //$orderid = "123456789_20160823165104_1853029628";//订单ID,从方法1返回值中获取
-  //queryOrderState($orderid);
-
-
-
-  //*****************************方法8 查询指定打印机某天的订单统计数接口*****************************************
-  //***接口返回值说明***
-  //正确例子:
-  //{"msg":"ok","ret":0,"data":{"print":6,"waiting":1},"serverExecutedTime":9}
-  //错误:{"msg":"验证失败 : 打印机编号和用户不匹配.","ret":1002,"data":null,"serverExecutedTime":3}
-
-  //提示:
-  //$date => 查询日期,格式YY-MM-DD,如:2016-09-20
-  //打开注释可测试
-  // $date = "2016-09-20";
-  // queryOrderInfoByDate(SN,$date);
-
-
-
-  //***********************************方法9 获取某台打印机状态接口***********************************************
-  //***接口返回值说明***
-  //正确例子:
-  //{"msg":"ok","ret":0,"data":"离线","serverExecutedTime":9}
-  //{"msg":"ok","ret":0,"data":"在线,工作状态正常","serverExecutedTime":9}
-  //{"msg":"ok","ret":0,"data":"在线,工作状态不正常","serverExecutedTime":9}
-
-  //提示:
-  //SN => 填打印机编号
-  //打开注释可测试
-  // queryPrinterStatus(SN);
-
-
-
-
-  /**
-   * [批量添加打印机接口 Open_printerAddlist]
-   * @param  [string] $printerContent [打印机的sn#key]
-   * @return [string]                 [接口返回值]
-   */
-  function printerAddlist($printerContent){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_printerAddlist',
-      'printerContent'=>$printerContent
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-
-  /**
-   * [打印订单接口 Open_printMsg]
-   * @param  [string] $sn      [打印机编号sn]
-   * @param  [string] $content [打印内容]
-   * @param  [string] $times   [打印联数]
-   * @return [string]          [接口返回值]
-   */
-  function printMsg($sn,$content,$times){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_printMsg',
-      'sn'=>$sn,
-      'content'=>$content,
-      'times'=>$times//打印次数
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      //服务器返回的JSON字符串,建议要当做日志记录起来
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [标签机打印订单接口 Open_printLabelMsg]
-   * @param  [string] $sn      [打印机编号sn]
-   * @param  [string] $content [打印内容]
-   * @param  [string] $times   [打印联数]
-   * @return [string]          [接口返回值]
-   */
-  function printLabelMsg($sn,$content,$times){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_printLabelMsg',
-      'sn'=>$sn,
-      'content'=>$content,
-      'times'=>$times//打印次数
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      //服务器返回的JSON字符串,建议要当做日志记录起来
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [批量删除打印机 Open_printerDelList]
-   * @param  [string] $snlist [打印机编号,多台打印机请用减号“-”连接起来]
-   * @return [string]         [接口返回值]
-   */
-  function printerDelList($snlist){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_printerDelList',
-      'snlist'=>$snlist
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [修改打印机信息接口 Open_printerEdit]
-   * @param  [string] $sn       [打印机编号]
-   * @param  [string] $name     [打印机备注名称]
-   * @param  [string] $phonenum [打印机流量卡号码,可以不传参,但是不能为空字符串]
-   * @return [string]           [接口返回值]
-   */
-  function printerEdit($sn,$name,$phonenum){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_printerEdit',
-      'sn'=>$sn,
-      'name'=>$name,
-      'phonenum'=>$phonenum
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-
-  /**
-   * [清空待打印订单接口 Open_delPrinterSqs]
-   * @param  [string] $sn [打印机编号]
-   * @return [string]     [接口返回值]
-   */
-  function delPrinterSqs($sn){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_delPrinterSqs',
-      'sn'=>$sn
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [查询订单是否打印成功接口 Open_queryOrderState]
-   * @param  [string] $orderid [调用打印机接口成功后,服务器返回的JSON中的编号 例如:123456789_20190919163739_95385649]
-   * @return [string]          [接口返回值]
-   */
-  function queryOrderState($orderid){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_queryOrderState',
-      'orderid'=>$orderid
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [查询指定打印机某天的订单统计数接口 Open_queryOrderInfoByDate]
-   * @param  [string] $sn   [打印机的编号]
-   * @param  [string] $date [查询日期,格式YY-MM-DD,如:2019-09-20]
-   * @return [string]       [接口返回值]
-   */
-  function queryOrderInfoByDate($sn,$date){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_queryOrderInfoByDate',
-      'sn'=>$sn,
-      'date'=>$date
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [获取某台打印机状态接口 Open_queryPrinterStatus]
-   * @param  [string] $sn [打印机编号]
-   * @return [string]     [接口返回值]
-   */
-  function queryPrinterStatus($sn){
-    $time = time();         //请求时间
-    $msgInfo = array(
-      'user'=>USER,
-      'stime'=>$time,
-      'sig'=>signature($time),
-      'apiname'=>'Open_queryPrinterStatus',
-      'sn'=>$sn
-    );
-    $client = new HttpClient(IP,PORT);
-    if(!$client->post(PATH,$msgInfo)){
-      echo 'error';
-    }else{
-      $result = $client->getContent();
-      echo $result;
-    }
-  }
-
-  /**
-   * [signature 生成签名]
-   * @param  [string] $time [当前UNIX时间戳,10位,精确到秒]
-   * @return [string]       [接口返回值]
-   */
-  function signature($time){
-    return sha1(USER.UKEY.$time);//公共参数,请求公钥
-  }
-
-?>
-
-}

+ 108 - 0
app/mshop/src/Buy.php

@@ -183,4 +183,112 @@ class Buy extends Core
 
         return Dever::load('mshop/lib/buy')->set(1,1)->finish($this->shop_id, $order_id);
     }
+
+    # 打印
+    public function printer()
+    {
+        $id = Dever::input('printer_id');
+        if (!$id) {
+            Dever::alert('请选择打印机');
+        }
+        $where['id'] = $id;
+        $where['shop_id'] = $this->shop_id;
+        $info = Dever::db('shop/print')->find($where);
+        if (!$info) {
+            Dever::alert('请选择打印机');
+        }
+
+        $order = $this->view();
+
+        $manage_config = Dever::db('main/manage_config')->find();
+        $sell_config = Dever::db('main/sell_config')->find();
+        $main_config = Dever::db('main/config')->find();
+        $config = Dever::db('shop/buy_order')->config;
+
+        $user = $this->user;
+
+        $left = 70;
+        $right = 30;
+        $head = array('名称', '数量', '单价', $left, $right);
+        $goods = array();
+        $tgoods = array();
+        foreach ($order['goods'] as $k => $v) {
+            $sku = isset($v['info']['sku_name']) ? '-' . str_replace(',', '', $v['info']['sku_name']) : '';
+            $d  = array
+            (
+                $v['info']['name'] . $sku,
+                $v['num'],
+                $v['price'],
+                $left,
+                $right
+            );
+            $goods[] = $d;
+            if ($v['status'] == 3) {
+                $tgoods[] = $d;
+            }
+        }
+
+        $print = Dever::load('mshop/lib/feieyun');
+
+        $print->hr('-', $main_config['name'])->br();
+        $print->text('单号:' . $order['order_num'], 'CB')->br();
+        $print->text('门店名称:' . $order['type_info']['name']);
+        $print->text('制 单 人:'.$user['name']);
+        $print->text('下单时间:'.$order['cdate']);
+        if ($order['fdate']) {
+            $print->text('完成时间:'.$order['fdate']);
+        }
+        
+        if ($goods) {
+            $print->table($head, $goods, '订单商品');
+        }
+        
+        if (isset($order['ps_cash']) && $order['ps_cash']) {
+            $print->lr('配送费:', $order['ps_cash']);
+        }
+        //$print->lr('应    付:', $order['price']);
+        //$print->hr();
+        $print->lr('微信支付:', $order['price']);
+        
+        if ($tgoods) {
+            $print->table($head, $tgoods, '退款商品');
+            $print->lr('退款金额:', $order['coupon_cash']);
+        }
+
+        $print->hr();
+
+        if (isset($order['source_info']) && $order['source_info']) {
+            $print->text('供应商');
+            $print->text($order['source_info']['name'] . ',' . $order['source_info']['mobile']);
+
+            $print->hr();
+        }
+
+
+        if (isset($order['type_info']) && $order['type_info']) {
+            $print->text('配送地址');
+            $print->text($order['type_info']['truename'] . ',' . $order['type_info']['mobile']);
+
+            $area = Dever::load("area/api.string", $order['type_info']['area'], '');
+            $print->text($order['type_info']['address']);
+            $print->hr();
+        }
+
+        if ($order['info']) {
+            $print->lr('备    注:', $order['info']);
+
+            $print->hr();
+        }
+        
+        $print->center('如遇任何问题请致电客服');
+        $print->center('电话:'.$manage_config['phone']);
+        $print->center($main_config['worktime']);
+        //$content .= '<QR>http://www.feieyun.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
+
+        $content = $print->getText();
+        echo $content;die;
+        $print->printOrder($info['number'], $content, 1);
+
+        return 'ok';
+    }
 }

+ 43 - 36
app/mshop/src/Data.php

@@ -494,81 +494,88 @@ class Data extends Core
         $shop = Dever::db('shop/info')->find($order['shop_id']);
 
         $user = $this->user;
+
+        $left = 70;
+        $right = 30;
+        $head = array('名称', '数量', '单价', $left, $right);
         $goods = array();
         $tgoods = array();
         foreach ($order['goods'] as $k => $v) {
-            $sku = isset($v['info']['sku_name']) ? '-' . $v['info']['sku_name'] : '';
+            $sku = isset($v['info']['sku_name']) ? '-' . str_replace(',', '', $v['info']['sku_name']) : '';
             $d  = array
             (
-                'title' => $v['info']['name'] . $sku,
-                'price' => '123.456',
-                'num' => $v['num'],
-                'total' => '123.456',
+                $v['info']['name'] . $sku,
+                $v['num'],
+                $v['price'],
+                $left,
+                $right
             );
             $goods[] = $d;
             if ($v['status'] == 3) {
                 $tgoods[] = $d;
             }
         }
-        $content = '------------'.$main_config['name'].'------------<BR><BR>';
-        $content .= '<C>'.$config['method'][$order['method']].'</C><BR>';
-        $content .= '<CB>单号:'.$order['order_num'].'</CB><BR><BR>';
-        $content .= '门店名称:'.$shop['name'].'<BR>';
-        $content .= '制 单 人:'.$user['name'].'<BR>';
-        $content .= '下单时间:'.$order['cdate'].'<BR>';
+
+        $print = Dever::load('mshop/lib/feieyun');
+
+        $print->hr('-', $main_config['name'])->br();
+        $print->center($config['method'][$order['method']]);
+        $print->text('单号:' . $order['order_num'], 'CB')->br();
+        $print->text('门店名称:' . $shop['name']);
+        $print->text('制 单 人:'.$user['name']);
+        $print->text('下单时间:'.$order['cdate']);
         if ($order['fdate']) {
-            $content .= '完成时间:'.$order['fdate'].'<BR>';
+            $print->text('完成时间:'.$order['fdate']);
         }
         
         if ($goods) {
-            $content .= Dever::load('mshop/lib/feieyun')->goods('订单商品', $goods);
+            $print->table($head, $goods, '订单商品');
         }
         
         if ($order['card_code_id']) {
             $card = Dever::db('goods/card_code')->find($order['card_code_id']);
             if ($card) {
-                $content .= '礼品卡:'.$card['card'].'<BR>';
+                $print->text('礼品卡:'.$card['card']);
             }
         }
-        $content .= Dever::load('mshop/lib/feieyun')->lr('优    惠:', $order['coupon_cash']).'<BR>';
+        $print->lr('优    惠:', $order['coupon_cash']);
         if (isset($order['ps_cash']) && $order['ps_cash']) {
-            $content .= Dever::load('mshop/lib/feieyun')->lr('配送费:', $order['ps_cash']).' <BR>';
+            $print->lr('配送费:', $order['ps_cash']);
         }
-        $content .= Dever::load('mshop/lib/feieyun')->lr('应    付:', $order['price']).'<BR>';
-        $content .= '--------------------------------<BR>';
-        $content .= Dever::load('mshop/lib/feieyun')->lr($order['pay_type_name'] . '支付:', $order['price']).'<BR>';
-        $content .= Dever::load('mshop/lib/feieyun')->lr('找    零:', $order['kou_cash']).'<BR>';
+        $print->lr('应    付:', $order['price']);
+        $print->hr();
+        $print->lr($order['pay_type_name'] . '支付:', $order['price']);
+        $print->lr('找    零:', $order['kou_cash']);
         
         if ($tgoods) {
-            $content .= Dever::load('mshop/lib/feieyun')->goods('退款商品', $tgoods);
-            $content .= Dever::load('mshop/lib/feieyun')->lr('退款金额:', $order['coupon_cash']).'<BR>';
+            $print->table($head, $tgoods, '退款商品');
+            $print->lr('退款金额:', $order['coupon_cash']);
         }
 
-        $content .= '--------------------------------<BR>';
+        $print->hr();
 
         if (isset($order['address']) && $order['address']) {
-            $content .= '配送地址<BR>';
-            $content .= $order['address']['contact'] . ',' . $order['address']['mobile'] . '<BR>';
+            $print->text('配送地址');
+            $print->text($order['address']['contact'] . ',' . $order['address']['mobile']);
 
-            $area = Dever::load("area/api.string", $order['address']['area']);
-            $content .= $area . $order['address']['address'] . $order['address']['house_number'] . '<BR>';
-            $content .= '--------------------------------<BR>';
+            $area = Dever::load("area/api.string", $order['address']['area'], '');
+            $print->text($area . $order['address']['address'] . $order['address']['house_number']);
+            $print->hr();
         }
 
         if ($order['info']) {
-            $content .= Dever::load('mshop/lib/feieyun')->lr('备    注:', $order['info']).'<BR>';
+            $print->lr('备    注:', $order['info']);
 
-            $content .= '--------------------------------<BR>';
+            $print->hr();
         }
         
-
-        $content .= '<C>如遇任何问题请致电客服</C><BR>';
-        $content .= '<C>电话:'.$manage_config['phone'].'</C><BR>';
-        $content .= '<C>'.$main_config['worktime'].'</C><BR>';
+        $print->center('如遇任何问题请致电客服');
+        $print->center('电话:'.$manage_config['phone']);
+        $print->center($main_config['worktime']);
         //$content .= '<QR>http://www.feieyun.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
 
-        echo $content;
-        Dever::load('mshop/lib/feieyun')->printOrder($info['number'], $content, 1);
+        $content = $print->getText();
+        $print->printOrder($info['number'], $content, 1);
 
         return 'ok';
     }

+ 29 - 21
app/mshop/src/Goods.php

@@ -30,13 +30,13 @@ class Goods extends Core
     {
         $manage_config = Dever::db('main/manage_config')->find();
         $sell_config = Dever::db('main/sell_config')->find();
-        $config = Dever::db('main/config')->find();
+        $main_config = Dever::db('main/config')->find();
         $data = Dever::load('shop/lib/info')->getGoodsSku($this->shop_id);
 
 
         $pdf = Dever::load('pdf/lib/base')->init();
 
-        $pdf->hr('-', $config['name']);
+        $pdf->hr('-', $main_config['name']);
 
         $pdf->br()->font(20)->center('库存清单');
         $pdf->font(10);
@@ -67,7 +67,7 @@ class Goods extends Core
         //$pdf->SetY(-100);
         $pdf->center('如遇任何问题请致电客服');
         $pdf->center('电话:' . $manage_config['phone']);
-        $pdf->center($config['worktime']);
+        $pdf->center($main_config['worktime']);
 
         $pdf->br(2)
         ->img($sell_config['applet'], 70)
@@ -94,35 +94,43 @@ class Goods extends Core
 
         $manage_config = Dever::db('main/manage_config')->find();
         $sell_config = Dever::db('main/sell_config')->find();
-        $config = Dever::db('main/config')->find();
+        $main_config = Dever::db('main/config')->find();
         $data = Dever::load('shop/lib/info')->getGoodsSku($this->shop_id);
 
-        $content = '--------------'.$main_config['name'].'------------<BR><BR>';
-        $content .= '门店名称:'.$this->shop['name'].'<BR>';
-        $content .= '制单人:'.$this->user['name'].'<BR>';
-        $content .= '制单时间:'.date('Y-m-d H:i:s').'<BR>';
+        $print = Dever::load('mshop/lib/feieyun');
+
+        $print->hr('-', $main_config['name'])->br();
+        $print->text('门店名称:' . $this->shop['name']);
+        $print->text('制 单 人:'.$this->user['name']);
+        $print->text('制单时间:'.date('Y-m-d H:i:s'));
         
         if ($data) {
-            $orderInfo .= '--------------------------------<BR>';
-            $orderInfo .= '名称                         数量<BR>';
+            $left = 70;
+            $right = 30;
+            $head = array('名称', '数量', $left, $right);
+            $body = array();
             foreach ($data as $k => $v) {
                 if (isset($v['price_array'])) {
-                    $orderInfo .= $v['name'] . '     <BR>';
-                    $orderInfo .= '----' . $v1['name'] . '     '.$v['total'].'<BR>';
+                    $body[] = array($v['name'], '', $left, $right);
+                    foreach ($v['price_array'] as $k1 => $v1) {
+                        $name = '----' . $v1['name'];
+                        $total = $v1['total'];
+                        $body[] = array($name, $total, $left, $right);
+                    }
+                    
                 } else {
-                    $orderInfo .= $v['name'] . '     '.$v['total'].'<BR>';
+                    $name = $v['name'];
+                    $total = $v['total'];
+                    $body[] = array($name, $total, $left, $right);
                 }
             }
-
-            $orderInfo .= '--------------------------------<BR>';
+            $print->table($head, $body, '', 'lr');
         }
 
-        $content .= '<C>如遇任何问题请致电客服</C><BR>';
-        $content .= '<C>电话:'.$factory_config['phone'].'</C><BR>';
-        $content .= '<C>'.$main_config['worktime'].'</C><BR>';
-        //$content .= '<QR>http://www.feieyun.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
-
-        echo $content;die;
+        $print->center('如遇任何问题请致电客服');
+        $print->center('电话:'.$manage_config['phone']);
+        $print->center($main_config['worktime']);
+        $content = $print->getText();
         Dever::load('mshop/lib/feieyun')->printOrder($info['number'], $content, 1);
 
         return 'ok';

+ 29 - 23
app/mshop/src/Out.php

@@ -124,36 +124,42 @@ class Out extends Core
 
         $manage_config = Dever::db('main/manage_config')->find();
         $sell_config = Dever::db('main/sell_config')->find();
-        $config = Dever::db('main/config')->find();
+        $main_config = Dever::db('main/config')->find();
         $data = $this->view();
 
-        $content = '--------------'.$main_config['name'].'------------<BR><BR>';
-        $content .= '门店名称:'.$this->shop['name'].'<BR>';
-        $content .= '制单人:'.$this->user['name'].'<BR>';
-        $content .= '制单时间:'.date('Y-m-d H:i:s').'<BR>';
+        $print = Dever::load('mshop/lib/feieyun');
+
+        $print->hr('-', $main_config['name'])->br();
+        $print->text('门店名称:' . $this->shop['name']);
+        $print->text('制 单 人:'.$this->user['name']);
+        $print->text('制单时间:'.date('Y-m-d H:i:s'));
         
-        if ($data) {
-            $orderInfo .= '--------------------------------<BR>';
-            $orderInfo .= '名称                         数量<BR>';
-            foreach ($data as $k => $v) {
-                if (isset($v['price_array'])) {
-                    $orderInfo .= $v['name'] . '     <BR>';
-                    $orderInfo .= '----' . $v1['name'] . '     '.$v['total'].'<BR>';
-                } else {
-                    $orderInfo .= $v['name'] . '     '.$v['total'].'<BR>';
-                }
+        if ($data && $data['goods']) {
+
+            $left = 70;
+            $right = 30;
+            $head = array('名称', '数量', $left, $right);
+            $body = array();
+            foreach ($data['goods'] as $k => $v) {
+                $sku = isset($v['info']['sku_name']) ? '-' . str_replace(',', '', $v['info']['sku_name']) : '';
+                $d  = array
+                (
+                    $v['info']['name'] . $sku,
+                    $v['num'],
+                    $left,
+                    $right
+                );
+                $body[] = $d;
             }
-
-            $orderInfo .= '--------------------------------<BR>';
+            $print->table($head, $body, '', 'lr');
         }
 
-        $content .= '<C>如遇任何问题请致电客服</C><BR>';
-        $content .= '<C>电话:'.$factory_config['phone'].'</C><BR>';
-        $content .= '<C>'.$main_config['worktime'].'</C><BR>';
-        //$content .= '<QR>http://www.feieyun.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
+        $print->center('如遇任何问题请致电客服');
+        $print->center('电话:'.$manage_config['phone']);
+        $print->center($main_config['worktime']);
 
-        echo $content;die;
-        Dever::load('mshop/lib/feieyun')->printOrder($info['number'], $content, 1);
+        $content = $print->getText();
+        $print->printOrder($info['number'], $content, 1);
 
         return 'ok';
     }