Пример #1
0
 /**
  * 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'));
 }
Пример #2
0
 /**
  * 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'));
 }
Пример #3
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'));
 }
Пример #4
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
             )
     
     )
     */
 }