StorageController.php 11 KB

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