StorageController.php 11 KB

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