QcodeAdd.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\QcodeCompany;
  4. use app\admin\model\QcodeGsmc;
  5. use app\admin\model\QcodeProduct;
  6. use app\common\controller\Backend;
  7. use app\admin\model\ResetFlow;
  8. use app\admin\model\QcodeLarge;
  9. use app\admin\model\QcodeBach;
  10. use app\admin\model\QcodeSmall;
  11. use app\admin\model\QcodeLiushui;
  12. use fast\Arr;
  13. use MongoDB\BSON\ObjectId;
  14. use think\Db;
  15. use think\Session;
  16. class QcodeAdd extends Backend{
  17. /**
  18. * 首页展示
  19. */
  20. public function index(){
  21. //获取登录账号信息【厂商信息】
  22. $userinfo = Session::get('admin');
  23. $data = [
  24. 'nickname' => $userinfo['company_name'],
  25. 'postcode' => $userinfo['postcode'],
  26. 'mobile' => $userinfo['mobile'],
  27. 'printer_code' => $userinfo['printer_code'],
  28. 'company_address' => $userinfo['company_address']
  29. ];
  30. $this->view->assign('row',$data);
  31. //将对此账号创建公司唯一id,进行创建公司对应公司表名company id
  32. $user_company_value = Db::name('admin')->where('id', $userinfo['id'])->value('company');
  33. if (empty($user_company_value)) {
  34. $max_company = Db::name('admin')->max('company');
  35. $new_company_value = $max_company ? ($max_company + 1) : 1;
  36. Db::name('admin')->where('id', $userinfo['id'])->update(['company' => $new_company_value]);
  37. } else {
  38. $new_company_value = $user_company_value;
  39. }
  40. $tableNames = [
  41. $new_company_value . '_qcode_bach',
  42. $new_company_value . '_qcode_company',
  43. $new_company_value . '_qcode_large',
  44. $new_company_value . '_qcode_liushui',
  45. $new_company_value . '_qcode_small',
  46. $new_company_value . '_reset_flow',
  47. ];
  48. foreach ($tableNames as $tableName) {
  49. try {
  50. Db::connect('mongodb')->name($tableName)->insert(['init' => 1]);
  51. // 删除测试数据(可选,如果不想保留这个测试数据)
  52. Db::connect('mongodb')->name($tableName)->where('init', 1)->delete();
  53. } catch (\Exception $e) {
  54. echo "创建集合 {$tableName} 失败:" . $e->getMessage();
  55. }
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 获取产品信息
  61. */
  62. public function product(){
  63. $params = input('');
  64. $page = max(1, (int)$params['page']);
  65. $limit = max(1, (int)$params['limit']);
  66. $offset = ($page - 1) * $limit;
  67. // 获取工单编号列表
  68. $db3 = Db::connect(config('database.db3'));
  69. $gdRows = $db3->query("SELECT DISTINCT `Gd_gdbh`, `Gd_客户代号`, `Gd_cpdh` FROM `工单_基本资料` WHERE `Gd_客户代号` = ?", ['J0031']);
  70. $Gd_gdbhList = array_column($gdRows, 'Gd_gdbh');
  71. $gdbhList = array_column($gdRows, 'Gd_cpdh');
  72. if (empty($gdbhList)) {
  73. $this->assign([
  74. 'data' => '',
  75. 'total' => '',
  76. ]);
  77. }
  78. // Mongo 查询
  79. $mongo = \think\Db::connect('mongodb');
  80. $where = ['成品编码' => ['in', $gdbhList],'jjcp_gdbh' => ['in', $Gd_gdbhList], 'jjcp_smb' => '末 板'];
  81. // $where = ['成品编码' => ['in', $gdbhList], 'jjcp_smb' => '末 板'];
  82. if (!empty($params['search'])) {
  83. $where['成品编码|成品名称|jjcp_gdbh|订单编号'] = new \MongoDB\BSON\Regex($params['search'], 'i');
  84. }
  85. // 查询符合条件的成品数据
  86. $al_products = $mongo->name('finished_products')
  87. ->where($where)
  88. ->order('Sys_rq', 'desc')
  89. ->select();
  90. // 查询 texts = 新增产品 的数据
  91. $xz_products = $mongo->name('finished_products')
  92. ->where('texts', '新增产品')
  93. ->order('Sys_rq', 'desc')
  94. ->select();
  95. // 合并数据
  96. $all_products = array_merge($al_products, $xz_products);
  97. // 分组聚合处理
  98. $grouped_products = [];
  99. foreach ($all_products as $item) {
  100. // 转换日期格式(如果是 d/m/Y H:i:s)
  101. $date = \DateTime::createFromFormat('d/m/Y H:i:s', $item['Sys_rq']);
  102. $item['Sys_rq'] = $date ? $date->format('Y-m-d H:i:s') : $item['Sys_rq'];
  103. $group_key = $item['订单编号'] . '_' . $item['jjcp_gdbh'];
  104. if (!isset($grouped_products[$group_key])) {
  105. $grouped_products[$group_key] = [
  106. 'Sys_rq' => $item['Sys_rq'],
  107. 'order_ddbh' => $item['订单编号'],
  108. 'gdbh' => $item['jjcp_gdbh'],
  109. 'cpbm' => $item['成品编码'],
  110. 'cpmc' => $item['成品名称'],
  111. 'sl' => 0,
  112. 'cpdh_list' => [],
  113. 'cpbm_list' => []
  114. ];
  115. }
  116. $grouped_products[$group_key]['sl'] += (int)$item['jjcp_sl'];
  117. if (!in_array($item['jjcp_cpdh'], $grouped_products[$group_key]['cpdh_list'])) {
  118. $grouped_products[$group_key]['cpdh_list'][] = $item['jjcp_cpdh'];
  119. }
  120. if (!in_array($item['成品编码'], $grouped_products[$group_key]['cpbm_list'])) {
  121. $grouped_products[$group_key]['cpbm_list'][] = $item['成品编码'];
  122. }
  123. }
  124. // 格式化列表字符串
  125. foreach ($grouped_products as &$group) {
  126. $group['cpdh'] = implode(',', $group['cpdh_list']);
  127. $group['cpbm'] = implode(',', $group['cpbm_list']);
  128. unset($group['cpdh_list'], $group['cpbm_list']);
  129. }
  130. // 聚合结果排序(按时间降序)
  131. $all_grouped = array_values($grouped_products);
  132. usort($all_grouped, function ($a, $b) {
  133. $timeA = strtotime($a['Sys_rq']) ?: 0;
  134. $timeB = strtotime($b['Sys_rq']) ?: 0;
  135. return $timeB <=> $timeA;
  136. });
  137. // 再分页
  138. $total = count($all_grouped);
  139. $paged_grouped = array_slice($all_grouped, $offset, $limit);
  140. // 查询库存并计算剩余数
  141. foreach ($paged_grouped as &$prod) {
  142. $inventory = $mongo->name('inventory_summary')->where([
  143. 'order_ddbh' => $prod['order_ddbh'],
  144. 'gdbh' => $prod['gdbh'],
  145. 'cpmc' => $prod['cpmc'],
  146. ])->find();
  147. $total_chu_quantity = isset($inventory['total_chu_quantity']) ? (int)$inventory['total_chu_quantity'] : 0;
  148. $prod['total_chu_quantity'] = $total_chu_quantity;
  149. $prod['remaining_quantity'] = $prod['sl'] - $total_chu_quantity;
  150. }
  151. unset($prod);
  152. return json([
  153. 'code' => 1,
  154. 'data' => $paged_grouped,
  155. 'total' => $total,
  156. 'page' => $page,
  157. 'limit' => $limit
  158. ]);
  159. }
  160. /**
  161. * 添加批次功能
  162. *
  163. * 功能说明:
  164. * 1. 处理AJAX请求,创建产品批次
  165. * 2. 自动计算托盘分配(完整托盘和不完整托盘)
  166. * 3. 生成批次号和相关统计信息
  167. * 4. 更新库存记录
  168. * 5. 支持多种托盘配置(18箱/24箱/36箱)
  169. */
  170. // public function add_bach()
  171. // {
  172. // if (!$this->request->isAjax()) {
  173. // $this->error('非法请求,必须使用AJAX方式提交');
  174. // }
  175. // $data = input('row'); // 获取原始数据
  176. // if (empty($data)) {
  177. // $this->error('请求参数不能为空');
  178. // }
  179. // $data = json_decode($data, true);
  180. // if (json_last_error() !== JSON_ERROR_NONE) {
  181. // $this->error('JSON数据解析失败:' . json_last_error_msg());
  182. // }
  183. // if (empty($data['products']) || !is_array($data['products'])) {
  184. // $this->error('产品数据不能为空且必须是数组');
  185. // }
  186. // $userinfo = Session::get('admin');
  187. // if (empty($userinfo) || !isset($userinfo['company'])) {
  188. // $this->error('获取用户信息失败,请重新登录');
  189. // }
  190. // //连接MongoDB
  191. // $mongo = \think\Db::connect('mongodb');
  192. // //动态生成集合名称(基于公司名称)
  193. // $collection = $userinfo['company'] . '_qcode_bach'; // 主表
  194. // $bachdetails = $userinfo['company'] . '_qcode_bachdetails'; // 托盘明细表
  195. // $bachsummary = $userinfo['company'] . '_qcode_bachsummary'; // 批次汇总表
  196. //
  197. // $currentDate = date('Y-m-d');
  198. // $currentDateTime = date('Y-m-d H:i:s');
  199. // $timestamp = time();
  200. // $bachNum = 'BACH' . date('YmdHis') . mt_rand(1000, 9999);
  201. //
  202. // $batchStats = [
  203. // 'total_quantity' => 0, // 总产品数量
  204. // 'total_boxes' => 0, // 总箱数
  205. // 'total_pallets' => 0, // 总托盘数
  206. // 'full_pallets' => 0, // 完整托盘数
  207. // 'partial_pallets' => 0, // 不完整托盘数
  208. // 'product_varieties' => count($data['products']) // 产品种类数
  209. // ];
  210. //
  211. // $productDetails = []; // 产品主表数据
  212. // $palletDetails = []; // 托盘明细数据
  213. // $currentPalletNo = 1; // 托盘编号计数器
  214. //
  215. // /**
  216. // * 处理完整托盘
  217. // * 先分配完整托盘
  218. // */
  219. // foreach ($data['products'] as $product) {
  220. // // 6.1 动态获取托盘配置
  221. // $tray_count = $product['tray_count'] ?? 18; // 默认18箱/托盘
  222. //
  223. // // 6.2 根据托盘配置确定层数和每层箱数
  224. // if ($tray_count == 18) {
  225. // $box_num = 3; // 3层
  226. // $per_box = 6; // 每层6箱
  227. // } elseif ($tray_count == 24) {
  228. // $box_num = 4; // 4层
  229. // $per_box = 6; // 每层6箱
  230. // } elseif ($tray_count == 36) {
  231. // $box_num = 4; // 4层
  232. // $per_box = 9; // 每层9箱
  233. // } else {
  234. // $this->error('不支持的托盘配置:' . $tray_count);
  235. // }
  236. //
  237. // $boxes_per_pallet = $per_box * $box_num; // 每托盘总箱数
  238. // $small_num = $product['items_per_box'] ?? 20; // 每箱数量,默认20
  239. // $default_layer_height = $product['default_layer_height'] ?? '1.35'; // 默认层高
  240. //
  241. // // 6.3 计算实际发货数量(不超过剩余数量)
  242. // $remaining = (int)$product['remaining_quantity'];
  243. // $actual = isset($product['actual_quantity']) ?
  244. // min((int)$product['actual_quantity'], $remaining) : $remaining;
  245. //
  246. // // 6.4 计算托盘分配
  247. // $total_boxes = ceil($actual / $small_num); // 总箱数
  248. // $full_pallets = floor($total_boxes / $boxes_per_pallet); // 完整托盘数
  249. // $remaining_boxes = $total_boxes % $boxes_per_pallet; // 剩余箱数
  250. //
  251. // // 6.5 构建产品基础信息
  252. // $baseInfo = [
  253. // 'bach_ids' => $bachNum,
  254. // 'userid' => $userinfo['id'],
  255. // 'gdbh' => $product['gdbh'],
  256. // 'order_ddbh' => $product['order_ddbh'],
  257. // 'cpbm' => $product['cpbm'],
  258. // 'cpmc' => $product['cpmc'],
  259. // 'matter_name' => $product['cpmc'],
  260. // 'remark' => $product['remark'] ?? '',
  261. // 'small_num' => $small_num,
  262. // 'unit' => $product['unit'] ?? '套',
  263. // 'tray_num' => $per_box,
  264. // 'box_num' => $box_num,
  265. // 'tray_count' => $tray_count,
  266. // 'layer_height' => $product['layer_height'] ?? $default_layer_height,
  267. // 'pallet_length' => $product['pallet_length'] ?? '0.9',
  268. // 'pallet_width' => $product['pallet_width'] ?? '1.2',
  269. // 'bach_status' => 0, // 状态(0:未处理)
  270. // 'sys_rq' => $currentDate,
  271. // 'created_at' => $currentDateTime,
  272. // 'create_time' => $timestamp,
  273. // 'delete_time' => ''
  274. // ];
  275. //
  276. // // 6.6 处理完整托盘
  277. // if ($full_pallets > 0) {
  278. // $full_qty = $full_pallets * $boxes_per_pallet * $small_num;
  279. // $endNo = $currentPalletNo + $full_pallets - 1;
  280. //
  281. // $productDetails[] = array_merge($baseInfo, [
  282. // 'actual_quantity' => $full_qty,
  283. // 'total_boxes' => $full_pallets * $boxes_per_pallet,
  284. // 'pallet_count' => $full_pallets,
  285. // 'pallet_type' => 'full',
  286. // 'pallet_range' => "$currentPalletNo-$endNo",
  287. // 'start_pallet_no' => $currentPalletNo,
  288. // 'end_pallet_no' => $endNo
  289. // ]);
  290. //
  291. // // 生成托盘明细记录
  292. // for ($i = 0; $i < $full_pallets; $i++) {
  293. // $palletDetails[] = [
  294. // 'bach_ids' => $bachNum,
  295. // 'product_id' => $product['gdbh'],
  296. // 'pallet_no' => $currentPalletNo + $i,
  297. // 'pallet_no_display' => $currentPalletNo + $i,
  298. // 'pallet_type' => 'full',
  299. // 'quantity' => $boxes_per_pallet * $small_num,
  300. // 'box_count' => $boxes_per_pallet,
  301. // 'layer_count' => $box_num,
  302. // 'bach_status' => 0,
  303. // 'created_at' => $currentDateTime,
  304. // 'delete_time' => ''
  305. // ];
  306. // }
  307. //
  308. // // 更新统计信息
  309. // $batchStats['full_pallets'] += $full_pallets;
  310. // $batchStats['total_quantity'] += $full_qty;
  311. // $batchStats['total_boxes'] += $full_pallets * $boxes_per_pallet;
  312. // $currentPalletNo += $full_pallets;
  313. // $batchStats['total_pallets'] += $full_pallets;
  314. // }
  315. // }
  316. //
  317. // /**
  318. // * 处理不完整托盘
  319. // * 分配剩余不能组成完整托盘的部分
  320. // */
  321. // foreach ($data['products'] as $product) {
  322. // // 同上获取托盘配置
  323. // $tray_count = $product['tray_count'] ?? 18;
  324. //
  325. // if ($tray_count == 18) {
  326. // $box_num = 3;
  327. // $per_box = 6;
  328. // } elseif ($tray_count == 24) {
  329. // $box_num = 4;
  330. // $per_box = 6;
  331. // } elseif ($tray_count == 36) {
  332. // $box_num = 4;
  333. // $per_box = 9;
  334. // } else {
  335. // continue; // 已在前阶段验证过,这里跳过
  336. // }
  337. //
  338. // $boxes_per_pallet = $per_box * $box_num;
  339. // $small_num = $product['items_per_box'] ?? 20;
  340. // $default_layer_height = $product['default_layer_height'] ?? '1.35';
  341. //
  342. // $remaining = (int)$product['remaining_quantity'];
  343. // $actual = isset($product['actual_quantity']) ?
  344. // min((int)$product['actual_quantity'], $remaining) : $remaining;
  345. //
  346. // $total_boxes = ceil($actual / $small_num);
  347. // $full_pallets = floor($total_boxes / $boxes_per_pallet);
  348. // $remaining_boxes = $total_boxes % $boxes_per_pallet;
  349. //
  350. // $baseInfo = [
  351. // 'bach_ids' => $bachNum,
  352. // 'userid' => $userinfo['id'],
  353. // 'gdbh' => $product['gdbh'],
  354. // 'order_ddbh' => $product['order_ddbh'],
  355. // 'cpbm' => $product['cpbm'],
  356. // 'cpmc' => $product['cpmc'],
  357. // 'matter_name' => $product['cpmc'],
  358. // 'remark' => $product['remark'] ?? '',
  359. // 'small_num' => $small_num,
  360. // 'unit' => $product['unit'] ?? '套',
  361. // 'tray_num' => $per_box,
  362. // 'box_num' => $box_num,
  363. // 'tray_count' => $tray_count,
  364. // 'layer_height' => $product['layer_height'] ?? $default_layer_height,
  365. // 'pallet_length' => $product['pallet_length'] ?? '0.9',
  366. // 'pallet_width' => $product['pallet_width'] ?? '1.2',
  367. // 'bach_status' => 0,
  368. // 'sys_rq' => $currentDate,
  369. // 'created_at' => $currentDateTime,
  370. // 'create_time' => $timestamp,
  371. // 'delete_time' => ''
  372. // ];
  373. //
  374. // // 处理不完整托盘
  375. // if ($remaining_boxes > 0) {
  376. // $partial_qty = $remaining_boxes * $small_num;
  377. //
  378. // $productDetails[] = array_merge($baseInfo, [
  379. // 'actual_quantity' => $partial_qty,
  380. // 'total_boxes' => $remaining_boxes,
  381. // 'pallet_count' => 1,
  382. // 'pallet_type' => 'partial',
  383. // 'pallet_range' => (string)$currentPalletNo,
  384. // 'start_pallet_no' => $currentPalletNo,
  385. // 'end_pallet_no' => $currentPalletNo
  386. // ]);
  387. //
  388. // $palletDetails[] = [
  389. // 'bach_ids' => $bachNum,
  390. // 'product_id' => $product['gdbh'],
  391. // 'pallet_no' => $currentPalletNo,
  392. // 'pallet_no_display' => $currentPalletNo,
  393. // 'pallet_type' => 'partial',
  394. // 'quantity' => $partial_qty,
  395. // 'box_count' => $remaining_boxes,
  396. // 'layer_count' => ceil($remaining_boxes / $per_box),
  397. // 'bach_status' => 0,
  398. // 'created_at' => $currentDateTime,
  399. // 'delete_time' => ''
  400. // ];
  401. //
  402. // // 更新统计信息
  403. // $batchStats['partial_pallets']++;
  404. // $batchStats['total_quantity'] += $partial_qty;
  405. // $batchStats['total_boxes'] += $remaining_boxes;
  406. // $currentPalletNo++;
  407. // $batchStats['total_pallets']++;
  408. // }
  409. // }
  410. //
  411. // $summaryData = [
  412. // 'bach_ids' => $bachNum,
  413. // 'userid' => $userinfo['id'],
  414. // 'total_quantity' => $batchStats['total_quantity'],
  415. // 'total_boxes' => $batchStats['total_boxes'],
  416. // 'total_pallets' => $batchStats['total_pallets'],
  417. // 'product_count' => $batchStats['product_varieties'],
  418. // 'full_pallets' => $batchStats['full_pallets'],
  419. // 'partial_pallets' => $batchStats['partial_pallets'],
  420. // 'bach_status' => 0,
  421. // 'sys_rq' => $currentDate,
  422. // 'created_at' => $currentDateTime,
  423. // 'create_time' => $timestamp,
  424. // 'delete_time' => ''
  425. // ];
  426. //
  427. //
  428. // // 写入产品主表
  429. // $mongo->name($collection)->insertAll($productDetails);
  430. //
  431. // // 写入托盘明细表
  432. // $mongo->name($bachdetails)->insertAll($palletDetails);
  433. //
  434. // // 写入批次汇总表
  435. // $mongo->name($bachsummary)->insert($summaryData);
  436. //
  437. //
  438. // foreach ($data['products'] as $product) {
  439. // $where = [
  440. // 'gdbh' => $product['gdbh'],
  441. // 'order_ddbh' => $product['order_ddbh'],
  442. // 'cpmc' => $product['cpmc'],
  443. // ];
  444. //
  445. // $actual = (int)($product['actual_quantity'] ?? 0);
  446. // $remaining = (int)$product['remaining_quantity'];
  447. //
  448. // // 查询现有库存记录
  449. // $existing = $mongo->name('inventory_summary')->where($where)->find();
  450. //
  451. // if ($existing) {
  452. // // 处理查询结果
  453. // if (is_object($existing)) {
  454. // $existing = (array)$existing;
  455. // }
  456. // if (isset($existing[0])) {
  457. // $existing = $existing[0];
  458. // }
  459. //
  460. // // 更新库存
  461. // $mongo->name('inventory_summary')
  462. // ->where($where)
  463. // ->update([
  464. // 'total_chu_quantity' => ($existing['total_chu_quantity'] ?? 0) + $actual,
  465. // 'remaining_quantity' => ($existing['remaining_quantity'] ?? 0) - $actual,
  466. // 'updated_at' => $currentDateTime,
  467. // ]);
  468. // } else {
  469. // // 新增库存记录
  470. // $mongo->name('inventory_summary')->insert([
  471. // 'gdbh' => $product['gdbh'],
  472. // 'order_ddbh' => $product['order_ddbh'],
  473. // 'cpbm' => $product['cpbm'],
  474. // 'cpmc' => $product['cpmc'],
  475. // 'total_ru_quantity' => $remaining,
  476. // 'total_chu_quantity' => $actual,
  477. // 'remaining_quantity' => $remaining - $actual,
  478. // 'created_at' => $currentDateTime,
  479. // 'company' => $data['company_name'] ?? '',
  480. // ]);
  481. // }
  482. //
  483. // // 添加库存记录
  484. // $mongo->name('inventory_records')->insert([
  485. // 'gdbh' => $product['gdbh'],
  486. // 'order_ddbh' => $product['order_ddbh'],
  487. // 'cpbm' => $product['cpbm'],
  488. // 'cpmc' => $product['cpmc'],
  489. // 'operation_type' => 'outbound',
  490. // 'quantity' => $actual,
  491. // 'remaining_quantity' => $remaining - $actual,
  492. // 'operator' => $userinfo['id'],
  493. // 'created_at' => $currentDateTime,
  494. // 'batch_number' => $bachNum,
  495. // 'company' => $data['company_name'] ?? '',
  496. // ]);
  497. // }
  498. // $this->success('批次创建成功');
  499. // }
  500. public function add_bach()
  501. {
  502. if (!$this->request->isAjax()) {
  503. $this->error('非法请求,必须使用AJAX方式提交');
  504. }
  505. $data = input('row');
  506. if (empty($data)) {
  507. $this->error('请求参数不能为空');
  508. }
  509. $data = json_decode($data, true);
  510. if (json_last_error() !== JSON_ERROR_NONE) {
  511. $this->error('JSON数据解析失败:' . json_last_error_msg());
  512. }
  513. if (empty($data['products']) || !is_array($data['products'])) {
  514. $this->error('产品数据不能为空且必须是数组');
  515. }
  516. $userinfo = Session::get('admin');
  517. if (empty($userinfo) || !isset($userinfo['company'])) {
  518. $this->error('获取用户信息失败,请重新登录');
  519. }
  520. $mongo = \think\Db::connect('mongodb');
  521. $collection = $userinfo['company'] . '_qcode_bach';
  522. $bachdetails = $userinfo['company'] . '_qcode_bachdetails';
  523. $bachsummary = $userinfo['company'] . '_qcode_bachsummary';
  524. $currentDate = date('Y-m-d');
  525. $currentDateTime = date('Y-m-d H:i:s');
  526. $timestamp = time();
  527. $bachNum = 'BACH' . date('YmdHis') . mt_rand(1000, 9999);
  528. $batchStats = [
  529. 'total_quantity' => 0,
  530. 'total_boxes' => 0,
  531. 'total_pallets' => 0,
  532. 'full_pallets' => 0,
  533. 'partial_pallets' => 0,
  534. 'product_varieties' => count($data['products'])
  535. ];
  536. $productDetails = [];
  537. $palletDetails = [];
  538. $currentPalletNo = 1;
  539. foreach ($data['products'] as $product) {
  540. $tray_count = $product['tray_count'] ?? 18;
  541. if ($tray_count == 18) {
  542. $box_num = 3;
  543. $per_box = 6;
  544. } elseif ($tray_count == 24) {
  545. $box_num = 4;
  546. $per_box = 6;
  547. } elseif ($tray_count == 36) {
  548. $box_num = 4;
  549. $per_box = 9;
  550. } else {
  551. $this->error('不支持的托盘配置:' . $tray_count);
  552. }
  553. $boxes_per_pallet = $per_box * $box_num;
  554. $small_num = $product['items_per_box'] ?? 20;
  555. $default_layer_height = $product['default_layer_height'] ?? '1.35';
  556. $remaining = (int)$product['remaining_quantity'];
  557. $actual = isset($product['actual_quantity']) ? min((int)$product['actual_quantity'], $remaining) : $remaining;
  558. $full_pallets = floor($actual / ($boxes_per_pallet * $small_num));
  559. $full_qty = $full_pallets * $boxes_per_pallet * $small_num;
  560. $partial_qty = $actual - $full_qty;
  561. $remaining_boxes = ceil($partial_qty / $small_num);
  562. $baseInfo = [
  563. 'bach_ids' => $bachNum,
  564. 'userid' => $userinfo['id'],
  565. 'gdbh' => $product['gdbh'],
  566. 'order_ddbh' => $product['order_ddbh'],
  567. 'cpbm' => $product['cpbm'],
  568. 'cpmc' => $product['cpmc'],
  569. 'matter_name' => $product['cpmc'],
  570. 'remark' => $product['remark'] ?? '',
  571. 'small_num' => $small_num,
  572. 'unit' => $product['unit'] ?? '套',
  573. 'tray_num' => $per_box,
  574. 'box_num' => $box_num,
  575. 'tray_count' => $tray_count,
  576. 'layer_height' => $product['layer_height'] ?? $default_layer_height,
  577. 'pallet_length' => $product['pallet_length'] ?? '0.9',
  578. 'pallet_width' => $product['pallet_width'] ?? '1.2',
  579. 'bach_status' => 0,
  580. 'sys_rq' => $currentDate,
  581. 'created_at' => $currentDateTime,
  582. 'create_time' => $timestamp,
  583. 'delete_time' => ''
  584. ];
  585. if ($full_pallets > 0) {
  586. $endNo = $currentPalletNo + $full_pallets - 1;
  587. $productDetails[] = array_merge($baseInfo, [
  588. 'actual_quantity' => $full_qty,
  589. 'total_boxes' => $full_pallets * $boxes_per_pallet,
  590. 'pallet_count' => $full_pallets,
  591. 'pallet_type' => 'full',
  592. 'pallet_range' => "$currentPalletNo-$endNo",
  593. 'start_pallet_no' => $currentPalletNo,
  594. 'end_pallet_no' => $endNo
  595. ]);
  596. for ($i = 0; $i < $full_pallets; $i++) {
  597. $palletDetails[] = [
  598. 'bach_ids' => $bachNum,
  599. 'code' => 'AB92' . $userinfo['printer_code'] . $product['cpbm'] . '0000000000' . date('Ymd') . $product['gdbh'] . date('Ymd') . '00000000000',
  600. 'product_id' => $product['gdbh'],
  601. 'pallet_no' => $currentPalletNo + $i,
  602. 'pallet_no_display' => $currentPalletNo + $i,
  603. 'pallet_type' => 'full',
  604. 'quantity' => $boxes_per_pallet * $small_num,
  605. 'box_count' => $boxes_per_pallet,
  606. 'per_box' => $per_box,
  607. 'box_num' => $box_num,
  608. 'bach_status' => 0,
  609. 'created_time' => $currentDate,
  610. 'created_at' => $currentDateTime,
  611. 'delete_time' => ''
  612. ];
  613. }
  614. $batchStats['full_pallets'] += $full_pallets;
  615. $batchStats['total_quantity'] += $full_qty;
  616. $batchStats['total_boxes'] += $full_pallets * $boxes_per_pallet;
  617. $currentPalletNo += $full_pallets;
  618. $batchStats['total_pallets'] += $full_pallets;
  619. }
  620. if ($partial_qty > 0) {
  621. $productDetails[] = array_merge($baseInfo, [
  622. 'actual_quantity' => $partial_qty,
  623. 'total_boxes' => $remaining_boxes,
  624. 'pallet_count' => 1,
  625. 'pallet_type' => 'partial',
  626. 'pallet_range' => (string)$currentPalletNo,
  627. 'start_pallet_no' => $currentPalletNo,
  628. 'end_pallet_no' => $currentPalletNo
  629. ]);
  630. $palletDetails[] = [
  631. 'bach_ids' => $bachNum,
  632. 'code' => 'AB92' . $userinfo['printer_code'] . $product['cpbm'] . '0000000000' . date('Ymd') . $product['gdbh'] . date('Ymd') . '00000000000',
  633. 'product_id' => $product['gdbh'],
  634. 'pallet_no' => $currentPalletNo,
  635. 'pallet_no_display' => $currentPalletNo,
  636. 'pallet_type' => 'partial',
  637. 'quantity' => $partial_qty,
  638. 'box_count' => $remaining_boxes,
  639. 'per_box' => $per_box,
  640. 'box_num' => $box_num,
  641. 'bach_status' => 0,
  642. 'created_time' => $currentDate,
  643. 'created_at' => $currentDateTime,
  644. 'delete_time' => ''
  645. ];
  646. $batchStats['partial_pallets']++;
  647. $batchStats['total_quantity'] += $partial_qty;
  648. $batchStats['total_boxes'] += $remaining_boxes;
  649. $currentPalletNo++;
  650. $batchStats['total_pallets']++;
  651. }
  652. }
  653. $summaryData = [
  654. 'bach_ids' => $bachNum,
  655. 'userid' => $userinfo['id'],
  656. 'total_quantity' => $batchStats['total_quantity'],
  657. 'total_boxes' => $batchStats['total_boxes'],
  658. 'total_pallets' => $batchStats['total_pallets'],
  659. 'product_count' => $batchStats['product_varieties'],
  660. 'full_pallets' => $batchStats['full_pallets'],
  661. 'partial_pallets' => $batchStats['partial_pallets'],
  662. 'bach_status' => 0,
  663. 'sys_rq' => $currentDate,
  664. 'created_at' => $currentDateTime,
  665. 'create_time' => $timestamp,
  666. 'delete_time' => ''
  667. ];
  668. $mongo->name($collection)->insertAll($productDetails);
  669. $mongo->name($bachdetails)->insertAll($palletDetails);
  670. $mongo->name($bachsummary)->insert($summaryData);
  671. // 库存更新部分(未改动)
  672. foreach ($data['products'] as $product) {
  673. $where = [
  674. 'gdbh' => $product['gdbh'],
  675. 'order_ddbh' => $product['order_ddbh'],
  676. 'cpmc' => $product['cpmc'],
  677. ];
  678. $actual = (int)($product['actual_quantity'] ?? 0);
  679. $remaining = (int)$product['remaining_quantity'];
  680. $existing = $mongo->name('inventory_summary')->where($where)->find();
  681. if ($existing) {
  682. if (is_object($existing)) $existing = (array)$existing;
  683. if (isset($existing[0])) $existing = $existing[0];
  684. $mongo->name('inventory_summary')
  685. ->where($where)
  686. ->update([
  687. 'total_chu_quantity' => ($existing['total_chu_quantity'] ?? 0) + $actual,
  688. 'remaining_quantity' => ($existing['remaining_quantity'] ?? 0) - $actual,
  689. 'updated_at' => $currentDateTime,
  690. ]);
  691. } else {
  692. $mongo->name('inventory_summary')->insert([
  693. 'gdbh' => $product['gdbh'],
  694. 'order_ddbh' => $product['order_ddbh'],
  695. 'cpbm' => $product['cpbm'],
  696. 'cpmc' => $product['cpmc'],
  697. 'total_ru_quantity' => $remaining,
  698. 'total_chu_quantity' => $actual,
  699. 'remaining_quantity' => $remaining - $actual,
  700. 'created_at' => $currentDateTime,
  701. 'company' => $data['company_name'] ?? '',
  702. ]);
  703. }
  704. $mongo->name('inventory_records')->insert([
  705. 'gdbh' => $product['gdbh'],
  706. 'order_ddbh' => $product['order_ddbh'],
  707. 'cpbm' => $product['cpbm'],
  708. 'cpmc' => $product['cpmc'],
  709. 'operation_type' => 'outbound',
  710. 'total_ru_quantity' => $remaining,
  711. 'total_chu_quantity' => $actual,
  712. 'remaining_quantity' => $remaining - $actual,
  713. 'operator' => $userinfo['id'],
  714. 'created_at' => $currentDateTime,
  715. 'batch_number' => $bachNum,
  716. 'company' => $data['company_name'] ?? '',
  717. ]);
  718. }
  719. $this->success('批次创建成功');
  720. }
  721. /**
  722. * 增加新批次
  723. */
  724. public function add()
  725. {
  726. $product = new QcodeProduct();
  727. $bach = new QcodeBach();
  728. $large = new QcodeLarge();
  729. $small = new QcodeSmall();
  730. $liushui = new QcodeLiushui();
  731. $resetFlow = new ResetFlow();
  732. $QcodeCompany = new QcodeCompany();
  733. if ($this->request->isAjax() === false){
  734. $this->error('请求错误');
  735. }
  736. $rows = input('row');
  737. if (empty($rows)){
  738. $this->error('参数错误');
  739. }
  740. $rows = json_decode($rows);
  741. $data = [];
  742. foreach ($rows as $value){
  743. foreach ($value as $k=>$v){
  744. $data[$k] = $v;
  745. }
  746. }
  747. // echo "接口获取";echo "<pre>";print_r($data);echo "<pre>";die;
  748. //记录库存操作
  749. $mongo = \think\Db::connect('mongodb');
  750. $where = [
  751. 'gdbh' => $data['gdbh'],
  752. 'order_ddbh' => $data['order_ddbh'],
  753. 'cpmc' => $data['cpmc'],
  754. ];
  755. //插入字段[inventory_summaryk库存明细]
  756. $insertData = [
  757. 'gdbh' => $data['gdbh'],
  758. 'order_ddbh' => $data['order_ddbh'],
  759. 'cpbm' => $data['cpbm'],
  760. 'cpmc' => $data['cpmc'],
  761. 'total_ru_quantity' => $data['sl'],//入库数
  762. 'total_chu_quantity' => $data['number'],//出库数
  763. 'remaining_quantity' => $data['remaining_quantity'] - $data['number'],//剩余数
  764. 'created_at' => date('Y-m-d H:i:s'),
  765. 'updated_at' => '',
  766. 'mod_rq' => '',
  767. 'company' => '',
  768. ];
  769. // 查询库存汇总表数据是否存在记录
  770. $list = $mongo->name('inventory_summary')->where($where)->find();
  771. if ($list) {
  772. // 如果数据存在,更新库存汇总记录
  773. $chu = $list['total_chu_quantity'] + $data['number'];//累计出库数量
  774. $jiecun = $list['remaining_quantity'] - $data['number'];//剩余结存数量
  775. $updateResult = $mongo->name('inventory_summary')
  776. ->where($where)
  777. ->update([
  778. 'total_ru_quantity' => $data['sl'],
  779. 'total_chu_quantity' => $chu,
  780. 'remaining_quantity' => $jiecun,
  781. 'updated_at' => date('Y-m-d H:i:s'),
  782. ]);
  783. } else {
  784. // 数据不存在则插入新记录
  785. $mongo->name('inventory_summary')->insert($insertData);
  786. }
  787. //记录库存明细
  788. $mongo->name('inventory_records')->insert($insertData);
  789. // // 调试输出
  790. // echo "<pre>"; print_r($list); echo "</pre>";die;
  791. switch ($data['danwei']) {
  792. case 1:
  793. $danwei = '个';
  794. break;
  795. case 2:
  796. $danwei = '套';
  797. break;
  798. case 3:
  799. $danwei = '张';
  800. break;
  801. default:
  802. $danwei = '';
  803. break;
  804. }
  805. $userinfo = Session::get('admin');//获取用户信息
  806. $arr = [
  807. 'batch' => $data['gdbh'],
  808. 'create_time' => time(),
  809. 'delect_time' => '',
  810. 'sync_flag' => 0,
  811. ];
  812. $productres = $QcodeCompany->save($arr);
  813. if ($productres === 0){
  814. $this->error('添加失败');
  815. }
  816. $batchList = [
  817. 'userid' => $userinfo['id'],//登录用户id
  818. 'supplier_id' => $userinfo['id'],//登录用户id
  819. 'supplier_code' => $userinfo['printer_code'],
  820. 'supplier_name' => $data['company_name'],//公司名称
  821. 'cpbm' => $data['cpbm'],//成品编码
  822. 'matter_name' => $data['cpmc'],//成品名称
  823. 'matter_no' => $data['gdbh'],//生产批次号-工单编号
  824. 'order_ddbh' => $data['order_ddbh'],//销售订单号
  825. 'matter_id' => $data['gdbh'],
  826. 'matter_type' => '01',
  827. 'manufacture_date' => (int)date('ymd',strtotime($data['manufacture_date'])),//生产日期
  828. 'print_date' => (int)date('ymd',strtotime($data['print_date'])),//打码日期
  829. 'num_danwei' => $data['danwei'],//单位
  830. 'danwei' => $danwei,//单位
  831. 'num' => $data['number'],//总数量(张/个)
  832. 'small_num' => $data['box_number'],//每一箱数量
  833. 'tray_num' => $data['tray_num'],//每层箱数【箱/层】
  834. 'box_num' => $data['tray_number'],//每托层数【 层/托】
  835. 'total_boxes' => $data['total_boxes'],//每托盘箱数【箱/托】
  836. 'large_num' => $data['box_num'],//本次打包托盘数
  837. 'larger_num' => $data['small_num'],//总箱数
  838. 'pallet_height' => $data['pallet_height'],//每托高度
  839. 'pallet_length' => $data['pallet_length'],//托盘规格
  840. 'pallet_width' => $data['pallet_width'],//托盘规格
  841. 'l_reservation' => '',
  842. // 处理可能为空的流水/重量字段
  843. 'l_flow' => $data['big_liushui'],//大件流水
  844. 'l_weight' => $data['big_weight'],//大件重量
  845. 's_flow' => $data['small_start_liushui'],//小件流水
  846. 's_weight' => $data['small_weight'],//小件重量
  847. 's_reservation' => '',
  848. 'bach_status' => 0,
  849. 'bach_num' => $data['gdbh'],//生产批次号-工单编号
  850. 'large_endnum' => $data['big_liushui'] + $data['box_num'] -1,
  851. 'create_time' => time(),//新增时间
  852. 'delect_time' => '',//删除时间
  853. ];
  854. $res = $bach->save($batchList);
  855. if ($res === 0){
  856. $this->error('添加失败');
  857. }
  858. $flow = [
  859. 'l_flow' => (int)$batchList['large_num'],
  860. 'bach_num' => $batchList['matter_no'],
  861. ];
  862. if ($resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_no'])->find()){
  863. $resetFlow->name($userinfo['company'].'_'."reset_flow")->where('product_id',$batchList['matter_no'])->update($flow);
  864. }else{
  865. $flow['product_id'] = $batchList['matter_no'];
  866. $resetFlow->save($flow);
  867. }
  868. $last_id = $bach->getLastInsID();
  869. if ($last_id){
  870. //插入大小二维码数据 二维码数据不变区域
  871. // echo "<pre>";print_r($batchList);echo "<pre>";die;
  872. $fixed_code = '';
  873. $fixed_code.=$this->intTochar($batchList['matter_type'],2);//2位 辅料种类编码
  874. $fixed_code .= $this->intTochar($batchList['supplier_code'], 21);//21位 供应商编码
  875. $fixed_code .= '9'; // 补0一位
  876. $fixed_code.=$this->intTochar($batchList['cpbm'],10);//10位 辅料编码
  877. $fixed_code.=$batchList['manufacture_date'];//6位 生产日期
  878. $print_code=$batchList['print_date'];//6位 打码日期
  879. $small_liushui = [
  880. 'onlycode' => 'AB92'.$fixed_code.$print_code,
  881. 'last_num' => 0,
  882. 'user_id' => $userinfo['company'],
  883. 'stype' => 2,
  884. 'dateTime' => time(),
  885. ];
  886. $whereSmall = [
  887. 'onlycode' => $small_liushui['onlycode'],
  888. 'user_id' => $userinfo['company'],
  889. ];
  890. if ($liushui->name($userinfo['company'].'_'.'qcode_liushui')->where($whereSmall)->find()){
  891. //小件二维码存在,更新小件二维码最后流水号
  892. $lastNum = $liushui->name($userinfo['company'].'_'.'qcode_liushui')->where($whereSmall)->find();
  893. }else{
  894. //小件二维码不存在,新增记录
  895. $liushui->save($small_liushui);
  896. $lastNum['last_num'] = 0;
  897. }
  898. //循环插入大件二维码数据
  899. for ($i=0;$i<$data['box_num'];$i++){
  900. $large = new QcodeLarge();
  901. $l_flow = $this->intTochar($batchList['l_flow']+$i,6);
  902. $l_weight = $this->intTochar($batchList['l_weight']*100,6);
  903. $l_reservation = $this->intTochar($batchList['matter_no'],10);
  904. $l_reservation = $l_reservation.'0000000000';
  905. $remainder = $batchList['num'] - $batchList['total_boxes'] * $i;//最后一托盘小件数量
  906. if ($remainder < $batchList['tray_num']){
  907. $small_n = $this->intTochar($remainder,3);//3位小件数量,不足补0
  908. }else{
  909. $small_n = $this->intTochar($batchList['tray_num'],3);
  910. }
  911. // $l_num = $small_n * $batchList['box_num'];
  912. $l_num = 0;
  913. //大件二维码数据
  914. $code_data = $this->CodeData('AB92',$fixed_code,$small_n,$print_code,$l_flow,$l_weight,'2',$l_reservation);
  915. //大码数据信息
  916. $l_data = [
  917. 'bach_id' => $last_id,
  918. 'code' => $code_data['code'],
  919. 'code_cp1' => $code_data['code_cp1'],
  920. 'code_cp2' => $code_data['code_cp2'],
  921. 'print_date' => $print_code,
  922. 'create_time' => time(),
  923. 'p_nums' => 0,
  924. 'userid' =>$userinfo['id'],
  925. 'l_weight' =>$batchList['l_weight']*100,
  926. 'l_num' =>$l_num,
  927. 'l_status' => 0,
  928. 'l_print' => 0
  929. ];
  930. $l_res = $large->save($l_data);
  931. if ($l_res === 0){
  932. $this->error('大件码插入失败');
  933. }
  934. $large_id = $large->getLastInsID();
  935. if ($large_id){
  936. // //小件码循环插入
  937. // for ($j=0;$j<$data['tray_num'] and ($j+$i*$data['tray_num'])<$batchList['small_num'];$j++){
  938. for ($j=0;$j<$data['total_boxes'] and ($j+$i*$data['total_boxes'])<$batchList['total_boxes'];$j++){
  939. $small = new QcodeSmall();
  940. $s_flow = $this->intTochar($batchList['s_flow']+$j+$i*$data['tray_num']+$lastNum['last_num'],6);//小件码序号从1开始
  941. $s_weight = $this->intTochar($batchList['s_weight'],6);
  942. $small_sign = '000';
  943. $s_reservation = $this->intTochar($batchList['bach_num'],10);
  944. $s_reservation = $s_reservation . '0000000000';
  945. //生成小件码
  946. $small_code_data = $this->CodeData('AB92',$fixed_code,$small_sign,$print_code,$s_flow,$s_weight,'1',$s_reservation);
  947. //小码数据
  948. $s_data = [
  949. 'large_id'=>$large_id,
  950. 'bach_id'=>$last_id,
  951. 'code'=>$small_code_data['code'],
  952. 'code_cp1'=>$small_code_data['code_cp1'],
  953. 'code_cp2'=>$small_code_data['code_cp2'],
  954. 'l_flow'=>$j+1,
  955. 'print_date'=>$print_code,
  956. 'create_time'=>time(),
  957. 'p_nums'=>0,
  958. 'userid'=>$userinfo['id'],//小码绑定用户id
  959. 's_weight'=>$batchList['s_weight'],//单个小件重量
  960. 'status' => 0,
  961. ];
  962. $s_res = $small->save($s_data);
  963. if ($s_res === 0){
  964. $this->error('小件码插入失败');
  965. }
  966. }
  967. }else{
  968. $this->error('添加失败');
  969. }
  970. }
  971. }
  972. $liushui_res = $liushui->name($userinfo['id'].'_'.'qcode_liushui')->where($whereSmall)->update(['last_num'=>$batchList['small_num']]);
  973. if ($liushui_res === false){
  974. $this->error('添加失败');
  975. }
  976. return json(['code' => 1, 'msg' => '成功', 'data' => '']);
  977. // $this->success('成功');
  978. }
  979. /**
  980. * 编码补位
  981. * @param $num
  982. * @param $len
  983. * @return string
  984. */
  985. function intTochar($num=0,$len){
  986. //规定的不足的时候自动补足零
  987. $code=(string)$num;
  988. $buwei='';
  989. if(strlen($code)<$len){
  990. for($i=strlen($code);$i<$len;$i++){
  991. $buwei.='0';
  992. }
  993. }
  994. return $buwei.$code;
  995. }
  996. /**
  997. * 二维码编码生成
  998. * @param $sign
  999. * @param $fixed_code
  1000. * @param $small_num
  1001. * @param $print_date
  1002. * @param $flow
  1003. * @param $weight
  1004. * @param $large_sign
  1005. * @param $reservation
  1006. * @return array
  1007. */
  1008. function CodeData($sign,$fixed_code,$small_num,$print_date,$flow,$weight,$large_sign,$reservation){
  1009. $code=$sign;//4 位固定标志位
  1010. $code.=$fixed_code; // 固定字符串
  1011. $code.=$small_num;//3位 小件数量
  1012. $code.=$print_date;//6 位 日期
  1013. $code.=$flow;//6位打印流水号
  1014. $code.=$weight;//6位辅料重量
  1015. $code.=$large_sign;//大小件标示位
  1016. $code.=$reservation;//20 位 预留号
  1017. //大码数据信息
  1018. $data=[
  1019. 'code'=>str_replace(" ","",$code),
  1020. 'code_cp1'=>$print_date.$flow,
  1021. 'code_cp2'=>$weight.$reservation,//20位补充
  1022. 'print_date'=>time(),
  1023. 'p_nums'=>0,
  1024. ];
  1025. return $data;
  1026. }
  1027. }