| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- namespace App\Http\Controllers\api\thirdPart\haiq;
- use App\Components\AsyncResponse;
- use App\Http\Requests\ForeignHaiRobotic_taskUpdateRequest;
- use App\MaterialBox;
- use App\Services\ForeignHaiRoboticsService;
- use App\Services\LogService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Http;
- use Ramsey\Uuid\Uuid;
- class StorageController
- {
- use AsyncResponse;
- protected $post;
- /** @var ForeignHaiRoboticsService $service */
- private $service;
- public function __construct()
- {
- $this->service=app('ForeignHaiRoboticsService');
- $stockInfo = [
- "skuCode" => "TEST-BSSKU",//商品编码 sku
- "qty" => 9,//数量
- ];
- $bin = [
- "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
- "binCode" => "TEST-BIN01",//料箱编码
- "fromLocCode" => "HAIB1-02-01",//源库位编码
- "toLocCode" => "HAIB1-02-01",//目标库位编码 出库填多个,表示这些库位都可以支持
- "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
- "stockInfo" => [$stockInfo],//商品信息
- ];
- /*$this->request = [[
- "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
- "taskMode" => 3,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
- "priority" => 99,//优先级 1-2147483647 1最低
- "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
- "bins" => [$bin],//可执行货箱任务
- ]];*///IDE0005714,IDE0004970,IDE0005676,IDE0005665
- $this->post = [[
- "taskMode" => 1,
- "bins"=>[
- [
- "binCode" => "IDE0005713",
- "taskCode" =>UUID::uuid4().'|'.microtime(true),
- "fromLocCode" => "BIN-IN1",
- "toLocCode" => "",
- ],
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->post2 = [[
- "taskMode" => 2,
- "bins"=>[
- [
- "taskCode" =>Uuid::uuid4().'|'.microtime(true),
- "binCode" => "IDE0005132",
- "fromLocCode" => "",
- "toLocCode" => "BIN-OUT1",
- ],
- [
- "taskCode" =>Uuid::uuid4().'|'.microtime(true),
- "binCode" => "IDE0005152",
- "fromLocCode" => "",
- "toLocCode" => "BIN-OUT1",
- ],
- [
- "taskCode" =>Uuid::uuid4().'|'.microtime(true),
- "binCode" => "IDE0000159",
- "fromLocCode" => "",
- "toLocCode" => "BIN-OUT1",
- ],
- [
- "taskCode" =>Uuid::uuid4().'|'.microtime(true),
- "binCode" => "IDE0004951",
- "fromLocCode" => "",
- "toLocCode" => "BIN-OUT1",
- ],
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->moveBinIn = [[
- "taskMode" => 6,
- "bins"=>[[
- "taskCode" =>'t1'.microtime(true),
- "binCode" => "IDE0005173",
- "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- "toLocCode" => "",
- ]
- // ,[
- // "taskCode" =>'t2'.microtime(true),
- // "binCode" => "IDE0004973",
- // "fromLocCode" => "HAIB1-02-03", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- // "toLocCode" => "",
- // ]
- // ,[
- // "taskCode" =>'t3'.microtime(true),
- // "binCode" => "IDE0005716",
- // "fromLocCode" => "HAIB1-03-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- // "toLocCode" => "",
- // ],
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->moveBinIn2 = [[
- "taskMode" => 3,
- "bins"=>[
- [
- "taskCode" =>'t1'.microtime(true),
- "binCode" => "IDE0005716",
- "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- "toLocCode" => "HAIB1-02-03",
- ],
- // [
- // "taskCode" =>'t2'.microtime(true),
- // "binCode" => "IDE0004973",
- // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- // "toLocCode" => "HAIB1-02-03",
- // ],[
- // "taskCode" =>'t3'.microtime(true),
- // "binCode" => "IDE0005716",
- // "fromLocCode" => "", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- // "toLocCode" => "HAIB1-03-02",
- // ],
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->move = [[
- "taskMode" => 3,
- "bins"=>[[
- "taskCode" =>'t'.Uuid::uuid4(),
- "binCode" => "IDE0005678",
- "fromLocCode" => "",
- "toLocCode" => "HAIB1-03-01",
- ],[
- "taskCode" =>'t'.Uuid::uuid4(),
- "binCode" => "IDE0004975",
- "fromLocCode" => "",
- "toLocCode" => "HAIB1-03-02",
- ],],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];//128,129.127
- $this->move2 = [[
- "taskMode" => 6,
- "bins"=>[
- [
- "taskCode" =>'t'.Uuid::uuid4(),
- "binCode" => "IDE0005711",
- "fromLocCode" => "HAIB1-01-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- "toLocCode" => "",
- ],
- [
- "taskCode" =>'t'.Uuid::uuid4(),
- "binCode" => "IDE0005680",
- "fromLocCode" => "HAIB1-02-02", //B1是面对架货右手,从右往左数列,第三个数字从下往上数行
- "toLocCode" => "",
- ],
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->move3 = [[
- "taskMode" => 6,
- "bins"=>[[
- "taskCode" =>"testm11",
- "binCode" => "IDE0000128",
- "fromLocCode" => "HAIB2-01-01",
- "toLocCode" => "",
- ],[
- "taskCode" =>"testm21",
- "binCode" => "IDE000129",
- "fromLocCode" => "HAIB2-02-01",
- "toLocCode" => "",
- ],[
- "taskCode" =>"testm31",
- "binCode" => "IDE0000127",
- "fromLocCode" => "HAIB2-03-01",
- "toLocCode" => "",
- ],],
- "groupCode" => 'WMm2',
- "priority" => 20,
- "sequenceFlag" => 1,
- ]];
- $this->lightOn = [
- "areaCode"=> "1004",
- "PTLAction"=> 1, //1是开,0是关
- "PTLSettings"=> [
- "color"=> 2, //灯颜色,0红,1绿,2绿,3黄
- "frequency"=> 0 //频率 0是不动,最大是3
- ],
- "displayInfo"=> [
- "detail01"=> "detail01",
- "detail02"=> "detail02",
- "detail03"=> "detail03",
- "qrCode"=> "qrCode",
- "qty00"=> "11",
- "qty01"=> 1,
- "qty02"=> 2,
- "title"=> "title",
- "uomDesc01"=> "uo",
- "uomDesc02"=> "uo"
- ],
- "locCode"=> "HAIB2-02-03"//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
- ];
- $this->lightOff = [
- "PTLAction"=> 0,
- "locCode"=> "HAIB2-02-02"
- ];
- }
- public function relocate(Request $request,$post){
- $response = Http::post(config('api.haiq.storage.moveBin'),$post);
- if (!$response->ok()){
- app('LogService')->log(__METHOD__,"haiq-请求失败,路径异常","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
- return ['success'=>false,"data"=>$response->body()];
- }
- if (($response["code"] ?? false) && $response["code"] != 200){
- app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
- return ['success'=>false,"data"=>$response["errMsg"]];
- }
- if (($response["status"] ?? false) && $response["status"] == 500){
- app('LogService')->log(__METHOD__,"haiq-料箱出库失败","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
- return ['success'=>false,"data"=>$response["msg"]];
- }
- app('LogService')->log(__METHOD__,"haiq-料箱出库成功","REQUEST:".json_encode($this->post)." | RESPONSE:".$response);
- return ["success"=>true,'data'=>$response->body()];
- }
- public function light(Request $request,$post){
- $response = Http::post(config('api.haiq.storage.light'),$post);
- return $response->body();
- }
- public function moveBinOut(Request $request){
- return $this->relocate($request,$this->post);
- }
- public function postBin1(Request $request){
- return $this->relocate($request,$this->post);
- }
- public function postBin2(Request $request){
- return $this->relocate($request,$this->post2);
- }
- public function moveBinIn(Request $request){
- return $this->relocate($request,$this->moveBinIn);
- }
- public function moveBinIn2(Request $request){
- return $this->relocate($request,$this->moveBinIn2);
- }
- public function moveBinM(Request $request){
- return $this->relocate($request,$this->move);
- }
- public function moveBinM2(Request $request){
- return $this->relocate($request,$this->move2);
- }
- public function lightOn(Request $request){
- return $this->light($request,$this->lightOn);
- }
- public function lightOff(Request $request){
- return $this->light($request,$this->lightOff);
- }
- /**
- * 海柔通知:任务状态变更
- *
- * @param ForeignHaiRobotic_taskUpdateRequest $request
- * @return array
- */
- public function taskUpdate(ForeignHaiRobotic_taskUpdateRequest $request):array
- {
- LogService::log('海柔请求','taskUpdate', json_encode($request->all()));
- try{
- $taskCode = explode('_',$request['taskCode']);
- if (count($taskCode)>1 && (integer)$taskCode[0]) {
- $this->service->taskUpdate($taskCode[0],$request['updateEventType']
- ,$request['status'],$request['binCode']
- );
- }
- return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
- }catch (\Exception $e){
- return ['code'=>$e->getCode(),'errMsg'=>$e->getMessage(),'data'=>$request->all()];
- }
- }
- public function exception(Request $request){
- $this->service->excepted('海柔异常','',json_encode($request));
- return ['code'=>200,'errMsg'=>'','data'=>$request->all()];
- }
- public function takeOutToULine(Request $request){
- $codesTxt=$request->input('codes');
- $codes=preg_split('/[\s,.,。]/',$codesTxt);
- if(!$codes||count($codes)==0)return ['result'=>'请输入料箱号'];
- $post = [
- [
- "taskMode" => 2,
- "bins"=>[
- ],
- "groupCode" => 'g'.microtime(true),
- "priority" => 20,
- "sequenceFlag" => 1,
- ]
- ];
- foreach ($codes as &$code){
- if(!trim($code))continue;
- $code=str_replace(['ide','IDE'],'',$code);
- $code='IDE'.str_pad($code,7,'0',STR_PAD_LEFT);
- $post[0]['bins'][]=[
- "taskCode" =>Uuid::uuid4().'|'.microtime(true),
- "binCode" => $code,
- "fromLocCode" => "",
- "toLocCode" => "BIN-OUT1",
- ];
- }
- $response = Http::post(config('api.haiq.storage.moveBin'),$post);
- $responseBody = $response->body();
- $result = ['status'=>'失败'];
- LogService::log(__CLASS__,__METHOD__,$responseBody);
- if(strstr($responseBody,'200')){
- $responseJson=json_decode($responseBody,true);
- $result = ['status'=>'成功'];
- $responseBody = '取料箱成功:' . implode(',', $codes);
- $data0part = $responseJson['data'][0]??[];
- if(($data0part['code']??'')==10007
- && count($data0part['datas']??[])>0){
- $responseBody = '以下料箱不在库内,无法取出:' . implode(',', $data0part['datas']??[]).
- '| 成功取出料箱:'.implode(',', array_diff($codes, $data0part['datas']??[]));
- $result = ['status'=>'部分成功'];
- }
- }
- if(strstr($responseBody,'成功')){
- MaterialBox::query()->whereIn('code',$codes)->update(['status'=>'在出库中']);
- }
- $result['result']=$responseBody;
- return $result;
- }
- /**
- * 填充空箱
- */
- public function paddingEmptyBox()
- {
- $amount = \request("amount") ?: 1;
- $boxes = app("MaterialBoxService")->getAnEmptyBoxSortedByOwner(null,[],$amount);
- if (!is_array($boxes))$boxes = [$boxes];
- $this->success(implode(",",array_column($boxes,"code")));
- }
- }
|