QcodeBach.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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 = input();
  173. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  174. $order = $req['order'];
  175. $offset = $req['offset'];
  176. $limit = $req['limit'];
  177. // 构造模糊查询条件
  178. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  179. // $filter = ['field' => $regex];
  180. $filter = json_decode($req['filter'], true);
  181. foreach ($filter as $k => $v){
  182. $where[$k] = new \MongoDB\BSON\Regex($v);
  183. }
  184. $qcodeSmall = new QcodeSmall();
  185. $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count();
  186. $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
  187. ->order($sort,$order)
  188. ->limit($limit)
  189. ->skip($offset)
  190. ->select();
  191. foreach ($list as $k=>$v) {
  192. $oid = $v['_id']->jsonSerialize();
  193. $list[$k]['id'] = $oid['$oid'];
  194. $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
  195. }
  196. $result = array("total" => $total, "rows" => $list);
  197. return json($result);
  198. }
  199. return $this->view->fetch();
  200. }
  201. /**
  202. * 小件导出状态修改
  203. */
  204. public function small_status()
  205. {
  206. $req = $this->request->param();
  207. $ids = $req['ids'];
  208. $userInfo = Session::get('admin');
  209. $company_id = (int)$userInfo['company'];
  210. $qcodeSmall = new QcodeSmall();
  211. $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status');
  212. if ($status === 0) {
  213. $newStatus = 1;
  214. } elseif ($status === 1) {
  215. $newStatus = 0;
  216. } else {
  217. // 处理其他情况,如果有需要
  218. }
  219. $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids'])
  220. ->update(['status' => $newStatus]);
  221. if ($bool){
  222. $this->success("切换成功", null, ['id' => $ids]);
  223. }else{
  224. $this->error("切换失败", null, ['id' => $ids]);
  225. }
  226. }
  227. /**
  228. * 自动打码(大件)
  229. */
  230. public function print_l()
  231. {
  232. //设置过滤方法
  233. $this->request->filter(['strip_tags', 'trim']);
  234. $req = $this->request->param();
  235. if ($this->request->isAjax()) {
  236. $ids = $req['ids'];
  237. $type = $req['type'];
  238. $numn = $req['numn'];
  239. $userInfo = Session::get('admin');
  240. $company_id = (int)$userInfo['company'];
  241. $qcodeLarge = new QcodeLarge();
  242. $qcodeSmall = new QcodeSmall();
  243. $qcodeProduct = new QcodeProduct();
  244. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  245. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  246. // matter_no.order_ddbh.matter_name
  247. $row = $qcodeProduct->where('product_code',json_decode($bach,true)['matter_no'])->find();
  248. $company_name = json_decode($bach,true)['supplier_name'];
  249. $product_name = json_decode($bach,true)['matter_name'];
  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. $main_unit = '';
  254. $sec_unit = json_decode($bach,true)['danwei'];
  255. $proportion = json_decode($bach,true)['num'];
  256. $rows = [];
  257. //查询打印大件码所需数据
  258. foreach ($ids as $key=>$value){
  259. $row = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  260. $row = json_decode($row,true);
  261. $code = $row['code'];
  262. $rows[$key]['company_name'] = $company_name;
  263. $rows[$key]['product_name'] = $product_name;
  264. $rows[$key]['sqrcd'] = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->count();
  265. $rows[$key]['main_unit'] = $main_unit;
  266. $rows[$key]['sec_unit'] = $sec_unit;
  267. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  268. $rows[$key]['l_flow'] = ltrim(substr($code,53,6),'0');
  269. $rows[$key]['qrcode'] = $code;
  270. $rows[$key]['pCode'] = $this->qrcode($code);
  271. //批次号特殊情况判断
  272. if (substr($code,76,10)=='0000000000'){
  273. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  274. }else{
  275. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  276. }
  277. //转换关系判断
  278. if($row['l_num']===null){
  279. //走转换关系
  280. if ($proportion){
  281. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  282. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  283. }else{
  284. $rows[$key]['num'] = '';
  285. }
  286. }else if($row['l_num']==0){
  287. //判断是否是公斤
  288. if($main_unit=='公斤'){
  289. //公斤使用l_weight
  290. $rows[$key]['num'] = $row['l_weight'];
  291. }else{
  292. //不是公斤走转换关系
  293. if ($proportion){
  294. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  295. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  296. }else{
  297. $rows[$key]['num'] = '';
  298. }
  299. }
  300. }else{
  301. //箱, 使用l_num
  302. $rows[$key]['num'] = $row['l_num'];
  303. }
  304. }
  305. $data = [
  306. 'type'=>$type,
  307. 'numn'=>$numn,
  308. 'rows'=>$rows,
  309. 'ids'=>$ids,
  310. ];
  311. $this->success('成功','',$data);
  312. }
  313. $this->view->assign('ids',$req['ids']);
  314. return $this->view->fetch();
  315. }
  316. /**
  317. * 自动打码(小件)
  318. */
  319. public function print_s()
  320. {
  321. //设置过滤方法
  322. $this->request->filter(['strip_tags', 'trim']);
  323. $req = $this->request->param();
  324. if ($this->request->isAjax()) {
  325. $ids = $req['ids'];
  326. $type = $req['type'];
  327. $numn = $req['numn'];
  328. $userInfo = Session::get('admin');
  329. $company_id = (int)$userInfo['company'];
  330. $qcodeLarge = new QcodeLarge();
  331. $qcodeSmall = new QcodeSmall();
  332. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  333. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  334. $company_name = json_decode($bach,true)['supplier_name'];
  335. $product_name = json_decode($bach,true)['matter_name'];
  336. //获取全部小件id
  337. $rows = [];
  338. $key = 0;
  339. foreach ($ids as $value){
  340. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  341. $large = json_decode($large,true);
  342. $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id');
  343. //查询打印大件码所需数据
  344. foreach ($arr as $v){
  345. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find();
  346. $small = json_decode($small,true);
  347. $code = $small['code'];
  348. $rows[$key]['company_name'] = $company_name;
  349. $rows[$key]['product_name'] = $product_name;
  350. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  351. $rows[$key]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  352. $rows[$key]['qrcode'] = $code;
  353. // $rows[$key]['pCode'] = $this->qrcode($code);
  354. //批次号特殊情况判断
  355. if (substr($code,76,10)=='0000000000'){
  356. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  357. }else{
  358. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  359. }
  360. $key++;
  361. }
  362. }
  363. $data = [
  364. 'type'=>$type,
  365. 'numn'=>$numn,
  366. 'rows'=>$rows,
  367. 'ids'=>$ids,
  368. ];
  369. $this->success('成功','',$data);
  370. }
  371. $this->view->assign('ids',$req['ids']);
  372. return $this->view->fetch();
  373. }
  374. /**
  375. * 手动打码(小件)
  376. */
  377. public function print_ls()
  378. {
  379. //设置过滤方法
  380. $this->request->filter(['strip_tags', 'trim']);
  381. $req = $this->request->param();
  382. if ($this->request->isAjax()) {
  383. $ids = $req['ids'];
  384. $type = $req['type'];
  385. $numn = $req['numn'];
  386. $userInfo = Session::get('admin');
  387. $company_id = (int)$userInfo['company'];
  388. $qcodeLarge = new QcodeLarge();
  389. $qcodeSmall = new QcodeSmall();
  390. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->find();
  391. $small = json_decode($small,true);
  392. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find();
  393. $large = json_decode($large,true);
  394. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find();
  395. $company_name = json_decode($bach,true)['supplier_name'];
  396. $product_name = json_decode($bach,true)['matter_name'];
  397. //获取全部小件id
  398. $rows = [];
  399. $code = $small['code'];
  400. $rows[0]['company_name'] = $company_name;
  401. $rows[0]['product_name'] = $product_name;
  402. $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  403. $rows[0]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  404. $rows[0]['qrcode'] = $code;
  405. // $rows[0]['pCode'] = $this->qrcode($code);
  406. //批次号特殊情况判断
  407. if (substr($code,76,10)=='0000000000'){
  408. $rows[0]['batch'] = ltrim(substr($code,66,10),'0');
  409. }else{
  410. $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  411. }
  412. $data = [
  413. 'type'=>$type,
  414. 'numn'=>$numn,
  415. 'rows'=>$rows,
  416. 'ids'=>$ids,
  417. ];
  418. $this->success('成功','',$data);
  419. }
  420. $this->view->assign('ids',$req['ids']);
  421. return $this->view->fetch();
  422. }
  423. /**
  424. * 打印数量设置
  425. */
  426. public function set_num()
  427. {
  428. $req = $this->request->param();
  429. //获取数据
  430. $status = $req['status'];
  431. $num = (int)$req['num'];
  432. $ids = $req['ids'];
  433. //获取company_id
  434. $userInfo = Session::get('admin');
  435. $company_id = (int)$userInfo['company'];
  436. //自动打印大件
  437. if($status==1){
  438. $qcodeLarge = new QcodeLarge();
  439. foreach ($ids as $v){
  440. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setInc('p_nums',$num);
  441. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setField('l_print','1');
  442. }
  443. }elseif($status==2){
  444. $qcodeSmall = new QcodeSmall();
  445. foreach ($ids as $v){
  446. $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$v)->setInc('p_nums',$num);
  447. }
  448. }elseif($status==3){
  449. $qcodeSmall = new QcodeSmall();
  450. $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->setInc('p_nums',$num);
  451. }
  452. }
  453. /**
  454. * 导出excel跳转
  455. */
  456. public function exp()
  457. {
  458. //获取产品配置菜单id
  459. $bool = db('auth_rule')->field('id')->where('title','发货管理')->find();
  460. if ($bool){
  461. $this->success('成功','',$bool);
  462. }else{
  463. $this->error('未获取到菜单','',$bool);
  464. }
  465. }
  466. /**
  467. * 修改大件重量数量
  468. */
  469. public function edit($ids = NULL)
  470. {
  471. $req = $this->request->param();
  472. if ($this->request->isAjax()){
  473. parse_str($req['data'],$req);
  474. if(!isset($req['row']['type']) || empty($req['row']['type'])){
  475. $this->error('请选择修改类型');
  476. }
  477. if(!isset($req['row']['numn']) || empty($req['row']['numn'])){
  478. $this->error('请填写修改数量');
  479. }
  480. $ids = explode(',',$req['row']['ids']);
  481. $data = [
  482. 'update_time'=>time(),
  483. 'sync_flag'=>0
  484. ];
  485. $userInfo = Session::get('admin');
  486. $company_id = (int)$userInfo['company'];
  487. $qcodeLarge = new QcodeLarge();
  488. if($req['row']['type']==1){//修改大件重量
  489. $data['l_weight'] = intval($req['row']['numn']*100);
  490. foreach($ids as $val){
  491. //查询code
  492. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('code')->where('_id',$val)->find();
  493. $code = json_decode($large,true)['code'];
  494. if($code){
  495. $code1 = substr($code,0,59);
  496. $code2 = substr($code,65,85);
  497. $data['code'] = $code1.str_pad(intval($req['row']['numn'])*100,6, '0', STR_PAD_LEFT).$code2;
  498. //修改code和大件重量
  499. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  500. }
  501. }
  502. $this->success('修改成功');
  503. }
  504. if($req['row']['type']==2){//修改大件总张数
  505. $data['l_num'] = intval($req['row']['numn']);
  506. foreach($ids as $val){
  507. //查询l_num, 判断是否可以修改总张数
  508. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('l_num')->where('_id',$val)->find();
  509. $l_num = json_decode($large,true)['l_num'];
  510. if($l_num > 0 || $l_num==null){
  511. //可以修改
  512. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  513. }else{
  514. $this->error('该产品不能修改大件数量');
  515. }
  516. }
  517. $this->success('修改成功');
  518. }
  519. }
  520. $this->view->assign('ids',$req['ids']);
  521. return $this->view->fetch();
  522. }
  523. /**
  524. * 删除批次
  525. */
  526. public function del($ids = NULL)
  527. {
  528. $userInfo = Session::get('admin');
  529. $company_id = (int)$userInfo['company'];
  530. $qcodeLarge = new QcodeLarge();
  531. $qcodeSmall = new QcodeSmall();
  532. $qcode_bach_list = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->find();
  533. // echo "<pre>";
  534. // print_r($qcode_bach_list);
  535. // echo "<pre>";
  536. $mongo = \think\Db::connect('mongodb');
  537. $where = [
  538. 'gdbh' => $qcode_bach_list['matter_no'],
  539. 'order_ddbh' => $qcode_bach_list['order_ddbh'],
  540. 'cpbm' => $qcode_bach_list['cpbm'],
  541. 'cpmc' => $qcode_bach_list['matter_name'],
  542. ];
  543. $inventory_summary = $mongo->name('inventory_summary')
  544. ->where($where)
  545. ->find();
  546. $updateResult = $mongo->name('inventory_summary')
  547. ->where($where)
  548. ->update([
  549. 'total_ru_quantity' => $inventory_summary['total_ru_quantity'] - $qcode_bach_list['num'],
  550. 'total_chu_quantity' => $inventory_summary['total_chu_quantity'] - $qcode_bach_list['num'],
  551. 'remaining_quantity' => $inventory_summary['remaining_quantity'] + $qcode_bach_list['num'],
  552. 'updated_at' => date('Y-m-d H:i:s'),
  553. ]);
  554. $where = [
  555. 'gdbh' => $qcode_bach_list['matter_no'],
  556. 'order_ddbh' => $qcode_bach_list['order_ddbh'],
  557. 'cpbm' => $qcode_bach_list['cpbm'],
  558. 'cpmc' => $qcode_bach_list['matter_name'],
  559. 'total_chu_quantity' => $qcode_bach_list['num'],
  560. ];
  561. $inventory_records_updateResult = $mongo->name('inventory_records')
  562. ->where($where)
  563. ->update([
  564. 'mod_rq' => date('Y-m-d H:i:s')
  565. ]);
  566. $data = [
  567. 'delete_time'=>time(),
  568. ];
  569. $bool1 = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->update($data);
  570. $bool2 = $qcodeLarge->name($company_id.'_'."qcode_large")->where('bach_id',$ids)->update($data);
  571. $bool3 = $qcodeSmall->name($company_id.'_'."qcode_small")->where('bach_id',$ids)->update($data);
  572. if($bool1!==false && $bool2!==false && $bool3!==false){
  573. $this->success('删除成功');
  574. }else{
  575. $this->error('删除失败');
  576. }
  577. }
  578. /**
  579. * 补打标签
  580. */
  581. public function reprint()
  582. {
  583. if ($this->request->isAjax()) {
  584. $data = $this->request->param();
  585. parse_str($data['data'],$req);
  586. if(!isset($req['row']['nickname']) || empty($req['row']['nickname'])){
  587. $this->error('请填写公司名称');
  588. }
  589. if((!isset($req['row']['product_name']) || empty($req['row']['product_name'])) && (!isset($req['row']['product_code']) || empty($req['row']['product_code']))){
  590. $this->error('请填写辅料名称或辅料编号');
  591. }
  592. if(!isset($req['row']['sqrcd']) || empty($req['row']['sqrcd'])){
  593. $this->error('请填写配盘数');
  594. }
  595. if(!isset($req['row']['num']) || empty($req['row']['num'])){
  596. $this->error('请填写数量');
  597. }
  598. //查询公司信息
  599. $qcodeGsmc = new QcodeGsmc();
  600. $print_code = $qcodeGsmc
  601. ->field('id, nickname, print_code')
  602. ->where('nickname',$req['row']['nickname'])
  603. ->find();
  604. if (!$print_code) $this->error('未查到公司信息');
  605. $print_code = json_decode($print_code,true);
  606. //查询产品信息
  607. $qcodeProduct = new QcodeProduct();
  608. if(!empty($req['row']['product_code'])){
  609. $sel = $qcodeProduct
  610. ->field('id, product_name, product_code, temple')
  611. ->where('product_code',$req['row']['product_code'])
  612. ->find();
  613. }else{
  614. $sel = $qcodeProduct
  615. ->field('id, product_name, product_code, temple')
  616. ->where('product_name',$req['row']['product_name'])
  617. ->find();
  618. }
  619. if (!$sel) $this->error('未查到辅料信息');
  620. $sel = json_decode($sel,true);
  621. $data = [
  622. 'company_name'=>$req['row']['nickname'],
  623. 'product_name'=>$sel['product_name'],
  624. 'sqrcd'=>$req['row']['sqrcd'],
  625. 'num'=>$req['row']['num'],
  626. 'main_unit'=>'盘',
  627. 'sec_unit'=>'万米',
  628. 'date'=>date('Y-m-d'),
  629. 'batch'=>substr(date('Ymd'),2,6),
  630. 'l_flow'=>1,
  631. ];
  632. $num = str_pad($req['row']['num'], 3, '0', STR_PAD_LEFT);
  633. $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';
  634. $data['pCode'] = $this->qrcode($qrcode);
  635. $data['qrcode'] = $qrcode;
  636. $this->success('成功','',$data);
  637. }
  638. return $this->view->fetch();
  639. }
  640. /**
  641. * 公司名称搜索
  642. */
  643. public function sel_n()
  644. {
  645. $name = $this->request->param()['q_word'][0];
  646. $where = [
  647. 'nickname'=>new \MongoDB\BSON\Regex($name),
  648. 'delete_time'=>'',
  649. ];
  650. $qcodeGsmc = new QcodeGsmc();
  651. $sel = $qcodeGsmc
  652. ->field('nickname')
  653. ->where($where)
  654. ->limit(0,10)
  655. ->select();
  656. return json(['list' => $sel, 'total' => count($sel)]);
  657. }
  658. /**
  659. * 辅料名称搜索
  660. */
  661. public function sel_p()
  662. {
  663. $name = $this->request->param()['q_word'][0];
  664. $where = [
  665. 'product_name'=>new \MongoDB\BSON\Regex($name),
  666. 'delete_time'=>'',
  667. ];
  668. $qcodeProduct = new QcodeProduct();
  669. $sel = $qcodeProduct
  670. ->field('product_name, product_code')
  671. ->where($where)
  672. ->limit(0,10)
  673. ->select();
  674. foreach ($sel as $k=>$v) {
  675. $oid = $v['_id']->jsonSerialize();
  676. $sel[$k]['id'] = $oid['$oid'];
  677. }
  678. return json(['list' => $sel, 'total' => count($sel)]);
  679. }
  680. /**
  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. }