QcodeController.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. <?php
  2. /*第一版后台控制器*/
  3. namespace Admin\Controller;
  4. use think\Log;
  5. use Think\Page;
  6. use think\Request;
  7. class QcodeController extends AddonController{
  8. public function test(){//测试页面hahha
  9. }
  10. public function delTg(){//删除批次信息
  11. $info['bach_status']=1;
  12. $bach = M('qcode_bach');
  13. if($bach->where("id=".I('post.bachid'))->save($info)){
  14. $session_config=I('session.ly_admin_');//获取登陆的session值
  15. $uid = $session_config['user_auth']['uid'];
  16. $large = M('qcode_large');
  17. $small = M('qcode_small');
  18. $l_flow = M('reset_flow');
  19. $s_flow = M('qcode_liushui');
  20. $bach_info = $bach->where('id='.I('post.bachid'))->field('id,matter_id,matter_type,supplier_code,matter_no,manufacture_date,print_date,bach_num')->find();
  21. $largeNum = $large->where('bach_id='.I('post.bachid'))->count();
  22. $smallNum = $small->where('bach_id='.I('post.bachid'))->count();
  23. $l_map['userid'] = $uid;
  24. $l_map['product_id'] = $bach_info['matter_id'];
  25. $l_map['bach_num'] = $bach_info['bach_num'];
  26. $large_flow = $l_flow->where($l_map)->find();
  27. $new_l_flow = $large_flow['l_flow'] - $largeNum;//删除后恢复的大件流水号
  28. $l_flow->where($l_map)->setField('l_flow',$new_l_flow);//操作更新
  29. $onlycode = '9092'.intTochar($bach_info['matter_type'],2).intTochar($bach_info['supplier_code'],12).intTochar($bach_info['matter_no'],20).$bach_info['manufacture_date'].$bach_info['print_date'];
  30. $s_map['user_id'] = $uid;
  31. $s_map['onlycode'] = $onlycode;
  32. $small_flow = $s_flow->where($s_map)->find();
  33. $new_s_flow = $small_flow['last_num'] - $smallNum;//删除后恢复的小件流水号
  34. $s_flow->where($s_map)->setField('last_num',$new_s_flow);
  35. $data['success']=true;
  36. $data['message']="删除成功";
  37. $this->ajaxReturn($data);
  38. }else{
  39. $data['error']=false;
  40. $data['message']="删除失败";
  41. $this->ajaxReturn($data);
  42. }
  43. }
  44. public function QcodeCompanyDel(){
  45. //产品删除
  46. if(IS_POST){
  47. if(empty($_POST)){
  48. $this->error('请至少选择一个选项');
  49. }else{
  50. $bar = D('QcodeCompany');
  51. $id = implode(',',$_POST['ids']);
  52. $return = $bar->DelQcodeCompany($id);
  53. if($return){
  54. $this->success('删除成功', U('Company'));
  55. }else{
  56. $this->error('删除失败');
  57. }
  58. }
  59. }else{
  60. $id = $_GET['id'];
  61. $bar = D('QcodeCompany');
  62. $return = $bar->DelQcodeCompany($id);
  63. if($return){
  64. $this->success('删除成功', U('Company'));
  65. }else{
  66. $this->error('删除失败');
  67. }
  68. }
  69. }
  70. public function QcodeCompanyAdd(){//生产厂商的添加和修改
  71. if (IS_POST ) {
  72. $bar_object = D('QcodeCompany');
  73. $data= $bar_object->create();
  74. if ($data) {
  75. if(I('post.id')){//有id是修改
  76. if ($bar_object->save($data)) {
  77. $this->success('修改成功', U('Company'));
  78. } else {
  79. $this->error('修改失败');
  80. }
  81. }else {//不存在id,新增
  82. if ($bar_object->add($data)) {
  83. $this->success('新增成功', U('Company'));
  84. } else {
  85. $this->error('新增失败');
  86. }
  87. }
  88. } else {
  89. $this->error($bar_object->getError());
  90. }
  91. } else {
  92. //使用FormBuilder快速建立表单页面。
  93. $builder = new \Common\Builder\FormBuilder();
  94. $builder->setMetaTitle('编辑厂商') //设置页面标题
  95. ->setPostUrl(U('QcodeCompanyAdd')) //设置表单提交地址
  96. ->addFormItem('id', 'hidden', 'ID', 'ID')
  97. ->addFormItem('company_name', 'text', '名称', '请输入供应商名称')
  98. ->addFormItem('company_code','num', '供应商编码', '请输入供应商唯一编码')
  99. ->addFormItem('postcode','num', '邮政编码', '邮政编码')
  100. ->addFormItem('phone','num', '联系电话', '请输入联系电话')
  101. ->addFormItem('company_addres','text', '地址', '请输入供应商地址')
  102. ->setFormData(D('QcodeCompany')->find(I('get.id')))
  103. ->display();
  104. }
  105. }
  106. public function Company(){//生产厂商列表
  107. // 搜索
  108. $keyword = I('keyword', '', 'string');
  109. $condition = array('like', '%' . $keyword . '%');
  110. $map['company_name|company_code'] = array(//查询条件数组
  111. $condition,
  112. $condition,
  113. '_multi' => true,
  114. );
  115. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  116. $product_object = D('qcode_company');
  117. $data_list= $product_object
  118. ->page($p, 15)
  119. ->where($map)
  120. ->order('id asc')
  121. ->select();
  122. $page = new Page(
  123. $product_object->where($map)->count(),
  124. 50
  125. );
  126. // 使用Builder快速建立列表页面。
  127. $builder = new \Common\Builder\ListBuilder();
  128. $builder->setMetaTitle('生产厂商管理') // 设置页面标题
  129. ->addTopButton('addnew',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/QcodeCompanyAdd')]) // 添加新增按钮
  130. ->addTopButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/QcodeCommanyDel')]) // 添加删除按钮
  131. ->setSearch(
  132. '请输入供应商名称或者供应商编码',
  133. U('Company')//重新进入到Productile页面;
  134. )
  135. ->addTableColumn('id', 'ID')
  136. ->addTableColumn('company_name', '名称')
  137. ->addTableColumn('company_code', '厂商编码')
  138. ->addTableColumn('postcode', '邮政编码')
  139. ->addTableColumn('phone', '联系电话')
  140. ->addTableColumn('company_addres', '地址')
  141. /*->addTableColumn('title', '自定义')*/
  142. ->addTableColumn('right_button', '操作', 'btn')
  143. ->setTableDataList($data_list) // 数据列表
  144. ->setTableDataPage($page) // 数据列表分页
  145. ->addRightButton('edit',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/QcodeCompanyAdd',array(
  146. 'id' => '__data_id__',
  147. ))]) // 添加编辑按钮
  148. ->addRightButton('delete',['href'=>U(MODULE_NAME . '/' . CONTROLLER_NAME . '/QcodeCompanyDel',array(
  149. 'id' => '__data_id__',
  150. ))]) // 添加删除按钮
  151. ->display();
  152. }
  153. public function Dama(){//打码统计页面
  154. $this->display();
  155. }
  156. public function damacount(){//打码统计详情页面
  157. $session_config=I('session.ly_admin_');
  158. $uid = $session_config['user_auth']['uid'];
  159. $user = M('admin_user');
  160. $user_info = $user->where('id='.$uid)->find();
  161. $product_id = explode(',',$user_info['product_id']);
  162. $map['id'] = array('in',$product_id);
  163. $product = M('qcode_product');
  164. $list = $product->where($map)->field('id,product_name')->select();
  165. $db=M('qcode_bach');
  166. $large = M('qcode_large');
  167. $small = M('qcode_small');
  168. $where['userid'] = $uid;
  169. $where['bach_status'] = 0;
  170. $damalist=$db->where($where)
  171. ->field('id')
  172. ->select();
  173. $damalist = array_column($damalist,'id');
  174. if ($damalist){
  175. $option['bach_id'] = array('in',$damalist);
  176. }
  177. $option['userid'] = $uid;
  178. $largeNum = $large->where($option)->count();
  179. $smallNum = $small->where($option)->count();
  180. $total = $largeNum + $smallNum;
  181. $this->assign('list',$list);
  182. $this->assign('total',$total);
  183. $this->display();
  184. }
  185. public function DamaCountApi(){//打码量统计产品列表
  186. $page=$_GET['page'];
  187. $damalist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  188. $pagenum=($page-1)* $damalist['pagesize'];//当前页码
  189. if($pagenum<0){
  190. $pagenum=0;
  191. }
  192. $map = array();
  193. if (!empty($_GET['sqrcd'])){
  194. $map['bach_num'] = $_GET['sqrcd'];
  195. }
  196. if ($_GET['sysCdNm'] > 0){
  197. $map['matter_id'] = $_GET['sysCdNm'];
  198. }
  199. $session_config=I('session.ly_admin_');
  200. $uid = $session_config['user_auth']['uid'];
  201. $map['userid'] = $uid;
  202. if($_GET['startDate']){//有开始日期
  203. $statrtime=strtotime($_GET['startDate']);
  204. $endtime=strtotime($_GET['endDate']);
  205. $map['creat_time']=array(array('egt',$statrtime),array('elt',$endtime),'AND');
  206. }
  207. $map['bach_status'] = 0;//未删除批次
  208. $db=M('qcode_bach');
  209. $damalist['rows']=$db->where($map)
  210. ->field('id,bach_num,matter_no,matter_name,matter_size')
  211. ->order( "id desc")
  212. ->limit($pagenum,$damalist['pagesize'])
  213. ->select();
  214. $largeNum = M('qcode_large');
  215. $smallNum = M('qcode_small');
  216. foreach ($damalist['rows'] as $key=>$value){
  217. $damalist['rows'][$key]['largeTotal'] = $largeNum->where('bach_id='.$value['id'])->count();
  218. $damalist['rows'][$key]['smallTotal'] = $smallNum->where('bach_id='.$value['id'])->count();
  219. }
  220. $count = $db->where($map)->count();
  221. $damalist['pagesize']=$_GET['rows']?$_GET['rows']:10;//每页显示的记录数
  222. $damalist['total']=$count;//总的记录数
  223. echo json_encode($damalist);
  224. }
  225. public function QcodeProductDel(){//产品删除
  226. if(IS_POST){
  227. if(empty($_POST)){
  228. $this->error('请至少选择一个选项');
  229. }else{
  230. $bar = D('QcodeProduct');
  231. $id = implode(',',$_POST['ids']);
  232. $return = $bar->DelQcodeProduct($id);
  233. if($return){
  234. $this->success('删除成功', U('Product'));
  235. }else{
  236. $this->error('删除失败');
  237. }
  238. }
  239. }else{
  240. $id = $_GET['id'];
  241. $bar = D('QcodeProduct');
  242. $return = $bar->DelQcodeProduct($id);
  243. if($return){
  244. $this->success('删除成功', U('Product'));
  245. }else{
  246. $this->error('删除失败');
  247. }
  248. }
  249. }
  250. public function QcodeProductAdd(){//产品添加或者是修改
  251. if (IS_POST ) {
  252. $bar_object = D('QcodeProduct');
  253. $data= $bar_object->create();
  254. if ($data) {
  255. if(I('post.id')){//有id是修改
  256. if ($bar_object->save($data)) {
  257. $this->success('修改成功', U('Product'));
  258. } else {
  259. $this->error('修改失败');
  260. }
  261. }else {//不存在id,新增
  262. if ($bar_object->add($data)) {
  263. $this->success('新增成功', U('Product'));
  264. } else {
  265. $this->error('新增失败');
  266. }
  267. }
  268. } else {
  269. $this->error($bar_object->getError());
  270. }
  271. } else {
  272. //使用FormBuilder快速建立表单页面。
  273. $builder = new \Common\Builder\FormBuilder();
  274. $builder->setMetaTitle('编辑产品') //设置页面标题
  275. ->setPostUrl(U('QcodeProductAdd')) //设置表单提交地址
  276. ->addFormItem('id', 'hidden', 'ID', 'ID')
  277. ->addFormItem('product_name', 'text', '名称', '请输入名称')
  278. ->addFormItem('product_code', 'text', '编码', '请输入编码')
  279. ->addFormItem('product_size','text', '规格', '规格单位为毫米')
  280. ->addFormItem('product_num','text', '产品批次', '产品批次')
  281. ->addFormItem('temple','text', '产品代号', '产品代号')
  282. ->setFormData(D('QcodeProduct')->find(I('get.id')))
  283. ->display();
  284. }
  285. }
  286. public function product(){//产品列表
  287. // 搜索
  288. $session_config=I('session.ly_admin_');
  289. $keyword = I('keyword', '', 'string');
  290. $condition = array('like', '%' . $keyword . '%');
  291. if ($keyword != '' && !empty($keyword)){
  292. $map['product_name|product_code'] = array(//查询条件数组
  293. $condition,
  294. $condition,
  295. '_multi' => true,
  296. );
  297. }
  298. $classification = I('classification', '', 'string');
  299. if ($classification != '03' && $classification !=''){
  300. $map['temple'] = substr($classification,2,2);
  301. }
  302. $uid = $session_config['user_auth']['uid'];
  303. $user = M('admin_user');
  304. $user_product = $user->where('id='.$uid)->field('product_id')->find();
  305. $user_product = explode(',',$user_product['product_id']);
  306. $map['id'] = array('gt',27);
  307. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  308. $product_object = D('qcode_product');
  309. $count = $product_object->where($map)->count();// 查询满足要求的总记录数
  310. $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
  311. $show = $Page->show();// 分页显示输出
  312. $data_list= $product_object->page($p.',10')->where($map)->order('id asc')->select();//所有未选中产品列表
  313. //辅料存货分类
  314. $qcode_classification = M('qcode_classification');
  315. $product_classification = $qcode_classification->where('status=1')->order('id asc')->select();
  316. //已选择产品列表
  317. $where['id'] = array('in',$user_product);
  318. $list= $product_object->where($where)->order('id asc')->select();
  319. $this->assign('search',$keyword);
  320. $this->assign('classification',$classification);
  321. $this->assign('product_classification',$product_classification);
  322. $this->assign('user_product',$user_product);
  323. $this->assign('list',$data_list);
  324. $this->assign('data',$list);
  325. $this->assign('page',$show);
  326. $this->display('product');
  327. }
  328. //更新用户生产产品
  329. public function updateProduct(){
  330. if (IS_POST){
  331. $session_config=I('session.ly_admin_');
  332. $uid = $session_config['user_auth']['uid'];
  333. $user = M('admin_user');
  334. $user_data = $user->where('id='.$uid)->field('product_id')->find();
  335. $user_product = $user_data['product_id'];
  336. $id = I('post.id');
  337. $ids = explode(',',$id);
  338. if(I('post.status')=="1"){//增加产品
  339. $new_product = array();
  340. if ($user_product == ''){//第一次增加
  341. $data['product_id'] = $id;
  342. }else{
  343. $user_product = explode(',',$user_product);
  344. $new_product = array_unique(array_merge($ids,$user_product));
  345. sort($new_product);
  346. $new_product_str = implode(',',$new_product);
  347. $data['product_id'] =$new_product_str;
  348. }
  349. $res = $user->where('id='.$uid)->save($data);
  350. $this->ajaxReturn(['status'=>1,'msg'=>'更新成功']);
  351. }else{//删除产品
  352. $data['product_id'] = $id;
  353. $res = $user->where('id='.$uid)->save($data);
  354. $this->ajaxReturn(['status'=>1,'msg'=>'更新成功']);
  355. }
  356. }
  357. }
  358. public function Productajax(){//动态调用产品或者供应商相关信息
  359. if(I('get.type')=="product"){//产品列表
  360. $condition['userid']=I('get.userid');
  361. $condition['product_id']=I('get.id');
  362. $l_flow=M('reset_flow')->field('l_flow,bach_num')->where($condition)->find();
  363. $model=M('qcode_product');
  364. $field='product_size,product_num,product_name,id,temple,product_code';
  365. $product=$model->field($field)->where('id='.I('get.id'))->select();
  366. $product['l_flow']=$l_flow['l_flow']+1;
  367. $product['bach_num']=$l_flow['bach_num']?($l_flow['bach_num']+1):(date('Y',time())."00000"+1);
  368. $this->ajaxReturn($product);
  369. }
  370. if(I('get.type')=="company"){//供应商列表
  371. $model=M('admin_user');
  372. $field='nickname,postcode,mobile,company_address,id,printer_code';
  373. $company=$model->field($field)->where('id='.I('get.id'))->select();
  374. $this->ajaxReturn($company) ;
  375. }
  376. }
  377. public function AddPrint(){//保存待打印的产品记录
  378. //var_dump(I('post.'));
  379. $data=I('post.');
  380. if(!empty($data)) {//提交的数据不为空
  381. $data['company_info']=I('post.company_address')." ".I('post.postname')." ".I('post.phone');
  382. $data['bd_num']=0;//保存就默认为0;
  383. $data['lable_type']=I('post.label_type');
  384. M('qcode_print')->add($data);//保存数据
  385. $this->success('保存成功','index.php?s=/Admin/Qcode/large');
  386. }else{
  387. $this->error('保存失败');
  388. // $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
  389. /* $this->error['errno'] = "添加数据失败";
  390. $this->success($this->error['errno'], '',100);*/
  391. }
  392. }
  393. public function Large(){
  394. /*var_dump(THINK_VERSION);
  395. die();*/
  396. $companylist=M('qcode_company')->field('company_name,postcode,phone,company_addres,company_code,id')->select();
  397. $productlist=M('qcode_product')->field('product_name,id,product_size,product_num,temple,product_code')->select();
  398. $this->assign('companylist',$companylist);
  399. $this->assign('productlist',$productlist);
  400. $this->display();
  401. }
  402. public function Print_ewm(){//生成二维码
  403. $time=time();
  404. if($_GET['temple']==1){//使用新模板
  405. $fixedheadcode = "90";//固定的头部编码2位;
  406. if ($_GET['label_type'] == 1) {//大件标签
  407. $type = "92";
  408. $big_num="095";//大件含有小件数量
  409. $big_liushui=$_GET['big_liushui'];//大件流水号
  410. $big_weight=$_GET['big_weight'];//大件重量
  411. $big_yuliu=$_GET['big_yuliu'];//大件预留号
  412. }
  413. if ($_GET['label_type'] == 2) {//小件标签
  414. $type = "93";//标签种类2位
  415. }
  416. $materialtype=$_GET['materialtype'];//辅料类型2位
  417. $company_code=$_GET['company_code'];//供应商编码
  418. $product_code=$_GET['product_code'];//辅料编码
  419. $product_time=20180807;//生产日期
  420. $print_time=date('Y-m-d',$time);//打码日期
  421. $big_unipue=$print_time.rand(100000,999999);//唯一编码
  422. $yuliu="000000000000000000";//预留码
  423. $url= $fixedheadcode.$type.$materialtype.$company_code.$product_code.$product_time.$big_num.$big_unipue.$yuliu;
  424. $this->qrcode($url);
  425. }
  426. if($_GET['temple']==2) {//使用老模板
  427. if ($_GET['label_type'] == 1) {//大件标签
  428. $type = "92";
  429. $uniquecode = date('Ymd', $time) . rand(100000, 500000);//大件唯一编码14位(生产日期8位+6位随机码)
  430. }
  431. if ($_GET['label_type'] == 2) {//小件标签
  432. $type = "93";//标签种类2位
  433. $uniquecode = date('Ymd', $time) . rand(500001, 999999);//小件唯一编码14位(生产日期8位+6位随机码)
  434. }
  435. $offercode = $_GET['company_code'];//供应商编码12位
  436. $materialcode = $_GET['product_code'];//辅料编码20位不足补零
  437. $producttime = date("Ymd", $time);//生产日期(年月日)8位
  438. $patchcode = "000000";//补位(6位);
  439. $fixedheadcode = "90";//固定的头部编码2位;
  440. $url = $fixedheadcode . $type . $_GET['materialtype'] . $offercode . $materialcode . $producttime . $uniquecode . $patchcode;
  441. $this->qrcode($url);
  442. }
  443. $this->display('large.html');
  444. }
  445. public function qrcode($url)//二维码生成类
  446. {
  447. $url=$url;
  448. $level=2;
  449. $size=4;
  450. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  451. $errorCorrectionLevel =intval($level) ;//容错级别
  452. $matrixPointSize = intval($size);//生成图片大小
  453. //生成二维码图片
  454. $object = new \QRcode();
  455. //打开缓冲区
  456. ob_start();
  457. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  458. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  459. $imageString = base64_encode(ob_get_contents());
  460. //关闭缓冲区
  461. ob_end_clean();
  462. //把生成的base64字符串返回给前端
  463. $data = array(
  464. 'labelcode'=>$url,
  465. 'code'=>200,
  466. 'data'=>$imageString,
  467. 'product_code'=>$url
  468. );
  469. $this->ajaxReturn($data);
  470. }
  471. /*补打标签*/
  472. public function small(){
  473. $this->display('buda');
  474. }
  475. public function buda(){//补打标签
  476. $this->display();
  477. }
  478. public function budadetail(){//补打标签详情页
  479. $session_config=I('session.ly_admin_');//获取登陆的session值
  480. if($session_config['user_auth']['addtype']==1) {
  481. $nickname=$session_config['user_auth']['nickname'];
  482. }else{
  483. $companylist=M('admin_user')->field('nickname')->where('status=1')->select();
  484. }
  485. $userinfo=M('admin_user')->where('id='.$session_config['user_auth']['uid'])->find();
  486. $user_product = explode(',',$userinfo['product_id']);
  487. $map = array();
  488. $map['id'] = array('in',$user_product);
  489. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  490. $this->assign('productlist',$productlist);
  491. $this->assign('nickname',$nickname);
  492. $this->assign('companylist',$companylist);
  493. $this->assign('user_type',$userinfo['user_type']);
  494. $this->display();
  495. }
  496. /*二级产品下拉框*/
  497. public function MaterialTwoApi(){
  498. /* if(I('get.id')==0 || I('get.id')==NULL){
  499. $secondlist=array('全部');
  500. }
  501. if(I('get.id')==1){
  502. $secondlist=array('全部','常规醋纤丝束','特种醋纤丝束','其他醋纤丝束');
  503. }
  504. if(I('get.id')==2){
  505. $secondlist=array('全部','常规聚丙烯丝束','低旦聚丙烯丝束','其他聚丙烯丝束');
  506. }
  507. if(I('get.id')==3){
  508. $secondlist=array('全部','普通成型纸','高透成型纸','其他成型纸');
  509. }
  510. if(I('get.id')==4){
  511. $secondlist=array('全部','醋酸纤维滤棒','常规聚丙烯丝束滤棒','低旦加胶聚丙烯丝束滤棒','纸质滤棒','沟槽滤棒');
  512. }
  513. echo json_encode($secondlist);*/
  514. }
  515. /*产品列表接口*/
  516. public function ProductApi(){
  517. //$productlist['code']=200;
  518. //$productlist['pagesize']=$_GET['pagesize']?$_GET['pagesize']:10;
  519. $page=$_GET['page'];
  520. $productlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  521. $pagenum=($page-1)* $productlist['pagesize'];//当前页码
  522. if($pagenum<0){
  523. $pagenum=0;
  524. }
  525. $productlist['rows']=M('qcode_product')->where('id!=0')->limit($pagenum,$productlist['pagesize'])->select();
  526. $total=M('qcode_product')->where('id!=0')->select();
  527. $productlist['total']=count($total);
  528. $productlist=json_encode($productlist);
  529. //echo date('Y-m-d',1533120226);
  530. echo $productlist;
  531. //die();
  532. }
  533. /*产品打印列表*/
  534. public function PrintListApi(){
  535. if(empty(I('get.product_id'))){//没有产品的id
  536. $printlist['code']=100;
  537. $printlist['total']="产品id为空";
  538. }else{
  539. //$printlist['code']=200;
  540. $page=$_GET['page'];
  541. $productlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  542. $pagenum=($page-1)* $productlist['pagesize'];//当前页码
  543. if($pagenum<0){
  544. $pagenum=0;
  545. }
  546. $printlist['rows']=M('qcode_print')->where('product_id='.I('get.product_id'))->limit($pagenum,$productlist['pagesize'])->select();
  547. /*if(count($printlist['productlist'])==0){//没有找到数据
  548. $printlist['code']=300;
  549. $printlist['total']="没有找到对应的数据";
  550. }else{*///有数据返回分页数据
  551. //$total=count($printlist['productlist']);
  552. $total=M('qcode_print')->where('product_id='.I('get.product_id'))->select();
  553. $printlist['total']=count($total);
  554. $printlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  555. //}
  556. }
  557. $printlist=json_encode($printlist);
  558. echo $printlist;
  559. }
  560. public function rePrintTg(){
  561. header("Content-type: text/html; charset=utf-8");
  562. $id = I('post.$ids');
  563. $ids=explode(",",$id);//将字符串以逗号转化为数组
  564. $num = I('post.reptQty')?I('post.reptQty'):4;
  565. $time=date('Y-m-d',time());//统一更新上一次
  566. for($i=0;$i< count($ids);$i++){//先更新补打次数
  567. $bd_num=M('qcode_print')->field("bd_num,print_time")->where('id='.$ids[$i])->find();//每个标签对应的补打次数
  568. $number=[
  569. 'bd_num'=>$bd_num['bd_num']+$num,
  570. 'last_time'=>$bd_num['print_time'],
  571. 'print_time'=>$time,
  572. ];
  573. M('qcode_print')->where('id='.$ids[$i])->save($number);//每次补打时更新对应的标签补打次数
  574. //unset($type);
  575. $sql=M('qcode_print')->getLastSql();
  576. }
  577. $where = array();
  578. $where['id'] = array('in',$id);//查询表里面id在
  579. $field = "company_name,product_name,product_size,print_time,qr_code,lable_type";
  580. $data = M('qcode_print')->field($field)->where($where)->select();
  581. $new = array();
  582. foreach($data as $v){
  583. $arr = array();
  584. $arr = $v;
  585. $arr['pnum']=$num;
  586. unset( $arr['time']);
  587. $new[]= $arr;
  588. }
  589. $this->ajaxReturn($id);
  590. }
  591. //中烟补打标签页面
  592. public function reprint(){
  593. $this->display();
  594. }
  595. public function reprintdetail(){//补打标签详情页
  596. $session_config=I('session.ly_admin_');//获取登陆的session值
  597. $where = array();
  598. $where['status'] = 1;
  599. $where['id'] = array('gt',1);
  600. $wh = array();
  601. if($_SERVER['REQUEST_METHOD']==='GET'){
  602. if($session_config['user_auth']['uid']==1 || $session_config['user_auth']['uid']==26) {
  603. // $companylist=M('admin_user')->where($where)->field('id,nickname')->select();
  604. $companylist=M('qcode_gsmc')->field('id,nickname')->select();
  605. $productlist=M('qcode_product')->where(['id'=>array('gt',27)])->field('product_name')->select();
  606. }
  607. $this->assign('companylist',$companylist);
  608. $this->assign('productlist',$productlist);
  609. $this->display();
  610. }elseif ($_SERVER['REQUEST_METHOD']==='POST'){
  611. $nickname = trim($_POST['nickname']);
  612. if ($nickname!=''){
  613. $wh['nickname']=array('like','%'.$nickname.'%');
  614. }
  615. if($session_config['user_auth']['uid']==1 || $session_config['user_auth']['uid']==26) {
  616. $companylist=M('qcode_gsmc')
  617. ->where($wh)
  618. ->field('id,nickname')
  619. ->select();
  620. }
  621. echo json_encode($companylist);
  622. }
  623. }
  624. public function logs($content, $subDir = ''){
  625. $subDir = trim($subDir, '/\\');
  626. if (empty($content)) return false;
  627. static $arrConfig = array();
  628. if (empty($arrConfig)){
  629. $arrPath = array(MODULE_NAME, CONTROLLER_NAME, ACTION_NAME);
  630. $arrConfig['root_path'] = './Runtime/Logs/';
  631. $arrConfig['sub_dir'] = implode('/', $arrPath);
  632. $arrConfig['file_name'] = '/' . date('Ymd') . '.log';
  633. $arrConfig['client_ip'] = get_client_ip();
  634. $arrConfig['logs_no'] = date('ymdHis') . microtime() * 1000000;
  635. }
  636. $filepath = $arrConfig['root_path'];
  637. if ($subDir){
  638. $filepath .= $subDir ;
  639. } else {
  640. $filepath .= $arrConfig['sub_dir'] ;
  641. }
  642. if (!file_exists($filepath)){
  643. mkdir($filepath, 0777, TRUE);
  644. }
  645. $filepath .= $arrConfig['file_name'];
  646. $header = sprintf("\r\n\r\n[%s][%s][%s] ", date('Y-m-d H:i:s'), $arrConfig['client_ip'],$arrConfig['logs_no']);
  647. @file_put_contents($filepath, $header . $content, FILE_APPEND);
  648. return $arrConfig['logs_no'] ;
  649. }
  650. public function getproduct(){
  651. if (I('post.type')==1){
  652. $map = array();
  653. $map['id'] = array('gt',27);
  654. $sysCdNm = trim($_POST['sysCdNm']);
  655. if ($sysCdNm!=''){
  656. $map['product_name']=array('like','%'.$sysCdNm.'%');
  657. }
  658. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  659. $this->ajaxReturn($productlist);
  660. }else if(I('post.type')==2){
  661. //写入日志
  662. $req = I('param.type');
  663. $this->logs($req);
  664. $map = array();
  665. $code = $_POST['code'];
  666. if ($code!=''){
  667. $map['code']=$code;
  668. }
  669. $productlist=M('qcode_unit')->where($map)->field('main_unit,sec_unit,proportion')->find();
  670. if ($productlist==[]){
  671. $productlist['main_unit'] = '万张';
  672. $productlist['sec_unit'] = '件';
  673. $productlist['proportion'] = 0.1;
  674. }else{
  675. if ($productlist['sec_unit']==null){
  676. $productlist['sec_unit'] = '件';
  677. }
  678. if ($productlist['proportion']==null){
  679. $productlist['proportion'] = 0.1;
  680. }
  681. }
  682. $pCode = $this->pCode(I('post.qrcode'));
  683. $productlist['pCode'] = $pCode;
  684. $this->ajaxReturn($productlist);
  685. }else if(I('post.type')==3){
  686. //写入日志
  687. $req = I('param.type');
  688. $this->logs($req);
  689. $map = array();
  690. $map['id'] = array('gt',27);
  691. $product_code = $_POST['product_code'];
  692. if ($product_code!=''){
  693. $map['product_code']=$product_code;
  694. }
  695. $productlist=M('qcode_product')->where($map)->field('product_name, temple')->find();
  696. $this->ajaxReturn($productlist);
  697. }else if(I('post.type')==4){
  698. //写入日志
  699. $req = I('param.type');
  700. $this->logs($req);
  701. $map = array();
  702. $nickname = trim($_POST['nickname']);
  703. if ($nickname!=''){
  704. $map['nickname']=$nickname;
  705. }
  706. $print_code=M('qcode_gsmc')->where($map)->field('print_code')->find();
  707. $map2 = array();
  708. $map2['id'] = array('gt',27);
  709. $product_name = trim($_POST['matter_name']);
  710. if ($nickname!=''){
  711. $map2['product_name']=$product_name;
  712. }
  713. $product_code=M('qcode_product')->where($map2)->field('product_code, temple')->find();
  714. $data['print_code'] = $print_code;
  715. $data['product_code'] = $product_code;
  716. $this->ajaxReturn($data);
  717. }else{
  718. $id = I('post.id');
  719. if (!empty($id)){
  720. $userinfo=M('admin_user')->where('id='.$id)->find();
  721. $user_product = explode(',',$userinfo['product_id']);
  722. $map = array();
  723. $map['id'] = array('in',$user_product);
  724. $sysCdNm = trim($_POST['sysCdNm']);
  725. if ($sysCdNm!=''){
  726. $map['product_name']=array('like','%'.$sysCdNm.'%');
  727. }
  728. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  729. $this->ajaxReturn($productlist);
  730. }
  731. }
  732. }
  733. public function pCode($url)//二维码生成类
  734. {
  735. $url=$url;
  736. $level=3;
  737. $size=6;
  738. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  739. $errorCorrectionLevel =intval($level) ;//容错级别
  740. $matrixPointSize = intval($size);//生成图片大小
  741. //生成二维码图片
  742. $object = new \QRcode();
  743. //打开缓冲区
  744. ob_start();
  745. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  746. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  747. $imageString = base64_encode(ob_get_contents());
  748. //关闭缓冲区
  749. ob_end_clean();
  750. //把生成的base64字符串返回给前端
  751. return 'data:image/png;base64,'.$imageString;
  752. /* $data = array(
  753. 'labelcode'=>$url,
  754. 'code'=>200,
  755. 'data'=>$imageString,
  756. 'product_code'=>$url
  757. );
  758. $this->ajaxReturn($data);*/
  759. }
  760. }