StorageController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. namespace App\Http\Controllers\api\thirdPart\haiq;
  3. use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
  4. use App\MaterialBox;
  5. use App\Services\ForeignHaiRoboticsService;
  6. use App\Services\LogService;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Http;
  9. use Ramsey\Uuid\Uuid;
  10. class StorageController
  11. {
  12. protected $post;
  13. /** @var ForeignHaiRoboticsService $service */
  14. private $service;
  15. public function __construct()
  16. {
  17. $this->service=app('ForeignHaiRoboticsService');
  18. $stockInfo = [
  19. "skuCode" => "TEST-BSSKU",//商品编码 sku
  20. "qty" => 9,//数量
  21. ];
  22. $bin = [
  23. "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
  24. "binCode" => "TEST-BIN01",//料箱编码
  25. "fromLocCode" => "HAIB1-02-01",//源库位编码
  26. "toLocCode" => "HAIB1-02-01",//目标库位编码 出库填多个,表示这些库位都可以支持
  27. "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
  28. "stockInfo" => [$stockInfo],//商品信息
  29. ];
  30. /*$this->request = [[
  31. "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
  32. "taskMode" => 3,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
  33. "priority" => 99,//优先级 1-2147483647 1最低
  34. "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
  35. "bins" => [$bin],//可执行货箱任务
  36. ]];*///IDE0005714,IDE0004970,IDE0005676,IDE0005665
  37. $this->post = [[
  38. "taskMode" => 1,
  39. "bins"=>[
  40. [
  41. "binCode" => "IDE0005713",
  42. "taskCode" =>UUID::uuid4().'|'.microtime(true),
  43. "fromLocCode" => "BIN-IN1",
  44. "toLocCode" => "",
  45. ],
  46. ],
  47. "groupCode" => 'g'.microtime(true),
  48. "priority" => 20,
  49. "sequenceFlag" => 1,
  50. ]];
  51. $this->post2 = [[
  52. "taskMode" => 2,
  53. "bins"=>[
  54. [
  55. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  56. "binCode" => "IDE0005132",
  57. "fromLocCode" => "",
  58. "toLocCode" => "BIN-OUT1",
  59. ],
  60. [
  61. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  62. "binCode" => "IDE0005152",
  63. "fromLocCode" => "",
  64. "toLocCode" => "BIN-OUT1",
  65. ],
  66. [
  67. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  68. "binCode" => "IDE0000159",
  69. "fromLocCode" => "",
  70. "toLocCode" => "BIN-OUT1",
  71. ],
  72. [
  73. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  74. "binCode" => "IDE0004951",
  75. "fromLocCode" => "",
  76. "toLocCode" => "BIN-OUT1",
  77. ],
  78. ],
  79. "groupCode" => 'g'.microtime(true),
  80. "priority" => 20,
  81. "sequenceFlag" => 1,
  82. ]];
  83. $this->moveBinIn = [[
  84. "taskMode" => 6,
  85. "bins"=>[[
  86. "taskCode" =>'t1'.microtime(true),
  87. "binCode" => "IDE0005173",
  88. "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  89. "toLocCode" => "",
  90. ]
  91. // ,[
  92. // "taskCode" =>'t2'.microtime(true),
  93. // "binCode" => "IDE0004973",
  94. // "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  95. // "toLocCode" => "",
  96. // ]
  97. // ,[
  98. // "taskCode" =>'t3'.microtime(true),
  99. // "binCode" => "IDE0005716",
  100. // "fromLocCode" => "HAIB1-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  101. // "toLocCode" => "",
  102. // ],
  103. ],
  104. "groupCode" => 'g'.microtime(true),
  105. "priority" => 20,
  106. "sequenceFlag" => 1,
  107. ]];
  108. $this->moveBinIn2 = [[
  109. "taskMode" => 3,
  110. "bins"=>[
  111. [
  112. "taskCode" =>'t1'.microtime(true),
  113. "binCode" => "IDE0005716",
  114. "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  115. "toLocCode" => "HAIB1-02-03",
  116. ],
  117. // [
  118. // "taskCode" =>'t2'.microtime(true),
  119. // "binCode" => "IDE0004973",
  120. // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  121. // "toLocCode" => "HAIB1-02-03",
  122. // ],[
  123. // "taskCode" =>'t3'.microtime(true),
  124. // "binCode" => "IDE0005716",
  125. // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  126. // "toLocCode" => "HAIB1-03-02",
  127. // ],
  128. ],
  129. "groupCode" => 'g'.microtime(true),
  130. "priority" => 20,
  131. "sequenceFlag" => 1,
  132. ]];
  133. $this->move = [[
  134. "taskMode" => 3,
  135. "bins"=>[[
  136. "taskCode" =>'t'.Uuid::uuid4(),
  137. "binCode" => "IDE0005678",
  138. "fromLocCode" => "",
  139. "toLocCode" => "HAIB1-03-01",
  140. ],[
  141. "taskCode" =>'t'.Uuid::uuid4(),
  142. "binCode" => "IDE0004975",
  143. "fromLocCode" => "",
  144. "toLocCode" => "HAIB1-03-02",
  145. ],],
  146. "groupCode" => 'g'.microtime(true),
  147. "priority" => 20,
  148. "sequenceFlag" => 1,
  149. ]];//128,129.127
  150. $this->move2 = [[
  151. "taskMode" => 6,
  152. "bins"=>[
  153. [
  154. "taskCode" =>'t'.Uuid::uuid4(),
  155. "binCode" => "IDE0005711",
  156. "fromLocCode" => "HAIB1-01-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  157. "toLocCode" => "",
  158. ],
  159. [
  160. "taskCode" =>'t'.Uuid::uuid4(),
  161. "binCode" => "IDE0005680",
  162. "fromLocCode" => "HAIB1-02-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
  163. "toLocCode" => "",
  164. ],
  165. ],
  166. "groupCode" => 'g'.microtime(true),
  167. "priority" => 20,
  168. "sequenceFlag" => 1,
  169. ]];
  170. $this->move3 = [[
  171. "taskMode" => 6,
  172. "bins"=>[[
  173. "taskCode" =>"testm11",
  174. "binCode" => "IDE0000128",
  175. "fromLocCode" => "HAIB2-01-01",
  176. "toLocCode" => "",
  177. ],[
  178. "taskCode" =>"testm21",
  179. "binCode" => "IDE000129",
  180. "fromLocCode" => "HAIB2-02-01",
  181. "toLocCode" => "",
  182. ],[
  183. "taskCode" =>"testm31",
  184. "binCode" => "IDE0000127",
  185. "fromLocCode" => "HAIB2-03-01",
  186. "toLocCode" => "",
  187. ],],
  188. "groupCode" => 'WMm2',
  189. "priority" => 20,
  190. "sequenceFlag" => 1,
  191. ]];
  192. $this->lightOn = [
  193. "areaCode"=> "1004",
  194. "PTLAction"=> 1, //1是开,0是关
  195. "PTLSettings"=> [
  196. "color"=> 2, //灯颜色,0红,1绿,2绿,3黄
  197. "frequency"=> 0 //频率 0是不动,最大是3
  198. ],
  199. "displayInfo"=> [
  200. "detail01"=> "detail01",
  201. "detail02"=> "detail02",
  202. "detail03"=> "detail03",
  203. "qrCode"=> "qrCode",
  204. "qty00"=> "11",
  205. "qty01"=> 1,
  206. "qty02"=> 2,
  207. "title"=> "title",
  208. "uomDesc01"=> "uo",
  209. "uomDesc02"=> "uo"
  210. ],
  211. "locCode"=> "HAIB2-02-03"//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  212. ];
  213. $this->lightOff = [
  214. "PTLAction"=> 0,
  215. "locCode"=> "HAIB2-02-02"
  216. ];
  217. }
  218. public function relocate(Request $request,$post){
  219. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  220. if (!$response->ok()){
  221. app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  222. return ['success'=>false,"data"=>$response->body()];
  223. }
  224. if (($response["code"] ?? false) && $response["code"] != 200){
  225. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  226. return ['success'=>false,"data"=>$response["errMsg"]];
  227. }
  228. if (($response["status"] ?? false) && $response["status"] == 500){
  229. app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  230. return ['success'=>false,"data"=>$response["msg"]];
  231. }
  232. app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
  233. return ["success"=>true,'data'=>$response->body()];
  234. }
  235. public function light(Request $request,$post){
  236. $response = Http::post(config('api.haiq.storage.light'),$post);
  237. return $response->body();
  238. }
  239. public function moveBinOut(Request $request){
  240. return $this->relocate($request,$this->post);
  241. }
  242. public function postBin1(Request $request){
  243. return $this->relocate($request,$this->post);
  244. }
  245. public function postBin2(Request $request){
  246. return $this->relocate($request,$this->post2);
  247. }
  248. public function moveBinIn(Request $request){
  249. return $this->relocate($request,$this->moveBinIn);
  250. }
  251. public function moveBinIn2(Request $request){
  252. return $this->relocate($request,$this->moveBinIn2);
  253. }
  254. public function moveBinM(Request $request){
  255. return $this->relocate($request,$this->move);
  256. }
  257. public function moveBinM2(Request $request){
  258. return $this->relocate($request,$this->move2);
  259. }
  260. public function lightOn(Request $request){
  261. return $this->light($request,$this->lightOn);
  262. }
  263. public function lightOff(Request $request){
  264. return $this->light($request,$this->lightOff);
  265. }
  266. public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request){
  267. LogService::log('海柔请求','taskUpdate',
  268. json_encode($request->all()));
  269. try{
  270. $stationTaskMaterialBox_id = explode('_',$request['taskCode'])[0];
  271. $this->service->taskUpdate(
  272. // $request['groupCode']
  273. $stationTaskMaterialBox_id
  274. ,$request['updateEventType']
  275. ,$request['status']
  276. ,$request['binCode']
  277. // ,$request['kubotId']
  278. // ,$request['description']
  279. );
  280. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  281. }catch (\Exception $e){
  282. return ['code'=>$e->getCode(),'errMsg'=>$e->getMessage(),'data'=>$request->all()];
  283. }
  284. }
  285. public function exception(Request $request){
  286. $this->service->excepted('海柔异常','',json_encode($request));
  287. return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
  288. }
  289. public function takeOutToULine(Request $request){
  290. $codesTxt=$request->input('codes');
  291. $codes=preg_split('/[\s,.,。]/',$codesTxt);
  292. if(!$codes||count($codes)==0)return ['result'=>'请输入料箱号'];
  293. $post = [
  294. [
  295. "taskMode" => 2,
  296. "bins"=>[
  297. ],
  298. "groupCode" => 'g'.microtime(true),
  299. "priority" => 20,
  300. "sequenceFlag" => 1,
  301. ]
  302. ];
  303. foreach ($codes as &$code){
  304. if(!trim($code))continue;
  305. $code=str_replace(['ide','IDE'],'',$code);
  306. $code='IDE'.str_pad($code,7,'0',STR_PAD_LEFT);
  307. $post[0]['bins'][]=[
  308. "taskCode" =>Uuid::uuid4().'|'.microtime(true),
  309. "binCode" => $code,
  310. "fromLocCode" => "",
  311. "toLocCode" => "BIN-OUT1",
  312. ];
  313. }
  314. $response = Http::post(config('api.haiq.storage.moveBin'),$post);
  315. $responseBody = $response->body();
  316. $result = ['status'=>'失败'];
  317. LogService::log(__CLASS__,__METHOD__,$responseBody);
  318. if(strstr($responseBody,'200')){
  319. $responseJson=json_decode($responseBody,true);
  320. $result = ['status'=>'成功'];
  321. $responseBody = '取料箱成功:' . implode(',', $codes);
  322. $data0part = $responseJson['data'][0]??[];
  323. if(($data0part['code']??'')==10007
  324. && count($data0part['datas']??[])>0){
  325. $responseBody = '以下料箱不在库内,无法取出:' . implode(',', $data0part['datas']??[]).
  326. '| 成功取出料箱:'.implode(',', array_diff($codes, $data0part['datas']??[]));
  327. $result = ['status'=>'部分成功'];
  328. }
  329. }
  330. if(strstr($responseBody,'成功')){
  331. MaterialBox::query()->whereIn('code',$codes)->update(['status'=>'在出库中']);
  332. }
  333. $result['result']=$responseBody;
  334. return $result;
  335. }
  336. }