NewQcodeController.class.php 35 KB

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