PrinterController.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fld
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class PrinterController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. $this->breadcrumb1='打印机设置';
  19. $this->breadcrumb2='打印机列表';
  20. $this->sellerid = SELLERUID;
  21. }
  22. /**
  23. * 打印机列表
  24. */
  25. public function index()
  26. {
  27. $_GPC = I('request.');
  28. $this->gpc = $_GPC;
  29. $condition = ' 1 ';
  30. $pindex = max(1, intval($_GPC['page']));
  31. $psize = 20;
  32. if (!empty($_GPC['keyword'])) {
  33. $_GPC['keyword'] = trim($_GPC['keyword']);
  34. $condition .= ' and printer_name like "%'.$_GPC['keyword'].'%" ';
  35. }
  36. $label = M('lionfish_comshop_printer')->where( $condition )->order(' id desc ')->limit( (($pindex - 1) * $psize) . ',' . $psize )->select();
  37. $total = M('lionfish_comshop_printer')->where( $condition )->count();
  38. $pager = pagination2($total, $pindex, $psize);
  39. $this->label = $label;
  40. $this->pager = $pager;
  41. $this->display("printer_index");
  42. }
  43. /**
  44. * 添加打印机
  45. */
  46. public function add_printer(){
  47. $_GPC = I('request.');
  48. if (IS_POST) {
  49. $data = $_GPC['data'];
  50. if (empty($data['printer_name'])) {
  51. show_json(0, array('message' => '打印机名称不能为空'));
  52. }
  53. if (empty($data['printer_type'])) {
  54. show_json(0, array('message' => '打印机类型不能为空'));
  55. }
  56. if($data['printer_type'] == 1){//飞鹅打印机
  57. if (empty($data['printer_sn'])) {
  58. show_json(0, array('message' => 'sn不能为空'));
  59. }
  60. if (empty($data['printer_key'])) {
  61. show_json(0, array('message' => 'key不能为空'));
  62. }
  63. }else if($data['printer_type'] == 2){//易联云打印机
  64. if (empty($data['api_id'])) {
  65. show_json(0, array('message' => '应用id不能为空'));
  66. }
  67. if (empty($data['api_key'])) {
  68. show_json(0, array('message' => '应用密钥key不能为空'));
  69. }
  70. if (empty($data['printer_yly_sn'])) {
  71. show_json(0, array('message' => '打印机终端号不能为空'));
  72. }
  73. if (empty($data['printer_yly_key'])) {
  74. show_json(0, array('message' => '终端密钥不能为空'));
  75. }
  76. }
  77. if (!empty($data['printer_num']) && !is_numeric($data['printer_num'])) {
  78. show_json(0, array('message' => '打印联数必须为数字'));
  79. }
  80. D('Seller/Printer')->update($data);
  81. show_json(1, array('url' => U('printer/index')));
  82. }
  83. $this->display("printer_add");
  84. }
  85. /**
  86. * 更新打印机状态
  87. */
  88. public function printer_status(){
  89. $_GPC = I('request.');
  90. $id = intval($_GPC['id']);
  91. if (empty($id)) {
  92. $id = $_GPC['ids'];
  93. }
  94. $is_printer_list = M('lionfish_comshop_config')->where( array('name' => 'is_printer_list') )->find();
  95. $printer_list = explode(',',$is_printer_list['value']);
  96. if( is_array($id) )
  97. {
  98. if($_GPC['status'] == 0){
  99. $all_list = array_merge($printer_list,$id);
  100. if(count($all_list) != count(array_unique($all_list))){
  101. show_json(0, array('message' => '请先取消默认打印机设置在进行操作'));
  102. }
  103. }
  104. $items = M('lionfish_comshop_printer')->field('id')->where( array('id' => array('in', $id)) )->select();
  105. }else{
  106. if($_GPC['status'] == 0) {
  107. if (in_array($id, $printer_list)) {
  108. show_json(0, array('message' => '请先取消默认打印机设置在进行操作'));
  109. }
  110. }
  111. $items = M('lionfish_comshop_printer')->field('id')->where( array('id' =>$id ) )->select();
  112. }
  113. if (empty($item)) {
  114. $item = array();
  115. }
  116. foreach ($items as $item) {
  117. M('lionfish_comshop_printer')->where( array('id' => $item['id']) )->save( array('status' => intval($_GPC['status'])) );
  118. }
  119. show_json(1, array('url' => U('printer/index')));
  120. }
  121. /**
  122. * 删除打印机
  123. */
  124. public function delete_printer(){
  125. $_GPC = I('request.');
  126. $id = intval($_GPC['id']);
  127. if (empty($id)) {
  128. $id = $_GPC['ids'];
  129. }
  130. $is_printer_list = M('lionfish_comshop_config')->where( array('name' => 'is_printer_list') )->find();
  131. $printer_list = explode(',',$is_printer_list['value']);
  132. if( is_array($id) )
  133. {
  134. $all_list = array_merge($printer_list,$id);
  135. if(count($all_list) != count(array_unique($all_list))){
  136. show_json(0, array('message' => '请先取消默认打印机设置在进行操作'));
  137. }
  138. $items = M('lionfish_comshop_printer')->field('id')->where( array('id' => array('in', $id)) )->select();
  139. }else{
  140. if(in_array($id,$printer_list)){
  141. show_json(0, array('message' => '请先取消默认打印机设置在进行操作'));
  142. }
  143. $items = M('lionfish_comshop_printer')->field('id')->where( array('id' =>$id ) )->select();
  144. }
  145. if (empty($item)) {
  146. $item = array();
  147. }
  148. foreach ($items as $item) {
  149. M('lionfish_comshop_printer')->where( array('id' => $item['id']) )->delete();
  150. }
  151. show_json(1, array('url' => U('printer/index')));
  152. }
  153. /**
  154. * 编辑打印机
  155. */
  156. public function edit_priner(){
  157. $_GPC = I('request.');
  158. $id = intval($_GPC['id']);
  159. if (!empty($id)) {
  160. $item = M('lionfish_comshop_printer')->where( array('id' =>$id ) )->find();
  161. $this->item = $item;
  162. }
  163. if (IS_POST) {
  164. $data = $_GPC['data'];
  165. if (empty($data['printer_name'])) {
  166. show_json(0, array('message' => '打印机名称不能为空'));
  167. }
  168. if (empty($data['printer_type'])) {
  169. show_json(0, array('message' => '打印机类型不能为空'));
  170. }
  171. if($data['printer_type'] == 1){//飞鹅打印机
  172. if (empty($data['printer_sn'])) {
  173. show_json(0, array('message' => 'sn不能为空'));
  174. }
  175. if (empty($data['printer_key'])) {
  176. show_json(0, array('message' => 'key不能为空'));
  177. }
  178. }else if($data['printer_type'] == 2){//易联云打印机
  179. if (empty($data['api_id'])) {
  180. show_json(0, array('message' => '应用id不能为空'));
  181. }
  182. if (empty($data['api_key'])) {
  183. show_json(0, array('message' => '应用密钥key不能为空'));
  184. }
  185. if (empty($data['printer_yly_sn'])) {
  186. show_json(0, array('message' => '打印机终端号不能为空'));
  187. }
  188. if (empty($data['printer_yly_key'])) {
  189. show_json(0, array('message' => '终端密钥不能为空'));
  190. }
  191. }
  192. if (!empty($data['printer_num']) && !is_numeric($data['printer_num'])) {
  193. show_json(0, array('message' => '打印联数必须为数字'));
  194. }
  195. D('Seller/Printer')->update($data);
  196. show_json(1, array('url' => U('printer/index')));
  197. }
  198. $this->display("printer_add");
  199. }
  200. /**
  201. * 打印机设置
  202. */
  203. public function config(){
  204. $_GPC = I('request.');
  205. if (IS_POST) {
  206. $data = $_GPC['data'];
  207. $config_data = array();
  208. $config_data['is_print_cancleorder'] = isset($data['is_print_cancleorder']) ? $data['is_print_cancleorder'] : 0;
  209. $config_data['is_print_admin_cancleorder'] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  210. $config_data['is_print_dansupply_order'] = isset($data['is_print_dansupply_order']) ? $data['is_print_dansupply_order'] : 0;
  211. $config_data['is_print_member_note'] = isset($data['is_print_member_note']) ? $data['is_print_member_note'] : 0;
  212. $config_data['is_print_order_note'] = isset($data['is_print_order_note']) ? $data['is_print_order_note'] : 0;
  213. $config_data['is_printer_list'] = isset($_GPC['is_printer_list']) ? $_GPC['is_printer_list'] : '';
  214. $config_data['open_feier_print'] = isset($data['open_feier_print']) ? $data['open_feier_print'] : 0;
  215. if($config_data['open_feier_print'] == 1){
  216. $feier_print_sn = isset($data['feier_print_sn']) ? $data['feier_print_sn']:'';
  217. $feier_print_key = isset($data['feier_print_key']) ? $data['feier_print_key']:'';
  218. $feier_print_lian = isset($data['feier_print_lian']) ? $data['feier_print_lian'] : 0;
  219. $config_data['feier_print_sn'] = $feier_print_sn;
  220. $config_data['feier_print_key'] = $feier_print_key;
  221. $config_data['feier_print_lian'] = $feier_print_lian;
  222. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn') )->find();
  223. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  224. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key') )->find();
  225. $feier_print_key_old = $feier_print_key_old_arr['value'];
  226. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  227. {
  228. //开始添加打印机
  229. //printaction
  230. $print_model = D('Seller/Printaction');
  231. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  232. $print_model->addprinter($snlist);
  233. }
  234. }else if($config_data['open_feier_print'] == 2){
  235. $yilian_machine_code = isset($data['yilian_machine_code']) ? $data['yilian_machine_code']:'';
  236. $yilian_msign = isset($data['yilian_msign']) ? $data['yilian_msign']:'';
  237. $yilian_client_id = isset($data['yilian_client_id']) ? $data['yilian_client_id']:'';
  238. $yilian_client_key = isset($data['yilian_client_key']) ? $data['yilian_client_key']:'';
  239. $yilian_print_lian = isset($data['yilian_print_lian']) ? $data['yilian_print_lian']:0;
  240. $config_data['yilian_machine_code'] = $yilian_machine_code;
  241. $config_data['yilian_msign'] = $yilian_msign;
  242. $config_data['yilian_client_id'] = $yilian_client_id;
  243. $config_data['yilian_client_key'] = $yilian_client_key;
  244. $config_data['yilian_print_lian'] = $yilian_print_lian;
  245. $yilian_client_id_old = D('Home/Front')->get_config_by_name('yilian_client_id');
  246. $yilian_machine_code_old = D('Home/Front')->get_config_by_name('yilian_machine_code');
  247. $yilian_msign_old = D('Home/Front')->get_config_by_name('yilian_msign');
  248. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  249. {
  250. //开始添加打印机
  251. //printaction
  252. $print_model = D('Seller/Printaction');
  253. $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  254. }
  255. }
  256. D('Seller/Config')->update($config_data);
  257. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  258. }else{
  259. $data = D('Seller/Config')->get_all_config();
  260. $this->data = $data;
  261. if(isset($data['is_printer_list']) && !empty($data['is_printer_list'])){
  262. $printer_list = M('lionfish_comshop_printer')->field('id,printer_name')->where( array('id' => array('in',$data['is_printer_list']) ) )->select();
  263. $this->printer_list = $printer_list;
  264. }
  265. }
  266. $this->display("printer_config");
  267. }
  268. /**
  269. * 打印机选择
  270. */
  271. public function query_printer(){
  272. $_GPC = I('request.');
  273. $kwd = trim($_GPC['keyword']);
  274. $params = array();
  275. $condition = " 1 ";
  276. if (!empty($kwd)) {
  277. $condition .= ' AND `printer_name` LIKE "%' . $kwd . '%" ';
  278. }
  279. $condition .= ' AND status = 1 ';
  280. $ds = M('lionfish_comshop_printer')->field('id as printerid,printer_name')->where( $condition )->select();
  281. $s_html = "";
  282. foreach ($ds as &$d) {
  283. $s_html.= '<tr>';
  284. $s_html.=" <td>".$d['printer_name']."</td>";
  285. $s_html.=' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link_goods" data-json=\''.json_encode($d).'\'>选择</a></td>';
  286. $s_html.="</tr>";
  287. }
  288. unset($d);
  289. if( isset($_GPC['is_ajax']) )
  290. {
  291. echo json_encode( array('code' => 0, 'html' =>$s_html ) );
  292. die();
  293. }
  294. $this->ds = $ds;
  295. $this->_GPC = $_GPC;
  296. $this->display('printer_mult');
  297. }
  298. }
  299. ?>