StorageController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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" => 1,
  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" => "IDE0004975",
  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" => "HAIB2-03-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  112. "toLocCode" => "",
  113. ]
  114. // ,[
  115. // "taskCode" =>'t'.Uuid::uuid4(),
  116. // "binCode" => "IDE0005680",
  117. // "fromLocCode" => "HAIB2-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  118. // "toLocCode" => "",
  119. // ],[
  120. // "taskCode" =>'t'.Uuid::uuid4(),
  121. // "binCode" => "IDE0005676",
  122. // "fromLocCode" => "HAIB2-03-01", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  123. // "toLocCode" => "",
  124. // ],[
  125. // "taskCode" =>'t'.Uuid::uuid4(),
  126. // "binCode" => "IDE0005714",
  127. // "fromLocCode" => "HAIB2-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  128. // "toLocCode" => "",
  129. // ],[
  130. // "taskCode" =>'t'.Uuid::uuid4(),
  131. // "binCode" => "IDE0005677",
  132. // "fromLocCode" => "HAIB2-02-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  133. // "toLocCode" => "",
  134. // ],[
  135. // "taskCode" =>'t'.Uuid::uuid4(),
  136. // "binCode" => "IDE0005682",
  137. // "fromLocCode" => "HAIB2-02-01", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  138. // "toLocCode" => "",
  139. // ],[
  140. // "taskCode" =>'t'.Uuid::uuid4(),
  141. // "binCode" => "IDE0005679",
  142. // "fromLocCode" => "HAIB2-01-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  143. // "toLocCode" => "",
  144. // ],[
  145. // "taskCode" =>'t'.Uuid::uuid4(),
  146. // "binCode" => "IDE0000166",
  147. // "fromLocCode" => "HAIB2-01-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  148. // "toLocCode" => "",
  149. // ],[
  150. // "taskCode" =>'t'.Uuid::uuid4(),
  151. // "binCode" => "IDE0005710",
  152. // "fromLocCode" => "HAIB2-01-01", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  153. // "toLocCode" => "",
  154. // ],[
  155. // "taskCode" =>'t'.Uuid::uuid4(),
  156. // "binCode" => "IDE0005678",
  157. // "fromLocCode" => "HAIB1-03-01", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  158. // "toLocCode" => "",
  159. // ],[
  160. // "taskCode" =>'t'.Uuid::uuid4(),
  161. // "binCode" => "IDE0004975",
  162. // "fromLocCode" => "HAIB1-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  163. // "toLocCode" => "",
  164. // ],
  165. ],
  166. "groupCode" => 'g'.microtime(true),
  167. "priority" => 20,
  168. "sequenceFlag" => 1,
  169. ]];
  170. $this->move3 = [[
  171. "taskMode" => 6,
  172. "bins"=>[[
  173. "taskCode" =>"testm11",
  174. "binCode" => "IDE0000128",
  175. "fromLocCode" => "HAIB2-01-01",
  176. "toLocCode" => "",
  177. ],[
  178. "taskCode" =>"testm21",
  179. "binCode" => "IDE000129",
  180. "fromLocCode" => "HAIB2-02-01",
  181. "toLocCode" => "",
  182. ],[
  183. "taskCode" =>"testm31",
  184. "binCode" => "IDE0000127",
  185. "fromLocCode" => "HAIB2-03-01",
  186. "toLocCode" => "",
  187. ],],
  188. "groupCode" => 'WMm2',
  189. "priority" => 20,
  190. "sequenceFlag" => 1,
  191. ]];
  192. $this->lightOn = [
  193. "areaCode"=> "1004",
  194. "PTLAction"=> 1,
  195. "PTLSettings"=> [
  196. "color"=> 1,
  197. "frequency"=> 1
  198. ],
  199. "displayInfo"=> [
  200. "detail01"=> "detail01",
  201. "detail02"=> "detail02",
  202. "detail03"=> "detail03",
  203. "qrCode"=> "qrCode",
  204. "qty00"=> "11",
  205. "qty01"=> 1,
  206. "qty02"=> 2,
  207. "title"=> "title",
  208. "uomDesc01"=> "uo",
  209. "uomDesc02"=> "uo"
  210. ],
  211. "locCode"=> "HAIB2-02-03"
  212. ];
  213. $this->lightOff = [
  214. "PTLAction"=> 0,
  215. "locCode"=> "HAIB2-02-03"
  216. ];
  217. }
  218. public function relocate(Request $request,$post){
  219. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  220. if (!$response->ok()){
  221. app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  222. return ['success'=>false,"data"=>$response->body()];
  223. }
  224. if (($response["code"] ?? false) && $response["code"] != 200){
  225. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  226. return ['success'=>false,"data"=>$response["errMsg"]];
  227. }
  228. if (($response["status"] ?? false) && $response["status"] == 500){
  229. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  230. return ['success'=>false,"data"=>$response["msg"]];
  231. }
  232. app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  233. return ["success"=>true];
  234. }
  235. public function light(Request $request,$post){
  236. $response = Http::post(config('api.haiq.storage.light'),$post);
  237. return $response->body();
  238. }
  239. public function moveBinOut(Request $request){
  240. return $this->relocate($request,$this->post);
  241. }
  242. public function postBin2(Request $request){
  243. return $this->relocate($request,$this->post2);
  244. }
  245. public function moveBinIn(Request $request){
  246. return $this->relocate($request,$this->backIn);
  247. }
  248. public function moveBinIn2(Request $request){
  249. return $this->relocate($request,$this->backIn2);
  250. }
  251. public function moveBinM(Request $request){
  252. return $this->relocate($request,$this->move);
  253. }
  254. public function moveBinM2(Request $request){
  255. return $this->relocate($request,$this->move2);
  256. }
  257. public function lightOn(Request $request){
  258. return $this->light($request,$this->lightOn);
  259. }
  260. public function lightOff(Request $request){
  261. return $this->light($request,$this->lightOff);
  262. }
  263. public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
  264. try{
  265. $this->service->taskUpdate(
  266. // $request['groupCode']
  267. $request['taskCode']
  268. ,$request['updateEventType']
  269. ,$request['status']
  270. ,$request['binCode']
  271. // ,$request['kubotId']
  272. // ,$request['description']
  273. );
  274. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  275. }catch (\Exception $e){
  276. return ['code'=>$e->getCode(),'errMsg'=>$e->getMessage(),'data'=>$request->all()];
  277. }
  278. }
  279. public function exception(Request $request){
  280. $this->service->excepted('海柔异常','',json_encode($request));
  281. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  282. }
  283. }