QcodeController.class.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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. $map['product_name|product_code'] = array(//查询条件数组
  292. $condition,
  293. $condition,
  294. '_multi' => true,
  295. );
  296. $classification = I('classification', '', 'string');
  297. if ($classification != '03'){
  298. $map['product_code'] = array('like','%'.$classification.'%');
  299. }
  300. $uid = $session_config['user_auth']['uid'];
  301. $user = M('admin_user');
  302. $user_product = $user->where('id='.$uid)->field('product_id')->find();
  303. $user_product = explode(',',$user_product['product_id']);
  304. $map['id'] = array('not in',$user_product);
  305. $map['id'] = array('gt',27);
  306. $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
  307. $product_object = D('qcode_product');
  308. $count = $product_object->where($map)->count();// 查询满足要求的总记录数
  309. $Page = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
  310. $show = $Page->show();// 分页显示输出
  311. $data_list= $product_object->page($p.',10')->where($map)->order('id asc')->select();//所有未选中产品列表
  312. //辅料存货分类
  313. $qcode_classification = M('qcode_classification');
  314. $product_classification = $qcode_classification->where('status=1')->order('id asc')->select();
  315. //已选择产品列表
  316. $where['id'] = array('in',$user_product);
  317. $list= $product_object->where($where)->order('id asc')->select();
  318. $this->assign('search',$keyword);
  319. $this->assign('classification',$classification);
  320. $this->assign('product_classification',$product_classification);
  321. $this->assign('user_product',$user_product);
  322. $this->assign('list',$data_list);
  323. $this->assign('data',$list);
  324. $this->assign('page',$show);
  325. $this->display('product');
  326. }
  327. //更新用户生产产品
  328. public function updateProduct(){
  329. if (IS_POST){
  330. $session_config=I('session.ly_admin_');
  331. $uid = $session_config['user_auth']['uid'];
  332. $user = M('admin_user');
  333. $user_data = $user->where('id='.$uid)->field('product_id')->find();
  334. $user_product = $user_data['product_id'];
  335. $id = I('post.id');
  336. $ids = explode(',',$id);
  337. if(I('post.status')=="1"){//增加产品
  338. $new_product = array();
  339. if (!isset($user_product)){//第一次增加
  340. $data['product_id'] = $id;
  341. }else{
  342. $user_product = explode(',',$user_product);
  343. $new_product = array_unique(array_merge($ids,$user_product));
  344. sort($new_product);
  345. $new_product_str = implode(',',$new_product);
  346. $data['product_id'] =$new_product_str;
  347. }
  348. $res = $user->where('id='.$uid)->save($data);
  349. $this->ajaxReturn(['status'=>1,'msg'=>'更新成功']);
  350. }else{//删除产品
  351. $data['product_id'] = $id;
  352. $res = $user->where('id='.$uid)->save($data);
  353. $this->ajaxReturn(['status'=>1,'msg'=>'更新成功']);
  354. }
  355. }
  356. }
  357. public function Productajax(){//动态调用产品或者供应商相关信息
  358. if(I('get.type')=="product"){//产品列表
  359. $condition['userid']=I('get.userid');
  360. $condition['product_id']=I('get.id');
  361. $l_flow=M('reset_flow')->field('l_flow,bach_num')->where($condition)->find();
  362. $model=M('qcode_product');
  363. $field='product_size,product_num,product_name,id,temple,product_code';
  364. $product=$model->field($field)->where('id='.I('get.id'))->select();
  365. $product['l_flow']=$l_flow['l_flow']+1;
  366. $product['bach_num']=$l_flow['bach_num']?($l_flow['bach_num']+1):(date('Y',time())."00000"+1);
  367. $this->ajaxReturn($product);
  368. }
  369. if(I('get.type')=="company"){//供应商列表
  370. $model=M('admin_user');
  371. $field='nickname,postcode,mobile,company_address,id,printer_code';
  372. $company=$model->field($field)->where('id='.I('get.id'))->select();
  373. $this->ajaxReturn($company) ;
  374. }
  375. }
  376. public function AddPrint(){//保存待打印的产品记录
  377. //var_dump(I('post.'));
  378. $data=I('post.');
  379. if(!empty($data)) {//提交的数据不为空
  380. $data['company_info']=I('post.company_address')." ".I('post.postname')." ".I('post.phone');
  381. $data['bd_num']=0;//保存就默认为0;
  382. $data['lable_type']=I('post.label_type');
  383. M('qcode_print')->add($data);//保存数据
  384. $this->success('保存成功','index.php?s=/Admin/Qcode/large');
  385. }else{
  386. $this->error('保存失败');
  387. // $this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
  388. /* $this->error['errno'] = "添加数据失败";
  389. $this->success($this->error['errno'], '',100);*/
  390. }
  391. }
  392. public function Large(){
  393. /*var_dump(THINK_VERSION);
  394. die();*/
  395. $companylist=M('qcode_company')->field('company_name,postcode,phone,company_addres,company_code,id')->select();
  396. $productlist=M('qcode_product')->field('product_name,id,product_size,product_num,temple,product_code')->select();
  397. $this->assign('companylist',$companylist);
  398. $this->assign('productlist',$productlist);
  399. $this->display();
  400. }
  401. public function Print_ewm(){//生成二维码
  402. $time=time();
  403. if($_GET['temple']==1){//使用新模板
  404. $fixedheadcode = "90";//固定的头部编码2位;
  405. if ($_GET['label_type'] == 1) {//大件标签
  406. $type = "92";
  407. $big_num="095";//大件含有小件数量
  408. $big_liushui=$_GET['big_liushui'];//大件流水号
  409. $big_weight=$_GET['big_weight'];//大件重量
  410. $big_yuliu=$_GET['big_yuliu'];//大件预留号
  411. }
  412. if ($_GET['label_type'] == 2) {//小件标签
  413. $type = "93";//标签种类2位
  414. }
  415. $materialtype=$_GET['materialtype'];//辅料类型2位
  416. $company_code=$_GET['company_code'];//供应商编码
  417. $product_code=$_GET['product_code'];//辅料编码
  418. $product_time=20180807;//生产日期
  419. $print_time=date('Y-m-d',$time);//打码日期
  420. $big_unipue=$print_time.rand(100000,999999);//唯一编码
  421. $yuliu="000000000000000000";//预留码
  422. $url= $fixedheadcode.$type.$materialtype.$company_code.$product_code.$product_time.$big_num.$big_unipue.$yuliu;
  423. $this->qrcode($url);
  424. }
  425. if($_GET['temple']==2) {//使用老模板
  426. if ($_GET['label_type'] == 1) {//大件标签
  427. $type = "92";
  428. $uniquecode = date('Ymd', $time) . rand(100000, 500000);//大件唯一编码14位(生产日期8位+6位随机码)
  429. }
  430. if ($_GET['label_type'] == 2) {//小件标签
  431. $type = "93";//标签种类2位
  432. $uniquecode = date('Ymd', $time) . rand(500001, 999999);//小件唯一编码14位(生产日期8位+6位随机码)
  433. }
  434. $offercode = $_GET['company_code'];//供应商编码12位
  435. $materialcode = $_GET['product_code'];//辅料编码20位不足补零
  436. $producttime = date("Ymd", $time);//生产日期(年月日)8位
  437. $patchcode = "000000";//补位(6位);
  438. $fixedheadcode = "90";//固定的头部编码2位;
  439. $url = $fixedheadcode . $type . $_GET['materialtype'] . $offercode . $materialcode . $producttime . $uniquecode . $patchcode;
  440. $this->qrcode($url);
  441. }
  442. $this->display('large.html');
  443. }
  444. public function qrcode($url)//二维码生成类
  445. {
  446. $url=$url;
  447. $level=2;
  448. $size=4;
  449. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  450. $errorCorrectionLevel =intval($level) ;//容错级别
  451. $matrixPointSize = intval($size);//生成图片大小
  452. //生成二维码图片
  453. $object = new \QRcode();
  454. //打开缓冲区
  455. ob_start();
  456. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  457. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  458. $imageString = base64_encode(ob_get_contents());
  459. //关闭缓冲区
  460. ob_end_clean();
  461. //把生成的base64字符串返回给前端
  462. $data = array(
  463. 'labelcode'=>$url,
  464. 'code'=>200,
  465. 'data'=>$imageString,
  466. 'product_code'=>$url
  467. );
  468. $this->ajaxReturn($data);
  469. }
  470. /*补打标签*/
  471. public function small(){
  472. $this->display('buda');
  473. }
  474. public function buda(){//补打标签
  475. $this->display();
  476. }
  477. public function budadetail(){//补打标签详情页
  478. $session_config=I('session.ly_admin_');//获取登陆的session值
  479. if($session_config['user_auth']['addtype']==1) {
  480. $nickname=$session_config['user_auth']['nickname'];
  481. }else{
  482. $companylist=M('admin_user')->field('nickname')->where('status=1')->select();
  483. }
  484. $userinfo=M('admin_user')->where('id='.$session_config['user_auth']['uid'])->find();
  485. $user_product = explode(',',$userinfo['product_id']);
  486. $map = array();
  487. $map['id'] = array('in',$user_product);
  488. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  489. $this->assign('productlist',$productlist);
  490. $this->assign('nickname',$nickname);
  491. $this->assign('companylist',$companylist);
  492. $this->display();
  493. }
  494. /*二级产品下拉框*/
  495. public function MaterialTwoApi(){
  496. /* if(I('get.id')==0 || I('get.id')==NULL){
  497. $secondlist=array('全部');
  498. }
  499. if(I('get.id')==1){
  500. $secondlist=array('全部','常规醋纤丝束','特种醋纤丝束','其他醋纤丝束');
  501. }
  502. if(I('get.id')==2){
  503. $secondlist=array('全部','常规聚丙烯丝束','低旦聚丙烯丝束','其他聚丙烯丝束');
  504. }
  505. if(I('get.id')==3){
  506. $secondlist=array('全部','普通成型纸','高透成型纸','其他成型纸');
  507. }
  508. if(I('get.id')==4){
  509. $secondlist=array('全部','醋酸纤维滤棒','常规聚丙烯丝束滤棒','低旦加胶聚丙烯丝束滤棒','纸质滤棒','沟槽滤棒');
  510. }
  511. echo json_encode($secondlist);*/
  512. }
  513. /*产品列表接口*/
  514. public function ProductApi(){
  515. //$productlist['code']=200;
  516. //$productlist['pagesize']=$_GET['pagesize']?$_GET['pagesize']:10;
  517. $page=$_GET['page'];
  518. $productlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  519. $pagenum=($page-1)* $productlist['pagesize'];//当前页码
  520. if($pagenum<0){
  521. $pagenum=0;
  522. }
  523. $productlist['rows']=M('qcode_product')->where('id!=0')->limit($pagenum,$productlist['pagesize'])->select();
  524. $total=M('qcode_product')->where('id!=0')->select();
  525. $productlist['total']=count($total);
  526. $productlist=json_encode($productlist);
  527. //echo date('Y-m-d',1533120226);
  528. echo $productlist;
  529. //die();
  530. }
  531. /*产品打印列表*/
  532. public function PrintListApi(){
  533. if(empty(I('get.product_id'))){//没有产品的id
  534. $printlist['code']=100;
  535. $printlist['total']="产品id为空";
  536. }else{
  537. //$printlist['code']=200;
  538. $page=$_GET['page'];
  539. $productlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  540. $pagenum=($page-1)* $productlist['pagesize'];//当前页码
  541. if($pagenum<0){
  542. $pagenum=0;
  543. }
  544. $printlist['rows']=M('qcode_print')->where('product_id='.I('get.product_id'))->limit($pagenum,$productlist['pagesize'])->select();
  545. /*if(count($printlist['productlist'])==0){//没有找到数据
  546. $printlist['code']=300;
  547. $printlist['total']="没有找到对应的数据";
  548. }else{*///有数据返回分页数据
  549. //$total=count($printlist['productlist']);
  550. $total=M('qcode_print')->where('product_id='.I('get.product_id'))->select();
  551. $printlist['total']=count($total);
  552. $printlist['pagesize']=$_GET['rows']?$_GET['rows']:10;
  553. //}
  554. }
  555. $printlist=json_encode($printlist);
  556. echo $printlist;
  557. }
  558. public function rePrintTg(){
  559. header("Content-type: text/html; charset=utf-8");
  560. $id = I('post.$ids');
  561. $ids=explode(",",$id);//将字符串以逗号转化为数组
  562. $num = I('post.reptQty')?I('post.reptQty'):4;
  563. $time=date('Y-m-d',time());//统一更新上一次
  564. for($i=0;$i< count($ids);$i++){//先更新补打次数
  565. $bd_num=M('qcode_print')->field("bd_num,print_time")->where('id='.$ids[$i])->find();//每个标签对应的补打次数
  566. $number=[
  567. 'bd_num'=>$bd_num['bd_num']+$num,
  568. 'last_time'=>$bd_num['print_time'],
  569. 'print_time'=>$time,
  570. ];
  571. M('qcode_print')->where('id='.$ids[$i])->save($number);//每次补打时更新对应的标签补打次数
  572. //unset($type);
  573. $sql=M('qcode_print')->getLastSql();
  574. }
  575. $where = array();
  576. $where['id'] = array('in',$id);//查询表里面id在
  577. $field = "company_name,product_name,product_size,print_time,qr_code,lable_type";
  578. $data = M('qcode_print')->field($field)->where($where)->select();
  579. $new = array();
  580. foreach($data as $v){
  581. $arr = array();
  582. $arr = $v;
  583. $arr['pnum']=$num;
  584. unset( $arr['time']);
  585. $new[]= $arr;
  586. }
  587. $this->ajaxReturn($id);
  588. }
  589. //中烟补打标签页面
  590. public function reprint(){
  591. $this->display();
  592. }
  593. public function reprintdetail(){//补打标签详情页
  594. $session_config=I('session.ly_admin_');//获取登陆的session值
  595. $where = array();
  596. $where['status'] = 1;
  597. $where['id'] = array('gt',1);
  598. $wh = array();
  599. if($_SERVER['REQUEST_METHOD']==='GET'){
  600. if($session_config['user_auth']['uid']==1 || $session_config['user_auth']['uid']==26) {
  601. // $companylist=M('admin_user')->where($where)->field('id,nickname')->select();
  602. $companylist=M('qcode_gsmc')->field('id,nickname')->select();
  603. $productlist=M('qcode_product')->where(['id'=>array('gt',27)])->field('product_name')->select();
  604. }
  605. $this->assign('companylist',$companylist);
  606. $this->assign('productlist',$productlist);
  607. $this->display();
  608. }elseif ($_SERVER['REQUEST_METHOD']==='POST'){
  609. $nickname = trim($_POST['nickname']);
  610. if ($nickname!=''){
  611. $wh['nickname']=array('like','%'.$nickname.'%');
  612. }
  613. if($session_config['user_auth']['uid']==1 || $session_config['user_auth']['uid']==26) {
  614. $companylist=M('qcode_gsmc')
  615. ->where($wh)
  616. ->field('id,nickname')
  617. ->select();
  618. }
  619. echo json_encode($companylist);
  620. }
  621. }
  622. public function logs($content, $subDir = ''){
  623. $subDir = trim($subDir, '/\\');
  624. if (empty($content)) return false;
  625. static $arrConfig = array();
  626. if (empty($arrConfig)){
  627. $arrPath = array(MODULE_NAME, CONTROLLER_NAME, ACTION_NAME);
  628. $arrConfig['root_path'] = './Runtime/Logs/';
  629. $arrConfig['sub_dir'] = implode('/', $arrPath);
  630. $arrConfig['file_name'] = '/' . date('Ymd') . '.log';
  631. $arrConfig['client_ip'] = get_client_ip();
  632. $arrConfig['logs_no'] = date('ymdHis') . microtime() * 1000000;
  633. }
  634. $filepath = $arrConfig['root_path'];
  635. if ($subDir){
  636. $filepath .= $subDir ;
  637. } else {
  638. $filepath .= $arrConfig['sub_dir'] ;
  639. }
  640. if (!file_exists($filepath)){
  641. mkdir($filepath, 0777, TRUE);
  642. }
  643. $filepath .= $arrConfig['file_name'];
  644. $header = sprintf("\r\n\r\n[%s][%s][%s] ", date('Y-m-d H:i:s'), $arrConfig['client_ip'],$arrConfig['logs_no']);
  645. @file_put_contents($filepath, $header . $content, FILE_APPEND);
  646. return $arrConfig['logs_no'] ;
  647. }
  648. public function getproduct(){
  649. if (I('post.type')==1){
  650. $map = array();
  651. $map['id'] = array('gt',27);
  652. $sysCdNm = trim($_POST['sysCdNm']);
  653. if ($sysCdNm!=''){
  654. $map['product_name']=array('like','%'.$sysCdNm.'%');
  655. }
  656. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  657. $this->ajaxReturn($productlist);
  658. }else if(I('post.type')==2){
  659. //写入日志
  660. $req = I('param.type');
  661. $this->logs($req);
  662. $map = array();
  663. $code = $_POST['code'];
  664. if ($code!=''){
  665. $map['code']=$code;
  666. }
  667. $productlist=M('qcode_unit')->where($map)->field('main_unit,sec_unit,proportion')->find();
  668. if ($productlist==[]){
  669. $productlist['main_unit'] = '万张';
  670. $productlist['sec_unit'] = '件';
  671. $productlist['proportion'] = 0.1;
  672. }else{
  673. if ($productlist['sec_unit']==null){
  674. $productlist['sec_unit'] = '件';
  675. }
  676. if ($productlist['proportion']==null){
  677. $productlist['proportion'] = 0.1;
  678. }
  679. }
  680. $this->ajaxReturn($productlist);
  681. }else if(I('post.type')==3){
  682. //写入日志
  683. $req = I('param.type');
  684. $this->logs($req);
  685. $map = array();
  686. $map['id'] = array('gt',27);
  687. $product_code = $_POST['product_code'];
  688. if ($product_code!=''){
  689. $map['product_code']=$product_code;
  690. }
  691. $productlist=M('qcode_product')->where($map)->field('product_name, temple')->find();
  692. $this->ajaxReturn($productlist);
  693. }else if(I('post.type')==4){
  694. //写入日志
  695. $req = I('param.type');
  696. $this->logs($req);
  697. $map = array();
  698. $nickname = trim($_POST['nickname']);
  699. if ($nickname!=''){
  700. $map['nickname']=$nickname;
  701. }
  702. $print_code=M('qcode_gsmc')->where($map)->field('print_code')->find();
  703. $map2 = array();
  704. $map2['id'] = array('gt',27);
  705. $product_name = trim($_POST['matter_name']);
  706. if ($nickname!=''){
  707. $map2['product_name']=$product_name;
  708. }
  709. $product_code=M('qcode_product')->where($map2)->field('product_code, temple')->find();
  710. $data['print_code'] = $print_code;
  711. $data['product_code'] = $product_code;
  712. $this->ajaxReturn($data);
  713. }else{
  714. $id = I('post.id');
  715. if (!empty($id)){
  716. $userinfo=M('admin_user')->where('id='.$id)->find();
  717. $user_product = explode(',',$userinfo['product_id']);
  718. $map = array();
  719. $map['id'] = array('in',$user_product);
  720. $sysCdNm = trim($_POST['sysCdNm']);
  721. if ($sysCdNm!=''){
  722. $map['product_name']=array('like','%'.$sysCdNm.'%');
  723. }
  724. $productlist=M('qcode_product')->where($map)->field('product_name,id,product_size,product_num,temple,product_code')->select();
  725. $this->ajaxReturn($productlist);
  726. }
  727. }
  728. }
  729. }