StorageController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. namespace App\Http\Controllers\api\thirdPart\haiq;
  3. use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
  4. use App\Services\ForeignHaiRoboticsService;
  5. use App\Services\LogService;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Http;
  8. use Ramsey\Uuid\Uuid;
  9. class StorageController
  10. {
  11. protected $post;
  12. /** @var ForeignHaiRoboticsService $service */
  13. private $service;
  14. public function __construct()
  15. {
  16. $this->service=app('ForeignHaiRoboticsService');
  17. $stockInfo = [
  18. "skuCode" => "TEST-BSSKU",//商品编码 sku
  19. "qty" => 9,//数量
  20. ];
  21. $bin = [
  22. "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
  23. "binCode" => "TEST-BIN01",//料箱编码
  24. "fromLocCode" => "HAIB1-02-01",//源库位编码
  25. "toLocCode" => "HAIB1-02-01",//目标库位编码 出库填多个,表示这些库位都可以支持
  26. "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
  27. "stockInfo" => [$stockInfo],//商品信息
  28. ];
  29. /*$this->request = [[
  30. "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
  31. "taskMode" => 3,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
  32. "priority" => 99,//优先级 1-2147483647 1最低
  33. "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
  34. "bins" => [$bin],//可执行货箱任务
  35. ]];*///IDE0005714,IDE0004970,IDE0005676,IDE0005665
  36. $this->post = [[
  37. "taskMode" => 1,
  38. "bins"=>[
  39. [
  40. "binCode" => "IDE0000009",
  41. "taskCode" =>'t1'.microtime(true),
  42. "fromLocCode" => "BIN-IN1",
  43. "toLocCode" => "",
  44. ],
  45. [
  46. "binCode" => "IDE0000032",
  47. "taskCode" =>'t2'.microtime(true),
  48. "fromLocCode" => "BIN-IN1",
  49. "toLocCode" => "",
  50. ],
  51. [
  52. "binCode" => "IDE0000153",
  53. "taskCode" =>'t3'.microtime(true),
  54. "fromLocCode" => "BIN-IN1",
  55. "toLocCode" => "",
  56. ],
  57. [
  58. "binCode" => "IDE0005227",
  59. "taskCode" =>'t4'.microtime(true),
  60. "fromLocCode" => "BIN-IN1",
  61. "toLocCode" => "",
  62. ],
  63. [
  64. "binCode" => "IDE0005659",
  65. "taskCode" =>'t5'.microtime(true),
  66. "fromLocCode" => "BIN-IN1",
  67. "toLocCode" => "",
  68. ],
  69. [
  70. "binCode" => "IDE0005719",
  71. "taskCode" =>'t7'.microtime(true),
  72. "fromLocCode" => "BIN-IN1",
  73. "toLocCode" => "",
  74. ],
  75. [
  76. "binCode" => "IDE0005132",
  77. "taskCode" =>'t8'.microtime(true),
  78. "fromLocCode" => "BIN-IN1",
  79. "toLocCode" => "",
  80. ],
  81. [
  82. "binCode" => "IDE0005134",
  83. "taskCode" =>'t9'.microtime(true),
  84. "fromLocCode" => "BIN-IN1",
  85. "toLocCode" => "",
  86. ],
  87. [
  88. "binCode" => "IDE0005133",
  89. "taskCode" =>'t10'.microtime(true),
  90. "fromLocCode" => "BIN-IN1",
  91. "toLocCode" => "",
  92. ],
  93. [
  94. "binCode" => "IDE0005256",
  95. "taskCode" =>'t11'.microtime(true),
  96. "fromLocCode" => "BIN-IN1",
  97. "toLocCode" => "",
  98. ],
  99. [
  100. "binCode" => "IDE0005262",
  101. "taskCode" =>'t12'.microtime(true),
  102. "fromLocCode" => "BIN-IN1",
  103. "toLocCode" => "",
  104. ],
  105. ],
  106. "groupCode" => 'g'.microtime(true),
  107. "priority" => 20,
  108. "sequenceFlag" => 1,
  109. ]];
  110. $this->post2 = [[
  111. "taskMode" => 2,
  112. "bins"=>[
  113. [
  114. "taskCode" =>'t1'.microtime(true),
  115. "binCode" => "IDE0000009",
  116. "fromLocCode" => "",
  117. "toLocCode" => "BIN-OUT1",
  118. ],
  119. [
  120. "taskCode" =>'t2'.microtime(true),
  121. "binCode" => "IDE0000032",
  122. "fromLocCode" => "",
  123. "toLocCode" => "BIN-OUT1",
  124. ],
  125. [
  126. "taskCode" =>'t5'.microtime(true),
  127. "binCode" => "IDE0000153",
  128. "fromLocCode" => "",
  129. "toLocCode" => "BIN-OUT1",
  130. ],
  131. [
  132. "taskCode" =>'t8'.microtime(true),
  133. "binCode" => "IDE0005227",
  134. "fromLocCode" => "",
  135. "toLocCode" => "BIN-OUT1",
  136. ],
  137. ],
  138. "groupCode" => 'g'.microtime(true),
  139. "priority" => 20,
  140. "sequenceFlag" => 1,
  141. ]];
  142. $this->moveBinIn = [[
  143. "taskMode" => 6,
  144. "bins"=>[[
  145. "taskCode" =>'t1'.microtime(true),
  146. "binCode" => "IDE0005682",
  147. "fromLocCode" => "HAIB1-01-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  148. "toLocCode" => "",
  149. ]
  150. // ,[
  151. // "taskCode" =>'t2'.microtime(true),
  152. // "binCode" => "IDE0004973",
  153. // "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  154. // "toLocCode" => "",
  155. // ]
  156. // ,[
  157. // "taskCode" =>'t3'.microtime(true),
  158. // "binCode" => "IDE0005716",
  159. // "fromLocCode" => "HAIB1-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  160. // "toLocCode" => "",
  161. // ],
  162. ],
  163. "groupCode" => 'g'.microtime(true),
  164. "priority" => 20,
  165. "sequenceFlag" => 1,
  166. ]];
  167. $this->moveBinIn2 = [[
  168. "taskMode" => 3,
  169. "bins"=>[[
  170. "taskCode" =>'t1'.microtime(true),
  171. "binCode" => "IDE0000036",
  172. "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  173. "toLocCode" => "HAIB1-01-03",
  174. ],[
  175. "taskCode" =>'t2'.microtime(true),
  176. "binCode" => "IDE0004973",
  177. "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  178. "toLocCode" => "HAIB1-02-03",
  179. ],[
  180. "taskCode" =>'t3'.microtime(true),
  181. "binCode" => "IDE0005716",
  182. "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  183. "toLocCode" => "HAIB1-03-02",
  184. ],],
  185. "groupCode" => 'g'.microtime(true),
  186. "priority" => 20,
  187. "sequenceFlag" => 1,
  188. ]];
  189. $this->move = [[
  190. "taskMode" => 3,
  191. "bins"=>[[
  192. "taskCode" =>'t'.Uuid::uuid4(),
  193. "binCode" => "IDE0005678",
  194. "fromLocCode" => "",
  195. "toLocCode" => "HAIB1-03-01",
  196. ],[
  197. "taskCode" =>'t'.Uuid::uuid4(),
  198. "binCode" => "IDE0004975",
  199. "fromLocCode" => "",
  200. "toLocCode" => "HAIB1-03-02",
  201. ],],
  202. "groupCode" => 'g'.microtime(true),
  203. "priority" => 20,
  204. "sequenceFlag" => 1,
  205. ]];//128,129.127
  206. $this->move2 = [[
  207. "taskMode" => 6,
  208. "bins"=>[
  209. [
  210. "taskCode" =>'t'.Uuid::uuid4(),
  211. "binCode" => "IDE0005711",
  212. "fromLocCode" => "HAIB1-01-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  213. "toLocCode" => "",
  214. ],
  215. [
  216. "taskCode" =>'t'.Uuid::uuid4(),
  217. "binCode" => "IDE0005680",
  218. "fromLocCode" => "HAIB1-02-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  219. "toLocCode" => "",
  220. ],
  221. ],
  222. "groupCode" => 'g'.microtime(true),
  223. "priority" => 20,
  224. "sequenceFlag" => 1,
  225. ]];
  226. $this->move3 = [[
  227. "taskMode" => 6,
  228. "bins"=>[[
  229. "taskCode" =>"testm11",
  230. "binCode" => "IDE0000128",
  231. "fromLocCode" => "HAIB2-01-01",
  232. "toLocCode" => "",
  233. ],[
  234. "taskCode" =>"testm21",
  235. "binCode" => "IDE000129",
  236. "fromLocCode" => "HAIB2-02-01",
  237. "toLocCode" => "",
  238. ],[
  239. "taskCode" =>"testm31",
  240. "binCode" => "IDE0000127",
  241. "fromLocCode" => "HAIB2-03-01",
  242. "toLocCode" => "",
  243. ],],
  244. "groupCode" => 'WMm2',
  245. "priority" => 20,
  246. "sequenceFlag" => 1,
  247. ]];
  248. $this->lightOn = [
  249. "areaCode"=> "1004",
  250. "PTLAction"=> 1, //1是开,0是关
  251. "PTLSettings"=> [
  252. "color"=> 1,
  253. "frequency"=> 1
  254. ],
  255. "displayInfo"=> [
  256. "detail01"=> "detail01",
  257. "detail02"=> "detail02",
  258. "detail03"=> "detail03",
  259. "qrCode"=> "qrCode",
  260. "qty00"=> "11",
  261. "qty01"=> 1,
  262. "qty02"=> 2,
  263. "title"=> "title",
  264. "uomDesc01"=> "uo",
  265. "uomDesc02"=> "uo"
  266. ],
  267. "locCode"=> "HAIB2-02-03"//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  268. ];
  269. $this->lightOff = [
  270. "PTLAction"=> 0,
  271. "locCode"=> "HAIB2-02-03"
  272. ];
  273. }
  274. public function relocate(Request $request,$post){
  275. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  276. if (!$response->ok()){
  277. app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  278. return ['success'=>false,"data"=>$response->body()];
  279. }
  280. if (($response["code"] ?? false) && $response["code"] != 200){
  281. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  282. return ['success'=>false,"data"=>$response["errMsg"]];
  283. }
  284. if (($response["status"] ?? false) && $response["status"] == 500){
  285. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  286. return ['success'=>false,"data"=>$response["msg"]];
  287. }
  288. app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  289. return ["success"=>true,'data'=>$response->body()];
  290. }
  291. public function light(Request $request,$post){
  292. $response = Http::post(config('api.haiq.storage.light'),$post);
  293. return $response->body();
  294. }
  295. public function moveBinOut(Request $request){
  296. return $this->relocate($request,$this->post);
  297. }
  298. public function postBin1(Request $request){
  299. return $this->relocate($request,$this->post);
  300. }
  301. public function postBin2(Request $request){
  302. return $this->relocate($request,$this->post2);
  303. }
  304. public function moveBinIn(Request $request){
  305. return $this->relocate($request,$this->moveBinIn);
  306. }
  307. public function moveBinIn2(Request $request){
  308. return $this->relocate($request,$this->moveBinIn2);
  309. }
  310. public function moveBinM(Request $request){
  311. return $this->relocate($request,$this->move);
  312. }
  313. public function moveBinM2(Request $request){
  314. return $this->relocate($request,$this->move2);
  315. }
  316. public function lightOn(Request $request){
  317. return $this->light($request,$this->lightOn);
  318. }
  319. public function lightOff(Request $request){
  320. return $this->light($request,$this->lightOff);
  321. }
  322. public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
  323. LogService::log('海柔请求','taskUpdate',
  324. json_encode($request->all()));
  325. try{
  326. $stationTaskMaterialBox_id = explode('_',$request['taskCode'])[0];
  327. $this->service->taskUpdate(
  328. // $request['groupCode']
  329. $stationTaskMaterialBox_id
  330. ,$request['updateEventType']
  331. ,$request['status']
  332. ,$request['binCode']
  333. // ,$request['kubotId']
  334. // ,$request['description']
  335. );
  336. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  337. }catch (\Exception $e){
  338. return ['code'=>$e->getCode(),'errMsg'=>$e->getMessage(),'data'=>$request->all()];
  339. }
  340. }
  341. public function exception(Request $request){
  342. $this->service->excepted('海柔异常','',json_encode($request));
  343. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  344. }
  345. }