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. 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. $this->response($res);
  98. }
  99. /**
  100. * @api {post} /inventory/getInventoryDetail 根据盘点任务号,库位,条码 获取盘点明细
  101. * @apiName getInventoryDetail
  102. * @apiGroup inventory
  103. *
  104. * @apiParam {int} taskId 盘点任务号
  105. * @apiParam {string} location 库位
  106. * @apiParam {string} barcode 条码
  107. *
  108. * @apiSuccess {string} message 响应描述
  109. * @apiSuccess {int} status_code HTTP响应码
  110. * @apiSuccess {object} data
  111. *
  112. * @apiSuccessExample {json} Success-Response:
  113. * HTTP/1.1 200 OK
  114. * {
  115. * "message": "请求成功",
  116. * "status_code": "200"
  117. * "data":{
  118. * "id" =>"盘点任务明细号",
  119. * "verified_amount" =>"已盘数量",
  120. * "produced_at"=>"生产日期",
  121. * "valid_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. Log::error('执行开始',[now()->toDateTimeString()]);
  172. $task_item_id = $request->input("task_item_id");
  173. $verified_amount = $request->input("verified_amount");
  174. /**
  175. * @var AndroidInventoryService $service
  176. *@var InventoryAccountService $stockService
  177. */
  178. $service=app('AndroidInventoryService');
  179. $stockService=app('InventoryAccountService');
  180. $inventoryAccountMission=InventoryAccountMission::query()->find($task_item_id);
  181. if (!$inventoryAccountMission)$this->response(null,410,'未查询到盘点明细');
  182. $task_id=$inventoryAccountMission->inventory_account_id;
  183. if (!$request->has('produced_at')&&!$request->has('valid_at')&&!$request->has('batch_number')){
  184. $stockService->盘点($task_id,$verified_amount,$inventoryAccountMission);
  185. }else{
  186. $stockService->盘点生产日期_失效日期_批号有改动任务($task_item_id, $verified_amount, $task_id,
  187. $request->input('produced_at')??'', $request->input('valid_at')??'',
  188. $request->input('batch_number')??'');
  189. $stockService->updateInventory($task_id);
  190. }
  191. $notStocktakingList=$service->getUnInventoryTaskList($task_id);
  192. Log::error('执行结束',[now()->toDateTimeString()]);
  193. $this->response($notStocktakingList);
  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. }