dever 3 yıl önce
ebeveyn
işleme
779c3df779

+ 18 - 14
app/goods/lib/Set.php

@@ -18,36 +18,38 @@ class Set
 
         $result = array();
         if ($data) {
+            $i = 0;
             foreach ($data as $k => $v) {
                 
                 $sku = Dever::db('goods/info_sku')->select(array('info_id' => $v['id']));
 
                 if ($sku) {
                     $other = Dever::db($table)->find(array($type => $id, 'goods_id' => $v['id'], 'key' => -1));
-                    $result[$k]['id'] = $v['id'];
-                    $result[$k]['name'] = $v['name'];
-                    $result[$k]['price'] = $v['price'];
-                    $result[$k]['price_type'] = $v['price_type'];
-                    $result[$k]['select'] = 2;
+                    $result[$i]['id'] = $v['id'];
+                    $result[$i]['name'] = $v['name'];
+                    $result[$i]['price'] = $v['price'];
+                    $result[$i]['price_type'] = $v['price_type'];
+                    $result[$i]['select'] = 2;
+                    $result[$i]['del'] = 1;
                     if ($type == 'factory_id') {
                         if ($other) {
-                            $result[$k]['p_price'] = $other['p_price'];
-                            $result[$k]['select'] = $other['state'];
+                            $result[$i]['p_price'] = $other['p_price'];
+                            $result[$i]['select'] = $other['state'];
                         } else {
-                            $result[$k]['p_price'] = $v['price'];
+                            $result[$i]['p_price'] = $v['price'];
                         }
                     } else {
                         if ($other) {
-                            $result[$k]['total'] = $other['total_num'] - $other['sell_num'];
-                            $result[$k]['select'] = $other['state'];
+                            $result[$i]['total'] = $other['total_num'] - $other['sell_num'];
+                            $result[$i]['select'] = $other['state'];
                         } else {
-                            $result[$k]['total'] = 0;
+                            $result[$i]['total'] = 0;
                         }
                     }
-                    $result[$k]['children'] = array();
+                    $result[$i]['children'] = array();
                     $num = count($sku);
                     if ($num == 1 && $sku[0]['key'] == -1) {
-                        $result[$k]['end'] = true;
+                        $result[$i]['end'] = true;
                     } else {
                         foreach ($sku as $k1 => $v1) {
                             $v1['sku_name'] = '';
@@ -71,6 +73,7 @@ class Set
                                 'name' => $name,
                                 'price' => $v1['price'] ? $v1['price'] : 0,
                                 'price_type' => $v['price_type'],
+                                'del' => 1,
                                 'end' => true,
                             );
 
@@ -91,9 +94,10 @@ class Set
                                 }
                             }
 
-                            $result[$k]['children'][] = $children;
+                            $result[$i]['children'][] = $children;
                         }
                     }
+                    $i++;
                 }
             }
         }

+ 232 - 437
app/mshop/lib/Feieyun.php

