public function postExttotrack() { $in = Input::get(); $results = Shipment::whereIn('_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); $ts = new MongoDate(); //print_r($results->toArray()); $reason = isset($in['reason']) ? $in['reason'] : 'move after print'; //if($results){ $res = false; //}else{ foreach ($results as $r) { $pre = clone $r; if ($r->logistic_type == 'external') { if (trim($r->awb) != '') { $r->bucket = Config::get('jayon.bucket_tracker'); $r->status = Config::get('jayon.trans_status_confirmed'); $r->save(); } } $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'print_external_barcode'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $r->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'print_external_barcode'; $sdata['reason'] = $reason; $sdata['objectType'] = 'shipment'; $sdata['object'] = $r->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = Auth::user()->_id; Shipmentlog::insert($sdata); $confirm = array('awb' => $r->awb, 'order_id' => $r->no_sales_order, 'consignee_id' => $r->consignee_olshop_cust, 'ff_id' => $r->consignee_olshop_orderid, 'ts' => $ts, 'sent' => 0); Confirmed::insert($confirm); } $res = true; //} if ($res) { return Response::json(array('result' => 'OK:MOVED')); } else { return Response::json(array('result' => 'ERR:MOVEFAILED')); } }
/** * Execute the console command. * * @return mixed */ public function fire() { date_default_timezone_set('Asia/Jakarta'); $base_url = 'http://www.jayonexpress.com/jexadmin/api/v1/service/confirm'; //$base_url = 'http://localhost/jexadmin/public/api/v1/service/awb'; //$logistic_id = '1400000655'; $logistic_id = '7735'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Confirmed::where(function ($q) use($logistic_id) { $q->where('consignee_id', '=', $logistic_id)->orWhere('consignee_id', '=', strval($logistic_id)); })->where('sent', '=', 0)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); /* foreach($orders as $ord){ $req[] = array('order_id'=>$ord->no_sales_order, 'ff_id'=>$ord->consignee_olshop_orderid); } */ $req = $orders->toArray(); //print_r($req); //print json_encode($req); //die(); //$client = new GuzzleClient(['defaults'=>['exceptions'=>false]]); try { //$response = $client->request('POST', $base_url , array('json'=>$req, 'query'=>array('key'=> $logistic->api_key ) ) ); $data_string = json_encode($req); //print_r($data_string); $url = $base_url . '?key=' . $logistic->api_key; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result = curl_exec($ch); //$awblist = json_decode($response->getBody()); $res = json_decode($result, true); print_r($result); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplconfirm::insert($reslog); if (isset($res['status']) && $res['status'] == 'OK') { $awblist = array(); foreach ($res['data'] as $r) { $awblist[] = $r['awb']; } print_r($awblist); $ships = Confirmed::whereIn('awb', $awblist)->get(); foreach ($ships as $sh) { $sh->sent = 1; $sh->save(); } } //die(); //$orderlist = Shipment::whereIn('fulfillment_code', $ffs)->get(); /* $orderlist = Confirmed::where('awb',$awblist)->get(); foreach($orderlist as $order){ $pre = clone $order; $order->sent = 1; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_awb'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $order->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_awb'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $order->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } */ } catch (Exception $e) { print $e; } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexConfDaemon', 'get', $actor, 'JEX PUSH CONFIRM DATA')); }