InventoryAccountController.php 25 KB

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