@@ -1,438 +1,233 @@
-<?php
-
-namespace Mshop\Lib;
-
-use Dever;
-
-class Feieyun
-{
-    private $config = array
-    (
-        //飞鹅云后台注册账号
-        'user' => '',
-        //飞鹅云后台注册账号后生成的UKEY
-        'ukey' => '',
-        //打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
-        'sn' => '',
-        //host地址
-        'host' => 'http://api.feieyun.cn:80/Api/Open/',
-    );
-    # 生成参数
-    public function param($param)
-    {
-        $time = time();
-        $param['user'] = this->config['user'];
-        $param[''] = sha1($this->config['user'] . $this->config['ukey'] . $time);
-    }
-
-    # 发货
-    public function send_api()
-    {
-        return Dever::load('mshop/lib/buy.send_commit');
-    }
-
-    <?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);//公共参数,请求公钥
-  }
-
-?>
-
+<?php
+
+namespace Mshop\Lib;
+
+use Dever;
+
+class Feieyun
+{
+    private $config = array
+    (
+        //飞鹅云后台注册账号
+        'user' => 'liuxuemei@zsma.com.cn',
+        //飞鹅云后台注册账号后生成的UKEY
+        'ukey' => 'pMsXhZWu5F65MYyV',
+        //host地址
+        'host' => 'http://api.feieyun.cn:80/Api/Open/',
+    );
+    # 生成参数
+    public function param($api, $send = array())
+    {
+        $time = time();
+        $param['user'] = $this->config['user'];
+        $param['stime'] = $time;
+        $param['sig'] = sha1($this->config['user'] . $this->config['ukey'] . $time);
+        $param['apiname'] = $api;
+        $param = array_merge($param, $send);
+        return $param;
+    }
+
+    # 发送
+    public function send($api, $send)
+    {
+        $url = $this->config['host'];
+        $param = $this->param($api, $send);
+        $result = Dever::curl($url, $param, 'post');
+        $result = Dever::json_decode($result);
+        if (isset($result['data']) && $result['data'] && isset($result['data'])) {
+        	return $result['data'];
+        }
+        if (isset($result['msg'])) {
+        	return $result['msg'];
+        }
+        return 'error';
+    }
+
+    # 添加打印机
+    public function add($data)
+    {
+      	$content = array();
+      	foreach ($data as $k => $v) {
+      		$content[] = $v['number'] . '#' . $v['key'] . '#' . $v['name'] . '#' . $v['phonenum'];
+      	}
+      	$content = implode('\n', $content);
+      	$send['printerContent'] = $content;
+      	$result = $this->send('Open_printerAddlist', $send);
+        return $result;
+    }
+
+    # 编辑打印机
+    public function edit($sn, $name, $phonenum)
+    {
+      	$send['sn'] = $sn;
+      	$send['name'] = $name;
+      	if ($phonenum && $phonenum != 'null') {
+      		$send['phonenum'] = $phonenum;
+      	}
+      	
+      	$result = $this->send('Open_printerEdit', $send);
+        return $result;
+    }
+
+    # 删除打印机
+    public function del($data)
+    {
+      	$content = array();
+      	foreach ($data as $k => $v) {
+      		$content[] = $v['number'];
+      	}
+      	$content = implode('-', $content);
+      	$send['snlist'] = $content;
+      	$result = $this->send('Open_printerDelList', $send);
+        return $result;
+    }
+
+    # 打印订单
+    public function printOrder($sn, $content, $times)
+    {
+    	$send['sn'] = $sn;
+    	$send['content'] = $content;
+    	$send['times'] = $times;
+      	$result = $this->send('Open_printMsg', $send);
+      	return $result;
+    }
+
+    # 打印标签机订单
+    public function printLabelOrder($sn, $content, $times)
+    {
+    	$send['sn'] = $sn;
+    	$send['content'] = $content;
+    	$send['times'] = $times;
+      	$result = $this->send('Open_printLabelMsg', $send);
+      	return $result;
+    }
+
+    # 清空待打印订单接口
+    public function delOrder($sn)
+    {
+    	$send['sn'] = $sn;
+      	$result = $this->send('Open_delPrinterSqs', $send);
+      	return $result;
+    }
+
+    # 查询订单是否打印成功接口
+    public function order($id)
+    {
+    	$send['orderid'] = $id;
+      	$result = $this->send('Open_queryOrderState', $send);
+      	return $result;
+    }
+
+    # 查询指定打印机某天的订单统计数接口
+    public function stat($sn, $date)
+    {
+		$send['sn'] = $sn;
+		$send['date'] = $date;
+		$result = $this->send('Open_queryOrderInfoByDate', $send);
+		return $result;
+    }
+
+    # 获取某台打印机状态接口
+    public function status($sn)
+    {
+		$send['sn'] = $sn;
+		$result = $this->send('Open_queryPrinterStatus', $send);
+		return $result;
+    }
+
+    # 打印商品排版 商品列表,名称长度,单价长度,数量长度,金额长度
+    public function goods($name, $goods, $A = 14, $B = 6, $C = 3, $D = 6)
+    {
+    	$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'];
+			$prices = $v5['price']*$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($price) < $B) {
+				$k1 = $B - strlen($price);
+				for ($q=0; $q<$k1; $q++) {
+					$kw1 .= ' ';
+				}
+				$price = $price.$kw1;
+			}
+			if (strlen($num) < $C) {
+				$k2 = $C - strlen($num);
+				for ($q=0; $q<$k2; $q++) {
+					$kw2 .= ' ';
+				}
+				$num = $num.$kw2;
+			}
+			if (strlen($prices) < $D) {
+				$k3 = $D - strlen($prices);
+				for ($q=0;$q<$k3;$q++) {
+					$kw4 .= ' ';
+				}
+				$prices = $prices.$kw4;
+			}
+			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.' '.$price.' '.$num.' '.$prices;
+						} 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.' '.$price.' '.$num.' '.$prices;
+				} else {
+					$head .= $value.'<BR>';
+				}
+			}
+			$orderInfo .= $head.$tail.'<BR>';
+		}
+
+		$orderInfo .= '--------------------------------<BR>';
+
+		return $orderInfo;
+    }
 }

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

