StorageController.php 13 KB

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