InventoryController.php 9.2 KB

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