StorageController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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" => "IDE0005713",
  41. "taskCode" =>UUID::uuid4().'|'.microtime(true),
  42. "fromLocCode" => "BIN-IN1",
  43. "toLocCode" => "",
  44. ],
  45. ],
  46. "groupCode" => 'g'.microtime(true),
  47. "priority" => 20,
  48. "sequenceFlag" => 1,
  49. ]];
  50. $this->post2 = [[
  51. "taskMode" => 2,
  52. "bins"=>[
  53. [
  54. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  55. "binCode" => "IDE0000009",
  56. "fromLocCode" => "",
  57. "toLocCode" => "BIN-OUT1",
  58. ],
  59. [
  60. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  61. "binCode" => "IDE0000101",
  62. "fromLocCode" => "",
  63. "toLocCode" => "BIN-OUT1",
  64. ],
  65. [
  66. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  67. "binCode" => "IDE0000153",
  68. "fromLocCode" => "",
  69. "toLocCode" => "BIN-OUT1",
  70. ],
  71. [
  72. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  73. "binCode" => "IDE0000167",
  74. "fromLocCode" => "",
  75. "toLocCode" => "BIN-OUT1",
  76. ],
  77. [
  78. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  79. "binCode" => "IDE0004462",
  80. "fromLocCode" => "",
  81. "toLocCode" => "BIN-OUT1",
  82. ],
  83. [
  84. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  85. "binCode" => "IDE0004463",
  86. "fromLocCode" => "",
  87. "toLocCode" => "BIN-OUT1",
  88. ],
  89. [
  90. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  91. "binCode" => "IDE0004954",
  92. "fromLocCode" => "",
  93. "toLocCode" => "BIN-OUT1",
  94. ],
  95. [
  96. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  97. "binCode" => "IDE0004966",
  98. "fromLocCode" => "",
  99. "toLocCode" => "BIN-OUT1",
  100. ],
  101. [
  102. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  103. "binCode" => "IDE0004968",
  104. "fromLocCode" => "",
  105. "toLocCode" => "BIN-OUT1",
  106. ],
  107. [
  108. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  109. "binCode" => "IDE0005226",
  110. "fromLocCode" => "",
  111. "toLocCode" => "BIN-OUT1",
  112. ],
  113. [
  114. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  115. "binCode" => "IDE0005227",
  116. "fromLocCode" => "",
  117. "toLocCode" => "BIN-OUT1",
  118. ],
  119. [
  120. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  121. "binCode" => "IDE0005256",
  122. "fromLocCode" => "",
  123. "toLocCode" => "BIN-OUT1",
  124. ],
  125. ],
  126. "groupCode" => 'g'.microtime(true),
  127. "priority" => 20,
  128. "sequenceFlag" => 1,
  129. ]];
  130. $this->moveBinIn = [[
  131. "taskMode" => 6,
  132. "bins"=>[[
  133. "taskCode" =>'t1'.microtime(true),
  134. "binCode" => "IDE0005173",
  135. "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  136. "toLocCode" => "",
  137. ]
  138. // ,[
  139. // "taskCode" =>'t2'.microtime(true),
  140. // "binCode" => "IDE0004973",
  141. // "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  142. // "toLocCode" => "",
  143. // ]
  144. // ,[
  145. // "taskCode" =>'t3'.microtime(true),
  146. // "binCode" => "IDE0005716",
  147. // "fromLocCode" => "HAIB1-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  148. // "toLocCode" => "",
  149. // ],
  150. ],
  151. "groupCode" => 'g'.microtime(true),
  152. "priority" => 20,
  153. "sequenceFlag" => 1,
  154. ]];
  155. $this->moveBinIn2 = [[
  156. "taskMode" => 3,
  157. "bins"=>[
  158. [
  159. "taskCode" =>'t1'.microtime(true),
  160. "binCode" => "IDE0005716",
  161. "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  162. "toLocCode" => "HAIB1-02-03",
  163. ],
  164. // [
  165. // "taskCode" =>'t2'.microtime(true),
  166. // "binCode" => "IDE0004973",
  167. // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  168. // "toLocCode" => "HAIB1-02-03",
  169. // ],[
  170. // "taskCode" =>'t3'.microtime(true),
  171. // "binCode" => "IDE0005716",
  172. // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  173. // "toLocCode" => "HAIB1-03-02",
  174. // ],
  175. ],
  176. "groupCode" => 'g'.microtime(true),
  177. "priority" => 20,
  178. "sequenceFlag" => 1,
  179. ]];
  180. $this->move = [[
  181. "taskMode" => 3,
  182. "bins"=>[[
  183. "taskCode" =>'t'.Uuid::uuid4(),
  184. "binCode" => "IDE0005678",
  185. "fromLocCode" => "",
  186. "toLocCode" => "HAIB1-03-01",
  187. ],[
  188. "taskCode" =>'t'.Uuid::uuid4(),
  189. "binCode" => "IDE0004975",
  190. "fromLocCode" => "",
  191. "toLocCode" => "HAIB1-03-02",
  192. ],],
  193. "groupCode" => 'g'.microtime(true),
  194. "priority" => 20,
  195. "sequenceFlag" => 1,
  196. ]];//128,129.127
  197. $this->move2 = [[
  198. "taskMode" => 6,
  199. "bins"=>[
  200. [
  201. "taskCode" =>'t'.Uuid::uuid4(),
  202. "binCode" => "IDE0005711",
  203. "fromLocCode" => "HAIB1-01-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  204. "toLocCode" => "",
  205. ],
  206. [
  207. "taskCode" =>'t'.Uuid::uuid4(),
  208. "binCode" => "IDE0005680",
  209. "fromLocCode" => "HAIB1-02-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  210. "toLocCode" => "",
  211. ],
  212. ],
  213. "groupCode" => 'g'.microtime(true),
  214. "priority" => 20,
  215. "sequenceFlag" => 1,
  216. ]];
  217. $this->move3 = [[
  218. "taskMode" => 6,
  219. "bins"=>[[
  220. "taskCode" =>"testm11",
  221. "binCode" => "IDE0000128",
  222. "fromLocCode" => "HAIB2-01-01",
  223. "toLocCode" => "",
  224. ],[
  225. "taskCode" =>"testm21",
  226. "binCode" => "IDE000129",
  227. "fromLocCode" => "HAIB2-02-01",
  228. "toLocCode" => "",
  229. ],[
  230. "taskCode" =>"testm31",
  231. "binCode" => "IDE0000127",
  232. "fromLocCode" => "HAIB2-03-01",
  233. "toLocCode" => "",
  234. ],],
  235. "groupCode" => 'WMm2',
  236. "priority" => 20,
  237. "sequenceFlag" => 1,
  238. ]];
  239. $this->lightOn = [
  240. "areaCode"=> "1004",
  241. "PTLAction"=> 1, //1是开,0是关
  242. "PTLSettings"=> [
  243. "color"=> 1,
  244. "frequency"=> 1
  245. ],
  246. "displayInfo"=> [
  247. "detail01"=> "detail01",
  248. "detail02"=> "detail02",
  249. "detail03"=> "detail03",
  250. "qrCode"=> "qrCode",
  251. "qty00"=> "11",
  252. "qty01"=> 1,
  253. "qty02"=> 2,
  254. "title"=> "title",
  255. "uomDesc01"=> "uo",
  256. "uomDesc02"=> "uo"
  257. ],
  258. "locCode"=> "HAIB2-02-03"//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  259. ];
  260. $this->lightOff = [
  261. "PTLAction"=> 0,
  262. "locCode"=> "HAIB2-02-03"
  263. ];
  264. }
  265. public function relocate(Request $request,$post){
  266. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  267. if (!$response->ok()){
  268. app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  269. return ['success'=>false,"data"=>$response->body()];
  270. }
  271. if (($response["code"] ?? false) && $response["code"] != 200){
  272. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  273. return ['success'=>false,"data"=>$response["errMsg"]];
  274. }
  275. if (($response["status"] ?? false) && $response["status"] == 500){
  276. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  277. return ['success'=>false,"data"=>$response["msg"]];
  278. }
  279. app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  280. return ["success"=>true,'data'=>$response->body()];
  281. }
  282. public function light(Request $request,$post){
  283. $response = Http::post(config('api.haiq.storage.light'),$post);
  284. return $response->body();
  285. }
  286. public function moveBinOut(Request $request){
  287. return $this->relocate($request,$this->post);
  288. }
  289. public function postBin1(Request $request){
  290. return $this->relocate($request,$this->post);
  291. }
  292. public function postBin2(Request $request){
  293. return $this->relocate($request,$this->post2);
  294. }
  295. public function moveBinIn(Request $request){
  296. return $this->relocate($request,$this->moveBinIn);
  297. }
  298. public function moveBinIn2(Request $request){
  299. return $this->relocate($request,$this->moveBinIn2);
  300. }
  301. public function moveBinM(Request $request){
  302. return $this->relocate($request,$this->move);
  303. }
  304. public function moveBinM2(Request $request){
  305. return $this->relocate($request,$this->move2);
  306. }
  307. public function lightOn(Request $request){
  308. return $this->light($request,$this->lightOn);
  309. }
  310. public function lightOff(Request $request){
  311. return $this->light($request,$this->lightOff);
  312. }
  313. public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
  314. LogService::log('海柔请求','taskUpdate',
  315. json_encode($request->all()));
  316. try{
  317. $stationTaskMaterialBox_id = explode('_',$request['taskCode'])[0];
  318. $this->service->taskUpdate(
  319. // $request['groupCode']
  320. $stationTaskMaterialBox_id
  321. ,$request['updateEventType']
  322. ,$request['status']
  323. ,$request['binCode']
  324. // ,$request['kubotId']
  325. // ,$request['description']
  326. );
  327. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  328. }catch (\Exception $e){
  329. return ['code'=>$e->getCode(),'errMsg'=>$e->getMessage(),'data'=>$request->all()];
  330. }
  331. }
  332. public function exception(Request $request){
  333. $this->service->excepted('海柔异常','',json_encode($request));
  334. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  335. }
  336. }