@@ -0,0 +1,460 @@
+<?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);//公共参数,请求公钥
+  }
+
+?>
+
+}

+ 67 - 0
app/mshop/src/Data.php

@@ -468,4 +468,71 @@ class Data extends Core
 
         return $this->data;
     }
+
+    # 打印
+    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_id = Dever::input('order_id');
+
+        $order = Dever::load('shop/lib/sell')->set(2, 2)->getView($this->shop_id, $order_id);
+
+        $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/sell_order')->config;
+        $shop = Dever::db('shop/info')->find($order['shop_id']);
+
+        $user = $this->user;
+        $goods = array();
+        foreach ($order['goods'] as $k => $v) {
+            $sku = isset($v['info']['sku_name']) ? '-' . $v['info']['sku_name'] : '';
+            $goods[] = array
+            (
+                'title' => $v['info']['name'] . $sku,
+                'price' => $v['price'],
+                'num' => $v['num'],
+            );
+        }
+        $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>';
+        $content .= '完成时间:'.$order['fdate'].'<BR>';
+        
+        $content .= Dever::load('mshop/lib/feieyun')->goods('订单商品', $goods);
+
+        if ($order['card_code_id']) {
+            $card = Dever::db('goods/card_code')->find($order['card_code_id']);
+            if ($card) {
+                $content .= '礼品卡:'.$card['card'].'<BR>';
+            }
+        }
+        $content .= '优惠:'.$order['coupon_cash'].'<BR>';
+        if (isset($order['ps_info']) && $order['ps_info']) {
+            $content .= '配送费:'.$order['ps_info']['price'].'<BR>';
+        }
+        $content .= '应付:'.$order['price'].'<BR>';
+        $content .= '送货地点:广州市南沙区xx路xx号<BR>';
+        $content .= '联系电话:13888888888888<BR>';
+        $content .= '订餐时间:2014-08-08 08:08:08<BR>';
+        $content .= '<QR>http://www.feieyun.com</QR>';//把二维码字符串用标签套上即可自动生成二维码
+
+        echo $content;die;
+        Dever::load('mshop/lib/feieyun')->printOrder($info['number'], $content, 1);
+
+        return 'ok';
+    }
 }

+ 16 - 2
app/mshop/src/My.php

@@ -190,7 +190,7 @@ class My extends Core
     public function getPrint()
     {
         $where['shop_id'] = $this->shop_id;
-        $this->data['print'] = Dever::db('shop/print')->select_page($where);
+        $this->data['print'] = Dever::db('shop/print')->select($where);
 
         return $this->data;
     }
@@ -213,6 +213,8 @@ class My extends Core
         $id = Dever::input('id');
         $name = Dever::input('name');
         $number = Dever::input('number');
+        $key = Dever::input('key');
+        $phonenum = Dever::input('phonenum');
         if ($name) {
             $update['name'] = $name;
         } else {
@@ -225,6 +227,16 @@ class My extends Core
             Dever::alert('编号不能为空');
         }
 
+        if ($key) {
+            $update['key'] = $key;
+        } else {
+            Dever::alert('识别码不能为空');
+        }
+
+        if ($phonenum) {
+            $update['phonenum'] = $phonenum;
+        }
+
         $update['shop_id'] = $this->shop_id;
 
         if ($id) {
@@ -243,7 +255,9 @@ class My extends Core
         $id = Dever::input('id');
         $info = Dever::db('shop/print')->find($id);
         if ($info && $info['shop_id'] == $this->shop_id) {
-            Dever::db('shop/print')->delete($id);
+            Dever::db('shop/print')->update(array('where_id' => $info['id'], 'state' => 2));
+
+            //Dever::load('mshop/lib/feieyun')->del(array($info));
         } else {
             Dever::alert('您没有权限删除');
         }

+ 45 - 6
app/shop/database/print.php

@@ -2,9 +2,10 @@
 # 获取分类权限
 $status = array
 (
-    1 => '使用中',
-    2 => '停止使用',
-    3 => '申请合作',
+    1 => '离线',
+    2 => '在线,工作状态正常',
+    3 => '在线,工作状态不正常',
+    10 => '绑定失败',
 );
 
 return array
@@ -16,6 +17,12 @@ return array
     # 后台菜单排序
     'order' => 10,
     'menu' => false,
+    'check' => 'number',
+    'end' => array
+    (
+        'insert' => 'shop/lib/manage.printInsert',
+        'update' => 'shop/lib/manage.printUpdate',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -67,6 +74,30 @@ return array
             'list'      => true,
         ),
 
+        'key'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '打印机识别码',
+            'default'   => '',
+            'desc'      => '打印机识别码',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'phonenum'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '流量卡号码',
+            'default'   => '',
+            'desc'      => '流量卡号码',
+            'match'     => 'option',
+            'update'    => 'text',
+            //'search'    => 'fulltext',
+            //'list'      => true,
+        ),
+
         'status'        => array
         (
             'type'      => 'int-11',
@@ -77,8 +108,8 @@ return array
             //'update'  => 'select',
             'option'    => $status,
             'search'    => 'select',
-            'list'      => true,
-            'edit'      => true,
+            'list'      => 'Dever::load("shop/lib/manage.printStatus", "{status}", "{number}")',
+            //'edit'      => true,
         ),
 
         'state'     => array
