InventoryController.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace App\Http\ApiControllers;
  3. use App\Components\ApiResponse;
  4. use App\InventoryAccount;
  5. use App\InventoryAccountMission;
  6. use App\Services\AndroidInventoryService;
  7. use App\Services\InventoryAccountService;
  8. use Illuminate\Http\Request;
  9. class InventoryController
  10. {
  11. use ApiResponse;
  12. /**
  13. * @api {get} /inventory/inventoryTask 获取盘点任务数据
  14. * @apiName inventoryTasks
  15. * @apiGroup inventory
  16. *
  17. * @apiParam {int} taskId 盘点任务号
  18. *
  19. * @apiSuccess {string} message 响应描述
  20. * @apiSuccess {int} status_code HTTP响应码
  21. * @apiSuccess {array} data 数据列表
  22. * @apiSuccess {int} data.sameDayInventoryCount 员工当日盘点数
  23. * @apiSuccess {int} data.stocktakingTask 当前盘点任务信息
  24. * @apiSuccess {int} data.notStocktakingList 未盘任务列表
  25. *
  26. * @apiSuccessExample {json} Success-Response:
  27. * HTTP/1.1 200 OK
  28. * {
  29. * "message": "请求成功",
  30. * "status_code": "200"
  31. * "data":[
  32. * "sameDayInventoryCount" => 0,
  33. * "inventoryTask" => {
  34. * "id" =>"盘点任务号",
  35. * "created_at" =>"任务创建时间",
  36. * "end_at" =>"库位最后操作时间",
  37. * "type"=>"任务类型",
  38. * "total"=>"盘点任务数",
  39. * "processed"=>"盘点数",
  40. * },
  41. * "notStocktakingList"=> [
  42. * {
  43. * "location" =>"库位",
  44. * "count" =>"未盘商品数",
  45. * }
  46. * ]
  47. * ]
  48. * }
  49. */
  50. public function getInventoryTask(Request $request)
  51. {
  52. $taskId = $request->input("taskId");
  53. /** @var AndroidInventoryService $service */
  54. $service=app('AndroidInventoryService');
  55. if (!$taskId) $this->response(null,410,"未获取到任务号");
  56. $stocktakingTask = InventoryAccount::query()
  57. ->whereIn('status',['待盘点','盘点中','复盘中'])
  58. ->where('id',$taskId)
  59. ->first();
  60. if (!$stocktakingTask) $this->response(null,410,"未查询到盘点任务");
  61. $notStocktakingList=$service->getUnInventoryTaskList($taskId);
  62. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  63. $this->response(['stocktakingTask' => $stocktakingTask,
  64. 'notStocktakingList' => $notStocktakingList,
  65. 'sameDayInventoryCount'=>$sameDayInventoryCount
  66. ]);
  67. }
  68. /**
  69. * @api {post} /inventory/locationInvPro 当前库位下盘点比例
  70. * @apiName locationInvPro
  71. * @apiGroup inventory
  72. *
  73. * @apiParam {int} taskId 盘点任务号
  74. * @apiParam {string} location 库位
  75. *
  76. * @apiSuccess {string} message 响应描述
  77. * @apiSuccess {int} status_code HTTP响应码
  78. * @apiSuccess {object} data
  79. *
  80. * @apiSuccessExample {json} Success-Response:
  81. * HTTP/1.1 200 OK
  82. * {
  83. * "message": "请求成功",
  84. * "status_code": "200"
  85. * "data":{
  86. * "total" =>"库位盘点任务总条数",
  87. * "invCount" =>"已盘条数"
  88. * }
  89. * }
  90. */
  91. public function locationInvPro(Request $request)
  92. {
  93. $taskId = $request->input("taskId");
  94. $location = $request->input("location");
  95. $res=app('AndroidInventoryService')->getLocInvPro($taskId,$location);
  96. $this->response($res);
  97. }
  98. /**
  99. * @api {post} /inventory/getInventoryDetail 根据盘点任务号,库位,条码 获取盘点明细
  100. * @apiName getInventoryDetail
  101. * @apiGroup inventory
  102. *
  103. * @apiParam {int} taskId 盘点任务号
  104. * @apiParam {string} location 库位
  105. * @apiParam {string} barcode 条码
  106. *
  107. * @apiSuccess {string} message 响应描述
  108. * @apiSuccess {int} status_code HTTP响应码
  109. * @apiSuccess {object} data
  110. *
  111. * @apiSuccessExample {json} Success-Response:
  112. * HTTP/1.1 200 OK
  113. * {
  114. * "message": "请求成功",
  115. * "status_code": "200"
  116. * "data":{
  117. * "id" =>"盘点任务明细号",
  118. * "location" =>"库位",
  119. * "produced_at"=>"生产日期",
  120. * "valid_at"=>"失效日期",
  121. * "stored_at"=>"入库日期",
  122. * "batch_number"=>"批号",
  123. * "erp_type_position"=>"属性仓",
  124. * "quality"=>"质量状态",
  125. * }
  126. * }
  127. */
  128. public function getInventoryDetail(Request $request)
  129. {
  130. $taskId = $request->input("taskId");
  131. $location = $request->input("location");
  132. $barcode = $request->input("barcode");
  133. $inventoryDetail=app('AndroidInventoryService')->getInventoryDetail($taskId,$location,$barcode);
  134. if ($inventoryDetail) {
  135. $this->response($inventoryDetail);
  136. }else{
  137. $this->response(null,410,'未检测到指定盘点任务');
  138. }
  139. }
  140. /**
  141. * @api {post} /inventory/stockInventory 盘点
  142. * @apiName stockInventory
  143. * @apiGroup inventory
  144. *
  145. * @apiParam {int} taskId 盘点任务号
  146. * @apiParam {string} location 库位
  147. * @apiParam {string} barcode 条码
  148. * @apiParam {int} amount 盘点数量
  149. *
  150. * @apiSuccess {string} message 响应描述
  151. * @apiSuccess {int} status_code HTTP响应码
  152. * @apiSuccess {array} data 数据列表
  153. *
  154. * @apiSuccessExample {json} Success-Response:
  155. * HTTP/1.1 200 OK
  156. * {
  157. * "message": "请求成功",
  158. * "status_code": "200"
  159. * "data":[
  160. * "notStocktakingList"=>[
  161. * {
  162. * "id"=>"盘点任务明细号",
  163. * "location"=>"库位",
  164. * }
  165. * ]
  166. * ]
  167. * }
  168. */
  169. public function stockInventory(Request $request)
  170. {
  171. $task_item_id = $request->input("task_item_id");
  172. $verified_amount = $request->input("verified_amount");
  173. /**
  174. * @var AndroidInventoryService $service
  175. *@var InventoryAccountService $stockService
  176. */
  177. $service=app('AndroidInventoryService');
  178. $stockService=app('InventoryAccountService');
  179. $inventoryAccountMission=InventoryAccountMission::query()->find($task_item_id);
  180. if (!$inventoryAccountMission)$this->response(null,410,'未查询到盘点明细');
  181. $task_id=$inventoryAccountMission->inventory_account_id;
  182. if (!$request->has('produced_at')&&!$request->has('valid_at')&&!$request->has('batch_number')){
  183. $stockService->盘点($task_id,$verified_amount,$inventoryAccountMission);
  184. }else{
  185. $stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
  186. $request->input('produced_at')??'', $request->input('valid_at')??'',
  187. $request->input('batch_number')??'');
  188. $stockService->updateInventory($task_id);
  189. }
  190. $notStocktakingList=$service->getUnInventoryTaskList($task_id);
  191. $this->response([
  192. "notStocktakingList" => $notStocktakingList,
  193. ]);
  194. }
  195. /**
  196. * @api {post} /inventory/skipInventory 跳过盘点
  197. * @apiName skipInventory
  198. * @apiGroup inventory
  199. *
  200. * @apiParam {int} inventoryDetailId 盘点任务明细id
  201. *
  202. * @apiSuccess {string} message 响应描述
  203. * @apiSuccess {int} status_code HTTP响应码
  204. * @apiSuccess {array} data 数据列表
  205. *
  206. * @apiSuccessExample {json} Success-Response:
  207. * HTTP/1.1 200 OK
  208. * {
  209. * "message": "请求成功",
  210. * "status_code": "200"
  211. * "data":[
  212. * inventoryTaskDetails=>[
  213. * {
  214. * "id"=>"盘点任务明细号",
  215. * "location"=>"库位",
  216. * }
  217. * ]
  218. * sameDayInventoryCount=>“当日盘点行数”
  219. * ]
  220. * }
  221. */
  222. public function skipInventory(Request $request)
  223. {
  224. $inventoryDetailId = $request->input("inventoryDetailId");
  225. /** @var AndroidInventoryService $service */
  226. $service=app('AndroidInventoryService');
  227. $inv=$service->skipInventory($inventoryDetailId);
  228. if ($inv){
  229. $inventoryTaskDetails=$service->getUnInventoryTaskList($inv->inventory_account_id);
  230. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  231. $this->response([
  232. 'inventoryTaskDetails' => $inventoryTaskDetails, 'sameDayInventoryCount'=>$sameDayInventoryCount
  233. ]);
  234. }else{
  235. $this->response(null,410,'跳过失败!');
  236. }
  237. }
  238. }