Deliver.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\QcodeLarge;
  4. use app\admin\model\QcodeSmall;
  5. use app\common\controller\Backend;
  6. use app\admin\model\QcodeProduct;
  7. use app\admin\model\QcodeCompany;
  8. use app\admin\model\QcodeBach;
  9. use app\admin\model\QcodeExport;
  10. use fast\Arr;
  11. use PhpOffice\PhpSpreadsheet\IOFactory;
  12. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  13. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  14. use PhpOffice\PhpSpreadsheet\Exception;
  15. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  16. use app\admin\model\QcodeGoods;
  17. use think\Config;
  18. use think\Session;
  19. class Deliver extends Backend
  20. {
  21. /**
  22. * 首页
  23. */
  24. public function index()
  25. {
  26. return $this->view->fetch();
  27. }
  28. /**
  29. * 大件发货
  30. */
  31. // public function lager()
  32. // {
  33. //
  34. // $company = new QcodeCompany();
  35. // $product = new QcodeProduct();
  36. // $large = new QcodeLarge();
  37. // $bach = new QcodeBach();
  38. // $small = new QcodeSmall();
  39. //
  40. // $this->request->filter(['strip_tags', 'trim']);
  41. //
  42. // if (false === $this->request->isAjax()) {
  43. // return $this->view->fetch();
  44. // }
  45. //
  46. // if ($this->request->request('keyField')) {
  47. // return $this->selectpage();
  48. // }
  49. //
  50. // $userInfo = Session::get('admin');
  51. // $where = ['delete_time'=> ''];
  52. // $filter = input('filter');
  53. // $filter = json_decode($filter, true);
  54. //
  55. // $whereList = ['delete_time'=>''];
  56. //
  57. // if (isset($filter['matter_name'])){
  58. // $whereList['matter_no'] = $filter['matter_name'];
  59. // }
  60. // if (isset($filter['bach'])){
  61. // $whereList['bach_num'] = $filter['bach'];
  62. // }
  63. // if (isset($filter['manufacture_date'])){
  64. // $begin = substr($filter['manufacture_date'], 0, 19);
  65. // $end = substr($filter['manufacture_date'], 22);
  66. // $begin = (int)date('ymd', strtotime($begin));
  67. // $end = (int)date('ymd', strtotime($end));
  68. // $whereList['manufacture_date'] = ['between', [$begin, $end]];
  69. // }
  70. //
  71. // // 查出相关 bach_id
  72. // $bach_list = $bach->name($userInfo['company'].'_qcode_bach')->where($whereList)->column('_id');
  73. // $bach_id = [];
  74. // foreach ($bach_list as $v){
  75. // $id = substr(json_encode($v), 9, -2);
  76. // $bach_id[] = $id;
  77. // }
  78. //
  79. //// // 获取分页参数
  80. // $offset = input('offset', 0); // 当前页数
  81. // $limit = input('limit', 10); // 每页多少条
  82. //
  83. // // 总数量
  84. // $total = $large->name($userInfo['company'].'_qcode_large')
  85. // ->where('l_status', 0)
  86. // ->where($where)
  87. // ->whereIn('bach_id', $bach_id)
  88. // ->count();
  89. //
  90. // // 当前页数据
  91. // $large_list = $large->name($userInfo['company'].'_qcode_large')
  92. // ->where($where)
  93. // ->where('l_status', 0)
  94. // ->whereIn('bach_id', $bach_id)
  95. // ->limit($limit)
  96. // ->skip($offset)
  97. // ->select();
  98. //
  99. // // 数据处理
  100. // $list = [];
  101. // foreach ($large_list as $k => $v) {
  102. // $bach_detail = $bach->name($userInfo['company'].'_qcode_bach')->where('_id', $v['bach_id'])->find();
  103. //
  104. // $larger_num = (int)$bach_detail['larger_num']; // 总箱数
  105. // $boxes_per_pallet = (int)$bach_detail['total_boxes']; // 每托盘箱数
  106. // $small_num = (int)$bach_detail['small_num']; // 每箱数量
  107. //
  108. // // 计算总托盘数和最后一托的箱数
  109. // $full_pallets = floor($larger_num / $boxes_per_pallet);
  110. // $last_pallet_boxes = $larger_num % $boxes_per_pallet;
  111. // $total_pallets = $full_pallets + ($last_pallet_boxes > 0 ? 1 : 0);
  112. //
  113. // // 当前大件是第几托
  114. // $current_flow = (int) ltrim(substr($v['code'], 53, 6), '0');
  115. //
  116. // // 默认每托盘箱数
  117. // $total_boxes = $boxes_per_pallet;
  118. //
  119. // // 如果是最后一托且有余数,修正箱数
  120. // if ($current_flow === $total_pallets && $last_pallet_boxes > 0) {
  121. // $total_boxes = $last_pallet_boxes;
  122. // }
  123. //
  124. //
  125. // $list[$k]['id'] = substr(json_encode($v['_id']), 9, -2);
  126. // $list[$k]['l_flow'] = $bach_detail['l_flow'];
  127. // $list[$k]['bach'] = $bach_detail['bach_num'];
  128. // $list[$k]['num'] = $bach_detail['num'];
  129. // $list[$k]['small_num'] = $bach_detail['small_num'];
  130. // $list[$k]['order_ddbh'] = $bach_detail['order_ddbh'];
  131. //
  132. // $list[$k]['danwei'] = $bach_detail['danwei'];
  133. //
  134. // $list[$k]['cpbm'] = $bach_detail['cpbm'];
  135. // $list[$k]['matter_name'] = $bach_detail['matter_name'];
  136. //// $list[$k]['total_boxes'] = $bach_detail['total_boxes'];
  137. // $list[$k]['total_boxes'] = $total_boxes;
  138. // $list[$k]['tray_num'] = $bach_detail['tray_num'];
  139. // $list[$k]['box_num'] = $bach_detail['box_num'];
  140. // $list[$k]['pallet_height'] = $bach_detail['pallet_height'];
  141. // $list[$k]['pallet_length'] = $bach_detail['pallet_length'];
  142. // $list[$k]['pallet_width'] = $bach_detail['pallet_width'];
  143. // $list[$k]['larger_num'] = $bach_detail['larger_num'];
  144. // $list[$k]['manufacture_date'] = date('Y-m-d', strtotime('20'.$bach_detail['manufacture_date']));
  145. // $list[$k]['code'] = $v['code'];
  146. // $list[$k]['l_flow'] = ltrim(substr($v['code'], 53, 6), '0');
  147. //
  148. //// $small_num = $small->name($userInfo['company'].'_qcode_small')
  149. //// ->where('large_id', $list[$k]['id'])
  150. //// ->count();
  151. //// $list[$k]['small_num'] = $small_num;
  152. // }
  153. // // 总数与分页
  154. //// $list = array_slice($list, $offset, $limit);
  155. // return json(['total' => $total, 'rows' => $list]);
  156. // }
  157. public function lager()
  158. {
  159. $company = new QcodeCompany();
  160. $product = new QcodeProduct();
  161. $large = new QcodeLarge();
  162. $bach = new QcodeBach();
  163. $small = new QcodeSmall();
  164. $this->request->filter(['strip_tags', 'trim']);
  165. if (false === $this->request->isAjax()) {
  166. return $this->view->fetch();
  167. }
  168. if ($this->request->request('keyField')) {
  169. return $this->selectpage();
  170. }
  171. $userInfo = Session::get('admin');
  172. $where = ['delete_time' => ''];
  173. $filter = input('filter');
  174. $filter = json_decode($filter, true);
  175. $whereList = ['delete_time' => ''];
  176. if (isset($filter['matter_name'])) {
  177. $whereList['matter_no'] = $filter['matter_name'];
  178. }
  179. if (isset($filter['bach'])) {
  180. $whereList['bach_num'] = $filter['bach'];
  181. }
  182. if (isset($filter['manufacture_date'])) {
  183. $begin = substr($filter['manufacture_date'], 0, 19);
  184. $end = substr($filter['manufacture_date'], 22);
  185. $begin = (int)date('ymd', strtotime($begin));
  186. $end = (int)date('ymd', strtotime($end));
  187. $whereList['manufacture_date'] = ['between', [$begin, $end]];
  188. }
  189. // 查出相关 bach_id
  190. $bach_list = $bach->name($userInfo['company'].'_qcode_bach')->where($whereList)->column('_id');
  191. $bach_id = [];
  192. foreach ($bach_list as $v) {
  193. $id = substr(json_encode($v), 9, -2);
  194. $bach_id[] = $id;
  195. }
  196. // 获取分页参数
  197. $offset = input('offset', 0);
  198. $limit = input('limit', 10);
  199. // 获取所有大件记录用于总量判断
  200. $all_large_list = $large->name($userInfo['company'].'_qcode_large')
  201. ->where($where)
  202. ->where('l_status', 0)
  203. ->whereIn('bach_id', $bach_id)
  204. ->select();
  205. // 统计总数量
  206. $total = count($all_large_list);
  207. // 分页
  208. $large_list = array_slice($all_large_list, $offset, $limit);
  209. $list = [];
  210. foreach ($large_list as $k => $v) {
  211. $bach_detail = $bach->name($userInfo['company'].'_qcode_bach')->where('_id', $v['bach_id'])->find();
  212. $num = (int)$bach_detail['num']; // 总张数
  213. $small_num = (int)$bach_detail['small_num']; // 每箱张数
  214. $boxes_per_pallet = (int)$bach_detail['total_boxes']; // 每托箱数
  215. // 重新计算总箱数
  216. $larger_num = (int)ceil($num / $small_num);
  217. // 当前批次对应的总托数
  218. $full_pallets = floor($larger_num / $boxes_per_pallet);
  219. $last_pallet_boxes = $larger_num % $boxes_per_pallet;
  220. $total_pallets = $full_pallets + ($last_pallet_boxes > 0 ? 1 : 0);
  221. // 当前是第几托(code中解析)
  222. $current_flow_str = substr($v['code'], 53, 6);
  223. $current_flow = (int) ltrim($current_flow_str, '0');
  224. $total_pallets = (int) $total_pallets;
  225. // 是否是最后一托
  226. $is_last = ($current_flow === $total_pallets) ? 1 : 0;
  227. // 修正箱数
  228. $total_boxes = $boxes_per_pallet;
  229. if ($is_last && $last_pallet_boxes > 0) {
  230. $total_boxes = $last_pallet_boxes;
  231. }
  232. $list[$k] = [
  233. 'id' => substr(json_encode($v['_id']), 9, -2),
  234. 'l_flow' => $current_flow,
  235. 'bach' => $bach_detail['bach_num'],
  236. 'num' => $num,
  237. 'small_num' => $small_num,
  238. 'order_ddbh' => $bach_detail['order_ddbh'],
  239. 'danwei' => $bach_detail['danwei'],
  240. 'cpbm' => $bach_detail['cpbm'],
  241. 'matter_name' => $bach_detail['matter_name'],
  242. 'total_boxes' => $total_boxes,
  243. 'tray_num' => $bach_detail['tray_num'],
  244. 'box_num' => $bach_detail['box_num'],
  245. 'pallet_height' => $bach_detail['pallet_height'],
  246. 'pallet_length' => $bach_detail['pallet_length'],
  247. 'pallet_width' => $bach_detail['pallet_width'],
  248. 'larger_num' => $larger_num,
  249. 'manufacture_date' => date('Y-m-d', strtotime('20' . $bach_detail['manufacture_date'])),
  250. 'code' => $v['code'],
  251. 'is_last' => $is_last,
  252. ];
  253. }
  254. return json(['total' => $total, 'rows' => $list]);
  255. }
  256. /**
  257. * 小件列表
  258. * @return \think\response\Json
  259. * @throws \think\Exception
  260. * @throws \think\db\exception\DataNotFoundException
  261. * @throws \think\db\exception\ModelNotFoundException
  262. * @throws \think\exception\DbException
  263. */
  264. public function smallList()
  265. {
  266. $userinfo = Session::get('admin');
  267. $lager = new QcodeLarge();
  268. $small = new QcodeSmall();
  269. if ($this->request->isAjax() === false){
  270. $this->error('请求错误');
  271. }
  272. $filter = input('filter');
  273. $filter = json_decode($filter,true);
  274. $order = input('order');
  275. $offset = input('offset');
  276. $limit = input('limit');
  277. $where = [
  278. 'delete_time' => '',
  279. ];
  280. if (isset($filter['large_id'])){
  281. $where['large_id'] =$filter['large_id'];
  282. }
  283. $smallList = $small->name($userinfo['company'].'_'.'qcode_small')
  284. ->where($where)
  285. ->skip($offset)
  286. ->limit($limit)
  287. ->select();
  288. $total = $small->name($userinfo['company'].'_'.'qcode_small')->where($where)->count();
  289. $list = [];
  290. foreach ($smallList as $k=>$v){
  291. $list[$k] = [
  292. 'code' => $v['code'],
  293. 'l_flow' => $v['l_flow'],
  294. 'print_num' => $v['p_nums'],
  295. 'status' => $v['status'],
  296. ];
  297. }
  298. return json(['total'=>$total,'rows'=>$list]);
  299. }
  300. /**
  301. * 导出发货
  302. * @return void
  303. * @throws \think\Exception
  304. * @throws \think\db\exception\DataNotFoundException
  305. * @throws \think\db\exception\ModelNotFoundException
  306. * @throws \think\exception\DbException
  307. */
  308. public function print()
  309. {
  310. $userinfo = Session::get('admin');
  311. $lager = new QcodeLarge();
  312. $bach = new QcodeBach();
  313. $small = new QcodeSmall();
  314. $export = new QcodeExport();
  315. if ($this->request->isAjax() === false){
  316. $this->error('请求错误');
  317. }
  318. $lager_id = input('lager_id');
  319. if ($lager_id === ''){
  320. $this->error('请至少选择一个大件');
  321. }
  322. $lagerId = [];
  323. if (strpos($lager_id,',') === false){
  324. $lagerId[0] = $lager_id;
  325. }else{
  326. $lagerId = explode(',',$lager_id);
  327. }
  328. $lager_num = count($lagerId);
  329. $bach_id = [];
  330. foreach ($lagerId as $k=>$v){
  331. $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$v)->find();
  332. $bachList = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$lagerList['bach_id'])->find();
  333. $bach_id[$k] = substr(json_encode($bachList['_id']),9,-2);
  334. }
  335. $bach_id = array_unique($bach_id);
  336. $data = [];
  337. foreach ($bach_id as $k=>$v){
  338. $data[$k] = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->field('matter_no')->find()['matter_no'];
  339. }
  340. $data = array_unique($data);
  341. if (count($data)>1){
  342. $this->error('请选择同一产品');
  343. }
  344. $n =0;
  345. foreach (explode(',',$lager_id) as $kk=>$vv){
  346. $n = $n + $small->name($userinfo['company'].'_'.'qcode_small')->where('large_id',$vv)->count();
  347. }
  348. // $bachDetail = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$bach_id[0])->find();
  349. $bachArray = $bach->name($userinfo['company'].'_'.'qcode_bach')
  350. ->where('_id', $bach_id[0])
  351. ->find();
  352. $bachDetail = $bachArray ? $bachArray->toArray() : [];
  353. if ($bachDetail['box_num'] === 1){
  354. $mater_type = 2;
  355. }else{
  356. $mater_type = 1;
  357. }
  358. $exportData = $this->exportdata($bach_id,$lager_id,$userinfo['company'],$lager_num,$n);
  359. $file_dir = $this->exportExcel($exportData);
  360. $row = [
  361. 'username' => $bachDetail['supplier_name'],//公司
  362. 'matter_no' => $bachDetail['matter_no'],
  363. 'order_ddbh' => $bachDetail['order_ddbh'],
  364. 'large_str' => $lager_id,
  365. 'status' => 0,
  366. 'bach_num' => $bachDetail['bach_num'],
  367. 'note' => '',
  368. 'user_id' => $userinfo['id'],
  369. 'create_time' => time(),
  370. 'file_dir' => $file_dir,
  371. 'company_id' => $userinfo['company'],
  372. 'large_num' => $lager_num,//你已选中 N 个大件【托盘数】
  373. 'small_num' => $n,//共包含了 N 个小件
  374. 'matter_name' => $bachDetail['matter_name'],//产品名称
  375. 'total_boxes' => $bachDetail['total_boxes'],//每托箱数
  376. 'tray_num' => $bachDetail['tray_num'],//每层箱数
  377. 'box_num' => $bachDetail['box_num'],//每托层数
  378. 'pallet_height' => $bachDetail['pallet_height'],//每托高度
  379. 'pallet_length' => $bachDetail['pallet_length'],//托盘规格
  380. 'pallet_width' => $bachDetail['pallet_width'],//托盘规格
  381. 'larger_num' => $bachDetail['larger_num'],//总箱数
  382. ];
  383. if ($bachDetail['box_num'] != 1){
  384. $row['num'] = $bachDetail['box_num'];
  385. $row['mater_type'] = 1;
  386. }else{
  387. $row['num'] = $bachDetail['s_weight'];
  388. $row['mater_type'] = 2;
  389. }
  390. $res = $export->save($row);
  391. if ($res === false){
  392. $this->error('发货失败');
  393. }
  394. $lager = new QcodeLarge();
  395. $lager->name($userinfo['company'].'_'.'qcode_large')->whereIn('_id',$lagerId)->update(['l_status'=>1]);
  396. $this->success('成功','',$file_dir);
  397. }
  398. /**
  399. * 表格数据处理
  400. * @param $bach_id
  401. * @param $large_str
  402. * @param $company
  403. * @param $large_num
  404. * @param $small_num
  405. * @return array
  406. * @throws \think\db\exception\DataNotFoundException
  407. * @throws \think\db\exception\ModelNotFoundException
  408. * @throws \think\exception\DbException
  409. */
  410. public function exportdata($bach_id,$large_str,$company,$large_num,$small_num)
  411. {
  412. $bach = new QcodeBach();
  413. $large = new QcodeLarge();
  414. $small = new QcodeSmall();
  415. $bachList = $bach->name($company . '_' . 'qcode_bach')->where('_id', $bach_id[0])->find();
  416. $data = [
  417. 'supplier_name' => $bachList['supplier_name'],
  418. 'supplier_no' => $bachList['supplier_code'],
  419. 'matter_name' => $bachList['matter_name'],
  420. 'matter_no' => $bachList['matter_no'],
  421. 'manufacture_date' => date('Y/m/d',strtotime('20'.$bachList['manufacture_date'])),
  422. 'print_date' => date('Y/m/d',strtotime('20'.$bachList['print_date'])),
  423. 'box_num' => $large_num,
  424. 'tray_num' => $bachList['tray_num'],
  425. 'small_num' => $small_num,
  426. 'l_reservation' => $bachList['l_reservation'],
  427. 's_reservation' => $bachList['s_reservation'],
  428. 'l_flow' => $bachList['l_flow'],
  429. 's_flow' => $bachList['s_flow'],
  430. 'l_weight' => 0,
  431. 's_weight' => $bachList['s_weight']/1000,
  432. 'code' => [],
  433. ];
  434. $large_id = explode(',', $large_str);
  435. foreach ($large_id as $k => $v) {
  436. $largeList = $large->name($company . '_' . 'qcode_large')->where('_id', $v)->find();
  437. $data['l_weight'] = $data['l_weight'] + (int)$largeList['l_weight']/100;
  438. $small_list = $small->name($company . '_' . 'qcode_small')->where('large_id', $v)->select();
  439. foreach ($small_list as $value) {
  440. $code = [
  441. 'large_code' => $largeList['code'],
  442. 'small_code' => $value['code'],
  443. ];
  444. array_push($data['code'],$code);
  445. }
  446. }
  447. return $data;
  448. }
  449. /**
  450. * 生成excel
  451. * @param $data
  452. * @return string
  453. * @throws Exception
  454. * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
  455. */
  456. public function exportExcel($data)
  457. {
  458. $objexcel = new Spreadsheet();
  459. $sheet = $objexcel->getActiveSheet();
  460. //设置全局单元格垂直居中
  461. $objexcel->getDefaultStyle()->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
  462. //设置全局单元格水平居中
  463. $objexcel->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
  464. //设置全局单元格自动换行
  465. $objexcel->getDefaultStyle()->getAlignment()->setWrapText(true);
  466. //设置单元格宽度
  467. $sheet->getDefaultColumnDimension()->setWidth(50);
  468. //设置表头
  469. $sheet->setCellValue('A1', '文件流水号');
  470. $sheet->setCellValue('A2', '订单号');
  471. $sheet->setCellValue('A3', '供应商');
  472. $sheet->setCellValue('A4', '供应商代码');
  473. $sheet->setCellValue('A5', '物料名称');
  474. $sheet->setCellValue('A6', '物料代码');
  475. $sheet->setCellValue('A7', '生产日期');
  476. $sheet->setCellValue('A8', '打码日期');
  477. $sheet->setCellValue('A9', '大件数量');
  478. $sheet->setCellValue('A10', '托盘小件数量');
  479. $sheet->setCellValue('A11', '小件总数量');
  480. $sheet->setCellValue('C3', '大件预留码');
  481. $sheet->setCellValue('C5', '小件预留码');
  482. $sheet->setCellValue('C7', '大件开始流水号');
  483. $sheet->setCellValue('C9', '小件开始流水号');
  484. $sheet->setCellValue('C11', '大件重量(Kg)');
  485. $sheet->setCellValue('C13', '小件重量(Kg)');
  486. $sheet->setCellValue('A15', '大件二维码');
  487. $sheet->setCellValue('B15', '大件条码(预留)');
  488. $sheet->setCellValue('C15', '小件二维码');
  489. $sheet->setCellValue('D15', '小件条码(预留)');
  490. //插入表格数据
  491. $sheet->getCell('B3')->setValue(isset($data['supplier_name'])?$data['supplier_name']:'');
  492. $sheet->getCell('B4')->setValue(isset($data['supplier_no'])?$data['supplier_no']:'');
  493. $sheet->getCell('B5')->setValue(isset($data['matter_name'])?$data['matter_name']:'');
  494. $sheet->getCell('B6')->setValue(isset($data['matter_no'])?$data['matter_no']:'');
  495. $sheet->getCell('B7')->setValue(isset($data['manufacture_date'])?$data['manufacture_date']:'');
  496. $sheet->getCell('B8')->setValue(isset($data['print_date'])?$data['print_date']:'');
  497. $sheet->getCell('B9')->setValue(isset($data['box_num'])?$data['box_num']:'');
  498. $sheet->getCell('B10')->setValue(isset($data['tray_num'])?$data['tray_num']:'');
  499. $sheet->getCell('B11')->setValue(isset($data['small_num'])?$data['small_num']:'');
  500. $sheet->getCell('C4')->setValue(isset($data['l_reservation'])?$data['l_reservation']:'');
  501. $sheet->getCell('C6')->setValue(isset($data['s_reservation'])?$data['s_reservation']:'');
  502. $sheet->getCell('C8')->setValue(isset($data['l_flow'])?$data['l_flow']:'');
  503. $sheet->getCell('C10')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
  504. $sheet->getCell('C12')->setValue(isset($data['l_weight'])?$data['l_weight']:'');
  505. $sheet->getCell('C14')->setValue(isset($data['s_weight'])?$data['s_weight']:'');
  506. foreach ($data['code'] as $k=>$v){
  507. $m = $k+16;
  508. $sheet->getCell('A'.$m)->setValue(isset($v['large_code'])?$v['large_code']:'');
  509. $sheet->getCell('B'.$m)->setValue('');
  510. $sheet->getCell('C'.$m)->setValue(isset($v['small_code'])?$v['small_code']:'');
  511. $sheet->getCell('D'.$m)->setValue('');
  512. }
  513. //文件另存
  514. $filename = date('Ymd',time()).rand(100,999).'_'.$data['supplier_name'].'_'.str_replace('/','_',$data['matter_name']).'_'.$data['small_num'].'.xlsx';
  515. // $filename = iconv("utf-8","gb2312",$filename);
  516. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  517. header('Content-Disposition:attachment;filename='.$filename);
  518. header('Cache-Control: max-age=0');
  519. header("Content-Type:text/html;charset=utf-8");
  520. if(is_dir(ROOT_PATH.'public/uploads/export/') === false)
  521. {
  522. mkdir(ROOT_PATH.'public/uploads/export/',0777,true);
  523. }
  524. $writer = IOFactory::createWriter($objexcel, 'Xlsx');
  525. $writer->save(ROOT_PATH.'public/uploads/export/'.$filename);
  526. return 'uploads/export/'.$filename;
  527. }
  528. /**
  529. * 批次发货申请
  530. * @return string|\think\response\Json
  531. * @throws \think\Exception
  532. */
  533. public function apply()
  534. {
  535. $export = new QcodeExport();
  536. $this->request->filter(['strip_tags', 'trim']);
  537. if (false === $this->request->isAjax()) {
  538. return $this->view->fetch();
  539. }
  540. if ($this->request->request('keyField')) {
  541. return $this->selectpage();
  542. }
  543. // 接收参数
  544. $userInfo = Session::get('admin');
  545. $where = [
  546. 'company_id' => $userInfo['company'],
  547. 'delete_time'=> ''
  548. ];
  549. $filter = input('filter');
  550. $filter = json_decode($filter,true);
  551. //样品编号查询
  552. if (isset($filter['matter_name'])){
  553. $where['matter_no'] =$filter['matter_name'];
  554. }
  555. if (isset($filter['username'])){
  556. $where['username'] = $filter['username'];
  557. }
  558. if (isset($filter['status'])){
  559. $where['status'] = (int)$filter['status'];
  560. }
  561. if (isset($filter['create_time'])){
  562. $begin = substr($filter['create_time'],0,19);
  563. $end = substr($filter['create_time'],22);
  564. $begin = strtotime($begin);
  565. $end = strtotime($end);
  566. $where['create_time'] = ['between',[$begin,$end]];
  567. }
  568. $order = input('order');
  569. $offset = input('offset');
  570. $limit = input('limit');
  571. $total = $export->where($where)->count();
  572. $export_list = $export
  573. ->order('_id',$order)
  574. ->where($where)
  575. ->whereIn('status',[0,1])
  576. ->skip($offset)
  577. ->limit($limit)
  578. ->select();
  579. $list=[];
  580. foreach ($export_list as $k=>$v) {
  581. $list[$k]['large_num'] = $v['large_num'];//托盘数量
  582. $list[$k]['total_boxes'] = $v['total_boxes'];//每箱托数
  583. $list[$k]['tray_num'] = $v['tray_num'];//每层箱数
  584. $list[$k]['box_num'] = $v['box_num'];//每托层数
  585. $list[$k]['pallet_height'] = $v['pallet_height'];//托盘高度
  586. $list[$k]['pallet_length'] = $v['pallet_length'];//托盘规格
  587. $list[$k]['pallet_width'] = $v['pallet_width'];//托盘规格
  588. $list[$k]['small_num'] = $v['small_num'];//总箱数
  589. $list[$k]['larger_num'] = $v['larger_num'];//总箱数
  590. $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
  591. $list[$k]['matter_name'] = $v['matter_name'];
  592. $list[$k]['matter_no'] = $v['matter_no'];
  593. $list[$k]['username'] = $v['username'];
  594. $list[$k]['large_num'] = $v['large_num'];
  595. $list[$k]['small_num'] = $v['small_num'];
  596. $list[$k]['create_time'] = $v['create_time'];
  597. $list[$k]['file_dir'] = $v['file_dir'];
  598. $list[$k]['status'] = $v['status'];
  599. }
  600. $result = ['total'=>$total,'rows'=>$list];
  601. return json($result);
  602. }
  603. /**
  604. * 批次发货删除
  605. * @param $ids
  606. * @return void
  607. */
  608. public function apply_del($ids)
  609. {
  610. $export = new QcodeExport();
  611. $userinfo = Session::get('admin');
  612. $large = new QcodeLarge();
  613. if (empty($ids)){
  614. $this->error('请求错误');
  615. }
  616. $res = $export->where('_id',$ids)->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
  617. if ($res === false){
  618. $this->error('删除失败');
  619. }
  620. $large_list = $export->where('_id',$ids)->find();
  621. $large_id = explode(',',$large_list['large_str']);
  622. foreach ($large_id as $v){
  623. $result = $large->name($userinfo['company'].'_'.'qcode_large')->where('_id',$v)->update(['l_status'=>0]);
  624. if ($result === 0){
  625. $this->error('删除失败');
  626. }
  627. }
  628. $this->success('成功');
  629. }
  630. /**
  631. * 司机弹窗
  632. * @param $ids
  633. * @return string
  634. * @throws \think\Exception
  635. */
  636. public function goods($ids)
  637. {
  638. $this->view->assign('ids',$ids);
  639. return $this->view->fetch();
  640. }
  641. /**
  642. * 批次发货提交
  643. * @return void
  644. * @throws \think\db\exception\DataNotFoundException
  645. * @throws \think\db\exception\ModelNotFoundException
  646. * @throws \think\exception\DbException
  647. */
  648. public function apply_add()
  649. {
  650. $goods = new QcodeGoods();
  651. $export = new QcodeExport();
  652. $userinfo = Session::get('admin');
  653. if ($this->request->isAjax() === false){
  654. $this->error('请求错误');
  655. }
  656. $ids = input('ids');
  657. $order_number = input('order_number');
  658. $deliveryman = input('deliveryman');
  659. $shr_phone = input('shr_phone');
  660. $plate_number = input('plate_number');
  661. $note = input('note');
  662. $id_list = [];
  663. if (strpos($ids,',') === false){
  664. $id_list[0] = $ids;
  665. }else{
  666. $id_list = explode(',',$ids);
  667. }
  668. $update_status = $export->where('company_id',$userinfo['company'])->whereIn('_id',$id_list)->update(['status'=>2]);
  669. if ($update_status){
  670. $export_list = $export->whereIn('_id',$id_list)->select();
  671. $daterq = date('ymd',time());
  672. $data = [
  673. 'shdh' => substr($daterq,2,2).' '.substr($daterq,2,6).mt_rand(1000,9999),
  674. 'order_number' => $order_number,
  675. 'deliveryman' => $deliveryman,
  676. 'shr_phone' => $shr_phone,
  677. 'plate_number' => $plate_number,
  678. 'shrq_date' => '',
  679. 'supplier_name' => $export_list[0]['username'],
  680. 'supplier_id' => $userinfo['id'],
  681. 'user_id' => $userinfo['id'],
  682. 'status' => 0,
  683. 'export_id' => $ids,
  684. 'create_time' => time(),
  685. 'note' => $note,
  686. 'company_id' => $userinfo['company'],
  687. ];
  688. $data['qrcode_add'] = $this->Qrcode($data['shdh']);
  689. $res = $goods->save($data);
  690. if ($res === false){
  691. $this->error('失败');
  692. }
  693. $this->success('成功');
  694. }else{
  695. $this->error('失败');
  696. }
  697. }
  698. /**
  699. * 生成二维码
  700. * @param $url
  701. * @return string
  702. */
  703. public function Qrcode($url)
  704. {
  705. $level=2;
  706. $size=5;
  707. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  708. $errorCorrectionLevel =intval($level) ;//容错级别
  709. $matrixPointSize = intval($size);//生成图片大小
  710. //生成二维码图片
  711. $object = new \QRcode();
  712. //打开缓冲区
  713. ob_start();
  714. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  715. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  716. $imageString = base64_encode(ob_get_contents());
  717. //关闭缓冲区
  718. ob_end_clean();
  719. //把生成的base64字符串返回给前端
  720. return 'data:image/png;base64,'.$imageString;
  721. }
  722. /**
  723. * 发货单
  724. * @return string|\think\response\Json
  725. * @throws \think\Exception
  726. */
  727. public function dispatch()
  728. {
  729. $export = new QcodeGoods();
  730. $this->request->filter(['strip_tags', 'trim']);
  731. if (false === $this->request->isAjax()) {
  732. return $this->view->fetch();
  733. }
  734. if ($this->request->request('keyField')) {
  735. return $this->selectpage();
  736. }
  737. // 接收参数
  738. $userInfo = Session::get('admin');
  739. $where = [
  740. 'company_id' => $userInfo['company'],
  741. 'delete_time'=> ''
  742. ];
  743. $search = input('search');
  744. if (isset($search)){
  745. $where['order_number|supplier_name|status|plate_number|shdh|deliveryman'] = new \MongoDB\BSON\Regex($search);
  746. }
  747. $filter = input('filter');
  748. $filter = json_decode($filter,true);
  749. //订单编号查询
  750. if (isset($filter['order_number'])){
  751. $where['order_number'] =$filter['order_number'];
  752. }
  753. //所属公司查询
  754. if (isset($filter['supplier_name'])){
  755. $where['supplier_name'] = $filter['supplier_name'];
  756. }
  757. if (isset($filter['status'])){
  758. $where['status'] = (int)$filter['status'];
  759. }
  760. if (isset($filter['create_time'])){
  761. $begin = substr($filter['create_time'],0,19);
  762. $end = substr($filter['create_time'],22);
  763. $begin = strtotime($begin);
  764. $end = strtotime($end);
  765. $where['create_time'] = ['between',[$begin,$end]];
  766. }
  767. $order = input('order');
  768. $offset = input('offset');
  769. $limit = input('limit');
  770. $total = $export->where($where)->count();
  771. $export_list = $export
  772. ->order('_id',$order)
  773. ->where($where)
  774. ->whereIn('status',[0,1])
  775. ->skip($offset)
  776. ->limit($limit)
  777. ->select();
  778. $list=[];
  779. foreach ($export_list as $k=>$v) {
  780. $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
  781. $list[$k]['shdh'] = $v['shdh'];
  782. $list[$k]['order_number'] = $v['order_number'];
  783. $list[$k]['supplier_name'] = $v['supplier_name'];
  784. $list[$k]['deliveryman'] = $v['deliveryman'];
  785. $list[$k]['plate_number'] = $v['plate_number'];
  786. $list[$k]['create_time'] = $v['create_time'];
  787. $list[$k]['status'] = $v['status'];
  788. }
  789. $result = ['total'=>$total,'rows'=>$list];
  790. return json($result);
  791. }
  792. /**
  793. * 发货单打印
  794. * @return \think\response\Json|void
  795. * @throws \think\db\exception\DataNotFoundException
  796. * @throws \think\db\exception\ModelNotFoundException
  797. * @throws \think\exception\DbException
  798. */
  799. public function printqrcode()
  800. {
  801. $goods = new QcodeGoods();
  802. $export = new QcodeExport();
  803. $large = new QcodeLarge();
  804. $userinfo = Session::get('admin');
  805. if ($this->request->isAjax() === false) {
  806. $this->error('请求错误');
  807. }
  808. $id = input('id');
  809. $good_list = $goods->where('_id', $id)->find();
  810. if ($good_list) {
  811. if (strpos($good_list['export_id'], ',') === false) {
  812. $export_id[0] = $good_list['export_id'];
  813. } else {
  814. $export_id = explode(',', $good_list['export_id']);
  815. }
  816. $data = [];
  817. $motter_nos = []; // 用于存储 motter_no 字段
  818. foreach ($export_id as $k => $v) {
  819. $data[$k] = $export->where('_id', $v)->find();
  820. // 确保 $data[$k] 是一个有效的对象
  821. if ($data[$k] instanceof QcodeExport) {
  822. if (!empty($data[$k]['order_ddbh'])) {
  823. $motter_nos[] = $data[$k]['order_ddbh'];
  824. }
  825. }
  826. $large_str = explode(',', $data[$k]['large_str']);
  827. $large_list = $large->name($userinfo['company'] . '_' . 'qcode_large')->whereIn('_id', $large_str)->select();
  828. $large_num = $large_weight = 0;
  829. foreach ($large_list as $value) {
  830. $large_num += $value['l_num']; // 累加数量
  831. $large_weight += $value['l_weight']; // 累加重量
  832. }
  833. // 更新数据
  834. $data[$k]['l_num'] = $large_num / 10000; // 转换数量
  835. $data[$k]['l_weight'] = $large_weight; // 更新重量
  836. // 添加 motter_no 到数组
  837. if (!empty($data[$k]['order_ddbh'])) {
  838. $order_ddbh[] = $data[$k]['order_ddbh'];
  839. }
  840. }
  841. // 拼接 motter_no 字段
  842. $good_list['order_ddbh'] = implode(',', $order_ddbh);
  843. // 继续处理其他数据
  844. $good_list['address'] = $userinfo['company_address'];
  845. $good_list['data'] = $data;
  846. $good_list['count'] = count($data);
  847. $good_list['shrq_date'] = substr($good_list['create_time'], 0, 10);
  848. if (empty($good_list['qrcode_add'])) {
  849. $good_list['qrcode_add'] = $this->Qrcode($good_list['shdh']);
  850. $goods->where('_id', $id)->update(['qrcode_add' => $good_list['qrcode_add']]);
  851. }
  852. if ($good_list['note'] === 'NULL') {
  853. $good_list['note'] = '';
  854. }
  855. // 新增代码
  856. $good_array = $good_list ? $good_list->toArray() : [];
  857. $dataList = $good_array['data'] ?? [];
  858. // 步骤1:按照 create_time 升序排序
  859. usort($dataList, function ($a, $b) {
  860. return strtotime($a['create_time']) - strtotime($b['create_time']);
  861. });
  862. // 步骤2:添加 large_ber 字段
  863. $start = 1;
  864. foreach ($dataList as &$item) {
  865. $count = intval($item['large_num']);
  866. $end = $start + $count - 1;
  867. $item['large_ber'] = ($start === $end) ? (string)$start : "$start-$end";
  868. $start = $end + 1;
  869. }
  870. unset($item);
  871. $good_list['data'] = $dataList;
  872. return json(['code' => 1, 'data' => $good_list]);
  873. }
  874. }
  875. // public function printqrcode()
  876. // {
  877. // $goods = new QcodeGoods();
  878. // $export = new QcodeExport();
  879. // $large = new QcodeLarge();
  880. // $userinfo = Session::get('admin');
  881. // if ($this->request->isAjax() === false) {
  882. // $this->error('请求错误');
  883. // }
  884. // $id = input('id');
  885. // $good_list = $goods->where('_id',$id)->find();
  886. //
  887. // if ($good_list){
  888. // if (strpos($good_list['export_id'],',') === false){
  889. // $export_id[0] = $good_list['export_id'];
  890. // }else{
  891. // $export_id = explode(',',$good_list['export_id']);
  892. // }
  893. // $data = [];
  894. // foreach ($export_id as $k=>$v){
  895. // $data[$k] = $export->where('_id',$v)->find();
  896. // $large_str = explode(',',$data[$k]['large_str']);
  897. // $large_list = $large->name($userinfo['company'].'_'.'qcode_large')->whereIn('_id',$large_str)->select();
  898. // $large_num = $large_weight = 0;
  899. // foreach ($large_list as $value){
  900. // $large_num = $large_num + $value['l_num'];
  901. // $large_weight = $large_weight + $value['l_weight'];
  902. // }
  903. // $data[$k]['l_num'] = $large_num/10000;
  904. // $data[$k]['l_weight'] = $large_weight;
  905. // }
  906. // $good_list['address'] = $userinfo['company_address'];
  907. // $good_list['data'] = $data;
  908. // $good_list['count'] = count($data);
  909. // $good_list['shrq_date'] = substr($good_list['create_time'],0,10) ;
  910. // if (empty($good_list['qrcode_add'])){
  911. // $good_list['qrcode_add'] = $this->Qrcode($good_list['shdh']);
  912. // $goods->where('_id',$id)->update(['qrcode_add'=>$good_list['qrcode_add']]);
  913. // }
  914. // if ($good_list['note'] == 'NULL'){
  915. // $good_list['note'] = '';
  916. // }
  917. //
  918. // //新增代码
  919. // $good_array = $good_list ? $good_list->toArray() : [];
  920. // // 假设 $goodArray 是已经转为普通数组的结构
  921. // $dataList = $good_array['data'] ?? [];
  922. // // 步骤1:按照 create_time 升序排序
  923. // usort($dataList, function ($a, $b) {
  924. // return strtotime($a['create_time']) - strtotime($b['create_time']);
  925. // });
  926. // // 步骤2:添加 large_ber 字段
  927. // $start = 1;
  928. // foreach ($dataList as &$item) {
  929. // $count = intval($item['large_num']);
  930. // $end = $start + $count - 1;
  931. // $item['large_ber'] = ($start === $end) ? (string)$start : "$start-$end";
  932. // $start = $end + 1;
  933. // }
  934. // unset($item);
  935. // $good_list['data'] = $dataList;
  936. //
  937. // return json(['code'=>1,'data'=>$good_list]);
  938. // }
  939. // }
  940. /**
  941. * 获取辅料名称
  942. * @return \think\response\Json
  943. * @throws \think\db\exception\DataNotFoundException
  944. * @throws \think\db\exception\ModelNotFoundException
  945. * @throws \think\exception\DbException
  946. */
  947. public function matterName()
  948. {
  949. $userinfo = Session::get('admin');
  950. $lager = new QcodeLarge();
  951. $bach = new QcodeBach();
  952. $bach_id = $lager->name($userinfo['company'].'_'.'qcode_large')->where('delete_time','')->column('bach_id');
  953. $matter_name = [];
  954. if (!empty($bach_id)){
  955. foreach ($bach_id as $v){
  956. $bach_list = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
  957. $matter_name[$bach_list['matter_no']] = $bach_list['matter_name'];
  958. }
  959. }
  960. $matter_name = array_unique($matter_name);
  961. return json($matter_name);
  962. }
  963. /**
  964. * 发货单删除
  965. * @param $ids
  966. * @return void
  967. */
  968. public function dispatch_del($ids)
  969. {
  970. $goods = new QcodeGoods();
  971. $export = new QcodeExport();
  972. if (empty($ids)){
  973. $this->error('参数错误');
  974. }
  975. $res = $goods->where('_id',$ids)->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
  976. if ($res === false){
  977. $this->error('删除失败');
  978. }
  979. $export_list = $goods->where('_id',$ids)->find();
  980. $export_id = explode(',',$export_list['export_id']);
  981. foreach ($export_id as $v){
  982. $result = $export->where('_id',$v)->update(['status'=>0]);
  983. if ($result === false){
  984. $this->error('删除失败');
  985. }
  986. }
  987. $this->success('成功');
  988. }
  989. /**
  990. * 收货列表
  991. */
  992. public function receive()
  993. {
  994. //当前是否为关联查询
  995. $this->relationSearch = false;
  996. //设置过滤方法
  997. $this->request->filter(['strip_tags', 'trim']);
  998. if ($this->request->isAjax()) {
  999. //如果发送的来源是Selectpage,则转发到Selectpage
  1000. if ($this->request->request('keyField')) {
  1001. return $this->selectpage();
  1002. }
  1003. $where = [
  1004. 'delete_time'=> ''
  1005. ];
  1006. $req = input();
  1007. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  1008. $order = $req['order'];
  1009. $offset = $req['offset'];
  1010. $limit = $req['limit'];
  1011. // 构造模糊查询条件
  1012. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  1013. // $filter = ['field' => $regex];
  1014. $filter = json_decode($req['filter'], true);
  1015. if (isset($filter['status'])){
  1016. $where['status'] = intval($filter['status']);
  1017. unset($filter['status']);
  1018. }
  1019. if (isset($filter['create_time'])){
  1020. $begin = substr($filter['create_time'],0,19);
  1021. $end = substr($filter['create_time'],22);
  1022. $begin = strtotime($begin);
  1023. $end = strtotime($end);
  1024. $where['create_time'] = ['between',[$begin,$end]];
  1025. unset($filter['create_time']);
  1026. }
  1027. foreach ($filter as $k => $v){
  1028. $where[$k] = new \MongoDB\BSON\Regex($v);
  1029. }
  1030. $goods = new QcodeGoods();
  1031. $total = $goods->where($where)->count();
  1032. $list = $goods->where($where)
  1033. ->order($sort,$order)
  1034. ->limit($limit)
  1035. ->skip($offset)
  1036. ->select();
  1037. foreach ($list as $k=>$v) {
  1038. $oid = $v['_id']->jsonSerialize();
  1039. $list[$k]['id'] = $oid['$oid'];
  1040. }
  1041. $result = array("total" => $total, "rows" => $list);
  1042. return json($result);
  1043. }
  1044. return $this->view->fetch();
  1045. }
  1046. /**
  1047. * 扫码/输入收货
  1048. */
  1049. public function receive_add()
  1050. {
  1051. $req = $this->request->param();
  1052. if(!isset($req['shdh']) || empty($req['shdh'])){
  1053. $this->error('请输入送货单号');
  1054. }
  1055. $data = [
  1056. 'shdh'=>$req['shdh'],
  1057. 'delete_time'=>'',
  1058. ];
  1059. $goods = new QcodeGoods();
  1060. $row = $goods->where($data)->find();
  1061. if (!$row) $this->error('未查询到该单号');
  1062. if ($row['status']==2) $this->error('该单号已收货');
  1063. //收货---修改status为2
  1064. $bool = $goods->where($data)->update(['status'=>2,'sync_flag'=>0]);
  1065. if ($bool){
  1066. $this->success('成功');
  1067. }else{
  1068. $this->error('失败');
  1069. }
  1070. }
  1071. /**
  1072. * 取消收货
  1073. */
  1074. public function receive_del()
  1075. {
  1076. $req = $this->request->param();
  1077. if(!isset($req['ids']) || empty($req['ids'])){
  1078. $this->error('id不能为空');
  1079. }
  1080. $data = [
  1081. '_id'=>$req['ids'],
  1082. 'delete_time'=>'',
  1083. ];
  1084. $goods = new QcodeGoods();
  1085. //收货---修改status为2
  1086. $bool = $goods->where($data)->update(['status'=>0,'sync_flag'=>0]);
  1087. if ($bool){
  1088. $this->success('成功');
  1089. }else{
  1090. $this->error('失败');
  1091. }
  1092. }
  1093. }