NewQcodeController.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. $remainder = $small_num - $tray_num*$i; //确定最后一个托盘大件里小件的数量
  171. if ($remainder < $tray_num){
  172. $small_n = intTochar($remainder,3);//小件数量3位 不足补零
  173. }else{
  174. $small_n = intTochar($tray_num,3);
  175. }
  176. $code_data= CodeData($this->sign,$fixed_code,$small_n,$print_date,$l_flow,$l_weight,$this->signLarge,$l_reservation);
  177. //大码数据信息
  178. $L_data=[
  179. 'bach_id'=>$Bach_id,
  180. 'code'=>$code_data['code'],
  181. 'code_cp1'=>$code_data['code_cp1'],
  182. 'code_cp2'=>$code_data['code_cp2'],
  183. 'print_date'=>$print_date,
  184. 'creat_time'=>time(),
  185. 'p_nums'=>0,
  186. 'userid'=>$userid,//大码绑定用户id
  187. 'l_weight'=>$l_weight//单个大件重量
  188. ];
  189. $large_id= $QcodeLarge->data($L_data)->add();
  190. //小码插入循环
  191. for($j=0;$j<$tray_num and ($j+$i*$tray_num)<$small_num;$j++){
  192. $s_flow=intTochar(I('post.s_flow/d')+$j+$i*$tray_num+$lastnum['last_num'],6);//小码序号从一开始
  193. $s_weight=intTochar(I('post.s_weight'),6);
  194. $small_sign = '000';
  195. // $small_production_date = (int)date('Ymd',strtotime(I('post.manufacture_date')));//8位生产日期
  196. $s_reservation=intTochar(I('post.bach_num'),10);//批次+0,不够10位在前面补0 第一个批次 后续会加第二个批次
  197. $s_reservation = $s_reservation.'0000000000';
  198. $small_code_data= CodeData($this->sign,$fixed_code,$small_sign,$print_date,$s_flow,$s_weight,$this->signSmall,$s_reservation);
  199. $S_data[$i][$j]=[
  200. 'large_id'=>$large_id,
  201. 'bach_id'=>$Bach_id,
  202. 'code'=>$small_code_data['code'],
  203. 'code_cp1'=>$small_code_data['code_cp1'],
  204. 'code_cp2'=>$small_code_data['code_cp2'],
  205. 'l_flow'=>$j+1,
  206. 'print_date'=>$print_date,
  207. 'creat_time'=>time(),
  208. 'p_nums'=>0,
  209. 'userid'=>$userid,//小码绑定用户id
  210. 's_weight'=>$s_weight//单个小件重量
  211. ];
  212. // $QcodeSmall->data($S_data)->add();
  213. }
  214. $QcodeSmall->addAll($S_data[$i]);
  215. }
  216. $liushui->where($whereSmall)->setInc('last_num',$small_num);
  217. }
  218. if(($j+($i-1)*$tray_num)==$small_num){
  219. M()->commit();
  220. $this->success('批次新增成功', U('Qcode/small'));
  221. }else{
  222. M()->rollback();
  223. $this->success('批次新增失败', U('Qcode/small'));
  224. }
  225. }else{
  226. $this->error('非法请求','NewQcode/index',5);
  227. }
  228. }
  229. }
  230. public function BachListApi(){//获取打印批次列表
  231. $session_config=I('session.ly_admin_');//获取登陆的session值
  232. if($_GET['sysCdNm']){//有搜索产品名称
  233. $where['a.matter_name']=array('like','%'.$_GET['sysCdNm'].'%');
  234. }
  235. if($_GET['nickname']){//有搜索公司名称
  236. $where['c.nickname']=$_GET['nickname'];
  237. }
  238. if($_GET['prodBth']){//有搜索产品批次
  239. $where['a.bach_num']=$_GET['prodBth'];
  240. }
  241. if($_GET['startDate']){//有开始打印日期
  242. $statrtime=((int)date('Ymd',(strtotime($_GET['startDate'])))-20000000);
  243. $endtime=((int)date('Ymd',(strtotime($_GET['endDate'])))-20000000);
  244. $where['a.print_date']=array(array('egt',$statrtime),array('elt',$endtime),'AND');
  245. }
  246. if($session_config['user_auth']['addtype']==1){
  247. $where['a.userid']=$session_config['user_auth']['uid'];
  248. }
  249. $where['a.bach_status']=0;
  250. if ($_GET['sqrcd']){//有搜索标签代码
  251. $map = array();
  252. $map['code'] = array('like','%'.$_GET['sqrcd'].'%');
  253. $large_bach = M('qcode_large')->where($map)->field('bach_id')->select();
  254. if (!empty($large_bach)){
  255. foreach ($large_bach as $key=>$value){
  256. $option[$key] = $value['bach_id'];
  257. }
  258. $option = array_unique($option);
  259. $where['a.id'] = array('IN',$option);
  260. }else{
  261. $small_bach = M('qcode_small')->where($map)->field('bach_id')->select();
  262. if (!empty($small_bach)){
  263. foreach ($small_bach as $key=>$value){
  264. $option[$key] = $value['bach_id'];
  265. }
  266. $option = array_unique($option);
  267. $where['a.id'] = array('IN',$option);
  268. }
  269. }
  270. }
  271. $BatchList=M('qcode_bach')->alias('a')
  272. ->join('qr_qcode_product b on a.matter_id=b.id','LEFT')
  273. ->join('qr_admin_user c on a.userid=c.id','LEFT')
  274. ->field('a.*,b.product_num,c.nickname')
  275. ->order($_GET['sort'].' '.$_GET['order'])
  276. ->page($_GET['page'],$_GET['rows'])
  277. ->where($where)
  278. ->select();
  279. //echo M('qcode_bach')->getLastSql();
  280. $total = M('qcode_bach')->alias('a')
  281. ->join('qr_qcode_product b on a.matter_name=b.product_name','LEFT')
  282. ->join('qr_admin_user c on a.userid=c.id')
  283. ->where($where)
  284. ->count();
  285. $result = [];
  286. $result['total'] = $total;
  287. $result['rows'] = $BatchList;
  288. $bachlist = json_encode($result);
  289. echo $bachlist;
  290. //echo json_encode($BatchList);
  291. }
  292. public function BachListApiTwo(){//补打界面获取补打批次列表
  293. // $session_config=I('session.ly_admin_');//获取登陆的session值
  294. if($_GET['sysCdNm']){//有搜索产品名称
  295. $where['a.matter_name']=array('like','%'.$_GET['sysCdNm'].'%');
  296. }
  297. if($_GET['nickname']){//有搜索公司名称
  298. $where['c.nickname']=array('like','%'.$_GET['nickname'].'%');
  299. }
  300. if($_GET['prodBth']){//有搜索产品批次
  301. $where['a.bach_num']=$_GET['prodBth'];
  302. }
  303. if($_GET['matter_no']){//有搜索产品批次
  304. $where['a.matter_no']=array('like','%'.$_GET['matter_no'].'%');
  305. }
  306. if($_GET['startDate']){//有开始打印日期
  307. $statrtime=((int)date('Ymd',(strtotime($_GET['startDate'])))-20000000);
  308. $endtime=((int)date('Ymd',(strtotime($_GET['endDate'])))-20000000);
  309. $where['a.print_date']=array(array('egt',$statrtime),array('elt',$endtime),'AND');
  310. }
  311. // if($session_config['user_auth']['addtype']==1){
  312. // $where['a.userid']=$session_config['user_auth']['uid'];
  313. // }
  314. $where['a.bach_status']=0;
  315. if ($_GET['sqrcd']){//有搜索标签代码
  316. $map = array();
  317. $map['code'] = array('like','%'.$_GET['sqrcd'].'%');
  318. $large_bach = M('qcode_large')->where($map)->field('bach_id')->select();
  319. if (!empty($large_bach)){
  320. foreach ($large_bach as $key=>$value){
  321. $option[$key] = $value['bach_id'];
  322. }
  323. $option = array_unique($option);
  324. $where['a.id'] = array('IN',$option);
  325. }else{
  326. $result = [];
  327. $result['total'] = '0';
  328. $result['rows'] = [];
  329. $bachlist = json_encode($result);
  330. return $bachlist;
  331. $small_bach = M('qcode_small')->where($map)->field('bach_id')->select();
  332. if (!empty($small_bach)){
  333. foreach ($small_bach as $key=>$value){
  334. $option[$key] = $value['bach_id'];
  335. }
  336. $option = array_unique($option);
  337. $where['a.id'] = array('IN',$option);
  338. }
  339. }
  340. }
  341. $BatchList=M('qcode_bach')->alias('a')
  342. ->join('qr_qcode_product b on a.matter_id=b.id','LEFT')
  343. ->join('qr_admin_user c on a.userid=c.id','LEFT')
  344. ->field('a.*,b.product_num,c.nickname')
  345. ->order($_GET['sort'].' '.$_GET['order'])
  346. ->page($_GET['page'],$_GET['rows'])
  347. ->where($where)
  348. ->select();
  349. //echo M('qcode_bach')->getLastSql();
  350. $total = M('qcode_bach')->alias('a')
  351. ->join('qr_qcode_product b on a.matter_name=b.product_name','LEFT')
  352. ->join('qr_admin_user c on a.userid=c.id')
  353. ->where($where)
  354. ->count();
  355. $result = [];
  356. $result['total'] = $total;
  357. $result['rows'] = $BatchList;
  358. $bachlist = json_encode($result);
  359. echo $bachlist;
  360. //echo json_encode($BatchList);
  361. }
  362. public function GetLargeLabelApi(){//获取关联批次的大件标签列表
  363. $field = "code,print_date,p_nums,id,code_cp1,l_print,l_status,archive";
  364. $LargeLabelList = M('qcode_large')->field($field)->where('bach_id='.I('get.product_id'))->select();
  365. // var_dump($LargeLabelList);
  366. foreach($LargeLabelList as $key=>$val){
  367. $qcode_small=$val['archive']?"qcode_small_".$val['archive']:"qcode_small";
  368. $smalltotal=M('qcode_small')->field('count(large_id)')->where('large_id='.$val['id'])->find();
  369. $LargeLabelList[$key]['code_cp1']=ltrim(substr($LargeLabelList[$key]['code_cp1'],6,10),'0');
  370. $LargeLabelList[$key]['smalltotal']=$smalltotal['count(large_id)'];
  371. if( $LargeLabelList[$key]['l_print']==0){
  372. $type="未打印";
  373. }
  374. if($LargeLabelList[$key]['l_print']==1){
  375. $type="已打印";
  376. }
  377. $LargeLabelList[$key]['type']=$type;
  378. }
  379. echo json_encode($LargeLabelList);
  380. }
  381. public function GetSmallLabelApi(){//获取关联大标签的的小标签列表
  382. if(I('get.large_id')){//获取小标签列表
  383. $field="id,code,code_cp1,status,l_flow,p_nums";
  384. $smalllist=M('qcode_small')
  385. ->field($field)
  386. ->where('large_id='.I('get.large_id'))
  387. ->select();
  388. $large_data = M('qcode_large')
  389. ->field('code_cp1')
  390. ->where('id='.I('get.large_id'))
  391. ->find();
  392. $large_flow = ltrim(substr($large_data['code_cp1'],6,10),'0');
  393. foreach($smalllist as $key=>$val){
  394. $smalllist[$key]['l_flow']= $large_flow.'-'.$smalllist[$key]['l_flow'];
  395. // if($val['id']>44091){
  396. // $smalllist[$key]['code_cp1']=I('get.large_tuopan').'-'.ltrim(substr($smalllist[$key]['code_cp2'],12,6),'0');}
  397. // else{
  398. // $smalllist[$key]['code_cp1']=I('get.large_tuopan').'-'.ltrim(substr($smalllist[$key]['code_cp1'],6,6),'0');
  399. // };
  400. }
  401. $this->ajaxReturn($smalllist);
  402. }
  403. if(I('get.code') ){//单个删除
  404. $field="id,code,status";
  405. $code=I('get.code');
  406. $data['status']=1;
  407. if( M('qcode_small')->where("code='$code'")->save($data)){
  408. $smalllist['status']=200;
  409. $smalllist['error']="操作成功";
  410. }else{
  411. $smalllist['status']=100;
  412. $smalllist['error']="操作失败";
  413. };
  414. $smalllist['list']=M('qcode_small')->field($field)->where("code='$code'")->select();
  415. $this->ajaxReturn($smalllist);
  416. }
  417. }
  418. public function OneSmallPrint(){//单个打印小标签
  419. // M('qcode_small')->where('id='.I('get.id'))->setInc('p_nums',I('get.reptQty'));//更新小标签的打印次数
  420. //echo M('qcode_small')->getLastSql();
  421. $smalllabel[]=M('qcode_small')->alias('b')
  422. ->join("qr_qcode_large c on b.large_id=c.id")
  423. ->join('qr_qcode_bach d on d.id=c.bach_id')
  424. ->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')
  425. ->where('b.id='.I('get.id'))
  426. ->select();
  427. /*foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  428. $imgcode=$this->qrcode($val['code']);
  429. $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  430. }*/
  431. $total['smalllabel']=$smalllabel;
  432. $total['num']=I('get.reptQty');
  433. $this->ajaxReturn($total);
  434. }
  435. //二维码打印
  436. // public function rePrintTg(){
  437. // header("Content-type: text/html; charset=utf-8");
  438. // $id = I('post.idList');//选中的大件标签的列表id
  439. // $ids=explode(",",$id);//将字符串以逗号转化为数组
  440. // $num = I('post.reptQty')?I('post.reptQty'):3;//重复打印次数
  441. // foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  442. // if(I('post.sign_type')==1){//打印的为大件标签
  443. // //先更新大标签的打印次数
  444. // M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  445. // M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  446. // //在查找相关的信息
  447. // $largelabel[]=M('qcode_large')->alias('a')
  448. // ->join('qr_qcode_bach q on a.bach_id=q.id')
  449. // ->field('a.*,q.supplier_name,q.l_weight')
  450. // ->where('a.id='.$val)
  451. // ->select();
  452. //
  453. // }
  454. // if(I('post.sign_type')==2){//打印的为小件标签
  455. // //先更新小标签的打印次数
  456. // M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  457. // /* M('qcode_small')->where('large_id='.$val)->setField('status','1');//更新小标签的打印状态$num*/
  458. // //在查找小标签的相关内容
  459. //
  460. // $smalllabel[]=M('qcode_small')->alias('b')
  461. // ->join("qr_qcode_large c on b.large_id=c.id")
  462. // ->join('qr_qcode_bach d on d.id=c.bach_id')
  463. // ->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')
  464. // ->where('b.large_id='.$val)
  465. // ->select();
  466. // }
  467. // //$sql=M('qcode_small')->getLastSql();
  468. // }
  469. //// foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  470. //// $imgcode=$this->qrcode($val['code']);
  471. //// $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  472. //// }
  473. // //var_dump($smalllabel[0]);
  474. // $total['largrlabel']=$largelabel?$largelabel:'';
  475. // $total['smalllabel']=$smalllabel?$smalllabel:'';
  476. // $total['num']=$num;
  477. // $this->ajaxReturn($total);
  478. //
  479. // }
  480. public function rePrintTg(){
  481. header("Content-type: text/html; charset=utf-8");
  482. $id = I('post.idList');//选中的大件标签的列表id
  483. $ids=explode(",",$id);//将字符串以逗号转化为数组
  484. $num = I('post.reptQty')?I('post.reptQty'):0;//重复打印次数
  485. if (I('post.status')==1){//修改打印次数--自动打码
  486. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  487. if(I('post.sign_type')==1){//打印的为大件标签
  488. //更新大标签的打印次数
  489. M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  490. M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  491. }
  492. if(I('post.sign_type')==2){//打印的为小件标签
  493. //更新小标签的打印次数
  494. M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  495. }
  496. }
  497. $total['num']=$num;
  498. $this->ajaxReturn($total);
  499. }else if (I('post.status')==2){//修改打印次数--小件
  500. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  501. M('qcode_small')->where('id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  502. }
  503. $total['num']=$num;
  504. $this->ajaxReturn($total);
  505. }else{
  506. foreach($ids as $key=>$val){//获取对应的大标签以及绑定的小标签的相关信息
  507. if(I('post.sign_type')==1){//打印的为大件标签
  508. //先更新大标签的打印次数
  509. // M('qcode_large')->where('id='.$val)->setInc('p_nums',$num);// 大标签的打印次数加$num
  510. // M('qcode_large')->where('id='.$val)->setField('l_print','1');//更新大标签的打印状态$num
  511. //在查找相关的信息
  512. $largelabel[$key] = M('qcode_large')->alias('c')
  513. ->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')
  514. ->join('qr_qcode_bach d on c.bach_id=d.id')
  515. ->join('qr_qcode_unit u on u.code=d.matter_no')
  516. ->where('c.id='.$val)
  517. ->select();
  518. $numn = M('qcode_small')->where('large_id='.$val)->count();
  519. $largelabel[$key][0]['numn']=$numn;
  520. }
  521. if(I('post.sign_type')==2){//打印的为小件标签
  522. //先更新小标签的打印次数
  523. // M('qcode_small')->where('large_id='.$val)->setInc('p_nums',$num);// 小标签的打印次数加$num
  524. /* M('qcode_small')->where('large_id='.$val)->setField('status','1');//更新小标签的打印状态$num*/
  525. //在查找小标签的相关内容
  526. $smalllabel[]=M('qcode_small')->alias('b')
  527. ->join("qr_qcode_large c on b.large_id=c.id")
  528. ->join('qr_qcode_bach d on d.id=c.bach_id')
  529. ->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')
  530. ->where('b.large_id='.$val)
  531. ->select();
  532. }
  533. //$sql=M('qcode_small')->getLastSql();
  534. }
  535. // foreach($smalllabel[0] as $key=>$val){//循环获取img标签内容
  536. // $imgcode=$this->qrcode($val['code']);
  537. // $smalllabel[0][$key]['imgcode']="data:image/png;base64,".$imgcode;
  538. // }
  539. //var_dump($smalllabel[0]);
  540. $total['largrlabel']=$largelabel?$largelabel:'';
  541. $total['smalllabel']=$smalllabel?$smalllabel:'';
  542. $total['num']=$num;
  543. $this->ajaxReturn($total);
  544. }
  545. }
  546. public function userinfoedit()
  547. {//修改用户的相关信息
  548. if (IS_POST) {
  549. $no_pass = 0;
  550. // 密码为空表示不修改密码
  551. if ($_POST['password'] === '') {
  552. unset($_POST['password']);
  553. $no_pass = 1;
  554. }
  555. // 提交数据
  556. $user_object = D('User');
  557. $data = $user_object->create();
  558. if ($data) {
  559. if ($no_pass == 1){
  560. $field = 'id,nickname,username,email,email_bind,mobile,mobile_bind,gender,avatar,update_time,printer_code,postcode,company_address';
  561. }else{
  562. $field = 'id,nickname,username,password,email,email_bind,mobile,mobile_bind,gender,avatar,update_time,printer_code,postcode,company_address';
  563. }
  564. $result = $user_object
  565. ->field($field)
  566. ->save($data);
  567. if ($result) {
  568. $this->success('更新成功', U('index'));
  569. } else {
  570. $this->error('更新失败', $user_object->getError());
  571. }
  572. } else {
  573. $this->error($user_object->getError());
  574. }
  575. } else {
  576. // 获取账号信息
  577. $session_config=I('session.ly_admin_');
  578. $id=$session_config['user_auth']['uid'];
  579. $info = D('User')->find($id);
  580. unset($info['password']);
  581. // 使用FormBuilder快速建立表单页面。
  582. $builder = new \Common\Builder\FormBuilder();
  583. $builder->setMetaTitle('编辑用户')// 设置页面标题
  584. ->setPostUrl(U('userinfoedit'))// 设置表单提交地址
  585. ->addFormItem('id', 'hidden', 'ID', 'ID')
  586. ->addFormItem('nickname', 'text', '供应商名称', '供应商名称')
  587. ->addFormItem('printer_code', 'text', '供应商编码', '供应商编码')
  588. ->addFormItem('postcode', 'num', '邮政编码', '邮政编码')
  589. ->addFormItem('company_address', 'text', '地址', '详细地址')
  590. ->addFormItem('username', 'text', '用户名', '用户名')
  591. ->addFormItem('password', 'password', '密码', '密码')
  592. ->addFormItem('email', 'text', '邮箱', '邮箱')
  593. ->addFormItem('email_bind', 'radio', '邮箱绑定', '手机绑定', array('1' => '已绑定', '0' => '未绑定'))
  594. ->addFormItem('mobile', 'text', '手机号', '手机号')
  595. ->addFormItem('mobile_bind', 'radio', '手机绑定', '手机绑定', array('1' => '已绑定', '0' => '未绑定'))
  596. /*->addFormItem('avatar', 'picture', '头像', '头像')*/
  597. ->setFormData($info)
  598. ->display();
  599. }
  600. }
  601. public function qrcode($url)//二维码生成类
  602. {
  603. $url=$url;
  604. $level=3;
  605. $size=4;
  606. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  607. $errorCorrectionLevel =intval($level) ;//容错级别
  608. $matrixPointSize = intval($size);//生成图片大小
  609. //生成二维码图片
  610. $object = new \QRcode();
  611. //打开缓冲区
  612. ob_start();
  613. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  614. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  615. $imageString = base64_encode(ob_get_contents());
  616. //关闭缓冲区
  617. ob_end_clean();
  618. //把生成的base64字符串返回给前端
  619. return $imageString;
  620. /* $data = array(
  621. 'labelcode'=>$url,
  622. 'code'=>200,
  623. 'data'=>$imageString,
  624. 'product_code'=>$url
  625. );
  626. $this->ajaxReturn($data);*/
  627. }
  628. public function changestatus(){//动态改变小标签的状态
  629. $data['status']=I('get.status');
  630. if(M('qcode_small')->where('id='.I('get.id'))->save($data)){
  631. $bach_id=M('qcode_large')->field('bach_id')->where('id='.I('get.large_id'))->find();//获取批次id
  632. $small_num=M('qcode_bach')->field('small_num')->where('id='.$bach_id['bach_id'])->find();//获取批次原有的小标签数量
  633. if(I('get.status')=='0'){
  634. //表示已删除的标签变为正常,批次小件数量加一
  635. $infos['small_num']=$small_num['small_num']+1;
  636. M('qcode_bach')->where('id='.$bach_id['bach_id'])->save($infos);//更新批次的小标签数量
  637. // echo M('qcode_bach')->getLastSql();
  638. }
  639. if(I('get.status')=='1'){
  640. //表示正常的标签变为已删除,批次小件数量减一
  641. $infos['small_num']=$small_num['small_num']-1;
  642. M('qcode_bach')->where('id='.$bach_id['bach_id'])->save($infos);//更新批次的小标签数量
  643. //echo M('qcode_bach')->getLastSql();
  644. }
  645. $info['code']=200;
  646. $info['error']="操作成功";
  647. }else{
  648. $info['code']=100;
  649. $info['error']="操作失败";
  650. };
  651. $this->ajaxReturn($info);
  652. }
  653. }