StorageController.php 12 KB

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