NewQcodeController.class.php 36 KB

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