QcodeBach.php 31 KB

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