123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?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;
- }
- }
|