Feieyun.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace Mshop\Lib;
  3. use Dever;
  4. class Feieyun
  5. {
  6. private $config = array
  7. (
  8. //飞鹅云后台注册账号
  9. 'user' => 'liuxuemei@zsma.com.cn',
  10. //飞鹅云后台注册账号后生成的UKEY
  11. 'ukey' => 'pMsXhZWu5F65MYyV',
  12. //host地址
  13. 'host' => 'http://api.feieyun.cn:80/Api/Open/',
  14. );
  15. # 生成参数
  16. public function param($api, $send = array())
  17. {
  18. $time = time();
  19. $param['user'] = $this->config['user'];
  20. $param['stime'] = $time;
  21. $param['sig'] = sha1($this->config['user'] . $this->config['ukey'] . $time);
  22. $param['apiname'] = $api;
  23. $param = array_merge($param, $send);
  24. return $param;
  25. }
  26. # 发送
  27. public function send($api, $send)
  28. {
  29. $url = $this->config['host'];
  30. $param = $this->param($api, $send);
  31. $result = Dever::curl($url, $param, 'post');
  32. $result = Dever::json_decode($result);
  33. if (isset($result['data']) && $result['data'] && isset($result['data'])) {
  34. return $result['data'];
  35. }
  36. if (isset($result['msg'])) {
  37. return $result['msg'];
  38. }
  39. return 'error';
  40. }
  41. # 添加打印机
  42. public function add($data)
  43. {
  44. $content = array();
  45. foreach ($data as $k => $v) {
  46. $content[] = $v['number'] . '#' . $v['key'] . '#' . $v['name'] . '#' . $v['phonenum'];
  47. }
  48. $content = implode('\n', $content);
  49. $send['printerContent'] = $content;
  50. $result = $this->send('Open_printerAddlist', $send);
  51. return $result;
  52. }
  53. # 编辑打印机
  54. public function edit($sn, $name, $phonenum)
  55. {
  56. $send['sn'] = $sn;
  57. $send['name'] = $name;
  58. if ($phonenum && $phonenum != 'null') {
  59. $send['phonenum'] = $phonenum;
  60. }
  61. $result = $this->send('Open_printerEdit', $send);
  62. return $result;
  63. }
  64. # 删除打印机
  65. public function del($data)
  66. {
  67. $content = array();
  68. foreach ($data as $k => $v) {
  69. $content[] = $v['number'];
  70. }
  71. $content = implode('-', $content);
  72. $send['snlist'] = $content;
  73. $result = $this->send('Open_printerDelList', $send);
  74. return $result;
  75. }
  76. # 打印订单
  77. public function printOrder($sn, $content, $times)
  78. {
  79. $send['sn'] = $sn;
  80. $send['content'] = $content;
  81. $send['times'] = $times;
  82. $result = $this->send('Open_printMsg', $send);
  83. return $result;
  84. }
  85. # 打印标签机订单
  86. public function printLabelOrder($sn, $content, $times)
  87. {
  88. $send['sn'] = $sn;
  89. $send['content'] = $content;
  90. $send['times'] = $times;
  91. $result = $this->send('Open_printLabelMsg', $send);
  92. return $result;
  93. }
  94. # 清空待打印订单接口
  95. public function delOrder($sn)
  96. {
  97. $send['sn'] = $sn;
  98. $result = $this->send('Open_delPrinterSqs', $send);
  99. return $result;
  100. }
  101. # 查询订单是否打印成功接口
  102. public function order($id)
  103. {
  104. $send['orderid'] = $id;
  105. $result = $this->send('Open_queryOrderState', $send);
  106. return $result;
  107. }
  108. # 查询指定打印机某天的订单统计数接口
  109. public function stat($sn, $date)
  110. {
  111. $send['sn'] = $sn;
  112. $send['date'] = $date;
  113. $result = $this->send('Open_queryOrderInfoByDate', $send);
  114. return $result;
  115. }
  116. # 获取某台打印机状态接口
  117. public function status($sn)
  118. {
  119. $send['sn'] = $sn;
  120. $result = $this->send('Open_queryPrinterStatus', $send);
  121. return $result;
  122. }
  123. # 打印商品排版 商品列表,名称长度,单价长度,数量长度,金额长度
  124. public function goods($name, $goods, $A = 14, $B = 6, $C = 3, $D = 6)
  125. {
  126. $orderInfo = '';
  127. $orderInfo .= '--------------------------------<BR>';
  128. if ($name) {
  129. $orderInfo .= '<C>'.$name.'</C><BR>';
  130. }
  131. $orderInfo .= '名称 单价 数量 金额<BR>';
  132. foreach ($goods as $k5 => $v5) {
  133. $name = $v5['title'];
  134. $price = '¥' . $v5['price'];
  135. $num = $v5['num'];
  136. $prices = $v5['price']*$v5['num'];
  137. $kw3 = '';
  138. $kw1 = '';
  139. $kw2 = '';
  140. $kw4 = '';
  141. $str = $name;
  142. $blankNum = $A;//名称控制为14个字节
  143. $lan = mb_strlen($str,'utf-8');
  144. $m = 0;
  145. $j=1;
  146. $blankNum++;
  147. $result = array();
  148. if (strlen($price) < $B) {
  149. $k1 = $B - strlen($price);
  150. for ($q=0; $q<$k1; $q++) {
  151. $kw1 .= ' ';
  152. }
  153. $price = $price.$kw1;
  154. }
  155. if (strlen($num) < $C) {
  156. $k2 = $C - strlen($num);
  157. for ($q=0; $q<$k2; $q++) {
  158. $kw2 .= ' ';
  159. }
  160. $num = $num.$kw2;
  161. }
  162. if (strlen($prices) < $D) {
  163. $k3 = $D - strlen($prices);
  164. for ($q=0;$q<$k3;$q++) {
  165. $kw4 .= ' ';
  166. }
  167. $prices = $prices.$kw4;
  168. }
  169. for ($i=0;$i<$lan;$i++) {
  170. $new = mb_substr($str,$m,$j,'utf-8');
  171. $j++;
  172. if (mb_strwidth($new,'utf-8')<$blankNum) {
  173. if ($m+$j>$lan) {
  174. $m = $m+$j;
  175. $tail = $new;
  176. $lenght = Dever::convert($new);
  177. $k = $A - strlen($lenght);
  178. for ($q=0;$q<$k;$q++) {
  179. $kw3 .= ' ';
  180. }
  181. if ($m==$j) {
  182. $tail .= $kw3.' '.$price.' '.$num.' '.$prices;
  183. } else {
  184. $tail .= $kw3.'<BR>';
  185. }
  186. break;
  187. } else {
  188. $next_new = mb_substr($str,$m,$j,'utf-8');
  189. if (mb_strwidth($next_new,'utf-8')<$blankNum) {
  190. continue;
  191. } else{
  192. $m = $i+1;
  193. $result[] = $new;
  194. $j=1;
  195. }
  196. }
  197. }
  198. }
  199. $head = '';
  200. foreach ($result as $key=>$value) {
  201. if ($key < 1) {
  202. $v_lenght = Dever::convert($value);
  203. $v_lenght = strlen($v_lenght);
  204. if($v_lenght == 13) $value = $value." ";
  205. $head .= $value.' '.$price.' '.$num.' '.$prices;
  206. } else {
  207. $head .= $value.'<BR>';
  208. }
  209. }
  210. $orderInfo .= $head.$tail.'<BR>';
  211. }
  212. $orderInfo .= '--------------------------------<BR>';
  213. return $orderInfo;
  214. }
  215. }