StorageController.php 11 KB

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