@@ -104,7 +135,15 @@ return array
 
     'manage' => array
     (
-        
+        //'delete' => false,
+        'edit' => false,
+
+        'list_button' => array
+        (
+            'fast' => array('编辑', '"print&where_id={id}&col=name,phonenum&oper_save_jump=print&oper_table=print&oper_parent=print"'),
+
+            //'delete' => array('删除', 'print', '{status} == 10'),
+        )
     ),
 
     'request' => array

+ 10 - 0
app/shop/database/sell_order.php

@@ -222,6 +222,16 @@ return array
             'update'    => 'text',
         ),
 
+        'ps_cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '配送费',
+            'default'   => '0',
+            'desc'      => '配送费',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'card_code_id'      => array
         (
             'type'      => 'int-11',

+ 45 - 20
app/shop/lib/Goods.php

@@ -75,28 +75,53 @@ class Goods
                 $v['sku_id'] = -1;
             }
 
-            $up['where_goods_id'] = $v['goods_id'];
-            $up[$num] = $v['num'];
-            $state = Dever::db($table . '/goods')->$method($up);
-            if ($state) {
-                $upSku = $up;
-                $upSku['where_sku_id'] = $v['sku_id'];
-                $state = Dever::db($table . '/goods_sku')->$method($upSku);
-                if (!$state) {
-                    Dever::db($table . '/goods')->$otherMethod($up);
+            $goods = Dever::db('goods/info')->find($v['goods_id']);
+            if (!$goods) {
+                continue;
+            }
+            
+            if ($goods['price_type'] == 4) {
+                $goods['goods'] = Dever::array_decode($goods['goods']);
+                if ($goods['goods']) {
+                    foreach ($goods['goods'] as $k1 => $v1) {
+                        if ($v1['goods_id']) {
+                            if (!isset($v1['sku_id'])) {
+                                $v1['sku_id'] = -1;
+                            }
+                            $v1['num'] = $v1['num'] * $v['num'];
+                            $this->set($up, $order, $num, $table, $method, $otherMethod, $type, $col, $v1);
+                        }
+                    }
                 }
+            } else {
+                $this->set($up, $order, $num, $table, $method, $otherMethod, $type, $col, $v);
+            }
+        }
+    }
 
