StorageController.php 11 KB

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