StorageController.php 13 KB

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