InventoryController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. namespace App\Http\ApiControllers;
  3. use App\Components\ApiResponse;
  4. use App\Http\Requests\AndroidGateRequest;
  5. use App\InventoryAccount;
  6. use App\Services\AndroidInventoryService;
  7. use Illuminate\Support\Facades\Auth;
  8. class InventoryController
  9. {
  10. use ApiResponse;
  11. /**
  12. * @api {get} /inventory/inventoryTasks 获取盘点任务数据
  13. * @apiName inventoryTasks
  14. * @apiGroup inventory
  15. *
  16. * @apiParam {int} taskId 盘点任务号
  17. *
  18. * @apiSuccess {string} message 响应描述
  19. * @apiSuccess {int} status_code HTTP响应码
  20. * @apiSuccess {array} data 数据列表
  21. *
  22. * @apiSuccessExample {json} Success-Response:
  23. * HTTP/1.1 200 OK
  24. * {
  25. * "message": "请求成功",
  26. * "status_code": "200"
  27. * "data":[
  28. * inventoryTask => {
  29. * "id" =>"盘点任务号",
  30. * "created_at" =>"任务创建时间",
  31. * "end_at" =>"库位最后操作时间",
  32. * "type"=>"任务类型",
  33. * "total"=>"盘点任务数",
  34. * "processed"=>"盘点数",
  35. * }
  36. * inventoryTaskDetails=> [
  37. * {
  38. * "id" =>"盘点任务明细号",
  39. * "location" =>"库位",
  40. * "commodity_id" =>"商品id",
  41. * "produced_at"=>"生产日期",
  42. * "valid_at"=>"失效日期",
  43. * "stored_at"=>"入库日期",
  44. * "batch_number"=>"批号",
  45. * "erp_type_position"=>"属性仓",
  46. * "quality"=>"质量状态",
  47. * "stored_amount"=>"库存数量",
  48. * "verified_amount"=>"盘点数量",
  49. * }
  50. * ]
  51. * ]
  52. * }
  53. */
  54. public function getInventoryTask(AndroidGateRequest $request)
  55. {
  56. $taskId = $request->input("taskId");
  57. /** @var AndroidInventoryService $service */
  58. $service=app('AndroidInventoryService');
  59. $inventoryTask = InventoryAccount::query()->find($taskId);
  60. $inventoryTaskDetails=$service->getUnInventoryTaskList($taskId);
  61. $staffName = Auth::user()['name'];
  62. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  63. $this->response(['inventoryTask' => $inventoryTask,
  64. 'inventoryTaskDetails' => $inventoryTaskDetails,
  65. 'staffName'=>$staffName,'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(AndroidGateRequest $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. * "commodity_id" =>"商品id",
  120. * "produced_at"=>"生产日期",
  121. * "valid_at"=>"失效日期",
  122. * "stored_at"=>"入库日期",
  123. * "batch_number"=>"批号",
  124. * "erp_type_position"=>"属性仓",
  125. * "quality"=>"质量状态",
  126. * "stored_amount"=>"库存数量",
  127. * "verified_amount"=>"盘点数量",
  128. * }
  129. * }
  130. */
  131. public function getInventoryDetail(AndroidGateRequest $request)
  132. {
  133. $taskId = $request->input("taskId");
  134. $location = $request->input("location");
  135. $barcode = $request->input("barcode");
  136. $inventoryDetail=app('AndroidInventoryService')->getInventoryDetail($taskId,$location,$barcode);
  137. if ($inventoryDetail) {
  138. $this->response($inventoryDetail);
  139. }else{
  140. $this->response(null,200,'未检测到指定盘点任务');
  141. }
  142. }
  143. /**
  144. * @api {post} /inventory/stockInventory 盘点
  145. * @apiName stockInventory
  146. * @apiGroup inventory
  147. *
  148. * @apiParam {int} taskId 盘点任务号
  149. * @apiParam {string} location 库位
  150. * @apiParam {string} barcode 条码
  151. * @apiParam {int} amount 盘点数量
  152. *
  153. * @apiSuccess {string} message 响应描述
  154. * @apiSuccess {int} status_code HTTP响应码
  155. * @apiSuccess {array} data 数据列表
  156. *
  157. * @apiSuccessExample {json} Success-Response:
  158. * HTTP/1.1 200 OK
  159. * {
  160. * "message": "请求成功",
  161. * "status_code": "200"
  162. * "data":[
  163. * inventoryTaskDetails=>[
  164. * {
  165. * "id"=>"盘点任务明细号",
  166. * "location"=>"库位",
  167. * }
  168. * ]
  169. * sameDayInventoryCount=>“当日盘点行数”
  170. * ]
  171. * }
  172. */
  173. public function stockInventory(AndroidGateRequest $request)
  174. {
  175. $taskId = $request->input("taskId");
  176. $location = $request->input("location");
  177. $barcode = $request->input("barcode");
  178. $amount = $request->input("amount");
  179. /** @var AndroidInventoryService $service */
  180. $service=app('AndroidInventoryService');
  181. $service->stockInventory($taskId,$location,$barcode,$amount);
  182. $inventoryTaskDetails=$service->getUnInventoryTaskList($taskId);
  183. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  184. $this->response([
  185. 'inventoryTaskDetails' => $inventoryTaskDetails, 'sameDayInventoryCount'=>$sameDayInventoryCount
  186. ]);
  187. }
  188. /**
  189. * @api {post} /inventory/skipInventory 跳过盘点
  190. * @apiName skipInventory
  191. * @apiGroup inventory
  192. *
  193. * @apiParam {int} inventoryDetailId 盘点任务明细id
  194. *
  195. * @apiSuccess {string} message 响应描述
  196. * @apiSuccess {int} status_code HTTP响应码
  197. * @apiSuccess {array} data 数据列表
  198. *
  199. * @apiSuccessExample {json} Success-Response:
  200. * HTTP/1.1 200 OK
  201. * {
  202. * "message": "请求成功",
  203. * "status_code": "200"
  204. * "data":[
  205. * inventoryTaskDetails=>[
  206. * {
  207. * "id"=>"盘点任务明细号",
  208. * "location"=>"库位",
  209. * }
  210. * ]
  211. * sameDayInventoryCount=>“当日盘点行数”
  212. * ]
  213. * }
  214. */
  215. public function skipInventory(AndroidGateRequest $request)
  216. {
  217. $inventoryDetailId = $request->input("inventoryDetailId");
  218. /** @var AndroidInventoryService $service */
  219. $service=app('AndroidInventoryService');
  220. $inv=$service->skipInventory($inventoryDetailId);
  221. if ($inv){
  222. $inventoryTaskDetails=$service->getUnInventoryTaskList($inv->inventory_account_id);
  223. $sameDayInventoryCount=$service->getStaffSameDayInvCount();
  224. $this->response([
  225. 'inventoryTaskDetails' => $inventoryTaskDetails, 'sameDayInventoryCount'=>$sameDayInventoryCount
  226. ]);
  227. }else{
  228. $this->response(null,403,'跳过失败!');
  229. }
  230. }
  231. }