InventoryAccountController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\Export;
  4. use App\InventoryAccount;
  5. use App\InventoryAccountMission;
  6. use App\Services\InventoryAccountService;
  7. use App\Services\OwnerService;
  8. use Exception;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\Auth;
  11. use Illuminate\Support\Facades\Gate;
  12. use Illuminate\Support\Facades\Http;
  13. use Illuminate\Support\Facades\Redis;
  14. use Maatwebsite\Excel\Facades\Excel;
  15. class InventoryAccountController extends Controller
  16. {
  17. public function __construct()
  18. {
  19. app()->singleton('inventoryAccountService', InventoryAccountService::class);
  20. }
  21. public function outToLineUpdateInventoryMissions(Request $request): array
  22. {
  23. if (!Gate::allows('库存管理-盘点')) {return ['success' => false, 'data' => '没有权限'];}
  24. $inventory=$request->input('inventory');
  25. $location=$request->input('location');
  26. $location_arr=array_filter(preg_split('/[,, ]+/is', $location));
  27. $wmsInventories='';
  28. if ($inventory['type']=='全盘'||$inventory['type']=='局部盘点')
  29. $wmsInventories=app('inventoryAccountService')->conditionTotalStock($inventory['owner_id'],$location,null);
  30. if ($inventory['type']=='动盘')
  31. $wmsInventories=app('inventoryAccountService')->conditionPortStock(substr($inventory['start_at'],0,10),substr($inventory['end_at'],0,10),$inventory['owner_id'],$location,null);
  32. app('inventoryAccountService')->updateInventoryAccountMissionRecord($inventory['owner_id'],$inventory['id'],$location_arr,$wmsInventories);
  33. return ['success' => true, 'data' => '更新成功'];
  34. }
  35. //创建盘点任务
  36. public function createStockInventoryMission(Request $request)
  37. {
  38. if (!Gate::allows("库存管理-盘点")) {return ['success' => false ,'data' => '没有对应权限'];}
  39. // $date_start=$request->input('formData.date_start');
  40. // $date_end=$request->input('formData.date_end');
  41. // $ownerId=$request->input('formData.owner_id')[0];
  42. $date_start = $request->input('date_start');
  43. $date_end = $request->input('date_end');
  44. $ownerId = $request->input('owner_id');
  45. $location = $request->input('location');
  46. $barcode = $request->input('barcode');
  47. $inventory = app('inventoryAccountService')->createMission($date_start, $date_end, $ownerId, $location, $barcode);
  48. $inventoryAccount = InventoryAccount::with('owner')->find($inventory->id);
  49. if (is_null($inventoryAccount)) return ['success' => false, 'data' => '参数错误!'];
  50. return ['success' => true, 'data' => $inventoryAccount];
  51. }
  52. //删除盘点任务
  53. public function deleteStockInventoryMission($id)
  54. {
  55. if (!Gate::allows('库存管理-盘点')) {
  56. return ['success' => 0, 'status' => '没有权限'];
  57. }
  58. if (is_null($id)) {
  59. return ['success' => false, 'data' => '传入id为空'];
  60. }
  61. $inventoryAccount = InventoryAccount::where('id', $id)->delete();
  62. return ['success' => true, 'data' => $inventoryAccount];
  63. }
  64. public function inventoryChecked(Request $request)
  65. {
  66. if (!Gate::allows('库存管理-盘点-项目审核')) {
  67. return ['success' => false, 'msg' => '没有权限'];
  68. }
  69. $id = $request->id;
  70. if (is_null($id)) {
  71. return ['success' => false, 'msg' => '传入id为空'];
  72. }
  73. $inventoryAccount = InventoryAccount::query()->where('id', $id)->update([
  74. 'auditor' => Auth::user()['id'],
  75. 'status' => '已审核',
  76. ]);
  77. if ($inventoryAccount == 1) {
  78. $inventoryAccount = InventoryAccount::query()->with('userAuditor')->find($id);
  79. return ['success' => true, 'data' => $inventoryAccount];
  80. } else {
  81. return ['success' => false, 'msg' => '审核失败!'];
  82. }
  83. }
  84. //盘点-任务页面
  85. public function mission(Request $request, OwnerService $ownerService)
  86. {
  87. if (!Gate::allows("库存管理-盘点")) {
  88. return redirect(url('/'));
  89. }
  90. $paginateParams = $request->input();
  91. $queryParam = $request->all();
  92. $inventoryAccounts = app('inventoryAccountService')->paginate($queryParam);
  93. $owners = $ownerService->getIntersectPermitting();
  94. return view('inventory.stockInventory.mission', compact('owners', 'inventoryAccounts', 'paginateParams'));
  95. }
  96. //进入盘点中或复盘页面
  97. public function enterStockInventory($id, Request $request)
  98. {
  99. if (!Gate::allows('库存管理-盘点')) {
  100. return redirect(url('/'));
  101. }
  102. if (!$id) return ['success' => false, 'data' => '参数错误!'];
  103. $inventoryAccount = InventoryAccount::with('owner')->find($id);
  104. $inventoryAccountMissions = InventoryAccountMission::with(['commodity.barcodes', 'stockInventoryPersons'])->where('inventory_account_id', $id)->orderBy('difference_amount', 'desc')->get();
  105. return view('inventory.stockInventory.inventoryMission', compact('inventoryAccount', 'inventoryAccountMissions'));
  106. }
  107. public function enterBlindReceive($id)
  108. {
  109. if (!Gate::allows('库存管理-盘点')) {
  110. return redirect(url('/'));
  111. }
  112. if (!$id) return ['success' => false, 'data' => '参数错误!'];
  113. $inventoryAccount = InventoryAccount::with('owner')->find($id);
  114. return view('inventory.stockInventory.blindReceive', compact('inventoryAccount'));
  115. }
  116. //依据盘点任务id进行 --盘点
  117. public function stockInventory(Request $request)
  118. {
  119. if (!Gate::allows('库存管理-盘点')) {
  120. return redirect(url('/'));
  121. }
  122. $location = $request->input('location');
  123. $barcode = $request->input('barcode');
  124. $inventoryId = $request->input('inventoryId');
  125. $count = $request->input('count');
  126. $id = $request->input('id');
  127. if (is_null($count)) return ['success' => false, 'data' => '盘点数不能为空!'];
  128. /** @var InventoryAccountService $inventoryAccountService */
  129. $inventoryAccountService = app('inventoryAccountService');
  130. $inventoryAccountMission = $inventoryAccountService->stockInventory($id, $location, $barcode, $count, $inventoryId);
  131. if (!$inventoryAccountMission) return ['success' => false, 'data' => '参数错误!'];
  132. /** @var InventoryAccountService $inventoryService */
  133. $inventoryService = app('inventoryAccountService');
  134. $inventoryAccount = $inventoryService->updateInventory($inventoryId);
  135. $stockInventoryPersons = $inventoryAccountMission->stockInventoryPersons;
  136. return ['success' => true, 'inventoryMission' => $inventoryAccountMission, 'inventory' => $inventoryAccount, 'stockInventoryPersons' => $stockInventoryPersons];
  137. }
  138. public function baseOnBlindReceive(Request $request)
  139. {
  140. if (!Gate::allows('库存管理-盘点')) {
  141. return redirect(url('/'));
  142. }
  143. $location = $request->input('location');
  144. $inventoryId = $request->input('inventoryId');
  145. $owner_code = $request->input('owner_code');
  146. $goodses = $request->input('goodses');
  147. if (!$location) return ['success' => false, 'fail_info' => '盘点库位不存在!'];
  148. if (count($goodses) < 1) return ['success' => false, 'fail_info' => '盘点商品不存在!'];
  149. /** @var InventoryAccountService $inventoryAccountMission */
  150. $inventoryAccountService = app('inventoryAccountService');
  151. $inventoryAccountMissions = $inventoryAccountService->baseOnBlindReceive($location, $owner_code, $goodses, $inventoryId);
  152. if (count($inventoryAccountMissions) < 0) return ['success' => false, 'fail_info' => '盲收盘点失败!'];
  153. /** @var InventoryAccountService $inventoryService */
  154. $inventoryService = app('inventoryAccountService');
  155. $inventoryAccount = $inventoryService->updateInventory($inventoryId);
  156. if ($inventoryAccountMissions && $inventoryAccount)
  157. $stockInventoryPersons = $inventoryAccountMissions[0]->stockInventoryPersons;
  158. return ['success' => true, 'inventoryMissions' => $inventoryAccountMissions, 'inventory' => $inventoryAccount, 'stockInventoryPersons' => $stockInventoryPersons];
  159. }
  160. //根据该库存和产品条码查询该条盘点记录??
  161. public function searchStockInventoryRecord(Request $request)
  162. {
  163. if (!Gate::allows('库存管理-盘点')) {
  164. return redirect(url('/'));
  165. }
  166. $location = $request->input('location');
  167. $barcode = $request->input('barcode');
  168. $inventoryId = $request->input('inventoryId');
  169. /** @var InventoryAccountService $application */
  170. $application = app('inventoryAccountService');
  171. $inventoryAccountMissions = $application->searchStockInventoryRecord($location, $barcode, $inventoryId);
  172. if ($inventoryAccountMissions->isEmpty()) return ['success' => false, 'data' => '没有找到相应记录!'];
  173. // $stockInventoryPersons=$inventoryAccountMissions->stockInventoryPersons;
  174. // return ['success'=>true,'data'=>$inventoryAccountMissions,'stockInventoryPersons'=>$stockInventoryPersons];
  175. return ['success' => true, 'data' => $inventoryAccountMissions];
  176. }
  177. //盘点任务导出
  178. public function stockInventoryExport(Request $request)
  179. {
  180. if (!Gate::allows('库存管理-盘点')) {
  181. return redirect(url('/'));
  182. }
  183. ini_set('max_execution_time', 3500);
  184. ini_set('memory_limit', '3526M');
  185. if ($request->checkAllSign) {
  186. $request->offsetUnset('checkAllSign');
  187. $queryParam = $request->all();
  188. $inventoryAccounts = app('inventoryAccountService')->get($queryParam);
  189. } else {
  190. $queryParam = $request->all();
  191. $inventoryAccounts = app('inventoryAccountService')->some($queryParam);
  192. }
  193. $row = [[
  194. 'id' => '盘点单号',
  195. 'status' => '盘点状态',
  196. 'created_at' => '创建时间',
  197. 'owner_id' => '货主',
  198. 'type' => '任务类型',
  199. 'start_at' => '起始时间',
  200. 'end_at' => '结束时间',
  201. 'total' => '盘点任务数',
  202. 'processed' => '盘点数量',
  203. 'surplus' => '未盘数量',
  204. 'ignored' => '跳过数量',
  205. 'difference' => '差异数量',
  206. 'returned' => '复盘归位',
  207. 'proportion' => '盘点比例',
  208. ]];
  209. $list = [];
  210. for ($i = 0; $i < count($inventoryAccounts); $i++) {
  211. $inventoryAccount = $inventoryAccounts[$i];
  212. $w = [
  213. 'id' => isset($inventoryAccount->id) ? $inventoryAccount->id : '',
  214. 'status' => isset($inventoryAccount->status) ? $inventoryAccount->status : '',
  215. 'created_at' => isset($inventoryAccount->created_at) ? $inventoryAccount->created_at : '',
  216. 'owner_id' => isset($inventoryAccount->owner->name) ? $inventoryAccount->owner->name : '',
  217. 'type' => isset($inventoryAccount->type) ? $inventoryAccount->type : '',
  218. 'start_at' => isset($inventoryAccount->start_at) ? $inventoryAccount->start_at : '',
  219. 'end_at' => isset($inventoryAccount->end_at) ? $inventoryAccount->end_at : '',
  220. 'total' => isset($inventoryAccount->total) ? $inventoryAccount->total : '',
  221. 'processed' => isset($inventoryAccount->processed) ? $inventoryAccount->processed : '',
  222. 'surplus' => isset($inventoryAccount->surplus) ? $inventoryAccount->surplus : '',
  223. 'ignored' => isset($inventoryAccount->ignored) ? $inventoryAccount->ignored : '',
  224. 'difference' => isset($inventoryAccount->difference) ? $inventoryAccount->difference : '',
  225. 'returned' => isset($inventoryAccount->returned) ? $inventoryAccount->returned : '',
  226. 'proportion' => isset($inventoryAccount->processed) && isset($inventoryAccount->total) ? $inventoryAccount->processed.'/'.$inventoryAccount->total : '',
  227. ];
  228. $list[$i] = $w;
  229. }
  230. return Excel::download(new Export($row, $list), date('YmdHis', time()) . '-盘点任务记录单.xlsx');
  231. }
  232. public function stockInventoryEnd(Request $request)
  233. {
  234. if (!Gate::allows('库存管理-盘点-结束初盘')) {
  235. return ['success' => false, 'data' => '没有权限'];
  236. }
  237. $id = $request->input('id');
  238. if (!$id) return ['success' => false, 'data' => '参数错误!'];
  239. $inventoryAccount = InventoryAccount::query()->where('id', $id)->update(['status' => '复盘中']);
  240. app('LogService')->log(__METHOD__, '结束初盘任务' . __FUNCTION__, json_encode($request->toArray()), Auth::user()['id']);
  241. if ($inventoryAccount > 0) return ['success' => true, 'data' => '复盘中'];
  242. return ['success' => false, 'data' => '参数错误!'];
  243. }
  244. public function syncOwners(OwnerService $ownerService)
  245. {
  246. if (!Gate::allows('库存管理-盘点')) {
  247. return redirect(url('/'));
  248. }
  249. $owners = $ownerService->syncOwnersData();
  250. if (!$owners) return ['success' => false, 'data' => '同步货主失败!'];
  251. return ['success' => true, 'data' => $owners];
  252. }
  253. public function 修改质量状态(Request $request)
  254. {
  255. if (!Gate::allows('库存管理-盘点')) {
  256. return redirect(url('/'));
  257. }
  258. $id = $request->input('id');
  259. $location = $request->location;
  260. $sku = $request->sku;
  261. $quality = $request->quality;
  262. $ownerCode = $request->ownerCode;
  263. $inventoryAccountMission = app('inventoryAccountService')->修改质量状态($id, $location, $sku, $quality, $ownerCode);
  264. app('LogService')->log(__METHOD__, __FUNCTION__, json_encode($request->toArray()), Auth::user()['id']);
  265. if ($inventoryAccountMission == null) return ['success' => false, 'data' => 'WMS中不存在该条记录!'];
  266. return ['success' => true, 'data' => '质量状态修改成功'];
  267. }
  268. public function 完结盘点任务($id)
  269. {
  270. if (!Gate::allows('库存管理-盘点-完结')) {
  271. return ['success' => false, 'status' => '没有权限'];
  272. }
  273. if (!$id) return ['success' => false, 'status' => '参数错误!'];
  274. $inventoryAccount = app('inventoryAccountService')->完结盘点任务($id);
  275. if (!$inventoryAccount) return ['success' => false, 'status' => '修改完结状态失败!'];
  276. return ['success' => true, 'data' => $inventoryAccount];
  277. }
  278. public function 增加系统之外的盘点记录(Request $request)
  279. {
  280. if (!Gate::allows('库存管理-盘点')) {
  281. return ['success' => false, 'data' => '没有权限'];
  282. }
  283. $location = $request->input('location');
  284. $barcode = $request->input('barcode');
  285. $inventoryId = $request->input('inventoryId');
  286. $count = $request->input('count');
  287. $owner_code = $request->input('owner_code');
  288. $param = $request->input('param');
  289. if (is_null($count)) return ['success' => false, 'data' => '盘点数不能为空!'];
  290. $inventoryAccountMission = app('inventoryAccountService')->增加系统之外的盘点记录($location, $barcode, $inventoryId, $count, $owner_code, $param);
  291. if (!$inventoryAccountMission) return ['success' => false, 'data' => '添加系统之外的库位记录失败!'];
  292. $inventoryAccountMission = InventoryAccountMission::with(['commodity.barcodes', 'stockInventoryPersons'])->where('id', $inventoryAccountMission->id)->first();
  293. $stockInventoryPersons = $inventoryAccountMission->stockInventoryPersons;
  294. return ['success' => true, 'inventoryAccountMission' => $inventoryAccountMission, 'stockInventoryPersons' => $stockInventoryPersons];
  295. }
  296. public function 盘点选中任务(Request $request)
  297. {
  298. if (!Gate::allows('库存管理-盘点')) {
  299. return ['success' => false, 'data' => '没有权限'];
  300. }
  301. $id = $request->input('id');
  302. $count = $request->count;
  303. $inventoryId = $request->input('inventoryId');
  304. $produced_at = $request->input('produced_at');
  305. $valid_at = $request->input('valid_at');
  306. $batch_number = $request->input('batch_number');
  307. if (is_null($count)) return ['success' => false, 'data' => '盘点数不能为空!'];
  308. if ($produced_at || $valid_at || $batch_number) {
  309. /** @var InventoryAccountService $inventoryAccountMission */
  310. $inventoryAccountService = app('inventoryAccountService');
  311. $inventoryAccountMission = $inventoryAccountService->盘点生产日期_失效日期_批号有改动任务($id, $count, $inventoryId, $produced_at, $valid_at, $batch_number);
  312. if (!$inventoryAccountMission) return ['success' => false, 'data' => '盘点生产日期_失效日期_批号有改动任务失败!'];
  313. /** @var InventoryAccountService $inventoryService */
  314. $inventoryService = app('inventoryAccountService');
  315. $inventoryAccount = $inventoryService->updateInventory($inventoryId);
  316. $stockInventoryPersons = $inventoryAccountMission[0]->stockInventoryPersons;
  317. return ['success' => true, 'inventoryMission' => $inventoryAccountMission, 'inventory' => $inventoryAccount, 'stockInventoryPersons' => $stockInventoryPersons];
  318. } else {
  319. /** @var InventoryAccountService $inventoryAccountMission */
  320. $inventoryAccountService = app('inventoryAccountService');
  321. $inventoryAccountMission = $inventoryAccountService->盘点选中任务($id, $count, $inventoryId);
  322. if (!$inventoryAccountMission) return ['success' => false, 'data' => '盘点选中任务失败!'];
  323. /** @var InventoryAccountService $inventoryService */
  324. $inventoryService = app('inventoryAccountService');
  325. $inventoryAccount = $inventoryService->updateInventory($inventoryId);
  326. $stockInventoryPersons = $inventoryAccountMission->stockInventoryPersons;
  327. return ['success' => true, 'inventoryMission' => $inventoryAccountMission, 'inventory' => $inventoryAccount, 'stockInventoryPersons' => $stockInventoryPersons];
  328. }
  329. }
  330. public function 删除盘点记录(Request $request)
  331. {
  332. if (!Gate::allows('库存管理-盘点-删除')) {
  333. return ['success' => false, 'data' => '没有权限'];
  334. }
  335. $inventoryAccountMissionId = $request->input('inventoryAccountMissionId');
  336. $inventoryAccountId = $request->input('inventoryAccountId');
  337. if (is_null($inventoryAccountMissionId)) {
  338. return ['success' => false, 'data' => '传入id为空'];
  339. }
  340. /** @var InventoryAccountService $inventoryService */
  341. $inventoryService = app('inventoryAccountService');
  342. $inventoryAccountMission = $inventoryService->删除盘点记录($inventoryAccountMissionId, $inventoryAccountId);
  343. return ['success' => true, 'data' => $inventoryAccountMission];
  344. }
  345. public function 跳过盘点记录(Request $request)
  346. {
  347. if (!Gate::allows('库存管理-盘点')) {
  348. return ['success' => false, 'data' => '没有权限'];
  349. }
  350. $inventoryAccountMissionId = $request->inventoryAccountMissionId;
  351. $inventoryAccountId = $request->input('inventoryAccountId');
  352. if (is_null($inventoryAccountMissionId)) {
  353. return ['success' => false, 'data' => '传入id为空'];
  354. }
  355. /** @var InventoryAccountService $inventoryService */
  356. $inventoryService = app('inventoryAccountService');
  357. $inventoryAccountMission = $inventoryService->跳过盘点记录($inventoryAccountMissionId, $inventoryAccountId);
  358. return ['success' => true, 'inventoryAccountMission' => $inventoryAccountMission];
  359. }
  360. public function 确认盘点差异(Request $request)
  361. {
  362. if (!Gate::allows('库存管理-盘点')) {
  363. return ['success' => false, 'data' => '没有权限'];
  364. }
  365. $inventoryAccountMissionId = $request->inventoryAccountMissionId;
  366. $inventoryAccountId = $request->input('inventoryAccountId');
  367. if (is_null($inventoryAccountMissionId)) {
  368. return ['success' => false, 'data' => '传入id为空'];
  369. }
  370. /** @var InventoryAccountService $inventoryService */
  371. $inventoryService = app('inventoryAccountService');
  372. $inventoryAccountMission = $inventoryService->确认盘点差异($inventoryAccountMissionId, $inventoryAccountId);
  373. return ['success' => true, 'inventoryAccountMission' => $inventoryAccountMission];
  374. }
  375. public function 批量跳过或确认差异(Request $request)
  376. {
  377. if (!Gate::allows('库存管理-盘点')) {
  378. return ['success' => false, 'data' => '没有权限'];
  379. }
  380. $checkData = $request->checkData;
  381. if (is_null($checkData)) {
  382. return ['success' => false, 'data' => '传入勾选盘点记录为空'];
  383. }
  384. $marks = [];
  385. foreach ($checkData as $inventoryMission) {
  386. if (isset($inventoryMission['mark']))array_push($marks,$inventoryMission['mark']);
  387. }
  388. if (in_array('确认差异', $marks) || in_array('跳过', $marks) || in_array('无差异', $marks) || in_array('已复盘无差异', $marks)) return ['success' => false, 'data' => '传入勾选盘点记录存在不可操作项!'];
  389. /** @var InventoryAccountService $inventoryService */
  390. $inventoryService = app('inventoryAccountService');
  391. $inventoryAccountMissions = $inventoryService->批量跳过或确认差异($checkData);
  392. return ['success' => true, 'inventoryAccountMissions' => $inventoryAccountMissions];
  393. }
  394. public function exportInventoryAccountMission(Request $request)
  395. {
  396. if (!Gate::allows("库存管理-盘点")) {
  397. return redirect(url('/'));
  398. }
  399. $list = [];
  400. foreach (json_decode($request->data,true) as $item){
  401. $list[] = [
  402. $item["location"],
  403. $item["commodity_name"],
  404. $item["commodity_barcode"],
  405. $item["commodity_sku"],
  406. $item["produced_at"],
  407. $item["valid_at"],
  408. $item["batch_number"],
  409. $item["stock_person"],
  410. $item["erp_type_position"],
  411. $item["quality"],
  412. $item["stored_amount"],
  413. $item["valid_amount"],
  414. $item["verified_amount"],
  415. $item["re_checked_amount"],
  416. $item["difference_amount"],
  417. $item["occupied_amount"],
  418. $item["mark"],
  419. ];
  420. }
  421. return \Oursdreams\Export\Export::make(["库位","产品名","商品条码","商品编码","生产日期","失效日期","批号","盘点人","ERP属性仓","质量状态","库存数量",
  422. "可用数量","盘点数量","复盘数量","复盘差异","分配数量","状态"],$list,"库存盘点记录");
  423. }
  424. public function searchCommodityByBarcode(Request $request)
  425. {
  426. if (!Gate::allows('库存管理-盘点')) {
  427. return ['success' => false, 'data' => '没有权限'];
  428. }
  429. $barcode = $request->input('barcode');
  430. $owner_code = $request->input('owner_code');
  431. /** @var InventoryAccountService $inventoryService */
  432. $inventoryService = app('inventoryAccountService');
  433. $commodity = $inventoryService->searchCommodityByBarcode($barcode, $owner_code);
  434. if ($commodity) {
  435. return ['success' => true, 'data' => $commodity];
  436. } else {
  437. return ['success' => false, 'data' => '输入的条码没有对应商品!'];
  438. }
  439. }
  440. //根据库位批量盘点该库位下盘点记录
  441. public function batchStockByLocation(Request $request)
  442. {
  443. if (!Gate::allows('库存管理-盘点')) return ['success' => false, 'msg' => '没有权限'];
  444. $missions=$request->mission;
  445. $inventoryId=$request->inventoryId;
  446. if (!$inventoryId||count($missions)<1) return ['success' => false, 'msg' => '参数错误'];
  447. /** @var InventoryAccountService $inventoryService */
  448. $inventoryService = app('inventoryAccountService');
  449. $inventoryMissions=$inventoryService->batchStockByLocation($missions,$inventoryId);
  450. $inventoryService = app('inventoryAccountService');
  451. $inventoryAccount = $inventoryService->updateInventory($inventoryId);
  452. $stockInventoryPersons = $inventoryMissions[0]->stockInventoryPersons;
  453. return ['success' => true, 'inventoryMission' => $inventoryMissions, 'inventory' => $inventoryAccount, 'stockInventoryPersons' => $stockInventoryPersons];
  454. }
  455. }