StorageController.php 11 KB

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