InventoryAccountController.php 25 KB

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