QcodeBach.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\QcodeCompany;
  4. use app\admin\model\QcodeProduct;
  5. use app\admin\model\QcodeGsmc;
  6. use app\admin\model\QcodeLarge;
  7. use app\admin\model\QcodeSmall;
  8. use app\common\controller\Backend;
  9. use \think\Session;
  10. use think\Db;
  11. /**
  12. *
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class QcodeBach extends Backend
  17. {
  18. /**
  19. * Product模型对象
  20. * @var \app\admin\model\QcodeBach
  21. */
  22. protected $model = null;
  23. protected $multiFields = 'status';
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\admin\model\QcodeBach();
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. /**
  35. * 查看
  36. */
  37. public function index()
  38. {
  39. //当前是否为关联查询
  40. $this->relationSearch = false;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. return $this->view->fetch();
  44. }
  45. /**
  46. * 主表查询
  47. */
  48. public function bach()
  49. {
  50. //当前是否为关联查询
  51. $this->relationSearch = false;
  52. //设置过滤方法
  53. $this->request->filter(['strip_tags', 'trim']);
  54. if ($this->request->isAjax()) {
  55. //如果发送的来源是Selectpage,则转发到Selectpage
  56. if ($this->request->request('keyField')) {
  57. return $this->selectpage();
  58. }
  59. $userInfo = Session::get('admin');
  60. $company_id = (int)$userInfo['company'];
  61. $where = [
  62. 'delete_time'=> ''
  63. ];
  64. $req = input();
  65. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  66. $order = $req['order'];
  67. $offset = $req['offset'];
  68. $limit = $req['limit'];
  69. // 构造模糊查询条件
  70. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  71. // $filter = ['field' => $regex];
  72. $filter = json_decode($req['filter'], true);
  73. foreach ($filter as $k => $v){
  74. $where[$k] = new \MongoDB\BSON\Regex($v);
  75. }
  76. $total = $this->model->name($company_id.'_'."qcode_bach")->where($where)->count();
  77. $list = $this->model->name($company_id.'_'."qcode_bach")->where($where)
  78. ->order($sort,$order)
  79. ->limit($limit)
  80. ->skip($offset)
  81. ->select();
  82. foreach ($list as $k=>$v) {
  83. $oid = $v['_id']->jsonSerialize();
  84. $list[$k]['id'] = $oid['$oid'];
  85. }
  86. $result = array("total" => $total, "rows" => $list);
  87. return json($result);
  88. }
  89. return $this->view->fetch();
  90. }
  91. /**
  92. * 大件列表
  93. */
  94. public function large()
  95. {
  96. //当前是否为关联查询
  97. $this->relationSearch = false;
  98. //设置过滤方法
  99. $this->request->filter(['strip_tags', 'trim']);
  100. if ($this->request->isAjax()) {
  101. //如果发送的来源是Selectpage,则转发到Selectpage
  102. if ($this->request->request('keyField')) {
  103. return $this->selectpage();
  104. }
  105. $userInfo = Session::get('admin');
  106. $company_id = (int)$userInfo['company'];
  107. $where = [
  108. // 'company_id'=>(int)$userInfo['company'],
  109. 'delete_time'=> ''
  110. ];
  111. $req = input();
  112. if($req['filter']=='{}'){
  113. $result = array("total" => 0, "rows" => []);
  114. return json($result);
  115. }
  116. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  117. $order = $req['order'];
  118. $offset = $req['offset'];
  119. $limit = $req['limit'];
  120. // 构造模糊查询条件
  121. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  122. // $filter = ['field' => $regex];
  123. $filter = json_decode($req['filter'], true);
  124. foreach ($filter as $k => $v){
  125. $where[$k] = new \MongoDB\BSON\Regex($v);
  126. }
  127. $db = new QcodeLarge();
  128. $total = $db->name($company_id.'_'."qcode_large")->where($where)->count();
  129. $list = $db->name($company_id.'_'."qcode_large")->where($where)
  130. ->order($sort,$order)
  131. ->limit($limit)
  132. ->skip($offset)
  133. ->select();
  134. $qcodeSmall = new QcodeSmall();
  135. foreach ($list as $k=>$v) {
  136. $oid = $v['_id']->jsonSerialize();
  137. $list[$k]['id'] = $oid['$oid'];
  138. //设置当前托盘号
  139. $list[$k]['l_flow'] = ltrim(substr($v['code'],53,6),'0');
  140. //查询小件数量
  141. $small_num = $qcodeSmall->name($company_id.'_'."qcode_small")
  142. ->where('large_id',$oid['$oid'])
  143. ->count();
  144. $list[$k]['small_num'] = $small_num;
  145. //设置当前大件重量
  146. $list[$k]['l_weight'] = floatval($v['l_weight'])/100;
  147. }
  148. $result = array("total" => $total, "rows" => $list);
  149. return json($result);
  150. }
  151. return $this->view->fetch();
  152. }
  153. /**
  154. * 小件列表
  155. */
  156. public function small()
  157. {
  158. //设置过滤方法
  159. $this->request->filter(['strip_tags', 'trim']);
  160. $req = $this->request->param();
  161. if ($this->request->isAjax()) {
  162. //如果发送的来源是Selectpage,则转发到Selectpage
  163. if ($this->request->request('keyField')) {
  164. return $this->selectpage();
  165. }
  166. $userInfo = Session::get('admin');
  167. $company_id = (int)$userInfo['company'];
  168. $where = [
  169. 'delete_time'=> '',
  170. 'large_id'=> $req['large_id']
  171. ];
  172. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  173. $order = $req['order'];
  174. $offset = $req['offset'];
  175. $limit = $req['limit'];
  176. // 构造模糊查询条件
  177. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  178. // $filter = ['field' => $regex];
  179. $filter = json_decode($req['filter'], true);
  180. foreach ($filter as $k => $v){
  181. $where[$k] = new \MongoDB\BSON\Regex($v);
  182. }
  183. $qcodeSmall = new QcodeSmall();
  184. $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count();
  185. $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
  186. ->order($sort,$order)
  187. ->limit($limit)
  188. ->skip($offset)
  189. ->select();
  190. foreach ($list as $k=>$v) {
  191. $oid = $v['_id']->jsonSerialize();
  192. $list[$k]['id'] = $oid['$oid'];
  193. $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
  194. }
  195. $result = array("total" => $total, "rows" => $list);
  196. return json($result);
  197. }
  198. return $this->view->fetch();
  199. }
  200. /**
  201. * 小件导出状态修改
  202. */
  203. public function small_status()
  204. {
  205. $req = $this->request->param();
  206. $ids = $req['ids'];
  207. $userInfo = Session::get('admin');
  208. $company_id = (int)$userInfo['company'];
  209. $qcodeSmall = new QcodeSmall();
  210. $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status');
  211. if ($status === 0) {
  212. $newStatus = 1;
  213. } elseif ($status === 1) {
  214. $newStatus = 0;
  215. } else {
  216. // 处理其他情况,如果有需要
  217. }
  218. $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids'])
  219. ->update(['status' => $newStatus]);
  220. if ($bool){
  221. $this->success("切换成功", null, ['id' => $ids]);
  222. }else{
  223. $this->error("切换失败", null, ['id' => $ids]);
  224. }
  225. }
  226. /**
  227. * 自动打码(大件)
  228. */
  229. public function print_l()
  230. {
  231. //设置过滤方法
  232. $this->request->filter(['strip_tags', 'trim']);
  233. $req = $this->request->param();
  234. if ($this->request->isAjax()) {
  235. $ids = $req['ids'];
  236. $type = $req['type'];
  237. $numn = $req['numn'];
  238. $userInfo = Session::get('admin');
  239. $company_id = (int)$userInfo['company'];
  240. $qcodeLarge = new QcodeLarge();
  241. $qcodeSmall = new QcodeSmall();
  242. $qcodeProduct = new QcodeProduct();
  243. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  244. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  245. $row = $qcodeProduct->where('product_code',json_decode($bach,true)['matter_no'])->find();
  246. $company_name = json_decode($bach,true)['supplier_name'];
  247. $product_name = json_decode($bach,true)['matter_name'];
  248. // $date = json_decode($bach,true)['manufacture_date'];
  249. // $batch = json_decode($bach,true)['bach_num'];
  250. $main_unit = json_decode($row,true)['main_unit'];
  251. $sec_unit = json_decode($row,true)['sec_unit'];
  252. $proportion = json_decode($row,true)['proportion'];
  253. $rows = [];
  254. //查询打印大件码所需数据
  255. foreach ($ids as $key=>$value){
  256. $row = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  257. $row = json_decode($row,true);
  258. $code = $row['code'];
  259. $rows[$key]['company_name'] = $company_name;
  260. $rows[$key]['product_name'] = $product_name;
  261. $rows[$key]['sqrcd'] = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->count();
  262. $rows[$key]['main_unit'] = $main_unit;
  263. $rows[$key]['sec_unit'] = $sec_unit;
  264. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  265. $rows[$key]['l_flow'] = ltrim(substr($code,53,6),'0');
  266. $rows[$key]['qrcode'] = $code;
  267. $rows[$key]['pCode'] = $this->qrcode($code);
  268. //批次号特殊情况判断
  269. if (substr($code,76,10)=='0000000000'){
  270. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  271. }else{
  272. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  273. }
  274. //转换关系判断
  275. if($row['l_num']===null){
  276. //走转换关系
  277. if ($proportion){
  278. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  279. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  280. }else{
  281. $rows[$key]['num'] = '';
  282. }
  283. }else if($row['l_num']==0){
  284. //判断是否是公斤
  285. if($main_unit=='公斤'){
  286. //公斤使用l_weight
  287. $rows[$key]['num'] = $row['l_weight'];
  288. }else{
  289. //不是公斤走转换关系
  290. if ($proportion){
  291. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  292. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  293. }else{
  294. $rows[$key]['num'] = '';
  295. }
  296. }
  297. }else{
  298. //箱, 使用l_num
  299. $rows[$key]['num'] = $row['l_num'];
  300. }
  301. }
  302. $data = [
  303. 'type'=>$type,
  304. 'numn'=>$numn,
  305. 'rows'=>$rows,
  306. 'ids'=>$ids,
  307. ];
  308. $this->success('成功','',$data);
  309. }
  310. $this->view->assign('ids',$req['ids']);
  311. return $this->view->fetch();
  312. }
  313. /**
  314. * 自动打码(小件)
  315. */
  316. public function print_s()
  317. {
  318. //设置过滤方法
  319. $this->request->filter(['strip_tags', 'trim']);
  320. $req = $this->request->param();
  321. if ($this->request->isAjax()) {
  322. $ids = $req['ids'];
  323. $type = $req['type'];
  324. $numn = $req['numn'];
  325. $userInfo = Session::get('admin');
  326. $company_id = (int)$userInfo['company'];
  327. $qcodeLarge = new QcodeLarge();
  328. $qcodeSmall = new QcodeSmall();
  329. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  330. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  331. $company_name = json_decode($bach,true)['supplier_name'];
  332. $product_name = json_decode($bach,true)['matter_name'];
  333. //获取全部小件id
  334. $rows = [];
  335. $key = 0;
  336. foreach ($ids as $value){
  337. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  338. $large = json_decode($large,true);
  339. $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id');
  340. //查询打印大件码所需数据
  341. foreach ($arr as $v){
  342. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find();
  343. $small = json_decode($small,true);
  344. $code = $small['code'];
  345. $rows[$key]['company_name'] = $company_name;
  346. $rows[$key]['product_name'] = $product_name;
  347. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  348. $rows[$key]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  349. $rows[$key]['qrcode'] = $code;
  350. // $rows[$key]['pCode'] = $this->qrcode($code);
  351. //批次号特殊情况判断
  352. if (substr($code,76,10)=='0000000000'){
  353. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  354. }else{
  355. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  356. }
  357. $key++;
  358. }
  359. }
  360. $data = [
  361. 'type'=>$type,
  362. 'numn'=>$numn,
  363. 'rows'=>$rows,
  364. 'ids'=>$ids,
  365. ];
  366. $this->success('成功','',$data);
  367. }
  368. $this->view->assign('ids',$req['ids']);
  369. return $this->view->fetch();
  370. }
  371. /**
  372. * 手动打码(小件)
  373. */
  374. public function print_ls()
  375. {
  376. //设置过滤方法
  377. $this->request->filter(['strip_tags', 'trim']);
  378. $req = $this->request->param();
  379. if ($this->request->isAjax()) {
  380. $ids = $req['ids'];
  381. $type = $req['type'];
  382. $numn = $req['numn'];
  383. $userInfo = Session::get('admin');
  384. $company_id = (int)$userInfo['company'];
  385. $qcodeLarge = new QcodeLarge();
  386. $qcodeSmall = new QcodeSmall();
  387. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->find();
  388. $small = json_decode($small,true);
  389. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find();
  390. $large = json_decode($large,true);
  391. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find();
  392. $company_name = json_decode($bach,true)['supplier_name'];
  393. $product_name = json_decode($bach,true)['matter_name'];
  394. //获取全部小件id
  395. $rows = [];
  396. $code = $small['code'];
  397. $rows[0]['company_name'] = $company_name;
  398. $rows[0]['product_name'] = $product_name;
  399. $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  400. $rows[0]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  401. $rows[0]['qrcode'] = $code;
  402. // $rows[0]['pCode'] = $this->qrcode($code);
  403. //批次号特殊情况判断
  404. if (substr($code,76,10)=='0000000000'){
  405. $rows[0]['batch'] = ltrim(substr($code,66,10),'0');
  406. }else{
  407. $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  408. }
  409. $data = [
  410. 'type'=>$type,
  411. 'numn'=>$numn,
  412. 'rows'=>$rows,
  413. 'ids'=>$ids,
  414. ];
  415. $this->success('成功','',$data);
  416. }
  417. $this->view->assign('ids',$req['ids']);
  418. return $this->view->fetch();
  419. }
  420. /**
  421. * 打印数量设置
  422. */
  423. public function set_num()
  424. {
  425. $req = $this->request->param();
  426. //获取数据
  427. $status = $req['status'];
  428. $num = (int)$req['num'];
  429. $ids = $req['ids'];
  430. //获取company_id
  431. $userInfo = Session::get('admin');
  432. $company_id = (int)$userInfo['company'];
  433. //自动打印大件
  434. if($status==1){
  435. $qcodeLarge = new QcodeLarge();
  436. foreach ($ids as $v){
  437. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setInc('p_nums',$num);
  438. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setField('l_print','1');
  439. }
  440. }elseif($status==2){
  441. $qcodeSmall = new QcodeSmall();
  442. foreach ($ids as $v){
  443. $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$v)->setInc('p_nums',$num);
  444. }
  445. }elseif($status==3){
  446. $qcodeSmall = new QcodeSmall();
  447. $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->setInc('p_nums',$num);
  448. }
  449. }
  450. /**
  451. * 导出excel跳转
  452. */
  453. public function exp()
  454. {
  455. //获取产品配置菜单id
  456. $bool = db('auth_rule')->field('id')->where('title','发货管理')->find();
  457. if ($bool){
  458. $this->success('成功','',$bool);
  459. }else{
  460. $this->error('未获取到菜单','',$bool);
  461. }
  462. }
  463. /**
  464. * 修改大件重量数量
  465. */
  466. public function edit($ids = NULL)
  467. {
  468. $req = $this->request->param();
  469. if ($this->request->isAjax()){
  470. parse_str($req['data'],$req);
  471. if(!isset($req['row']['type']) || empty($req['row']['type'])){
  472. $this->error('请选择修改类型');
  473. }
  474. if(!isset($req['row']['numn']) || empty($req['row']['numn'])){
  475. $this->error('请填写修改数量');
  476. }
  477. $ids = explode(',',$req['row']['ids']);
  478. $data = [
  479. 'update_time'=>time(),
  480. 'sync_flag'=>0
  481. ];
  482. $userInfo = Session::get('admin');
  483. $company_id = (int)$userInfo['company'];
  484. $qcodeLarge = new QcodeLarge();
  485. if($req['row']['type']==1){//修改大件重量
  486. $data['l_weight'] = intval($req['row']['numn'])*100;
  487. foreach($ids as $val){
  488. //查询code
  489. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('code')->where('_id',$val)->find();
  490. $code = json_decode($large,true)['code'];
  491. if($code){
  492. $code1 = substr($code,0,59);
  493. $code2 = substr($code,65,85);
  494. $data['code'] = $code1.str_pad(intval($req['row']['numn'])*100,6, '0', STR_PAD_LEFT).$code2;
  495. //修改code和大件重量
  496. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  497. }
  498. }
  499. $this->success('修改成功');
  500. }
  501. if($req['row']['type']==2){//修改大件总张数
  502. $data['l_num'] = intval($req['row']['numn']);
  503. foreach($ids as $val){
  504. //查询l_num, 判断是否可以修改总张数
  505. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('l_num')->where('_id',$val)->find();
  506. $l_num = json_decode($large,true)['l_num'];
  507. if($l_num > 0 || $l_num==null){
  508. //可以修改
  509. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  510. }else{
  511. $this->error('该产品不能修改大件数量');
  512. }
  513. }
  514. $this->success('修改成功');
  515. }
  516. }
  517. $this->view->assign('ids',$req['ids']);
  518. return $this->view->fetch();
  519. }
  520. /**
  521. * 删除批次
  522. */
  523. public function del($ids = NULL)
  524. {
  525. $userInfo = Session::get('admin');
  526. $company_id = (int)$userInfo['company'];
  527. $qcodeLarge = new QcodeLarge();
  528. $qcodeSmall = new QcodeSmall();
  529. $data = [
  530. 'delete_time'=>time(),
  531. ];
  532. $bool1 = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->update($data);
  533. $bool2 = $qcodeLarge->name($company_id.'_'."qcode_large")->where('bach_id',$ids)->update($data);
  534. $bool3 = $qcodeSmall->name($company_id.'_'."qcode_small")->where('bach_id',$ids)->update($data);
  535. if($bool1!==false && $bool2!==false && $bool3!==false){
  536. $this->success('删除成功');
  537. }else{
  538. $this->error('删除失败');
  539. }
  540. }
  541. /**
  542. * 补打标签
  543. */
  544. public function reprint()
  545. {
  546. if ($this->request->isAjax()) {
  547. $data = $this->request->param();
  548. parse_str($data['data'],$req);
  549. if(!isset($req['row']['nickname']) || empty($req['row']['nickname'])){
  550. $this->error('请填写公司名称');
  551. }
  552. if((!isset($req['row']['product_name']) || empty($req['row']['product_name'])) && (!isset($req['row']['product_code']) || empty($req['row']['product_code']))){
  553. $this->error('请填写辅料名称或辅料编号');
  554. }
  555. if(!isset($req['row']['sqrcd']) || empty($req['row']['sqrcd'])){
  556. $this->error('请填写配盘数');
  557. }
  558. if(!isset($req['row']['num']) || empty($req['row']['num'])){
  559. $this->error('请填写数量');
  560. }
  561. //查询公司信息
  562. $qcodeGsmc = new QcodeGsmc();
  563. $print_code = $qcodeGsmc
  564. ->field('id, nickname, print_code')
  565. ->where('nickname',$req['row']['nickname'])
  566. ->find();
  567. if (!$print_code) $this->error('未查到公司信息');
  568. $print_code = json_decode($print_code,true);
  569. //查询产品信息
  570. $qcodeProduct = new QcodeProduct();
  571. if(!empty($req['row']['product_code'])){
  572. $sel = $qcodeProduct
  573. ->field('id, product_name, product_code, temple')
  574. ->where('product_code',$req['row']['product_code'])
  575. ->find();
  576. }else{
  577. $sel = $qcodeProduct
  578. ->field('id, product_name, product_code, temple')
  579. ->where('product_name',$req['row']['product_name'])
  580. ->find();
  581. }
  582. if (!$sel) $this->error('未查到辅料信息');
  583. $sel = json_decode($sel,true);
  584. $data = [
  585. 'company_name'=>$req['row']['nickname'],
  586. 'product_name'=>$sel['product_name'],
  587. 'sqrcd'=>$req['row']['sqrcd'],
  588. 'num'=>$req['row']['num'],
  589. 'main_unit'=>'盘',
  590. 'sec_unit'=>'万米',
  591. 'date'=>date('Y-m-d'),
  592. 'batch'=>substr(date('Ymd'),2,6),
  593. 'l_flow'=>1,
  594. ];
  595. $num = str_pad($req['row']['num'], 3, '0', STR_PAD_LEFT);
  596. $qrcode = 'AB'.'92'.$sel['temple'].'0'.$print_code['print_code'].('000'.$sel['product_code']).$data['batch'].$num.$data['batch'].'000001'.'000000'.'2'.'0000'.$data['batch'].'0000000000';
  597. $data['pCode'] = $this->qrcode($qrcode);
  598. $data['qrcode'] = $qrcode;
  599. $this->success('成功','',$data);
  600. }
  601. return $this->view->fetch();
  602. }
  603. /**
  604. * 公司名称搜索
  605. */
  606. public function sel_n()
  607. {
  608. $name = $this->request->param()['q_word'][0];
  609. $where = [
  610. 'nickname'=>new \MongoDB\BSON\Regex($name),
  611. 'delete_time'=>'',
  612. ];
  613. $qcodeGsmc = new QcodeGsmc();
  614. $sel = $qcodeGsmc
  615. ->field('nickname')
  616. ->where($where)
  617. ->limit(0,10)
  618. ->select();
  619. return json(['list' => $sel, 'total' => count($sel)]);
  620. }
  621. /**
  622. * 辅料名称搜索
  623. */
  624. public function sel_p()
  625. {
  626. $name = $this->request->param()['q_word'][0];
  627. $where = [
  628. 'product_name'=>new \MongoDB\BSON\Regex($name),
  629. 'delete_time'=>'',
  630. ];
  631. $qcodeProduct = new QcodeProduct();
  632. $sel = $qcodeProduct
  633. ->field('product_name, product_code')
  634. ->where($where)
  635. ->limit(0,10)
  636. ->select();
  637. foreach ($sel as $k=>$v) {
  638. $oid = $v['_id']->jsonSerialize();
  639. $sel[$k]['id'] = $oid['$oid'];
  640. }
  641. return json(['list' => $sel, 'total' => count($sel)]);
  642. }
  643. /**
  644. * 辅料编码搜索
  645. */
  646. public function sel_c()
  647. {
  648. $name = $this->request->param()['q_word'][0];
  649. $where = [
  650. 'product_code'=>new \MongoDB\BSON\Regex($name),
  651. 'delete_time'=>'',
  652. ];
  653. $qcodeProduct = new QcodeProduct();
  654. $sel = $qcodeProduct
  655. ->field('id, product_name, product_code')
  656. ->where($where)
  657. ->limit(0,10)
  658. ->select();
  659. foreach ($sel as $k=>$v) {
  660. $oid = $v['_id']->jsonSerialize();
  661. $sel[$k]['id'] = $oid['$oid'];
  662. }
  663. return json(['list' => $sel, 'total' => count($sel)]);
  664. }
  665. /**
  666. * 二维码生成类
  667. */
  668. public function qrcode($url)//二维码生成类
  669. {
  670. $url=$url;
  671. $level=3;
  672. $size=6;
  673. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  674. $errorCorrectionLevel =intval($level) ;//容错级别
  675. $matrixPointSize = intval($size);//生成图片大小
  676. //生成二维码图片
  677. $object = new \QRcode();
  678. //打开缓冲区
  679. ob_start();
  680. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  681. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  682. $imageString = base64_encode(ob_get_contents());
  683. //关闭缓冲区
  684. ob_end_clean();
  685. //把生成的base64字符串返回给前端
  686. // $data = array(
  687. // 'labelcode'=>$url,
  688. // 'code'=>200,
  689. // 'data'=>$imageString,
  690. // 'product_code'=>$url
  691. // );
  692. return 'data:image/png;base64,'.$imageString;
  693. }
  694. }