StorageController.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. namespace App\Http\Controllers\api\thirdPart\haiq;
  3. use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
  4. use App\Services\ForeignHaiRoboticsService;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Http;
  7. class StorageController
  8. {
  9. protected $post;
  10. /** @var ForeignHaiRoboticsService $service */
  11. private $service;
  12. public function __construct()
  13. {
  14. $this->service=app('ForeignHaiRoboticsService');
  15. $stockInfo = [
  16. "skuCode" => "TEST-BSSKU",//商品编码 sku
  17. "qty" => 9,//数量
  18. ];
  19. $bin = [
  20. "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
  21. "binCode" => "TEST-BIN01",//料箱编码
  22. "fromLocCode" => "HAIB1-02-01",//源库位编码
  23. "toLocCode" => "HAIB1-02-01",//目标库位编码 出库填多个,表示这些库位都可以支持
  24. "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
  25. "stockInfo" => [$stockInfo],//商品信息
  26. ];
  27. /*$this->request = [[
  28. "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
  29. "taskMode" => 3,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
  30. "priority" => 99,//优先级 1-2147483647 1最低
  31. "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
  32. "bins" => [$bin],//可执行货箱任务
  33. ]];*/
  34. $this->post = [[
  35. "taskMode" => 1,
  36. "bins"=>[[
  37. "taskCode" =>"TESTx1za3X14",
  38. "binCode" => "IDE0000130",
  39. "fromLocCode" => "BIN-IN1",
  40. "toLocCode" => "BIN-OUT1",
  41. ],[
  42. "taskCode" =>"TESTx2za3X43",
  43. "binCode" => "IDE0000131",
  44. "fromLocCode" => "BIN-IN1",
  45. "toLocCode" => "BIN-OUT1",
  46. ]],
  47. "groupCode" => 'WMxz3acX14',
  48. "priority" => 20,
  49. "sequenceFlag" => 1,
  50. ]];
  51. $this->post2 = [[
  52. "taskMode" => 2,
  53. "bins"=>[[
  54. "taskCode" =>"TESTxx2zbaa1",
  55. "binCode" => "IDE0000034",
  56. "fromLocCode" => "BIN-IN1",
  57. "toLocCode" => "BIN-OUT1",
  58. ],[
  59. "taskCode" =>"TESTxx3zbaa1",
  60. "binCode" => "IDE0000093",
  61. "fromLocCode" => "BIN-IN1",
  62. "toLocCode" => "BIN-OUT1",
  63. ],[
  64. "taskCode" =>"TESTxx4zbaa1",
  65. "binCode" => "IDE0000128",
  66. "fromLocCode" => "BIN-IN1",
  67. "toLocCode" => "BIN-OUT1",
  68. ],[
  69. "taskCode" =>"TESTxx5zbaa1",
  70. "binCode" => "IDE0000129",
  71. "fromLocCode" => "BIN-IN1",
  72. "toLocCode" => "BIN-OUT1",
  73. ],[
  74. "taskCode" =>"TESTxx6zbaa1",
  75. "binCode" => "IDE0000127",
  76. "fromLocCode" => "BIN-IN1",
  77. "toLocCode" => "BIN-OUT1",
  78. ]],
  79. "groupCode" => 'WMxz64b2a1',
  80. "priority" => 20,
  81. "sequenceFlag" => 1,
  82. ]];;
  83. $this->backIn = [[
  84. "taskMode" => 1,
  85. "bins"=>[[
  86. "taskCode" =>"testIn1ax",
  87. "binCode" => "IDE0000007",
  88. "fromLocCode" => "BIN-IN1",
  89. "toLocCode" => "",
  90. ],[
  91. "taskCode" =>"testIn2ax",
  92. "binCode" => "IDE0000129",
  93. "fromLocCode" => "BIN-IN1",
  94. "toLocCode" => "",
  95. ],],
  96. "groupCode" => 'WMx135ax',
  97. "priority" => 20,
  98. "sequenceFlag" => 1,
  99. ]];
  100. $this->backIn2 = [[
  101. "taskMode" => 6,
  102. "bins"=>[[
  103. "taskCode" =>"testIn123",
  104. "binCode" => "IDE0000130",
  105. "fromLocCode" => "HAIB2-01-03",
  106. "toLocCode" => "",
  107. ],[
  108. "taskCode" =>"testIn223",
  109. "binCode" => "IDE0000034",
  110. "fromLocCode" => "HAIB2-02-03",
  111. "toLocCode" => "",
  112. ],[
  113. "taskCode" =>"testIn323",
  114. "binCode" => "IDE0000093",
  115. "fromLocCode" => "HAIB2-03-03",
  116. "toLocCode" => "",
  117. ]],
  118. "groupCode" => 'WMx14',
  119. "priority" => 20,
  120. "sequenceFlag" => 1,
  121. ]];
  122. $this->move = [[
  123. "taskMode" => 1,
  124. "bins"=>[[
  125. "taskCode" =>"testm1z6",
  126. "binCode" => "IDE0000034",
  127. "fromLocCode" => "BIN-IN1",
  128. "toLocCode" => "",
  129. ],[
  130. "taskCode" =>"testm2z6",
  131. "binCode" => "IDE0000093",
  132. "fromLocCode" => "BIN-IN1",
  133. "toLocCode" => "",
  134. ],[
  135. "taskCode" =>"testm3z6",
  136. "binCode" => "IDE0000130",
  137. "fromLocCode" => "BIN-IN1",
  138. "toLocCode" => "",
  139. ],],
  140. "groupCode" => 'WMm1z6',
  141. "priority" => 20,
  142. "sequenceFlag" => 1,
  143. ]];//128,129.127
  144. $this->move2 = [[
  145. "taskMode" => 6,
  146. "bins"=>[[
  147. "taskCode" =>"testm11",
  148. "binCode" => "IDE0000128",
  149. "fromLocCode" => "HAIB2-01-01",
  150. "toLocCode" => "",
  151. ],[
  152. "taskCode" =>"testm21",
  153. "binCode" => "IDE000129",
  154. "fromLocCode" => "HAIB2-02-01",
  155. "toLocCode" => "",
  156. ],[
  157. "taskCode" =>"testm31",
  158. "binCode" => "IDE0000127",
  159. "fromLocCode" => "HAIB2-03-01",
  160. "toLocCode" => "",
  161. ],],
  162. "groupCode" => 'WMm2',
  163. "priority" => 20,
  164. "sequenceFlag" => 1,
  165. ]];
  166. $this->lightOn = [
  167. "areaCode"=> "1004",
  168. "PTLAction"=> 1,
  169. "PTLSettings"=> [
  170. "color"=> 1,
  171. "frequency"=> 1
  172. ],
  173. "displayInfo"=> [
  174. "detail01"=> "detail01",
  175. "detail02"=> "detail02",
  176. "detail03"=> "detail03",
  177. "qrCode"=> "qrCode",
  178. "qty00"=> "11",
  179. "qty01"=> 1,
  180. "qty02"=> 2,
  181. "title"=> "title",
  182. "uomDesc01"=> "uo",
  183. "uomDesc02"=> "uo"
  184. ],
  185. "locCode"=> "HAIB2-02-03"
  186. ];
  187. $this->lightOff = [
  188. "PTLAction"=> 0,
  189. "locCode"=> "HAIB2-02-03"
  190. ];
  191. }
  192. public function relocate(Request $request,$post){
  193. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  194. if (!$response->ok()){
  195. app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  196. return ['success'=>false,"data"=>$response->body()];
  197. }
  198. if (($response["code"] ?? false) && $response["code"] != 200){
  199. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  200. return ['success'=>false,"data"=>$response["errMsg"]];
  201. }
  202. if (($response["status"] ?? false) && $response["status"] == 500){
  203. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  204. return ['success'=>false,"data"=>$response["msg"]];
  205. }
  206. app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  207. return ["success"=>true];
  208. }
  209. public function light(Request $request,$post){
  210. $response = Http::post(config('api.haiq.storage.light'),$post);
  211. return $response->body();
  212. }
  213. public function moveBinOut(Request $request){
  214. return $this->relocate($request,$this->post);
  215. }
  216. public function moveBin2(Request $request){
  217. return $this->relocate($request,$this->post2);
  218. }
  219. public function moveBinIn(Request $request){
  220. return $this->relocate($request,$this->backIn);
  221. }
  222. public function moveBinIn2(Request $request){
  223. return $this->relocate($request,$this->backIn2);
  224. }
  225. public function moveBinM(Request $request){
  226. return $this->relocate($request,$this->move);
  227. }
  228. public function moveBinM2(Request $request){
  229. return $this->relocate($request,$this->move2);
  230. }
  231. public function lightOn(Request $request){
  232. return $this->light($request,$this->lightOn);
  233. }
  234. public function lightOff(Request $request){
  235. return $this->light($request,$this->lightOff);
  236. }
  237. public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
  238. $this->service->taskUpdate(
  239. $request['groupCode'],
  240. $request['taskCode'],
  241. $request['updateEventType'],
  242. $request['status'],
  243. $request['binCode'],
  244. $request['kubotId'],
  245. $request['description']
  246. );
  247. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->all()));
  248. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  249. }
  250. public function exception(Request $request){
  251. $this->service->throwException();
  252. app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->all()));
  253. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  254. }
  255. }