BarController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <?php
  2. namespace Admin\Controller;
  3. use Think\Page;
  4. class BarController extends AddonController{
  5. /*****************************************************大件模块*******************************************************************8888*/
  6. public function Large(){
  7. if(IS_POST){
  8. $data = $_POST;
  9. $where = array();
  10. $search = $_POST['search'];
  11. $where['name'] = array('like', '%'.$search.'%');
  12. $where['title'] = array('like', '%'.$search.'%');
  13. $where['no'] = array('like', '%'.$search.'%');
  14. $where['board_no'] = array('like', '%'.$search.'%');
  15. $where['mix_board'] = array('like', '%'.$search.'%');
  16. $where['quality_no'] = array('like', '%'.$search.'%');
  17. $where['batch_number'] = array('like', '%'.$search.'%');
  18. $where['tray_no'] = array('like', '%'.$search.'%');
  19. $where['inspector'] = array('like', '%'.$search.'%');
  20. $where['_logic'] = 'or';
  21. }else{
  22. $where = array();
  23. }
  24. $model = D('BarLarge');
  25. $count = $model->where($where)->count();
  26. $p = getpage($count,50);
  27. $list = $model->getList($where,$p);
  28. $this->assign('meta_title','条码大件打印');
  29. $this->assign('list',$list);
  30. $this->assign('page', $p->show()); // 赋值分页输出
  31. $this->assign('search',$search);
  32. $this->display('list');
  33. }
  34. public function largeEdit(){
  35. if(IS_POST){
  36. header("Content-type: text/html; charset=utf-8");
  37. $data = $_POST['data'];
  38. $return = $this->dispose($data);
  39. if($return){
  40. $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']);
  41. }else{
  42. $this->ajaxReturn(['status'=>0,'msg'=>'修改失败']);
  43. }
  44. }else {
  45. $id = $_GET['id'];
  46. $productList = D('BarProduct')->select();
  47. $this->assign('productList', $productList);
  48. $model = D('BarLarge');
  49. $list = $model->slectById($id);
  50. $url = "/index.php?s=/Admin/Bar/largeEdit.html";
  51. $this->assign('url', $url);
  52. $this->assign('list', $list[0]);
  53. $this->display('add');
  54. }
  55. }
  56. public function largeAdd(){
  57. if(IS_POST){
  58. header("Content-type: text/html; charset=utf-8");
  59. $data = $_POST['data'];
  60. $return = $this->dispose($data);
  61. if($return){
  62. $this->ajaxReturn(['status'=>1,'msg'=>'增加成功']);
  63. }else{
  64. $this->ajaxReturn(['status'=>0,'msg'=>'增加失败']);
  65. }
  66. }else{
  67. $productList = D('BarProduct')->select();
  68. $this->assign('productList',$productList);
  69. $url = "/index.php?s=/Admin/Bar/largeAdd.html";
  70. $this->assign('url',$url);
  71. $this->display('add');
  72. }
  73. }
  74. public function LargeDel(){
  75. if(IS_POST){
  76. header("Content-type: text/html; charset=utf-8");
  77. $id = $_POST['id'];
  78. $model = D('BarLarge');
  79. $return = $model->delete($id);
  80. if($return){
  81. $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
  82. }else{
  83. $this->ajaxReturn(['status'=>0,'msg'=>'删除失败']);
  84. }
  85. }else{
  86. $this->error('非法请求','/index',5);
  87. }
  88. }
  89. public function dispose($data){
  90. $title = explode('|',$data['title']);
  91. $data['title'] = $title[0];
  92. if(strstr($title[0],'_')){
  93. $arr = explode('_',$title[0]);
  94. }else{
  95. $arr = explode('-',$title[0]);
  96. }
  97. $data['name'] = $arr[0];
  98. if(isset($data['mix_board'])){
  99. $data['mix_board'] = 'Y';
  100. $isMix = 1;
  101. }else{
  102. $data['mix_board'] = 'N';
  103. $isMix = 0;
  104. }
  105. $bach = substr($data['batch_number'],-5);
  106. $date = substr(preg_replace("/(-)/","",$data['time']),2);
  107. $board_no = $this->addZero($data['board_no'],3,'left');
  108. $tray_no = $this->addZero($data['tray_no'],5,'left');
  109. $data['sn'] = '(92)'.$data['custome_sn'].'01A'.'(11)'.$date.'(21)'.$bach.$board_no.$isMix.$tray_no;
  110. $data['time'] = strtotime($data['time']);
  111. $model = D('BarLarge');
  112. $return = $model->save1($data);
  113. return $return;
  114. }
  115. public function addZero($a,$le,$pos='left'){
  116. $str =$a;
  117. $len = substr($a);
  118. $cha = $le-$len;
  119. if($cha>0){
  120. if($pos=='left'){
  121. $str = str_pad($str,$le,"0",STR_PAD_LEFT);
  122. }else{
  123. $str = str_pad($str,$le,"0",STR_PAD_RIGHT);
  124. }
  125. }
  126. return $str;
  127. }
  128. /**************************************************小件*******************************************************************/
  129. /*大件模块*/
  130. public function small(){
  131. if(IS_POST){
  132. $data = $_POST;
  133. $where = array();
  134. $search = $_POST['search'];
  135. $where['name'] = array('like', '%'.$search.'%');
  136. $where['title'] = array('like', '%'.$search.'%');
  137. $where['no'] = array('like', '%'.$search.'%');
  138. $where['batch_number'] = array('like', '%'.$search.'%');
  139. $where['technics_number'] = array('like', '%'.$search.'%');
  140. $where['quality_no'] = array('like', '%'.$search.'%');
  141. $where['_logic'] = 'or';
  142. }else{
  143. $where = array();
  144. }
  145. $model = D('BarSmall');
  146. $count = $model->where($where)->count();
  147. $p = getpage($count,100);
  148. $list = $model->getList($where,$p);
  149. $this->assign('meta_title','条码小件件打印');
  150. $this->assign('list',$list);
  151. $this->assign('page', $p->show()); // 赋值分页输出
  152. $this->assign('search',$search);
  153. $this->display('smalllist');
  154. }
  155. public function smallAdd(){
  156. if(IS_POST){
  157. header("Content-type: text/html; charset=utf-8");
  158. $data = $_POST['data'];
  159. $return = $this->disposeSmall($data);
  160. $return_arr = json_decode($return);
  161. $msg = '成功条数'.$return_arr[0].',失败条数'.($return_arr[1]-$return_arr[0]);
  162. $this->ajaxReturn(['msg'=>$msg]);
  163. }else{
  164. $productList = D('BarProduct')->select();
  165. $this->assign('productList',$productList);
  166. $url = "/index.php?s=/Admin/Bar/smallAdd.html";
  167. $this->assign('url',$url);
  168. $this->display('smalladd');
  169. }
  170. }
  171. public function smallEdit(){
  172. if(IS_POST){
  173. header("Content-type: text/html; charset=utf-8");
  174. $data = $_POST['data'];
  175. $return = $this->disposeSmall($data);
  176. $return_arr = json_decode($return);
  177. if($return_arr[0]>0){
  178. $msg = '编辑成功';
  179. }else{
  180. $msg = '编辑失败';
  181. }
  182. $this->ajaxReturn(['msg'=>$msg]);
  183. }else {
  184. $id = $_GET['id'];
  185. $productList = D('BarProduct')->select();
  186. $this->assign('productList', $productList);
  187. $model = D('BarSmall');
  188. $list = $model->slectById($id);
  189. $list = $list[0];
  190. $url = "/index.php?s=/Admin/Bar/smallEdit.html";
  191. $this->assign('url', $url);
  192. $this->assign('list', $list);
  193. $this->display('smalladd');
  194. }
  195. }
  196. public function smallDel(){
  197. if(IS_POST){
  198. header("Content-type: text/html; charset=utf-8");
  199. $id = $_POST['id'];
  200. $model = D('BarSmall');
  201. $return = $model->delete($id);
  202. if($return){
  203. $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
  204. }else{
  205. $this->ajaxReturn(['status'=>0,'msg'=>'删除失败']);
  206. }
  207. }else{
  208. $this->error('非法请求','/index',5);
  209. }
  210. }
  211. public function disposeSmall($data){
  212. $model = D('BarSmall');
  213. $title = explode('|',$data['title']);
  214. $data['title'] = $title[0];
  215. if(strstr($title[0],'_')){
  216. $arr = explode('_',$title[0]);
  217. }else{
  218. $arr = explode('-',$title[0]);
  219. }
  220. $data['name'] = $arr[0];
  221. $data['num'] = $arr[1];
  222. $date = substr(preg_replace("/(-)/","",$data['time']),2);
  223. $quality = $this->addZero($data['technics_number'],9,'right');
  224. $border = $this->addZero($data['board_no'],3,'left');
  225. $mix_board = $this->addZero($data['mix_board'],3,'left');
  226. $success = 0;
  227. $i = (int)$data['start'];
  228. $step = (int)$data['step'];
  229. if($step==0){
  230. $step = 1;
  231. }
  232. $end = $i+$step-1;
  233. for ($i;$i<=$end;$i++) {
  234. $new = array();
  235. $new = $data;
  236. $new['time'] = time();
  237. $new['board_no_serial'] = $i;
  238. $board_no_serial = $this->addZero($i,5,'left');
  239. $new['sn'] = $data['custome_sn'].'01A'.$quality.$date.$border.$mix_board.$board_no_serial;
  240. unset($new['start']);
  241. unset($new['step']);
  242. unset($new['custome_sn']);
  243. $id = $model->save1($new);
  244. if($id){
  245. $success = $success+1;
  246. }
  247. }
  248. return json_encode([$success,$step]);
  249. }
  250. /*****************************************************产品模块******************************************************************/
  251. /*产品配置*/
  252. public function product(){
  253. // 搜索
  254. $keyword = I('keyword', '', 'string');
  255. $condition = array('like', '%' . $keyword . '%');
  256. $map['code|title|code1|standard'] = array(
  257. $condition,
  258. $condition,
  259. $condition,
  260. $condition,
  261. '_multi' => true,
  262. );
  263. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  264. $product_object = D('BarProduct');
  265. $data_list = $product_object
  266. ->page($p, 50)
  267. ->where($map)
  268. ->order('id asc')
  269. ->select();
  270. $page = new Page(
  271. $product_object->where($map)->count(),
  272. 50
  273. );
  274. // 使用Builder快速建立列表页面。
  275. $builder = new \Common\Builder\ListBuilder();
  276. $builder->setMetaTitle('配置列表') // 设置页面标题
  277. ->addTopButton('addnew',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductAdd')]) // 添加新增按钮
  278. ->addTopButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductDel')]) // 添加删除按钮
  279. ->setSearch(
  280. '请输入代码/自定义名称',
  281. U('product')
  282. )
  283. ->addTableColumn('id', 'ID')
  284. ->addTableColumn('code', '代码')
  285. ->addTableColumn('code1', '客户产品编码')
  286. ->addTableColumn('standard', '产品规则')
  287. ->addTableColumn('title', '自定义')
  288. ->addTableColumn('right_button', '操作', 'btn')
  289. ->setTableDataList($data_list) // 数据列表
  290. ->setTableDataPage($page->show()) // 数据列表分页
  291. ->addRightButton('edit',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductEdit',array(
  292. 'id' => '__data_id__',
  293. ))]) // 添加编辑按钮
  294. ->addRightButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/barProductDel',array(
  295. 'id' => '__data_id__',
  296. ))]) // 添加删除按钮
  297. ->display();
  298. }
  299. /**
  300. * 产品新增配置
  301. *
  302. */
  303. public function barProductAdd()
  304. {
  305. if (IS_POST) {
  306. $bar_object = D('BarProduct');
  307. $data = $bar_object->create();
  308. if ($data) {
  309. if ($bar_object->add($data)) {
  310. $this->success('新增成功', U('product'));
  311. } else {
  312. $this->error('新增失败');
  313. }
  314. } else {
  315. $this->error($bar_object->getError());
  316. }
  317. } else {
  318. //使用FormBuilder快速建立表单页面。
  319. $builder = new \Common\Builder\FormBuilder();
  320. $builder->setMetaTitle('新增条形码产品配置') //设置页面标题
  321. ->setPostUrl(U('barProductAdd')) //设置表单提交地址
  322. ->addFormItem('code', 'text', '产品代码', '产品代码')
  323. ->addFormItem('code1','text', '客户产品编码', '客户产品编码')
  324. ->addFormItem('standard','text', '产品规则', '产品规则')
  325. ->addFormItem('title', 'text', '自定义名称', '自定义名称')
  326. ->display();
  327. }
  328. }
  329. /*条形码产品删除*/
  330. public function barProductDel(){
  331. if(IS_POST){
  332. if(empty($_POST)){
  333. $this->error('请至少选择一个选项');
  334. }else{
  335. $bar = D('BarProduct');
  336. $id = implode(',',$_POST['ids']);
  337. $return = $bar->DelQcodeProduct($id);
  338. if($return){
  339. $this->success('删除成功', U('product'));
  340. }else{
  341. $this->error('删除失败');
  342. }
  343. }
  344. }else{
  345. $id = $_GET['id'];
  346. $bar = D('BarProduct');
  347. $return = $bar->DelQcodeProduct($id);
  348. if($return){
  349. $this->success('删除成功', U('product'));
  350. }else{
  351. $this->error('删除失败');
  352. }
  353. }
  354. }
  355. /*条形码产品修改*/
  356. public function barProductEdit(){
  357. if (IS_POST) {
  358. $bar = D('BarProduct');
  359. $data = $bar->create();
  360. if ($data) {
  361. if ($bar->save($data)) {
  362. $this->success('更新成功', U('product'));
  363. } else {
  364. $this->error('更新失败');
  365. }
  366. } else {
  367. $this->error($bar->getError());
  368. }
  369. } else {
  370. $id = $_GET['id'];
  371. $bar = D('BarProduct');
  372. if (!$id) {
  373. $this->error('参数错误');
  374. }
  375. $data = $bar->where('id = ' . $id)->find();
  376. if (!$data) {
  377. $this->error('参数错误');
  378. } else {
  379. // 使用FormBuilder快速建立表单页面。
  380. $builder = new \Common\Builder\FormBuilder();
  381. $builder->setMetaTitle('编辑产品数据')// 设置页面标题
  382. ->setPostUrl(U('barProductEdit'))// 设置表单提交地址
  383. ->addFormItem('id', 'hidden', 'ID', 'ID')
  384. ->addFormItem('code', 'text', '产品代码', '产品代码')
  385. ->addFormItem('code1','text', '客户产品编码', '客户产品编码')
  386. ->addFormItem('standard','text', '产品规则', '产品规则')
  387. ->addFormItem('title', 'text', '自定义名称', '自定义名称')
  388. ->setFormData(D('BarProduct')->find($id))
  389. ->display();
  390. }
  391. }
  392. }
  393. /******************************************二维码********************************************************************************/
  394. public function qrcode($url)//二维码生成类
  395. {
  396. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  397. $level=3;
  398. $size=4;
  399. $errorCorrectionLevel =intval($level) ;//容错级别
  400. $matrixPointSize = intval($size);//生成图片大小
  401. //生成二维码图片
  402. $object = new \QRcode();
  403. //打开缓冲区
  404. ob_start();
  405. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  406. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  407. $imageString = base64_encode(ob_get_contents());
  408. //关闭缓冲区
  409. ob_end_clean();
  410. //把生成的base64字符串返回给前端
  411. /*$data = array(
  412. 'labelcode'=>$url,
  413. 'code'=>200,
  414. 'data'=>$imageString
  415. );
  416. $this->ajaxReturn($data);*/
  417. }
  418. public function getLargeDate(){
  419. $id = $_POST['id'];
  420. $id_arr = explode(',',$id);
  421. /*查询相关的数据*/
  422. $data = [];
  423. $Model = D('BarLarge');
  424. $return = $Model->getById($id);
  425. $this->ajaxReturn($return);
  426. }
  427. public function getSmallDate(){
  428. $id = $_POST['id'];
  429. /*查询相关的数据*/
  430. $data = [];
  431. $Model = D('BarSmall');
  432. $return = $Model->getById($id);
  433. $this->ajaxReturn($return);
  434. }
  435. }