StorageController.php 8.7 KB

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