-                if (isset($order['source_type']) && $order['source_type'] == 2 && $type == 1 && $col == 1) {
-                    # 如果是仓库发货的,要减少仓库库存
-                    $sup['where_store_id'] = $order['source_id'];
-                    $sup['where_goods_id'] = $v['goods_id'];
-                    $sup[$num] = $v['num'];
-                    $state = Dever::db('store/goods')->$otherMethod($sup);
-                    if ($state) {
-                        $supSku = $sup;
-                        $supSku['where_sku_id'] = $v['sku_id'];
-                        $state = Dever::db('store/goods_sku')->$otherMethod($supSku);
-                    }
+    private function set($up, $order, $num, $table, $method, $otherMethod, $type, $col, $v)
+    {
+        $up['where_goods_id'] = $v['goods_id'];
+        $up[$num] = $v['num'];
+        $state = Dever::db($table . '/goods')->$method($up);
+        if ($state) {
+            $upSku = $up;
+            $upSku['where_sku_id'] = $v['sku_id'];
+            $state = Dever::db($table . '/goods_sku')->$method($upSku);
+            if (!$state) {
+                Dever::db($table . '/goods')->$otherMethod($up);
+            }
+
+            if (isset($order['source_type']) && $order['source_type'] == 2 && $type == 1 && $col == 1) {
+                # 如果是仓库发货的,要减少仓库库存
+                $sup['where_store_id'] = $order['source_id'];
+                $sup['where_goods_id'] = $v['goods_id'];
+                $sup[$num] = $v['num'];
+                $state = Dever::db('store/goods')->$otherMethod($sup);
+                if ($state) {
+                    $supSku = $sup;
+                    $supSku['where_sku_id'] = $v['sku_id'];
+                    $state = Dever::db('store/goods_sku')->$otherMethod($supSku);
                 }
             }
         }

+ 9 - 1
app/shop/lib/Info.php

@@ -213,7 +213,11 @@ class Info
     {
         $where['shop_id'] = $shop_id;
         $where['goods_id'] = isset($info['goods_id']) ? $info['goods_id'] : $info;
+        $where['sku_id'] = $sku_id ? $sku_id : -1;
         $other = Dever::db('shop/goods_sku')->getData($where);
+        if (!$other) {
+            return false;
+        }
         $data = Dever::load('goods/lib/info')->getInfo($info, $attr, array($other, array('total')));
 
         if($data) {
@@ -249,7 +253,11 @@ class Info
     {
         $info = $this->getGoodsInfo($shop_id, $goods_id, $sku_id, false);
         if (!$info) {
-            Dever::alert('商品不存在');
+            if ($state == 2) {
+                Dever::alert('商品不存在');
+            } else {
+                return false;
+            }
         }
         $total = $info['total'];
         $min = $info['min'];

+ 57 - 0
app/shop/lib/Manage.php

@@ -53,6 +53,63 @@ class Manage
         
     }
 
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function printInsert($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $name = Dever::param('name', $data);
+        $number = Dever::param('number', $data);
+        $phonenum = Dever::param('phonenum', $data);
+        $key = Dever::param('key', $data);
+        if ($number && $key) {
+            $data = array();
+            $data['name'] = $name;
+            $data['number'] = $number;
+            $data['phonenum'] = $phonenum;
+            $data['key'] = $key;
+            $result = Dever::load('mshop/lib/feieyun')->add(array($data));
+            if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
+                Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
+            } else {
+                Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
+            }
+        }
+    }
+
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function printUpdate($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $info = Dever::db('shop/print')->one($id);
+        $name = Dever::param('name', $data);
+        $phonenum = Dever::param('phonenum', $data);
+        if ($info && $name) {
+            if ($info['status'] == 10) {
+                $this->printInsert($id, $name, $info);
+            } else {
+                Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
+            }
+        }
+    }
+
+    /**
+     * 打印机状态
+     *
+     * @return mixed
+     */
+    public function printStatus($status, $sn)
+    {
+        return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
+    }
+
     /**
      * 更新信息
      *

+ 16 - 9
app/shop/lib/Sell.php

@@ -223,6 +223,14 @@ class Sell
 
         if ($info['operdate']) {
             $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
+        } else {
+            $info['operdate'] = '';
+        }
+
+        if ($info['fdate']) {
+            $info['fdate'] = date('Y-m-d H:i', $info['fdate']);
+        } else {
+            $info['fdate'] = '';
         }
 
         $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
@@ -294,9 +302,6 @@ class Sell
         if ($type == 1) {
             if (isset($data['uid']) && $data['uid'] > 0) {
                 # 默认选择优惠券
-                if ($data['price'] <= 0) {
-                    Dever::alert('付款价格错误');
-                }
                 # 查找符合要求的优惠券
                 $coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $data['uid'], 'city' => $data['shop']['city'], 'status' => 1, 'edate' => time()));
 
@@ -437,7 +442,7 @@ class Sell
                 foreach ($data['list'] as $k => $v) {
                     $data['list'][$k]['coupon_id'] = $data['coupon_id'];
                     $data['list'][$k]['user_coupon_id'] = $data['user_coupon_id'];
-                    $data['list'][$k]['coupon_cash'] = round($v['price']/$data['price'], 2) * $data['coupon_cash'];
+                    $data['list'][$k]['coupon_cash'] = round(($v['price'] * $v['buy_num'])/$data['price'], 2) * $data['coupon_cash'];
                 }
             }
             $data['price'] -= $data['coupon_cash'];
@@ -574,12 +579,8 @@ class Sell
         foreach ($goods_id as $k => $v) {
             $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
             $n = isset($num[$k]) ? $num[$k] : 1;
+
             $data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s);
-            if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) {
-                if ($n < $data['list'][$k]['min']) {
-                    $data['list'][$k]['ku_state'] = 2;
-                }
-            }
             $data['list'][$k]['num'] = $n;
 
             # 2是库存不足
@@ -588,6 +589,12 @@ class Sell
             # 验证是否有货
             $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $data['shop']['id'], $s);
 
+            if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) {
+                if ($total < $data['list'][$k]['min']) {
+                    $total = 0;
+                }
+            }
+
             if ($total <= 0) {
                 $data['list'][$k]['ku_state'] = 2;
                 $data['list'][$k]['buy_num'] = 0;