InventoryController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. * "verified_amount" =>"已盘数量",
  119. * "produced_at"=>"生产日期",
  120. * "valid_at"=>"失效日期",
  121. * "batch_number"=>"批号",
  122. * "erp_type_position"=>"属性仓",
  123. * "quality"=>"质量状态",
  124. * }
  125. * }
  126. */
  127. public function getInventoryDetail(Request $request)
  128. {
  129. $taskId = $request->input("taskId");
  130. $location = $request->input("location");
  131. $barcode = $request->input("barcode");
  132. $inventoryDetail=app('AndroidInventoryService')->getInventoryDetail($taskId,$location,$barcode);
  133. if ($inventoryDetail) {
  134. $this->response($inventoryDetail);
  135. }else{
  136. $this->response(null,410,'未检测到指定盘点任务');
  137. }
  138. }
  139. /**
  140. * @api {post} /inventory/stockInventory 盘点
  141. * @apiName stockInventory
  142. * @apiGroup inventory
  143. *
  144. * @apiParam {int} taskId 盘点任务号
  145. * @apiParam {string} location 库位
  146. * @apiParam {string} barcode 条码
  147. * @apiParam {int} amount 盘点数量
  148. *
  149. * @apiSuccess {string} message 响应描述
  150. * @apiSuccess {int} status_code HTTP响应码
  151. * @apiSuccess {array} data 数据列表
  152. *
  153. * @apiSuccessExample {json} Success-Response:
  154. * HTTP/1.1 200 OK
  155. * {
  156. * "message": "请求成功",
  157. * "status_code": "200"
  158. * "data":[
  159. * "notStocktakingList"=>[
  160. * {
  161. * "id"=>"盘点任务明细号",
  162. * "location"=>"库位",
  163. * }
  164. * ]
  165. * ]
  166. * }
  167. */
  168. public function stockInventory(Request $request)
  169. {
  170. $task_item_id = $request->input("task_item_id");
  171. $verified_amount = $request->input("verified_amount");
  172. /**
  173. * @var AndroidInventoryService $service
  174. *@var InventoryAccountService $stockService
  175. */
  176. $service=app('AndroidInventoryService');
  177. $stockService=app('InventoryAccountService');
  178. $inventoryAccountMission=InventoryAccountMission::query()->find($task_item_id);
  179. if (!$inventoryAccountMission)$this->response(null,410,'未查询到盘点明细');
  180. $task_id=$inventoryAccountMission->inventory_account_id;
  181. if (!$request->has('produced_at')&&!$request->has('valid_at')&&!$request->has('batch_number')){
  182. $stockService->盘点($task_id,$verified_amount,$inventoryAccountMission);
  183. }else{
  184. $stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
  185. $request->input('produced_at')??'', $request->input('valid_at')??'',
  186. $request->input('batch_number')??'');
  187. $stockService->updateInventory($task_id);
  188. }
  189. $notStocktakingList=$service->getUnInventoryTaskList($task_id);
  190. $this->response([
  191. "notStocktakingList" => $notStocktakingList,
  192. ]);
  193. }
  194. /**
  195. * @api {post} /inventory/skipInventory 跳过盘点
  196. * @apiName skipInventory
  197. * @apiGroup inventory
  198. *
  199. * @apiParam {int} inventoryDetailId 盘点任务明细id
  200. *
  201. * @apiSuccess {string} message 响应描述
  202. * @apiSuccess {int} status_code HTTP响应码
  203. * @apiSuccess {array} data 数据列表
  204. *
  205. * @apiSuccessExample {json} Success-Response:
  206. * HTTP/1.1 200 OK
  207. * {
  208. * "message": "请求成功",
  209. * "status_code": "200"
  210. * "data":[
  211. * inventoryTaskDetails=>[
  212. * {
  213. * "id"=>"盘点任务明细号",
  214. * "location"=>"库位",
  215. * }
  216. * ]
  217. * sameDayInventoryCount=>“当日盘点行数”
  218. * ]
  219. * }
  220. */
  221. public function skipInventory(Request $request)
  222. {
  223. $inventoryDetailId = $request->input("inventoryDetailId");
  224. /** @var AndroidInventoryService $service */
  225. $service=app('AndroidInventoryService');
  226. $inv=$service->skipInventory($inventoryDetailId);
  227. if ($inv){
  228. $inventoryTaskDetails=$service->getUnInventoryTaskList($inv->inventory_account_id);
  229. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  230. $this->response([
  231. 'inventoryTaskDetails' => $inventoryTaskDetails, 'sameDayInventoryCount'=>$sameDayInventoryCount
  232. ]);
  233. }else{
  234. $this->response(null,410,'跳过失败!');
  235. }
  236. }
  237. }