QcodeBach.php 28 KB

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