NewQcodeController.class.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Admin
  5. * Date: 2018/8/8
  6. * Time: 15:11
  7. */
  8. namespace Admin\Controller;
  9. use think\Request;
  10. use Think\Page;
  11. class NewQcodeController extends AddonController
  12. {
  13. // protected $sign='9092';//固定标示位
  14. protected $sign='AB92';//固定标示位
  15. protected $signLarge='2';//大件标示位
  16. protected $signSmall='1';//小件标示位
  17. public function index(){
  18. // $db = M('qcode_product');
  19. // $map['temple'] = array('exp','is null');
  20. // $productlist=$db->where($map)->field('id,temple,product_code')->select();
  21. // foreach ($productlist as $key=>$value){
  22. // $code = substr($value['product_code'],2,2);
  23. // $db->where('id='.$value['id'])->setField('temple',$code);
  24. // }
  25. $session_config=I('session.ly_admin_');//获取登陆的session值
  26. $userinfo=M('admin_user')->where('id='.$session_config['user_auth']['uid'])->find();
  27. $user_product = explode(',',$userinfo['product_id']);
  28. $map = array();
  29. $map['id'] = array('in',$user_product);
  30. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  31. if($session_config['addtype']==0){//最高管理员登陆渲染供应商列表到前台
  32. $field='nickname,postcode,mobile,company_address,printer_code,id';
  33. $companylist=M('admin_user')->field($field)->select();
  34. $this->assign('companylist',$companylist);
  35. }
  36. $this->assign("session_config",$session_config['user_auth']);
  37. $this->assign('userinfo',$userinfo);
  38. $this->assign('productlist',$productlist);
  39. $this->display();
  40. }
  41. public function get_bach_info(){
  42. //获取批次相关信息
  43. $addtobach=M('qcode_bach')->alias('a')
  44. ->join('qr_qcode_large b on a.id=b.bach_id')
  45. ->join('qr_qcode_small c on b.id=c.large.id ')
  46. ->field('bach_num,large_endnum')
  47. ->where('id='.I('get.id'))
  48. ->find();
  49. }
  50. //批次新增
  51. public function add_bath(){
  52. $userid=I('post.userid');//当前用户的id
  53. $product_id=I('post.matter_id');//当前产品的id
  54. //新增批次
  55. if (IS_POST) {
  56. if(!empty($_POST)){
  57. $QcodeBach= M("QcodeBach");
  58. $data=array();
  59. $data= $_POST;
  60. // print_r($data);
  61. if(I('post.danwei')==1) {
  62. //以箱为单位
  63. $tray_num = I('post.tray_num/d');//一托盘多少箱
  64. $small_num = ceil(I('post.num/d') / I('post.box_num/d'));//总共多少箱
  65. $larger_num = ceil($small_num / $tray_num);//托盘总数量
  66. }
  67. if(I('post.danwei')==2){//以卷为单位
  68. $tray_num = I('post.box_num1');//一托盘多少卷
  69. $small_num = ceil(I('post.small_num'));//总共多少卷
  70. $larger_num = ceil($small_num / $tray_num);//托盘总数量
  71. }
  72. $reset_flow=M('reset_flow');
  73. $codition['userid']=$userid;
  74. $codition['product_id']=$product_id;
  75. if(I('reset_large_liushui_status')==1){
  76. //没有重置大件流水号,在原有的基础上叠加
  77. $l_flow=GetTuopan($userid,$product_id);
  78. if($l_flow){
  79. //找到之前已经存在托盘号
  80. $info['l_flow']=$l_flow['l_flow']+$larger_num;
  81. $info['bach_num']=I('post.bach_num');
  82. $reset_flow->where($codition)->save($info);
  83. //var_dump($reset_flow->getLastSql());
  84. }else{
  85. //没有找到就添加
  86. $infos=[
  87. 'userid'=>$userid,
  88. 'product_id'=>$product_id,
  89. 'l_flow'=>$larger_num,
  90. 'bach_num'=>I('post.bach_num'),
  91. ];
  92. $reset_flow->add($infos);//加到对应的商家与产品上
  93. //var_dump($reset_flow->getLastSql());
  94. };
  95. }
  96. if(I('reset_large_liushui_status')==2){//表示用户已经重置大件流水号,更新对应的托盘数
  97. $infoss['l_flow']=$larger_num;
  98. $infoss['bach_num']=I('post.bach_num');
  99. $l_flow=GetTuopan($userid,$product_id);
  100. // print_r($infoss);die;
  101. if($l_flow){
  102. //找到了对应的数据就更新
  103. $reset_flow->where($codition)->save($infoss);//更新用户的托盘数
  104. }else{
  105. //没有就添加
  106. $infos=[
  107. 'userid'=>$userid,
  108. 'product_id'=>$product_id,
  109. 'l_flow'=>$larger_num,
  110. 'bach_num'=>I('post.bach_num'),
  111. ];
  112. $reset_flow->add($infos);
  113. }
  114. }
  115. // die;
  116. $data['small_num']=$small_num;
  117. $data['larger_num']=$larger_num;
  118. $data['manufacture_date']=((int)date('Ymd',strtotime(I('post.manufacture_date')))-20000000);//六位生产日期
  119. $data['print_date']=((int)date('Ymd',strtotime(I('post.print_date')))-20000000);//六位打码日期
  120. $data['userid']=$userid;//批次绑定用户id
  121. $data['bach_num']=I('post.bach_num');//生产批次列表
  122. $data['large_endnum']=$larger_num+I('post.l_flow')-1;
  123. $data['creat_time']=time();
  124. $Bach_id =$QcodeBach->data($data)->add();
  125. //成功插入批次信息之后开始插入大小二维码数据
  126. if($Bach_id){
  127. $QcodeLarge= M("QcodeLarge");
  128. $QcodeSmall= M("QcodeSmall");
  129. $liushui=M("QcodeLiushui");
  130. //不变区域
  131. $fixed_code='';
  132. $fixed_code.=intTochar(I('post.matter_type'),2);//2位 辅料种类
  133. $fixed_code.=intTochar(I('post.supplier_code'),12);//12位 供应商编码
  134. $fixed_code.=intTochar(I('post.matter_no'),20);//20位 辅料编码
  135. $fixed_code.=((int)date('Ymd',strtotime(I('post.manufacture_date')))-20000000);//六位生产日期
  136. $print_date=((int)date('Ymd',strtotime(I('post.print_date')))-20000000);//6位打码日期
  137. $small_liushui=[
  138. 'onlycode'=> "AB92".$fixed_code.$print_date,
  139. 'last_num'=> 0,
  140. 'user_id'=>$userid,
  141. 'stype'=>2,
  142. 'addtime'=>time()
  143. ];
  144. $whereSmall=[
  145. 'onlycode'=> $small_liushui['onlycode'],
  146. 'user_id'=> $userid
  147. ];
  148. if($liushui->where($whereSmall)->find()){
  149. //小件二维码重复了,更新这个批次的最后流水号
  150. /* $liushui->where($whereSmall)->setInc('last_num',$small_num);*/
  151. $lastnum=$liushui->field('last_num')->where($whereSmall)->find();
  152. }else{
  153. //没有重复,新增一条记录
  154. $liushui->data($small_liushui)->add();
  155. };
  156. for($i=0;$i<$larger_num;$i++){
  157. $l_flows=I('post.l_flow/d')+$i;
  158. $l_flow=intTochar(I('post.l_flow/d')+$i,6);
  159. $l_weight=intTochar(I('post.l_weight')*100,6);//2023年3月20日 修改大件可以有小数,小件重量不变 不能有小数
  160. // $l_reservation=intTochar($Bach_id.I('post.l_reservation'),12);//批次id+0,不够12位在前面补0 具体点击方法看代码
  161. $l_reservation=intTochar(I('post.bach_num'),10);//批次+0,不够10位在前面补0 第一个批次 后续会加第二个批次
  162. $l_reservation = $l_reservation.'0000000000';
  163. $small_n = intTochar($tray_num,3);
  164. if(I('post.danwei')==2){//以卷为单位
  165. $remainder = $small_num - $tray_num*$i; //确定最后一个托盘大件里小件的数量
  166. if ($remainder < $tray_num){
  167. $small_n = intTochar($remainder,3);//小件数量3位 不足补零
  168. }
  169. }
  170. $code_data= CodeData($this->sign,$fixed_code,$small_n,$print_date,$l_flow,$l_weight,$this->signLarge,$l_reservation);
  171. //大码数据信息
  172. $L_data=[
  173. 'bach_id'=>$Bach_id,
  174. 'code'=>$code_data['code'],
  175. 'code_cp1'=>$code_data['code_cp1'],
  176. 'code_cp2'=>$code_data['code_cp2'],
  177. 'print_date'=>$print_date,
  178. 'creat_time'=>time(),
  179. 'p_nums'=>0,
  180. 'userid'=>$userid,//大码绑定用户id
  181. 'l_weight'=>$l_weight//单个大件重量
  182. ];
  183. $large_id= $QcodeLarge->data($L_data)->add();
  184. //小码插入循环
  185. for($j=0;$j<$tray_num and ($j+$i*$tray_num)<$small_num;$j++){
  186. $s_flow=intTochar(I('post.s_flow/d')+$j+$i*$tray_num+$lastnum['last_num'],6);//小码序号从一开始
  187. $s_weight=intTochar(I('post.s_weight'),6);
  188. $small_sign = '000';
  189. // $small_production_date = (int)date('Ymd',strtotime(I('post.manufacture_date')));//8位生产日期
  190. $s_reservation=intTochar(I('post.bach_num'),10);//批次+0,不够10位在前面补0 第一个批次 后续会加第二个批次
  191. $s_reservation = $s_reservation.'0000000000';
  192. $small_code_data= CodeData($this->sign,$fixed_code,$small_sign,$print_date,$s_flow,$s_weight,$this->signSmall,$s_reservation);
  193. $S_data=[
  194. 'large_id'=>$large_id,
  195. 'bach_id'=>$Bach_id,
  196. 'code'=>$small_code_data['code'],
  197. 'code_cp1'=>$small_code_data['code_cp1'],
  198. 'code_cp2'=>$small_code_data['code_cp2'],
  199. 'l_flow'=>$j+1,
  200. 'print_date'=>$print_date,
  201. 'creat_time'=>time(),
  202. 'p_nums'=>0,
  203. 'userid'=>$userid,//小码绑定用户id
  204. 's_weight'=>$s_weight//单个小件重量
  205. ];
  206. $QcodeSmall->data($S_data)->add();
  207. }
  208. }
  209. $liushui->where($whereSmall)->setInc('last_num',$small_num);
  210. }
  211. if(($j+($i-1)*$tray_num)==$small_num){
  212. M()->commit();
  213. $this->success('批次新增成功', U('Qcode/small'));
  214. }else{
  215. M()->rollback();
  216. $this->success('批次新增失败', U('Qcode/small'));
  217. }
  218. }else{
  219. $this->error('非法请求','NewQcode/index',5);
  220. }
  221. }
  222. }
  223. public function BachListApi(){//获取打印批次列表
  224. $session_config=I('session.ly_admin_');//获取登陆的session值
  225. if($_GET['sysCdNm']){//有搜索产品名称
  226. $where['a.matter_name']=array('like','%'.$_GET['sysCdNm'].'%');
  227. }
  228. if($_GET['nickname']){//有搜索公司名称
  229. $where['c.nickname']=$_GET['nickname'];
  230. }
  231. if($_GET['prodBth']){//有搜索产品批次
  232. $where['a.bach_num']=$_GET['prodBth'];
  233. }
  234. if($_GET['startDate']){//有开始打印日期
  235. $statrtime=((int)date('Ymd',(strtotime($_GET['startDate'])))-20000000);
  236. $endtime=((int)date('Ymd',(strtotime($_GET['endDate'])))-20000000);
  237. $where['a.print_date']=array(array('egt',$statrtime),array('elt',$endtime),'AND');
  238. }
  239. if($session_config['user_auth']['addtype']==1){
  240. $where['a.userid']=$session_config['user_auth']['uid'];
  241. }
  242. $where['a.bach_status']=0;
  243. if ($_GET['sqrcd']){//有搜索标签代码
  244. $map = array();
  245. $map['code'] = array('like','%'.$_GET['sqrcd'].'%');
  246. $large_bach = M('qcode_large')->where($map)->field('bach_id')->select();
  247. if (!empty($large_bach)){
  248. foreach ($large_bach as $key=>$value){
  249. $option[$key] = $value['bach_id'];
  250. }
  251. $option = array_unique($option);
  252. $where['a.id'] = array('IN',$option);
  253. }else{
  254. $small_bach = M('qcode_small')->where($map)->field('bach_id')->select();
  255. if (!empty($small_bach)){
  256. foreach ($small_bach as $key=>$value){
  257. $option[$key] = $value['bach_id'];
  258. }
  259. $option = array_unique($option);
  260. $where['a.id'] = array('IN',$option);
  261. }
  262. }
  263. }
  264. $BatchList=M('qcode_bach')->alias('a')
  265. ->join('qr_qcode_product b on a.matter_id=b.id','LEFT')
  266. ->join('qr_admin_user c on a.userid=c.id','LEFT')
  267. ->field('a.*,b.product_num,c.nickname')
  268. ->order($_GET['sort'].' '.$_GET['order'])
  269. ->page($_GET['page'],$_GET['rows'])
  270. ->where($where)
  271. ->select();
  272. //echo M('qcode_bach')->getLastSql();
  273. $total = M('qcode_bach')->alias('a')
  274. ->join('qr_qcode_product b on a.matter_name=b.product_name','LEFT')
  275. ->join('qr_admin_user c on a.userid=c.id')
  276. ->where($where)
  277. ->count();
  278. $result = [];
  279. $result['total'] = $total;
  280. $result['rows'] = $BatchList;
  281. $bachlist = json_encode($result);
  282. echo $bachlist;
  283. //echo json_encode($BatchList);
  284. }
  285. public function BachListApiTwo(){//补打界面获取补打批次列表
  286. // $session_config=I('session.ly_admin_');//获取登陆的session值
  287. if($_GET['sysCdNm']){//有搜索产品名称
  288. $where['a.matter_name']=array('like','%'.$_GET['sysCdNm'].'%');
  289. }
  290. if($_GET['nickname']){//有搜索公司名称
  291. $where['c.nickname']=array('like','%'.$_GET['nickname'].'%');
  292. }
  293. if($_GET['prodBth']){//有搜索产品批次
  294. $where['a.bach_num']=$_GET['prodBth'];
  295. }
  296. if($_GET['matter_no']){//有搜索产品批次
  297. $where['a.matter_no']=array('like','%'.$_GET['matter_no'].'%');
  298. }
  299. if($_GET['startDate']){//有开始打印日期
  300. $statrtime=((int)date('Ymd',(strtotime($_GET['startDate'])))-20000000);
  301. $endtime=((int)date('Ymd',(strtotime($_GET['endDate'])))-20000000);
  302. $where['a.print_date']=array(array('egt',$statrtime),array('elt',$endtime),'AND');
  303. }
  304. // if($session_config['user_auth']['addtype']==1){
  305. // $where['a.userid']=$session_config['user_auth']['uid'];
  306. // }
  307. $where['a.bach_status']=0;
  308. if ($_GET['sqrcd']){//有搜索标签代码
  309. $map = array();
  310. $map['code'] = array('like','%'.$_GET['sqrcd'].'%');
  311. $large_bach = M('qcode_large')->where($map)->field('bach_id')->select();
  312. if (!empty($large_bach)){
  313. foreach ($large_bach as $key=>$value){
  314. $option[$key] = $value['bach_id'];
  315. }
  316. $option = array_unique($option);
  317. $where['a.id'] = array('IN',$option);
  318. }else{
  319. $result = [];
  320. $result['total'] = '0';
  321. $result['rows'] = [];
  322. $bachlist = json_encode($result);
  323. return $bachlist;
  324. $small_bach = M('qcode_small')->where($map)->field('bach_id')->select();
  325. if (!empty($small_bach)){
  326. foreach ($small_bach as $key=>$value){
  327. $option[$key] = $value['bach_id'];
  328. }
  329. $option = array_unique($option);
  330. $where['a.id'] = array('IN',$option);
  331. }
  332. }
  333. }
  334. $BatchList=M('qcode_bach')->alias('a')
  335. ->join('qr_qcode_product b on a.matter_id=b.id','LEFT')
  336. ->join('qr_admin_user c on a.userid=c.id','LEFT')
  337. ->field('a.*,b.product_num,c.nickname')
  338. ->order($_GET['sort'].' '.$_GET['order'])
  339. ->page($_GET['page'],$_GET['rows'])
  340. ->where($where)
  341. ->select();
  342. //echo M('qcode_bach')->getLastSql();
  343. $total = M('qcode_bach')->alias('a')
  344. ->join('qr_qcode_product b on a.matter_name=b.product_name','LEFT')
  345. ->join('qr_admin_user c on a.userid=c.id')
  346. ->where($where)
  347. ->count();
  348. $result = [];
  349. $result['total'] = $total;
  350. $result['rows'] = $BatchList;
  351. $bachlist = json_encode($result);
  352. echo $bachlist;
  353. //echo json_encode($BatchList);
  354. }
  355. public function GetLargeLabelApi(){//获取关联批次的大件标签列表
  356. $field = "code,print_date,p_nums,id,code_cp1,l_print,l_status,archive";
  357. $LargeLabelList = M('qcode_large')->field($field)->where('bach_id='.I('get.product_id'))->select();
  358. // var_dump($LargeLabelList);
  359. foreach($LargeLabelList as $key=>$val){
  360. $qcode_small=$val['archive']?"qcode_small_".$val['archive']:"qcode_small";
  361. $smalltotal=M('qcode_small')->field('count(large_id)')->where('large_id='.$val['id'])->find();
  362. $LargeLabelList[$key]['code_cp1']=ltrim(substr($LargeLabelList[$key]['code_cp1'],6,10),'0');
  363. $LargeLabelList[$key]['smalltotal']=$smalltotal['count(large_id)'];
  364. if( $LargeLabelList[$key]['l_print']==0){
  365. $type="未打印";
  366. }
  367. if($LargeLabelList[$key]['l_print']==1){
  368. $type="已打印";
  369. }
  370. $LargeLabelList[$key]['type']=$type;
  371. }
  372. echo json_encode($LargeLabelList);
  373. }
  374. public function GetSmallLabelApi(){//获取关联大标签的的小标签列表
  375. if(I('get.large_id')){//获取小标签列表
  376. $field="id,code,code_cp1,status,l_flow,p_nums";
  377. $smalllist=M('qcode_small')
  378. ->field($field)
  379. ->where('large_id='.I('get.large_id'))
  380. ->select();
  381. $large_data = M('qcode_large')
  382. ->field('code_cp1')
  383. ->where('id='.I('get.large_id'))
  384. ->find();
  385. $large_flow = ltrim(substr($large_data['code_cp1'],6,10),'0');
  386. foreach($smalllist as $key=>$val){
  387. $smalllist[$key]['l_flow']= $large_flow.'-'.$smalllist[$key]['l_flow'];
  388. // if($val['id']>44091){
  389. // $smalllist[$key]['code_cp1']=I('get.large_tuopan').'-'.ltrim(substr($smalllist[$key]['code_cp2'],12,6),'0');}
  390. // else{
  391. // $smalllist[$key]['code_cp1']=I('get.large_tuopan').'-'.ltrim(substr($smalllist[$key]['code_cp1'],6,6),'0');
  392. // };
  393. }
  394. $this->ajaxReturn($smalllist);
  395. }
  396. if(I('get.code') ){//单个删除
  397. $field="id,code,status";
  398. $code=I('get.code');
  399. $data['status']=1;
  400. if( M('qcode_small')->where("code='$code'")->save($data)){
  401. $smalllist['status']=200;
  402. $smalllist['error']="操作成功";
  403. }else{
  404. $smalllist['status']=100;
  405. $smalllist['error']="操作失败";
  406. };
  407. $smalllist['list']=M('qcode_small')->field($field)->where("code='$code'")->select();
  408. $this->ajaxReturn($smalllist);
  409. }
  410. }
  411. public function OneSmallPrint(){//单个打印小标签
  412. // M('qcode_small')->where('id='.I('get.id'))->setInc('p_nums',I('get.reptQty'));//更新小标签的打印次数
  413. //echo M('qcode_small')->getLastSql();
  414. $smalllabel[]=M('qcode_small')->alias('b')
  415. ->join("qr_qcode_large c on b.large_id=c.id")
  416. ->join('qr_qcode_bach d on d.id=c.bach_id')
  417. ->field('b.*,d.id as bath_id,d.supplier_name, b.l_flow, d.matter_name,d.matter_size,d.num,d.manufacture_date,d.l_flow as dl_flow,c.code as ccode,c.code_cp1 as banhao,d.box_num,d.bach_num')
  418. ->where('b.id='.I('get.id'))
  419. ->select();
  420. /*foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  421. $imgcode=$this->qrcode($val['code']);
  422. $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  423. }*/
  424. $total['smalllabel']=$smalllabel;
  425. $total['num']=I('get.reptQty');
  426. $this->ajaxReturn($total);
  427. }
  428. //二维码打印
  429. // public function rePrintTg(){
  430. // header("Content-type: text/html; charset=utf-8");
  431. // $id = I('post.idList');//选中的大件标签的列表id
  432. // $ids=explode(",",$id);//将字符串以逗号转化为数组
  433. // $num = I('post.reptQty')?I('post.reptQty'):3;//重复打印次数
  434. // foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  435. // if(I('post.sign_type')==1){//打印的为大件标签
  436. // //先更新大标签的打印次数
  437. // M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  438. // M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  439. // //在查找相关的信息
  440. // $largelabel[]=M('qcode_large')->alias('a')
  441. // ->join('qr_qcode_bach q on a.bach_id=q.id')
  442. // ->field('a.*,q.supplier_name,q.l_weight')
  443. // ->where('a.id='.$val)
  444. // ->select();
  445. //
  446. // }
  447. // if(I('post.sign_type')==2){//打印的为小件标签
  448. // //先更新小标签的打印次数
  449. // M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  450. // /* M('qcode_small')->where('large_id='.$val)->setField('status','1');//更新小标签的打印状态$num*/
  451. // //在查找小标签的相关内容
  452. //
  453. // $smalllabel[]=M('qcode_small')->alias('b')
  454. // ->join("qr_qcode_large c on b.large_id=c.id")
  455. // ->join('qr_qcode_bach d on d.id=c.bach_id')
  456. // ->field('b.*,d.s_weight,d.id as bath_id,d.supplier_name,d.matter_name,d.matter_size,d.num,d.manufacture_date,d.l_flow as dl_flow, b.l_flow,c.code_cp1 as banhao,d.box_num,d.bach_num')
  457. // ->where('b.large_id='.$val)
  458. // ->select();
  459. // }
  460. // //$sql=M('qcode_small')->getLastSql();
  461. // }
  462. //// foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  463. //// $imgcode=$this->qrcode($val['code']);
  464. //// $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  465. //// }
  466. // //var_dump($smalllabel[0]);
  467. // $total['largrlabel']=$largelabel?$largelabel:'';
  468. // $total['smalllabel']=$smalllabel?$smalllabel:'';
  469. // $total['num']=$num;
  470. // $this->ajaxReturn($total);
  471. //
  472. // }
  473. public function rePrintTg(){
  474. header("Content-type: text/html; charset=utf-8");
  475. $id = I('post.idList');//选中的大件标签的列表id
  476. $ids=explode(",",$id);//将字符串以逗号转化为数组
  477. $num = I('post.reptQty')?I('post.reptQty'):0;//重复打印次数
  478. if (I('post.status')==1){//修改打印次数--自动打码
  479. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  480. if(I('post.sign_type')==1){//打印的为大件标签
  481. //更新大标签的打印次数
  482. M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  483. M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  484. }
  485. if(I('post.sign_type')==2){//打印的为小件标签
  486. //更新小标签的打印次数
  487. M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  488. }
  489. }
  490. $total['num']=$num;
  491. $this->ajaxReturn($total);
  492. }else if (I('post.status')==2){//修改打印次数--小件
  493. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  494. M('qcode_small')->where('id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  495. }
  496. $total['num']=$num;
  497. $this->ajaxReturn($total);
  498. }else{
  499. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  500. if(I('post.sign_type')==1){//打印的为大件标签
  501. //先更新大标签的打印次数
  502. // M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  503. // M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  504. //在查找相关的信息
  505. $largelabel[$key] = M('qcode_large')->alias('c')
  506. ->field('u.main_unit, u.sec_unit, u.proportion, d.s_weight,d.id as bath_id,d.supplier_name,d.matter_name, d.matter_no, d.matter_size,d.num,d.manufacture_date,d.l_flow,c.code, c.code_cp1 as banhao,d.box_num,d.bach_num')
  507. ->join('qr_qcode_bach d on c.bach_id=d.id')
  508. ->join('qr_qcode_unit u on u.code=d.matter_no')
  509. ->where('c.id='.$val)
  510. ->select();
  511. $numn = M('qcode_small')->where('large_id='.$val)->count();
  512. $largelabel[$key][0]['numn']=$numn;
  513. }
  514. if(I('post.sign_type')==2){//打印的为小件标签
  515. //先更新小标签的打印次数
  516. // M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  517. /* M('qcode_small')->where('large_id='.$val)->setField('status','1');//更新小标签的打印状态$num*/
  518. //在查找小标签的相关内容
  519. $smalllabel[]=M('qcode_small')->alias('b')
  520. ->join("qr_qcode_large c on b.large_id=c.id")
  521. ->join('qr_qcode_bach d on d.id=c.bach_id')
  522. ->field('b.*,d.s_weight,d.id as bath_id,d.supplier_name,d.matter_name, d.matter_no, d.matter_size,d.num,d.manufacture_date,d.l_flow as dl_flow, b.l_flow,c.code as ccode, c.code_cp1 as banhao,d.box_num,d.bach_num')
  523. ->where('b.large_id='.$val)
  524. ->select();
  525. }
  526. //$sql=M('qcode_small')->getLastSql();
  527. }
  528. // foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  529. // $imgcode=$this->qrcode($val['code']);
  530. // $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  531. // }
  532. //var_dump($smalllabel[0]);
  533. $total['largrlabel']=$largelabel?$largelabel:'';
  534. $total['smalllabel']=$smalllabel?$smalllabel:'';
  535. $total['num']=$num;
  536. $this->ajaxReturn($total);
  537. }
  538. }
  539. public function userinfoedit()
  540. {//修改用户的相关信息
  541. if (IS_POST) {
  542. // 密码为空表示不修改密码
  543. if ($_POST['password'] === '') {
  544. unset($_POST['password']);
  545. }
  546. // 提交数据
  547. $user_object = D('User');
  548. $data = $user_object->create();
  549. if ($data) {
  550. $result = $user_object
  551. ->field('id,nickname,username,password,email,email_bind,mobile,mobile_bind,gender,avatar,update_time,printer_code,postcode,company_address')
  552. ->save($data);
  553. if ($result) {
  554. $this->success('更新成功', U('index'));
  555. } else {
  556. $this->error('更新失败', $user_object->getError());
  557. }
  558. } else {
  559. $this->error($user_object->getError());
  560. }
  561. } else {
  562. // 获取账号信息
  563. $session_config=I('session.ly_admin_');
  564. $id=$session_config['user_auth']['uid'];
  565. $info = D('User')->find($id);
  566. unset($info['password']);
  567. // 使用FormBuilder快速建立表单页面。
  568. $builder = new \Common\Builder\FormBuilder();
  569. $builder->setMetaTitle('编辑用户')// 设置页面标题
  570. ->setPostUrl(U('userinfoedit'))// 设置表单提交地址
  571. ->addFormItem('id', 'hidden', 'ID', 'ID')
  572. ->addFormItem('nickname', 'text', '供应商名称', '供应商名称')
  573. ->addFormItem('printer_code', 'text', '供应商编码', '供应商编码')
  574. ->addFormItem('postcode', 'num', '邮政编码', '邮政编码')
  575. ->addFormItem('company_address', 'text', '地址', '详细地址')
  576. ->addFormItem('username', 'text', '用户名', '用户名')
  577. ->addFormItem('password', 'password', '密码', '密码')
  578. ->addFormItem('email', 'text', '邮箱', '邮箱')
  579. ->addFormItem('email_bind', 'radio', '邮箱绑定', '手机绑定', array('1' => '已绑定', '0' => '未绑定'))
  580. ->addFormItem('mobile', 'text', '手机号', '手机号')
  581. ->addFormItem('mobile_bind', 'radio', '手机绑定', '手机绑定', array('1' => '已绑定', '0' => '未绑定'))
  582. /*->addFormItem('avatar', 'picture', '头像', '头像')*/
  583. ->setFormData($info)
  584. ->display();
  585. }
  586. }
  587. public function qrcode($url)//二维码生成类
  588. {
  589. $url=$url;
  590. $level=3;
  591. $size=4;
  592. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  593. $errorCorrectionLevel =intval($level) ;//容错级别
  594. $matrixPointSize = intval($size);//生成图片大小
  595. //生成二维码图片
  596. $object = new \QRcode();
  597. //打开缓冲区
  598. ob_start();
  599. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  600. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  601. $imageString = base64_encode(ob_get_contents());
  602. //关闭缓冲区
  603. ob_end_clean();
  604. //把生成的base64字符串返回给前端
  605. return $imageString;
  606. /* $data = array(
  607. 'labelcode'=>$url,
  608. 'code'=>200,
  609. 'data'=>$imageString,
  610. 'product_code'=>$url
  611. );
  612. $this->ajaxReturn($data);*/
  613. }
  614. public function changestatus(){//动态改变小标签的状态
  615. $data['status']=I('get.status');
  616. if(M('qcode_small')->where('id='.I('get.id'))->save($data)){
  617. $bach_id=M('qcode_large')->field('bach_id')->where('id='.I('get.large_id'))->find();//获取批次id
  618. $small_num=M('qcode_bach')->field('small_num')->where('id='.$bach_id['bach_id'])->find();//获取批次原有的小标签数量
  619. if(I('get.status')=='0'){
  620. //表示已删除的标签变为正常,批次小件数量加一
  621. $infos['small_num']=$small_num['small_num']+1;
  622. M('qcode_bach')->where('id='.$bach_id['bach_id'])->save($infos);//更新批次的小标签数量
  623. // echo M('qcode_bach')->getLastSql();
  624. }
  625. if(I('get.status')=='1'){
  626. //表示正常的标签变为已删除,批次小件数量减一
  627. $infos['small_num']=$small_num['small_num']-1;
  628. M('qcode_bach')->where('id='.$bach_id['bach_id'])->save($infos);//更新批次的小标签数量
  629. //echo M('qcode_bach')->getLastSql();
  630. }
  631. $info['code']=200;
  632. $info['error']="操作成功";
  633. }else{
  634. $info['code']=100;
  635. $info['error']="操作失败";
  636. };
  637. $this->ajaxReturn($info);
  638. }
  639. }