'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 .= '--------------------------------
'; if ($name) { $orderInfo .= ''.$name.'
'; } $orderInfo .= '名称 单价 数量 金额
'; 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.'
'; } 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.'
'; } } $orderInfo .= $head.$tail.'
'; } $orderInfo .= '--------------------------------
'; return $orderInfo; } }