/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = 'CGKN00027'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); $res = array(); print 'count ' . count($orders->toArray()); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { //$req[] = array('order_id'=>$ord->no_sales_order.'-'.$ord->consignee_olshop_orderid,'awb'=>$ord->awb); $req[] = array('order_id' => $ord->consignee_olshop_orderid, 'awb' => $ord->consignee_olshop_orderid); } $client = new GuzzleClient(); //TO DO : Send data in chunk $reqchunks = array_chunk($req, 100); foreach ($reqchunks as $rq) { $this->sendData($rq, $client, $logistic, $logistic_id); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JayaStatusDaemon', 'get', $actor, 'JAYA STATUS PULL')); }
public function postStatus() { $delivery_trigger = 'DELIVERED'; $returned_trigger = $this->fl_status['RETURN']; $undelivered_trigger = $this->fl_status['NOT DELIVERED']; $key = \Input::get('key'); //$user = \Apiauth::user($key); if (is_null($key) || $key == '') { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty key')); return \Response::json(array('status' => 'ERR:EMPTYKEY', 'timestamp' => time(), 'message' => 'Empty Key')); } $logistic = \Logistic::where('api_key', '=', $key)->first(); $json = \Input::json(); $reslog = \Input::all(); $slog = $json; $reslog['timestamp'] = new \MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust; \Threeplstatuslog::insert($reslog); $this->saveStatus($slog, $logistic->consignee_olshop_cust, $logistic->logistic_code); $batch = \Input::get('batch'); $awbarray = array(); $awbs = array(); $statusarray = array(); $inawbstatus = array(); foreach ($json as $j) { $tawb = trim($j['awb']); $awbarray[] = $tawb; $awbs[$tawb] = $j; $inawbstatus[$tawb] = 'NOT FOUND'; } /* $reslog = $json; $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust; \Threeplstatuslog::insert($reslog); */ $result = array(); $orderlist = \Shipment::whereIn('awb', $awbarray)->get(); if ($orderlist) { foreach ($orderlist as $order) { $pre = clone $order; $lst = trim($awbs[$order->awb]['last_status']); if ($lst == $delivery_trigger) { $order->status = \Config::get('jayon.trans_status_mobile_delivered'); $order->position = 'CUSTOMER'; } if (in_array($lst, $returned_trigger) || $lst == 'RETURN') { $order->status = \Config::get('jayon.trans_status_mobile_return'); } if (in_array($lst, $undelivered_trigger) || $lst == 'NOT DELIVERED') { $order->status = \Config::get('jayon.trans_status_mobile_return'); } $lts = isset($awbs[$order->awb]['timestamp']) && $awbs[$order->awb]['timestamp'] != '' ? $awbs[$order->awb]['timestamp'] : $awbs[$order->awb]['delivered_date'] . ' ' . $awbs[$order->awb]['delivered_time']; $order->logistic_status = $awbs[$order->awb]['last_status']; $order->logistic_status_ts = $lts; $order->logistic_raw_status = $awbs[$order->awb]; $saved = $order->save(); if ($saved) { $inawbstatus[$order->awb] = 'STATUS UPDATED'; } $ts = new \MongoDate(); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $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); } $actor = 'FL : STATUS PUSH'; foreach ($inawbstatus as $k => $v) { $statusarray[] = array('AWB' => $k, 'status' => $v); } if (count($statusarray) > 0) { \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'FL status update')); return \Response::json(array('status' => 'OK', 'timestamp' => time(), 'message' => 'FL Status Update', 'statusarray' => $statusarray)); } else { \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty order list')); return \Response::json(array('status' => 'ERR:EMPTYORDER', 'timestamp' => time(), 'message' => 'Empty Order List')); } } else { $actor = 'FL : STATUS PUSH'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty order list')); return \Response::json(array('status' => 'ERR:EMPTYORDER', 'timestamp' => time(), 'message' => 'Empty Order List')); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = 'B234-JKT'; $delivery_trigger = $this->e21status['DELIVERED']; $returned_trigger = $this->e21status['RETURNED']; $undelivered_trigger = $this->e21status['UNDELIVERED']; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } if ($logistic) { } else { die('logistic data not found'); } $token = ''; $token_file = public_path() . '/storage/21oauth.key'; if (file_exists($token_file)) { $token = file_get_contents(public_path() . '/storage/21oauth.key'); } if ($token == '') { $token = $this->getToken($logistic); } else { $token = json_decode($token); if (isset($token->access_token)) { $token = $token->access_token; } } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $result = $this->sendRequest($ord->awb, $logistic, $token); $res = json_decode($result, true); if (isset($res['code']) && ($res['code'] == '0' || $res['code'] == 0)) { print 'reset token' . "\r\n"; $token = $this->getToken($logistic); $res = $this->sendRequest($ord->awb, $logistic, $token); $res = json_decode($result, true); } $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['shipment'])) { $ord = Shipment::where('awb', '=', $res['shipment']['code'])->orderBy('created_at', 'desc')->first(); if ($ord) { $pre = clone $ord; $laststat = $res['shipment']['statuses']; $laststat = array_pop($laststat); $lst = trim($laststat['status']); if (in_array($lst, $delivery_trigger) || $lst == 'RECEIVED') { $ord->status = \Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if (in_array($lst, $returned_trigger) || $lst == 'RETURN') { $ord->status = \Config::get('jayon.trans_status_mobile_return'); } if (in_array($lst, $undelivered_trigger) || $lst == 'NOT DELIVERED') { $ord->status = \Config::get('jayon.trans_status_undelivered'); } //$ord->district = $ls->district; $ord->logistic_status = $laststat['status']; $ord->logistic_status_ts = $laststat['datetime']; $ord->logistic_raw_status = $laststat; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } Logger::api($this->name, $ord->awb, $res); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('E21StatusDaemon', 'get', $actor, 'E21 STATUS PULL')); }
/** * Execute the console command. * * @return mixed */ public function fire() { //$base_url = 'http://localhost/jexadmin/public/api/v1/service/status'; $base_url = 'http://api.sap-express.com/api/tracking/list/ref/'; //$base_url = 'http://182.23.64.151/serverapi.sap/api/tracking/list/id/'; $base_url = 'http://api.sap-express.com/api/tracking/list'; $logistic_id = 'CGKN00284'; $delivery_trigger = 'DELIVERED'; $returned_trigger = 'UNDELIVERED'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'undelivered')->where('status', '!=', 'canceled')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { //$req[] = array('awb'=>$ord->awb); //$client = new GuzzleClient(); //$request = $client->get($url, array()); //$request->setAuth('sapclientapi', 'SAPCLIENTAPI_2014'); //$response = $request->send(); //print $response->getBody(); //$url = $base_url.$ord->consignee_olshop_orderid; $username = '******'; $password = '******'; $url = $base_url . '?ref=' . $ord->consignee_olshop_orderid; print $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); //$result = curl_exec($ch); if (!($result = curl_exec($ch))) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); } $status_code = curl_getinfo($ch); //get status code //$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close($ch); //print $result; $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['cn_no'])) { $pre = clone $ord; $ls = $res['laststatus']; if ($ls['status'] == $delivery_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if ($ls['status'] == $returned_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_return'); } //$ord->district = $ls->district; $ord->logistic_status = $ls['status']; $ord->logistic_status_ts = $ls['time']; $ord->logistic_raw_status = $ls; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } Logger::api($this->name, $ord->consignee_olshop_orderid, $res); } /* $awblist = json_decode($response->getBody()); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $awbarray[] = trim($awb->awb); $awbs[$awb->awb] = $awb; } $orderlist = Shipment::whereIn('awb', $awbarray)->get(); foreach($orderlist as $order){ $pre = clone $order; if( $awbs[$order->awb]->status == $delivery_trigger){ $order->status = Config::get('jayon.trans_status_mobile_delivered'); $order->position = 'CUSTOMER'; } if($awbs[$order->awb]->status == $returned_trigger){ $order->status = Config::get('jayon.trans_status_mobile_return'); } $order->district = $awbs[$order->awb]->district; $order->logistic_status = $awbs[$order->awb]->status; $order->logistic_status_ts = $awbs[$order->awb]->timestamp; $order->logistic_raw_status = $awbs[$order->awb]; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $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_status'; $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); } */ } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('SapStatusDaemon', 'get', $actor, 'SAP STATUS PULL')); }
/** * Execute the console command. * * @return mixed */ public function fire() { date_default_timezone_set('Asia/Jakarta'); //$base_url = 'http://103.14.21.47:8579/sp_sap2.gvm'; // XML $base_url = 'http://103.14.21.47:8579/sp_sap_json.gvm'; // JSON //$base_url = 'https://103.14.21.47:8879/sp_sap.gvm'; //$base_url = 'http://localhost/jexadmin/public/api/v1/service/awb'; $logistic_id = 'CGKN00284'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '=', '')->where('logistic_type', '=', 'external')->where('status', '=', Config::get('jayon.trans_status_admin_dated'))->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $req = array('orderid' => $ord->consignee_olshop_orderid, 'awb' => 0, 'invoice' => $ord->no_sales_order, 'address' => str_replace(array("\r", "\n"), ' ', $ord->consignee_olshop_addr), 'name' => $ord->consignee_olshop_name, 'province' => $ord->consignee_olshop_province == '' ? 'NA' : $ord->consignee_olshop_province, 'cod' => $ord->cod, 'volumes' => 1, 'chargeable' => $ord->cod, 'actualweight' => $ord->w_v, 'volumeweight' => $ord->w_v, 'partner' => 'Bilna', 'city' => $ord->consignee_olshop_city, 'userid' => 5490188, 'passwd' => 5351); $formatter = Formatter::make($req, Formatter::ARR); try { //$response = $client->request('POST', $base_url , array('json'=>$req, 'query'=>array('key'=> $logistic->api_key ) ) ); //$data_string = $formatter->toXml(); //$data_string = str_replace(array('<xml>','</xml>'), array('<sap>','</sap>'), $data_string); //print $data_string; $data_string = json_encode($req); $url = $base_url; //.'?key='.$logistic->api_key; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "5490188:5351"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result = curl_exec($ch); //$awblist = json_decode($response->getBody()); //$parser = new Parser(); //$res = $parser->xml($result); $res = json_decode($result, true); /* Array ( [invoice] => X100350935 [status] => 00 [awb] => KWLM151209162715 [orderid] => TEST320476XT [message] => Success, your request xml have been success. [trx_id] => 121505091627 ) */ //print_r($res); if (isset($res['status']) && strval($res['status']) == '00') { $pre = clone $ord; if (isset($res['awb']) && $res['awb'] != '') { $ord->awb = isset($res['awb']) ? $res['awb'] : ''; //$ord->awb = $awbs[$ord->fulfillment_code]; //$ord->bucket = Config::get('jayon.bucket_tracker'); //$ord->position = '3PL'; $ord->trx_id = isset($res['trx_id']) ? $res['trx_id'] : ''; $ord->uploaded = 1; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_awb'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->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'] = $ord; $sdata['preObject'] = $pre; $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); } } //$awblist = json_decode($result); //print $result; //die(); /* $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $ffs[] = $awb->ff_id; $awbs[$awb->ff_id] = $awb->awb; } $orderlist = Shipment::whereIn('fulfillment_code', $ffs)->get(); foreach($orderlist as $order){ $pre = clone $order; $order->awb = $awbs[$order->fulfillment_code]; //$order->bucket = Config::get('jayon.bucket_tracker'); $order->position = '3PL'; $order->uploaded = 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; } } // end order loop //$req = $orders->toArray(); //print json_encode($req); //die(); //$client = new GuzzleClient(['defaults'=>['exceptions'=>false]]); } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexAwbDaemon', 'get', $actor, 'SAP PUSH DATA AWB PULL')); }
public function postStatus() { /* "awb":"awb1", "order_id":"no order", "last_status":"kode status kiriman FL ", "cn_name":"penerima", "delivered_date":"tanggal", "delivered_time":"jam" */ $delivery_trigger = 'delivered'; $returned_trigger = 'returned'; $key = \Input::get('key'); //$user = \Apiauth::user($key); if (is_null($key) || $key == '') { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty key')); return \Response::json(array('status' => 'ERR:EMPTYKEY', 'timestamp' => time(), 'message' => 'Empty Key')); } $logistic = \Logistic::where('api_key', '=', $key)->first(); $json = \Input::json(); $batch = \Input::get('batch'); $awbarray = array(); $awbs = array(); $statusarray = array(); $inawbstatus = array(); foreach ($json as $j) { $awbarray[] = $j['awb']; $awbs[$j['awb']] = $j; $inawbstatus[$j['awb']] = 'NOT FOUND'; } $result = array(); $orderlist = \Shipment::whereIn('awb', $awbarray)->get(); if ($orderlist) { foreach ($orderlist as $order) { $pre = clone $order; if ($awbs[$order->awb]['last_status'] == $delivery_trigger) { $order->status = \Config::get('jayon.trans_status_mobile_delivered'); $order->position = 'CUSTOMER'; } if ($awbs[$order->awb]['last_status'] == $returned_trigger) { $order->status = \Config::get('jayon.trans_status_mobile_return'); } $lts = isset($awbs[$order->awb]['timestamp']) && $awbs[$order->awb]['timestamp'] != '' ? $awbs[$order->awb]['timestamp'] : $awbs[$order->awb]['delivered_date'] . ' ' . $awbs[$order->awb]['delivered_time']; $order->logistic_status = $awbs[$order->awb]['last_status']; $order->logistic_status_ts = $lts; $order->logistic_raw_status = $awbs[$order->awb]; $saved = $order->save(); if ($saved) { $inawbstatus[$order->awb] = 'STATUS UPDATED'; } $ts = new \MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $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_status'; $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); } $actor = 'FL : STATUS PUSH'; foreach ($inawbstatus as $k => $v) { $statusarray[] = array('AWB' => $k, 'status' => $v); } if (count($statusarray) > 0) { \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'FL status update')); return \Response::json(array('status' => 'OK', 'timestamp' => time(), 'message' => 'FL Status Update', 'statusarray' => $statusarray)); } else { \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty order list')); return \Response::json(array('status' => 'ERR:EMPTYORDER', 'timestamp' => time(), 'message' => 'Empty Order List')); } } else { $actor = 'FL : STATUS PUSH'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'empty order list')); return \Response::json(array('status' => 'ERR:EMPTYORDER', 'timestamp' => time(), 'message' => 'Empty Order List')); } }
public function beforeImportCommit($data) { date_default_timezone_set('Asia/Jakarta'); /* unset($data['createdDate']); unset($data['lastUpdate']); $data['created'] = $data['created_at']; unset($data['created_at']); unset($data['updated_at']); */ $trav = $this->traverseFields(Config::get('jex.default_export_fields')); foreach ($data as $key => $value) { if (array_key_exists($key, $trav)) { if ($trav[$key]['kind'] == 'text') { $data[$key] = strval($value); } if ($trav[$key]['kind'] == 'daterange' || $trav[$key]['kind'] == 'datetimerange' || $trav[$key]['kind'] == 'date' || $trav[$key]['kind'] == 'datetime') { if ($key != 'createdDate' && $key != 'lastUpdate') { $data[$key] = new MongoDate(strtotime($data[$key])); } } } } /* $data['CONSIGNEE_OLSHOP_CUST'] = strval($data['CONSIGNEE_OLSHOP_CUST']); $data['CONSIGNEE_OLSHOP_ORDERID'] = strval($data['CONSIGNEE_OLSHOP_ORDERID']); $data['CONSIGNEE_OLSHOP_PHONE'] = strval($data['CONSIGNEE_OLSHOP_PHONE']); $data['CONSIGNEE_OLSHOP_ZIP'] = strval($data['CONSIGNEE_OLSHOP_ZIP']); $data['NO_SALES_ORDER'] = strval($data['NO_SALES_ORDER']); */ //$data['PICK_UP_DATE'] = new MongoDate( strtotime($data['PICK_UP_DATE']) ); if (isset($data['consignee_olshop_cust'])) { $logistic = Logistic::where('consignee_olshop_cust', '=', $data['consignee_olshop_cust'])->first(); if ($logistic) { $data['logistic'] = $logistic->logistic_code; $data['logistic_type'] = $logistic->type; } else { $data['logistic'] = 'BEST001'; $data['logistic_type'] = 'internal'; } } if (isset($data['consignee_olshop_province'])) { } else { $data['consignee_olshop_province'] = ''; } $data['delivery_type'] = isset($data['delivery_type']) ? $data['delivery_type'] : 'REG'; $data['trip'] = isset($data['trip']) ? intval($data['trip']) : 1; $data['awb'] = isset($data['awb']) ? trim($data['awb']) : ''; if (isset($data['cod'])) { if ($data['cod'] == '' || is_null($data['cod'])) { //print 'cod is null'; $data['cod'] = 0; } $data['cod'] = doubleval($data['cod']); $data['cod'] = floor($data['cod'] * 100) / 100; } $data['bucket'] = Config::get('jayon.bucket_incoming'); $data['delivery_id'] = Prefs::getDeliveryId(); $data['order_id'] = $data['no_sales_order']; $data['fulfillment_code'] = $data['consignee_olshop_orderid']; // for AWB update if (isset($data['number_of_package'])) { $this->updateBox($data['delivery_id'], $data['order_id'], $data['fulfillment_code'], $data['number_of_package'], $data['position']); } $data['status'] = Config::get('jayon.trans_status_confirmed'); $data['logistic_status'] = ''; $data['pending_count'] = 0; $data['courier_status'] = Config::get('jayon.trans_cr_atmerchant'); $data['warehouse_status'] = Config::get('jayon.trans_wh_atmerchant'); $data['pickup_status'] = Config::get('jayon.trans_status_tobepickup'); $data['device_key'] = ''; $data['device_name'] = ''; $data['device_id'] = ''; $data['courier_name'] = ''; $data['courier_id'] = ''; $data['uploaded'] = 0; unset($data['volume']); unset($data['sessId']); unset($data['isHead']); return $data; }
public function postChangelogistic() { $in = Input::get(); $results = Shipment::whereIn('_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); if (is_null($in['logistic']) || $in['logistic'] == '') { $logistic = false; } else { $logistic = Logistic::where('logistic_code', '=', $in['logistic'])->first(); if ($logistic) { } else { $logistic = false; } } //print_r($results->toArray()); //if($results){ $res = false; //}else{ $ts = new MongoDate(); if ($logistic) { foreach ($results as $sh) { $pre = clone $sh; if ($sh->logistic == $logistic->logistic_code) { // no changes } else { if ($logistic->type == 'external') { $sh->awb = ''; $sh->bucket = Config::get('jayon.bucket_incoming'); $sh->status = Config::get('jayon.trans_status_confirmed'); $sh->logistic_status = ''; $sh->courier_status = Config::get('jayon.trans_cr_atmerchant'); $sh->warehouse_status = Config::get('jayon.trans_wh_atmerchant'); $sh->pickup_status = Config::get('jayon.trans_status_tobepickup'); //'consig' => '001', //$sh->courier_id = ''; //$sh->courier_name = ''; //$sh->courier_status = 'at_initial_node'; //$sh->device_id = ''; //$sh->device_key = ''; //$sh->device_name = ''; } else { $sh->awb = $sh->delivery_id; if (preg_match('/incoming$/', $in['url'])) { //$sh->status = Config::get('jayon.trans_status_confirmed'); } else { $sh->bucket = Config::get('jayon.bucket_dispatcher'); $sh->status = Config::get('jayon.trans_status_admin_dated'); } $sh->courier_id = ''; $sh->courier_name = ''; $sh->courier_status = 'at_initial_node'; $sh->device_id = ''; $sh->device_key = ''; $sh->device_name = ''; } $sh->consignee_olshop_cust = $logistic->consignee_olshop_cust; //$sh->consignee_olshop_inst_amt = '0'; //$sh->consignee_olshop_service = 'REG'; $sh->logistic = $logistic->logistic_code; $sh->logistic_type = $logistic->type; $sh->last_action_ts = $ts; $sh->last_action = 'Change Logistic'; $sh->last_reason = $in['reason']; $sh->save(); //print_r(Auth::user()); } $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'change_logistic'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $sh->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; //print_r($hdata); History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'change_logistic'; $sdata['reason'] = $in['reason']; $sdata['objectType'] = 'shipment'; $sdata['object'] = $sh->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = Auth::user()->_id; Shipmentlog::insert($sdata); } $res = true; } //} if ($res) { return Response::json(array('result' => 'OK:CHGLOGISTIC')); } else { return Response::json(array('result' => 'ERR:CHGLOGISTICFAILED')); } }
/** * 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/awb'; //$base_url = 'http://localhost/jexadmin/public/api/v1/service/awb'; $logistic_id = '7735'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '=', '')->where('logistic_type', '=', 'external')->where(function ($q) { $q->where('status', '=', \Config::get('jayon.trans_status_admin_dated'))->orWhere('status', '=', \Config::get('jayon.trans_status_confirmed')); })->where('consignee_olshop_cust', '=', $logistic_id)->where(function ($q) { $q->where('consignee_olshop_service', '=', 'COD')->orWhere('consignee_olshop_service', '=', 'CCOD'); })->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(); $reslog = $req; $reslog['timestamp'] = new \MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust; Threepluploadlog::insert($reslog); //print json_encode($req); //die(); //$client = new GuzzleClient(['defaults'=>['exceptions'=>false]]); try { print_r($req); //$response = $client->request('POST', $base_url , array('json'=>$req, 'query'=>array('key'=> $logistic->api_key ) ) ); $data_string = json_encode($req); $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()); $awblist = json_decode($result); print $result; //die(); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $ffs[] = $awb->ff_id; $awbs[$awb->ff_id] = $awb->awb; } $orderlist = Shipment::whereIn('fulfillment_code', $ffs)->get(); foreach ($orderlist as $order) { $pre = clone $order; $order->awb = $awbs[$order->fulfillment_code]; //$order->bucket = Config::get('jayon.bucket_tracker'); $order->position = '3PL'; $order->uploaded = 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'] = ''; print_r($sdata); //try{ Shipmentlog::insert($sdata); //}catch(Exception $e){ // print_r($e); //} } } catch (Exception $e) { print $e; } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexAwbDaemon', 'get', $actor, 'JEX PUSH DATA AWB PULL')); }
/** * 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')); }
/** * Execute the console command. * * @return mixed */ public function fire() { $logistic_id = '3758'; $delivery_trigger = $this->kjktstatus['DELIVERED']; $returned_trigger = $this->kjktstatus['RETURNED']; $undelivered_trigger = $this->kjktstatus['UNDELIVERED']; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); if (Prefs::isRunning($this->name)) { $l = array(); $l['ts'] = new MongoDate(); $l['error'] = 'process already running'; $l['consignee_logistic_id'] = $logistic->logistic_code; $l['consignee_olshop_cust'] = $logistic_id; Threeplstatuserror::insert($l); die('process already running'); } if ($logistic) { } else { die('logistic data not found'); } $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where(function ($sq) { $sq->where('status', '!=', 'delivered')->where('status', '!=', 'canceled')->where('status', '!=', 'undelivered')->where('status', '!=', 'returned'); })->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $result = $this->sendRequest($ord->awb, $logistic); $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['result_code']) && $res['result_code'] == 1) { $ord = Shipment::where('awb', '=', $res['data']['order_no'])->orderBy('created_at', 'desc')->first(); if ($ord) { $pre = clone $ord; $laststat = $res['data']; $lst = intval(trim($laststat['status_code'])); if (in_array($lst, $delivery_trigger)) { $ord->status = \Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if (in_array($lst, $returned_trigger)) { $ord->status = \Config::get('jayon.trans_status_mobile_return'); } /* if( in_array( $lst , $undelivered_trigger) ){ $ord->status = \Config::get('jayon.trans_status_undelivered'); } */ //$ord->district = $ls->district; $ord->logistic_status = $laststat['status_description']; $ord->logistic_status_ts = date('Y-m-d H:i:s', time()); $ord->logistic_raw_status = $laststat; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; //History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } Logger::api($this->name, $ord->awb, $res); } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('KurirJKTStatusDaemon', 'get', $actor, 'KurirJKT STATUS PULL')); /* Array ( [result_code] => 1 [result_description] => success [data] => Array ( [order_no] => 2240 [order_date] => 2015-02-27 09:19:37 [service_name] => SAME DAY SERVICE [status_code] => 3 [status_description] => Terkirim [pickup_date] => 2015-02-27 00:00:00 [delivered_date] => 2015-02-27 12:45:00 [pickup_name] => Ibu Mei [pickup_addess] => RS Siloam Hospital Kebon Jeruk, Lt. 1 Medical Checkup, Jl. Raya Perjuangan Kav. 8 Kebon Jeruk Jakarta Barat DKI Jakarta No. Ponsel: 085713331787 No. Kantor/Rumah: 02153695676 [destionation_name] => Ibu Stiyati [destionation_addess] => AIA Financial Menara Falma Lt. 18, Jl. HR Rasuna Said Blok X-2 Kav. 6 Jakarta Selatan DKI Jakarta No. Ponsel: No. Kantor/Rumah: [recipient_name] => bayu [kurir_name] => Fachrul [kurir_longitude] => [kurir_latitude] => [last_update] => 2015-02-27 12:45:00 ) ) */ }
/** * Execute the console command. * * @return mixed */ public function fire() { //$base_url = 'http://localhost/jexadmin/public/api/v1/service/status'; $base_url = 'http://www.jayonexpress.com/jexadmin/api/v1/service/status'; $logistic_id = '7735'; $delivery_trigger = 'delivered'; $returned_trigger = 'returned'; $canceled_trigger = 'canceled'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where('status', '!=', 'delivered')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $req[] = array('awb' => $ord->awb); } $req[] = array('awb' => '007735-16-122015-00155749'); $client = new GuzzleClient(); $response = $client->request('POST', $base_url, array('json' => $req, 'query' => array('key' => $logistic->api_key))); //print( $response->getBody() ); $awblist = json_decode($response->getBody()); $reslog = $awblist; $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); $this->saveStatus($awblist, $logistic->logistic_code, $logistic_id); $awbs = array(); $ffs = array(); foreach ($awblist as $awb) { $awbarray[] = trim($awb->awb); $awbs[$awb->awb] = $awb; } print_r($awbs); $orderlist = Shipment::whereIn('awb', $awbarray)->get(); foreach ($orderlist as $order) { $pre = clone $order; if ($awbs[$order->awb]->status == $delivery_trigger) { $order->status = Config::get('jayon.trans_status_mobile_delivered'); $order->delivered_time = $awbs[$order->awb]->delivery_time; $order->position = 'CUSTOMER'; } if ($awbs[$order->awb]->status == $returned_trigger) { $order->status = Config::get('jayon.trans_status_mobile_return'); } if ($awbs[$order->awb]->status == $canceled_trigger) { $order->status = Config::get('jayon.trans_status_canceled'); } $order->district = $awbs[$order->awb]->district; $order->logistic_status = $awbs[$order->awb]->status; $order->logistic_status_ts = $awbs[$order->awb]->timestamp; $order->logistic_raw_status = $awbs[$order->awb]; $order->logistic_delivered_time = $awbs[$order->awb]->delivery_time; $order->logistic_pickup_time = $awbs[$order->awb]->pickup_time; $order->logistic_last_note = $awbs[$order->awb]->note; $order->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $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_status'; $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); } Logger::api($this->name, $req, $awblist); } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('JexStatusDaemon', 'get', $actor, 'JEX STATUS PULL')); }
/** * Execute the console command. * * @return mixed */ public function fire() { $wsdl = "http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl"; //$client = new SoapClient($wsdl); $username = '******'; $password = '******'; SoapWrapper::add(function ($service) use($wsdl, $username, $password) { $service->name('trackAWB')->wsdl($wsdl)->trace(true)->cache(WSDL_CACHE_NONE); // Optional: Set the WSDL cache //->options(['user' => $username, 'password' => $password, 'format'=>'JSON' ]); // Optional: Set some extra options }); $logistic_id = 'B234-JKT'; $delivery_trigger = 'DELIVERED'; $returned_trigger = 'UNDELIVERED'; $logistic = Logistic::where('consignee_olshop_cust', '=', $logistic_id)->first(); $orders = Shipment::where('awb', '!=', '')->where('bucket', '=', Config::get('jayon.bucket_tracker'))->where('status', '!=', 'delivered')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->get(); if ($orders && count($orders->toArray()) > 0) { $req = array(); foreach ($orders as $ord) { $username = $logistic->api_user; $password = $logistic->api_pass; $data = [$username, $password, '8979867812376', 'JSON']; //string $user, string $password, string $awb, string $format SoapWrapper::service('trackAWB', function ($service) use($data) { var_dump($service->getFunctions()); print $service->call('getTrackingAWB', $data); //print_r($service->call('getTrackingAWB', [$data])); }); $res = json_decode($result, true); $reslog = $res; $reslog['timestamp'] = new MongoDate(); $reslog['consignee_logistic_id'] = $logistic->logistic_code; $reslog['consignee_olshop_cust'] = $logistic_id; Threeplstatuslog::insert($reslog); print_r($res); if (isset($res['cn_no'])) { $pre = clone $ord; $ls = $res['laststatus']; if ($ls['status'] == $delivery_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_delivered'); $ord->position = 'CUSTOMER'; } if ($ls['status'] == $returned_trigger) { $ord->status = Config::get('jayon.trans_status_mobile_return'); } //$ord->district = $ls->district; $ord->logistic_status = $ls['status']; $ord->logistic_status_ts = $ls['time']; $ord->logistic_raw_status = $ls; $ord->save(); $ts = new MongoDate(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $ord->toArray(); $hdata['actor'] = $this->name; $hdata['actor_id'] = ''; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $ord->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $this->name; $sdata['actor_id'] = ''; Shipmentlog::insert($sdata); $this->saveStatus($res, $logistic->logistic_code, $logistic_id); } } } else { print 'Empty order list' . "\r\n"; } $actor = $this->name; Event::fire('log.api', array('RPXStatusDaemon', 'get', $actor, 'RPX STATUS PULL')); // }
public static function getLogistic($key = null, $val = null) { if (is_null($key)) { $c = Logistic::get(); self::$logistic = $c; return new self(); } else { $c = Logistic::where($key, '=', $val)->first(); self::$logistic = $c; return $c; } }