StorageController.php 13 KB

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