/**
  * 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'));
 }
示例#2
0
 /**
  * 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'));
 }
示例#3
0
 public function postStatus()
 {
     $methodname = 'fl:status';
     $delivery_trigger = 'DELIVERED';
     $returned_trigger = $this->fl_status['RETURN'];
     $undelivered_trigger = $this->fl_status['NOT DELIVERED'];
     $pickup_trigger = 'PICK UP';
     $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();
     try {
         $json = $json->all();
     } catch (Exception $e) {
         //print $e->getMessage();
     }
     $reslog = \Input::get();
     $slog = $json;
     $rlog['timestamp'] = new \MongoDate();
     $rlog['data'] = $reslog;
     $rlog['consignee_logistic_id'] = $logistic->logistic_code;
     $rlog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust;
     \Threeplstatuslog::insert($rlog);
     //$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';
     }
     //print_r($awbarray);
     /*
     $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 || preg_match('\\^' . $delivery_trigger . '\\i', $awbs[$order->awb]['last_status'])) {
                 $order->status = \Config::get('jayon.trans_status_mobile_delivered');
                 $ord->delivered_time = $awbs[$order->awb]['delivered_date'] . ' ' . $awbs[$order->awb]['delivered_time'];
                 $order->position = 'CUSTOMER';
             }
             if ($lst == $pickup_trigger || preg_match('\\^' . $pickup_trigger . '\\i', $awbs[$order->awb]['last_status'])) {
                 $order->logistic_pickup_time = $awbs[$order->awb]['delivered_date'] . ' ' . $awbs[$order->awb]['delivered_time'];
             }
             if (in_array($lst, $returned_trigger) || $lst == 'RETURN' || preg_match('\\^RETURN\\i', $awbs[$order->awb]['last_status'])) {
                 $order->status = \Config::get('jayon.trans_status_mobile_return');
             }
             if (in_array($lst, $undelivered_trigger) || $lst == 'NOT DELIVERED' || preg_match('\\^NOT DELIVERED\\i', $awbs[$order->awb]['last_status'])) {
                 $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];
             $order->save();
             $this->saveStatusSingle($awbs[$order->awb], $logistic->consignee_olshop_cust, $logistic->logistic_code);
             //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->daemonname;
             $sdata['actor_id'] = '';
             \Shipmentlog::insert($sdata);
         }
         $actor = 'FL : STATUS PUSH';
         foreach ($inawbstatus as $k => $v) {
             $statusarray[] = array('AWB' => $k, 'status' => $v);
         }
         //print_r($json);
         //print_r($statusarray);
         \Logger::api($methodname, $json, $statusarray);
         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 sendData($req, $client, $logistic, $logistic_id)
 {
     $delivery_trigger = 'KIRIMAN DITERIMA OLEH';
     $returned_trigger = 'KEMBALI KE KOTA ASAL';
     $data_string = json_encode($req);
     //print $data_string;
     //$request->setHeader("Accept" , "application/json");
     /*
     $response = $client->request('POST', $base_url , array('json'=>$req,
         'query'=>array('key'=> $logistic->api_key ),
         'auth' => array($logistic->api_user, $logistic->api_pass, 'Basic'),
         'headers' => array('Accept' => 'application/json') ) );
     
     $awblist = json_decode($response->getBody());
     */
     $base_url = 'http://j-express.id/serverapi.jet/api/tracking/tracking-list.php';
     $postArr = array('awbs' => $data_string);
     $url = "http://j-express.id/serverapi.jet/api/tracking/tracking-list.php";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $base_url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postArr));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     $result = curl_exec($ch);
     /*
     $ch = curl_init($base_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);
     print $result;
     
     die();
     */
     $awblist = json_decode($result);
     $res[] = $awblist;
     Logger::api($this->name, $data_string, $awblist);
     $slog = json_decode($result, true);
     $this->saveStatus($slog, $logistic->logistic_code, $logistic_id);
     $awbs = array();
     $ffs = array();
     print_r($awblist);
     $reslog = $res;
     $reslog['timestamp'] = new MongoDate();
     $reslog['consignee_logistic_id'] = $logistic->logistic_code;
     $reslog['consignee_olshop_cust'] = $logistic_id;
     Threeplstatuslog::insert($reslog);
     try {
         if (is_array($awblist)) {
             foreach ($awblist as $awb) {
                 if (!is_null($awb->cn_no) && $awb->status != 'AWB TIDAK DITEMUKAN') {
                     $awbarray[] = trim($awb->cn_no);
                     $awbs[$awb->cn_no] = $awb;
                 }
             }
             if (count($awbs) > 0) {
                 //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->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]->time;
                     $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 {
             $l = array();
             $l['data'] = $awblist;
             $l['ts'] = new MongoDate();
             $l['consignee_logistic_id'] = $logistic->logistic_code;
             $l['consignee_olshop_cust'] = $logistic_id;
             Threeplstatuserror::insert($l);
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
示例#5
0
 /**
  * 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
             )
     
     )
     */
 }
示例#6
0
 /**
  * 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'));
 }