StorageController.php 12 KB

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