InventoryController.php 8.8 KB

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