QcodeBach.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. $bach_detail = $this->model
  137. ->name($company_id . '_qcode_bach')
  138. ->where('_id', $filter['bach_id'])
  139. ->find();
  140. $num = (float)$bach_detail['num'];
  141. $small_num = (float)$bach_detail['small_num'];
  142. $boxes_per_pallet = (float)$bach_detail['total_boxes'];
  143. $larger_num = $num / $small_num;
  144. $full_pallets = floor($larger_num / $boxes_per_pallet);
  145. $last_pallet_boxes = fmod($larger_num, $boxes_per_pallet); // 真正浮点取余
  146. $total_pallets = $full_pallets + ($last_pallet_boxes > 0 ? 1 : 0);
  147. // 当前是第几托(code中解析)
  148. $current_flow_str = substr($v['code'], 53, 6);
  149. $current_flow = (int) ltrim($current_flow_str, '0');
  150. $total_pallets = (int) $total_pallets;
  151. // 是否是最后一托
  152. $is_last = ($current_flow === $total_pallets) ? 1 : 0;
  153. // 修正箱数
  154. $total_boxes = $boxes_per_pallet;
  155. if ($is_last && $last_pallet_boxes > 0) {
  156. // 精准保留1位小数,不做四舍五入
  157. $total_boxes = number_format($last_pallet_boxes, 1, '.', '');
  158. }
  159. $oid = $v['_id']->jsonSerialize();
  160. $list[$k]['id'] = $oid['$oid'];
  161. //设置当前托盘号
  162. $list[$k]['l_flow'] = ltrim(substr($v['code'],53,6),'0');
  163. //查询小件数量
  164. $small_num = $qcodeSmall->name($company_id.'_'."qcode_small")
  165. ->where('large_id',$oid['$oid'])
  166. ->count();
  167. $list[$k]['small_num'] = $small_num;
  168. $list[$k]['tray_num'] = $bach_detail['tray_num'];
  169. $list[$k]['total_boxes'] = $total_boxes;
  170. //设置当前大件重量
  171. $list[$k]['l_weight'] = floatval($v['l_weight'])/100;
  172. }
  173. $result = array("total" => $total, "rows" => $list);
  174. return json($result);
  175. }
  176. return $this->view->fetch();
  177. }
  178. /**
  179. * 小件列表
  180. */
  181. public function small()
  182. {
  183. //设置过滤方法
  184. $this->request->filter(['strip_tags', 'trim']);
  185. $req = $this->request->param();
  186. if ($this->request->isAjax()) {
  187. //如果发送的来源是Selectpage,则转发到Selectpage
  188. if ($this->request->request('keyField')) {
  189. return $this->selectpage();
  190. }
  191. $userInfo = Session::get('admin');
  192. $company_id = (int)$userInfo['company'];
  193. $where = [
  194. 'delete_time'=> '',
  195. 'large_id'=> $req['large_id']
  196. ];
  197. $req = input();
  198. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  199. $order = $req['order'];
  200. $offset = $req['offset'];
  201. $limit = $req['limit'];
  202. // 构造模糊查询条件
  203. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  204. // $filter = ['field' => $regex];
  205. $filter = json_decode($req['filter'], true);
  206. foreach ($filter as $k => $v){
  207. $where[$k] = new \MongoDB\BSON\Regex($v);
  208. }
  209. $qcodeSmall = new QcodeSmall();
  210. $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->count();
  211. $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
  212. ->order($sort,$order)
  213. ->limit($limit)
  214. ->skip($offset)
  215. ->select();
  216. foreach ($list as $k=>$v) {
  217. $oid = $v['_id']->jsonSerialize();
  218. $list[$k]['id'] = $oid['$oid'];
  219. $list[$k]['l_flow'] = $req['l_flow'].'-'.$v['l_flow'];
  220. }
  221. $result = array("total" => $total, "rows" => $list);
  222. return json($result);
  223. }
  224. return $this->view->fetch();
  225. }
  226. /**
  227. * 小件导出状态修改
  228. */
  229. public function small_status()
  230. {
  231. $req = $this->request->param();
  232. $ids = $req['ids'];
  233. $userInfo = Session::get('admin');
  234. $company_id = (int)$userInfo['company'];
  235. $qcodeSmall = new QcodeSmall();
  236. $status = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $ids)->value('status');
  237. if ($status === 0) {
  238. $newStatus = 1;
  239. } elseif ($status === 1) {
  240. $newStatus = 0;
  241. } else {
  242. // 处理其他情况,如果有需要
  243. }
  244. $bool = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id', $req['ids'])
  245. ->update(['status' => $newStatus]);
  246. if ($bool){
  247. $this->success("切换成功", null, ['id' => $ids]);
  248. }else{
  249. $this->error("切换失败", null, ['id' => $ids]);
  250. }
  251. }
  252. /**
  253. * 自动打码(大件)
  254. */
  255. public function print_l()
  256. {
  257. //设置过滤方法
  258. $this->request->filter(['strip_tags', 'trim']);
  259. $req = $this->request->param();
  260. if ($this->request->isAjax()) {
  261. $ids = $req['ids'];
  262. $type = $req['type'];
  263. $numn = $req['numn'];
  264. $userInfo = Session::get('admin');
  265. $company_id = (int)$userInfo['company'];
  266. $qcodeLarge = new QcodeLarge();
  267. $qcodeSmall = new QcodeSmall();
  268. $qcodeProduct = new QcodeProduct();
  269. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  270. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  271. // matter_no.order_ddbh.matter_name
  272. $row = $qcodeProduct->where('product_code',json_decode($bach,true)['matter_no'])->find();
  273. $company_name = json_decode($bach,true)['supplier_name'];
  274. $product_name = json_decode($bach,true)['matter_name'];
  275. // $main_unit = json_decode($row,true)['main_unit'];
  276. // $sec_unit = json_decode($row,true)['sec_unit'];
  277. // $proportion = json_decode($row,true)['proportion'];
  278. $main_unit = '';
  279. $sec_unit = json_decode($bach,true)['danwei'];
  280. $proportion = json_decode($bach,true)['num'];
  281. $rows = [];
  282. //查询打印大件码所需数据
  283. foreach ($ids as $key=>$value){
  284. $row = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  285. $row = json_decode($row,true);
  286. $code = $row['code'];
  287. $rows[$key]['company_name'] = $company_name;
  288. $rows[$key]['product_name'] = $product_name;
  289. $rows[$key]['sqrcd'] = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->count();
  290. $rows[$key]['main_unit'] = $main_unit;
  291. $rows[$key]['sec_unit'] = $sec_unit;
  292. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  293. $rows[$key]['l_flow'] = ltrim(substr($code,53,6),'0');
  294. $rows[$key]['qrcode'] = $code;
  295. $rows[$key]['pCode'] = $this->qrcode($code);
  296. //批次号特殊情况判断
  297. if (substr($code,76,10)=='0000000000'){
  298. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  299. }else{
  300. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  301. }
  302. //转换关系判断
  303. if($row['l_num']===null){
  304. //走转换关系
  305. if ($proportion){
  306. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  307. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  308. }else{
  309. $rows[$key]['num'] = '';
  310. }
  311. }else if($row['l_num']==0){
  312. //判断是否是公斤
  313. if($main_unit=='公斤'){
  314. //公斤使用l_weight
  315. $rows[$key]['num'] = $row['l_weight'];
  316. }else{
  317. //不是公斤走转换关系
  318. if ($proportion){
  319. $rows[$key]['num'] = $rows[$key]['sqrcd']*$proportion;
  320. $rows[$key]['num'] = floor($rows[$key]['num'] * 100) / 100;
  321. }else{
  322. $rows[$key]['num'] = '';
  323. }
  324. }
  325. }else{
  326. //箱, 使用l_num
  327. $rows[$key]['num'] = $row['l_num'];
  328. }
  329. }
  330. $data = [
  331. 'type'=>$type,
  332. 'numn'=>$numn,
  333. 'rows'=>$rows,
  334. 'ids'=>$ids,
  335. ];
  336. $this->success('成功','',$data);
  337. }
  338. $this->view->assign('ids',$req['ids']);
  339. return $this->view->fetch();
  340. }
  341. /**
  342. * 自动打码(小件)
  343. */
  344. public function print_s()
  345. {
  346. //设置过滤方法
  347. $this->request->filter(['strip_tags', 'trim']);
  348. $req = $this->request->param();
  349. if ($this->request->isAjax()) {
  350. $ids = $req['ids'];
  351. $type = $req['type'];
  352. $numn = $req['numn'];
  353. $userInfo = Session::get('admin');
  354. $company_id = (int)$userInfo['company'];
  355. $qcodeLarge = new QcodeLarge();
  356. $qcodeSmall = new QcodeSmall();
  357. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$ids[0])->find();
  358. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',json_decode($large,true)['bach_id'])->find();
  359. $company_name = json_decode($bach,true)['supplier_name'];
  360. $product_name = json_decode($bach,true)['matter_name'];
  361. //获取全部小件id
  362. $rows = [];
  363. $key = 0;
  364. foreach ($ids as $value){
  365. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$value)->find();
  366. $large = json_decode($large,true);
  367. $arr = $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$value)->column('_id');
  368. //查询打印大件码所需数据
  369. foreach ($arr as $v){
  370. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$v->jsonSerialize()['$oid'])->find();
  371. $small = json_decode($small,true);
  372. $code = $small['code'];
  373. $rows[$key]['company_name'] = $company_name;
  374. $rows[$key]['product_name'] = $product_name;
  375. $rows[$key]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  376. $rows[$key]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  377. $rows[$key]['qrcode'] = $code;
  378. // $rows[$key]['pCode'] = $this->qrcode($code);
  379. //批次号特殊情况判断
  380. if (substr($code,76,10)=='0000000000'){
  381. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0');
  382. }else{
  383. $rows[$key]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  384. }
  385. $key++;
  386. }
  387. }
  388. $data = [
  389. 'type'=>$type,
  390. 'numn'=>$numn,
  391. 'rows'=>$rows,
  392. 'ids'=>$ids,
  393. ];
  394. $this->success('成功','',$data);
  395. }
  396. $this->view->assign('ids',$req['ids']);
  397. return $this->view->fetch();
  398. }
  399. /**
  400. * 手动打码(小件)
  401. */
  402. public function print_ls()
  403. {
  404. //设置过滤方法
  405. $this->request->filter(['strip_tags', 'trim']);
  406. $req = $this->request->param();
  407. if ($this->request->isAjax()) {
  408. $ids = $req['ids'];
  409. $type = $req['type'];
  410. $numn = $req['numn'];
  411. $userInfo = Session::get('admin');
  412. $company_id = (int)$userInfo['company'];
  413. $qcodeLarge = new QcodeLarge();
  414. $qcodeSmall = new QcodeSmall();
  415. $small = $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->find();
  416. $small = json_decode($small,true);
  417. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$small['large_id'])->find();
  418. $large = json_decode($large,true);
  419. $bach = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$small['bach_id'])->find();
  420. $company_name = json_decode($bach,true)['supplier_name'];
  421. $product_name = json_decode($bach,true)['matter_name'];
  422. //获取全部小件id
  423. $rows = [];
  424. $code = $small['code'];
  425. $rows[0]['company_name'] = $company_name;
  426. $rows[0]['product_name'] = $product_name;
  427. $rows[0]['date'] = substr_replace(substr_replace('20'.substr($code,38,6), '-', 4, 0), '-', 7, 0);
  428. $rows[0]['l_flow'] = ltrim(substr($large['code'],53,6),'0').'-'.$small['l_flow'];
  429. $rows[0]['qrcode'] = $code;
  430. // $rows[0]['pCode'] = $this->qrcode($code);
  431. //批次号特殊情况判断
  432. if (substr($code,76,10)=='0000000000'){
  433. $rows[0]['batch'] = ltrim(substr($code,66,10),'0');
  434. }else{
  435. $rows[0]['batch'] = ltrim(substr($code,66,10),'0').'、'.ltrim(substr($code,76,10),'0');
  436. }
  437. $data = [
  438. 'type'=>$type,
  439. 'numn'=>$numn,
  440. 'rows'=>$rows,
  441. 'ids'=>$ids,
  442. ];
  443. $this->success('成功','',$data);
  444. }
  445. $this->view->assign('ids',$req['ids']);
  446. return $this->view->fetch();
  447. }
  448. /**
  449. * 打印数量设置
  450. */
  451. public function set_num()
  452. {
  453. $req = $this->request->param();
  454. //获取数据
  455. $status = $req['status'];
  456. $num = (int)$req['num'];
  457. $ids = $req['ids'];
  458. //获取company_id
  459. $userInfo = Session::get('admin');
  460. $company_id = (int)$userInfo['company'];
  461. //自动打印大件
  462. if($status==1){
  463. $qcodeLarge = new QcodeLarge();
  464. foreach ($ids as $v){
  465. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setInc('p_nums',$num);
  466. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$v)->setField('l_print','1');
  467. }
  468. }elseif($status==2){
  469. $qcodeSmall = new QcodeSmall();
  470. foreach ($ids as $v){
  471. $qcodeSmall->name($company_id.'_'."qcode_small")->where('large_id',$v)->setInc('p_nums',$num);
  472. }
  473. }elseif($status==3){
  474. $qcodeSmall = new QcodeSmall();
  475. $qcodeSmall->name($company_id.'_'."qcode_small")->where('_id',$ids)->setInc('p_nums',$num);
  476. }
  477. }
  478. /**
  479. * 导出excel跳转
  480. */
  481. public function exp()
  482. {
  483. //获取产品配置菜单id
  484. $bool = db('auth_rule')->field('id')->where('title','发货管理')->find();
  485. if ($bool){
  486. $this->success('成功','',$bool);
  487. }else{
  488. $this->error('未获取到菜单','',$bool);
  489. }
  490. }
  491. /**
  492. * 修改大件重量数量
  493. */
  494. public function edit($ids = NULL)
  495. {
  496. $req = $this->request->param();
  497. if ($this->request->isAjax()){
  498. parse_str($req['data'],$req);
  499. if(!isset($req['row']['type']) || empty($req['row']['type'])){
  500. $this->error('请选择修改类型');
  501. }
  502. if(!isset($req['row']['numn']) || empty($req['row']['numn'])){
  503. $this->error('请填写修改数量');
  504. }
  505. $ids = explode(',',$req['row']['ids']);
  506. $data = [
  507. 'update_time'=>time(),
  508. 'sync_flag'=>0
  509. ];
  510. $userInfo = Session::get('admin');
  511. $company_id = (int)$userInfo['company'];
  512. $qcodeLarge = new QcodeLarge();
  513. if($req['row']['type']==1){//修改大件重量
  514. $data['l_weight'] = intval($req['row']['numn']*100);
  515. foreach($ids as $val){
  516. //查询code
  517. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('code')->where('_id',$val)->find();
  518. $code = json_decode($large,true)['code'];
  519. if($code){
  520. $code1 = substr($code,0,59);
  521. $code2 = substr($code,65,85);
  522. $data['code'] = $code1.str_pad(intval($req['row']['numn'])*100,6, '0', STR_PAD_LEFT).$code2;
  523. //修改code和大件重量
  524. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  525. }
  526. }
  527. $this->success('修改成功');
  528. }
  529. if($req['row']['type']==2){//修改大件总张数
  530. $data['l_num'] = intval($req['row']['numn']);
  531. foreach($ids as $val){
  532. //查询l_num, 判断是否可以修改总张数
  533. $large = $qcodeLarge->name($company_id.'_'."qcode_large")->field('l_num')->where('_id',$val)->find();
  534. $l_num = json_decode($large,true)['l_num'];
  535. if($l_num > 0 || $l_num==null){
  536. //可以修改
  537. $qcodeLarge->name($company_id.'_'."qcode_large")->where('_id',$val)->update($data);
  538. }else{
  539. $this->error('该产品不能修改大件数量');
  540. }
  541. }
  542. $this->success('修改成功');
  543. }
  544. }
  545. $this->view->assign('ids',$req['ids']);
  546. return $this->view->fetch();
  547. }
  548. /**
  549. * 删除批次
  550. */
  551. public function del($ids = NULL)
  552. {
  553. $userInfo = Session::get('admin');
  554. $company_id = (int)$userInfo['company'];
  555. $qcodeLarge = new QcodeLarge();
  556. $qcodeSmall = new QcodeSmall();
  557. $qcode_bach_list = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->find();
  558. // echo "<pre>";
  559. // print_r($qcode_bach_list);
  560. // echo "<pre>";
  561. $mongo = \think\Db::connect('mongodb');
  562. $where = [
  563. 'gdbh' => $qcode_bach_list['matter_no'],
  564. 'order_ddbh' => $qcode_bach_list['order_ddbh'],
  565. 'cpbm' => $qcode_bach_list['cpbm'],
  566. 'cpmc' => $qcode_bach_list['matter_name'],
  567. ];
  568. $inventory_summary = $mongo->name('inventory_summary')
  569. ->where($where)
  570. ->find();
  571. $updateResult = $mongo->name('inventory_summary')
  572. ->where($where)
  573. ->update([
  574. 'total_ru_quantity' => $inventory_summary['total_ru_quantity'] - $qcode_bach_list['num'],
  575. 'total_chu_quantity' => $inventory_summary['total_chu_quantity'] - $qcode_bach_list['num'],
  576. 'remaining_quantity' => $inventory_summary['remaining_quantity'] + $qcode_bach_list['num'],
  577. 'updated_at' => date('Y-m-d H:i:s'),
  578. ]);
  579. $where = [
  580. 'gdbh' => $qcode_bach_list['matter_no'],
  581. 'order_ddbh' => $qcode_bach_list['order_ddbh'],
  582. 'cpbm' => $qcode_bach_list['cpbm'],
  583. 'cpmc' => $qcode_bach_list['matter_name'],
  584. 'total_chu_quantity' => $qcode_bach_list['num'],
  585. ];
  586. $inventory_records_updateResult = $mongo->name('inventory_records')
  587. ->where($where)
  588. ->update([
  589. 'mod_rq' => date('Y-m-d H:i:s')
  590. ]);
  591. $data = [
  592. 'delete_time'=>time(),
  593. ];
  594. $bool1 = $this->model->name($company_id.'_'."qcode_bach")->where('_id',$ids)->update($data);
  595. $bool2 = $qcodeLarge->name($company_id.'_'."qcode_large")->where('bach_id',$ids)->update($data);
  596. $bool3 = $qcodeSmall->name($company_id.'_'."qcode_small")->where('bach_id',$ids)->update($data);
  597. if($bool1!==false && $bool2!==false && $bool3!==false){
  598. $this->success('删除成功');
  599. }else{
  600. $this->error('删除失败');
  601. }
  602. }
  603. /**
  604. * 补打标签
  605. */
  606. public function reprint()
  607. {
  608. if ($this->request->isAjax()) {
  609. $data = $this->request->param();
  610. parse_str($data['data'],$req);
  611. if(!isset($req['row']['nickname']) || empty($req['row']['nickname'])){
  612. $this->error('请填写公司名称');
  613. }
  614. if((!isset($req['row']['product_name']) || empty($req['row']['product_name'])) && (!isset($req['row']['product_code']) || empty($req['row']['product_code']))){
  615. $this->error('请填写辅料名称或辅料编号');
  616. }
  617. if(!isset($req['row']['sqrcd']) || empty($req['row']['sqrcd'])){
  618. $this->error('请填写配盘数');
  619. }
  620. if(!isset($req['row']['num']) || empty($req['row']['num'])){
  621. $this->error('请填写数量');
  622. }
  623. //查询公司信息
  624. $qcodeGsmc = new QcodeGsmc();
  625. $print_code = $qcodeGsmc
  626. ->field('id, nickname, print_code')
  627. ->where('nickname',$req['row']['nickname'])
  628. ->find();
  629. if (!$print_code) $this->error('未查到公司信息');
  630. $print_code = json_decode($print_code,true);
  631. //查询产品信息
  632. $qcodeProduct = new QcodeProduct();
  633. if(!empty($req['row']['product_code'])){
  634. $sel = $qcodeProduct
  635. ->field('id, product_name, product_code, temple')
  636. ->where('product_code',$req['row']['product_code'])
  637. ->find();
  638. }else{
  639. $sel = $qcodeProduct
  640. ->field('id, product_name, product_code, temple')
  641. ->where('product_name',$req['row']['product_name'])
  642. ->find();
  643. }
  644. if (!$sel) $this->error('未查到辅料信息');
  645. $sel = json_decode($sel,true);
  646. $data = [
  647. 'company_name'=>$req['row']['nickname'],
  648. 'product_name'=>$sel['product_name'],
  649. 'sqrcd'=>$req['row']['sqrcd'],
  650. 'num'=>$req['row']['num'],
  651. 'main_unit'=>'盘',
  652. 'sec_unit'=>'万米',
  653. 'date'=>date('Y-m-d'),
  654. 'batch'=>substr(date('Ymd'),2,6),
  655. 'l_flow'=>1,
  656. ];
  657. $num = str_pad($req['row']['num'], 3, '0', STR_PAD_LEFT);
  658. $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';
  659. $data['pCode'] = $this->qrcode($qrcode);
  660. $data['qrcode'] = $qrcode;
  661. $this->success('成功','',$data);
  662. }
  663. return $this->view->fetch();
  664. }
  665. /**
  666. * 公司名称搜索
  667. */
  668. public function sel_n()
  669. {
  670. $name = $this->request->param()['q_word'][0];
  671. $where = [
  672. 'nickname'=>new \MongoDB\BSON\Regex($name),
  673. 'delete_time'=>'',
  674. ];
  675. $qcodeGsmc = new QcodeGsmc();
  676. $sel = $qcodeGsmc
  677. ->field('nickname')
  678. ->where($where)
  679. ->limit(0,10)
  680. ->select();
  681. return json(['list' => $sel, 'total' => count($sel)]);
  682. }
  683. /**
  684. * 辅料名称搜索
  685. */
  686. public function sel_p()
  687. {
  688. $name = $this->request->param()['q_word'][0];
  689. $where = [
  690. 'product_name'=>new \MongoDB\BSON\Regex($name),
  691. 'delete_time'=>'',
  692. ];
  693. $qcodeProduct = new QcodeProduct();
  694. $sel = $qcodeProduct
  695. ->field('product_name, product_code')
  696. ->where($where)
  697. ->limit(0,10)
  698. ->select();
  699. foreach ($sel as $k=>$v) {
  700. $oid = $v['_id']->jsonSerialize();
  701. $sel[$k]['id'] = $oid['$oid'];
  702. }
  703. return json(['list' => $sel, 'total' => count($sel)]);
  704. }
  705. /**
  706. * 辅料编码搜索
  707. */
  708. public function sel_c()
  709. {
  710. $name = $this->request->param()['q_word'][0];
  711. $where = [
  712. 'product_code'=>new \MongoDB\BSON\Regex($name),
  713. 'delete_time'=>'',
  714. ];
  715. $qcodeProduct = new QcodeProduct();
  716. $sel = $qcodeProduct
  717. ->field('id, product_name, product_code')
  718. ->where($where)
  719. ->limit(0,10)
  720. ->select();
  721. foreach ($sel as $k=>$v) {
  722. $oid = $v['_id']->jsonSerialize();
  723. $sel[$k]['id'] = $oid['$oid'];
  724. }
  725. return json(['list' => $sel, 'total' => count($sel)]);
  726. }
  727. /**
  728. * 二维码生成类
  729. */
  730. public function qrcode($url)//二维码生成类
  731. {
  732. $url=$url;
  733. $level=3;
  734. $size=6;
  735. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  736. $errorCorrectionLevel =intval($level) ;//容错级别
  737. $matrixPointSize = intval($size);//生成图片大小
  738. //生成二维码图片
  739. $object = new \QRcode();
  740. //打开缓冲区
  741. ob_start();
  742. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  743. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  744. $imageString = base64_encode(ob_get_contents());
  745. //关闭缓冲区
  746. ob_end_clean();
  747. //把生成的base64字符串返回给前端
  748. // $data = array(
  749. // 'labelcode'=>$url,
  750. // 'code'=>200,
  751. // 'data'=>$imageString,
  752. // 'product_code'=>$url
  753. // );
  754. return 'data:image/png;base64,'.$imageString;
  755. }
  756. }