/** * 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')); }
public function postAssigncourier() { //courier_name:Shia Le Beouf //courier_id:5605512bccae5b64010041b6 //device_key:0f56deadbc6df60740ef5e2c576876b0e3310f7d //device_name:JY-002 //pickup_date:28-09-2 $in = Input::get(); $pickup_date = new MongoDate(strtotime($in['pickup_date'])); $shipments = Shipment::where('device_key', '=', $in['device_key'])->where('pick_up_date', '=', $pickup_date)->where('status', '=', Config::get('jayon.trans_status_admin_zoned'))->get(); //print_r($shipments->toArray()); $ts = new MongoDate(); foreach ($shipments as $sh) { $pre = clone $sh; $sh->bucket = Config::get('jayon.bucket_tracker'); $sh->status = Config::get('jayon.trans_status_admin_courierassigned'); $sh->courier_id = $in['courier_id']; $sh->courier_name = $in['courier_name']; $sh->save(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'assign_courier'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $sh->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'assign_courier'; $sdata['reason'] = 'initial'; $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); //print_r($sh); } return Response::json(array('result' => 'OK', 'shipment' => $shipments)); }
/** * 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')); }
/** * 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')); }
public function postAssigndevice() { $in = Input::get(); $device = Device::where('key', '=', $in['device'])->first(); $shipments = Shipment::whereIn('delivery_id', $in['ship_ids'])->get(); //print_r($shipments->toArray()); $ts = new MongoDate(); foreach ($shipments as $sh) { $pre = clone $sh; $sh->status = Config::get('jayon.trans_status_admin_zoned'); $sh->device_key = $device->key; $sh->device_name = $device->identifier; $sh->device_id = $device->_id; $sh->save(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'assign_device'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $sh->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'assign_device'; $sdata['reason'] = 'initial'; $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); } return Response::json(array('result' => 'OK', 'shipment' => $shipments)); }
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 postExttotrack() { $in = Input::get(); $results = Shipment::whereIn('_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); $ts = new MongoDate(); //print_r($results->toArray()); $reason = isset($in['reason']) ? $in['reason'] : 'move after print'; //if($results){ $res = false; //}else{ foreach ($results as $r) { $pre = clone $r; if ($r->logistic_type == 'external') { if (trim($r->awb) != '') { $r->bucket = Config::get('jayon.bucket_tracker'); $r->status = Config::get('jayon.trans_status_confirmed'); $r->save(); } } $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'print_external_barcode'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $r->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = Auth::user()->_id; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'print_external_barcode'; $sdata['reason'] = $reason; $sdata['objectType'] = 'shipment'; $sdata['object'] = $r->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = Auth::user()->_id; Shipmentlog::insert($sdata); $confirm = array('awb' => $r->awb, 'order_id' => $r->no_sales_order, 'consignee_id' => $r->consignee_olshop_cust, 'ff_id' => $r->consignee_olshop_orderid, 'ts' => $ts, 'sent' => 0); Confirmed::insert($confirm); } $res = true; //} if ($res) { return Response::json(array('result' => 'OK:MOVED')); } else { return Response::json(array('result' => 'ERR:MOVEFAILED')); } }
/** * Execute the console command. * * @return mixed */ public function fire() { //$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')); }
public function postCanceldata() { $in = Input::get(); $results = Shipment::whereIn('delivery_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); //print_r($results->toArray()); //if($results){ $res = false; //}else{ $ts = new MongoDate(); foreach ($results as $sh) { $sh->status = Config::get('jayon.trans_status_canceled'); //$sh->last_action_ts = $ts; //$sh->last_action = 'Cancel Data'; $sh->delivery_note = $in['reason']; $sh->save(); //print_r($sh); //print_r(Auth::user()); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'cancel_data'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $sh->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = isset(Auth::user()->_id) ? Auth::user()->_id : Auth::user()->id; //print_r($hdata); History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'cancel_data'; $sdata['reason'] = $in['reason']; $sdata['objectType'] = 'shipment'; $sdata['object'] = $sh->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = isset(Auth::user()->_id) ? Auth::user()->_id : Auth::user()->id; Shipmentlog::insert($sdata); $res = true; } //} if ($res) { return Response::json(array('result' => 'OK')); } else { return Response::json(array('result' => 'ERR:CANCELFAILED')); } }
/** * Store a newly created resource in storage. * * @return Response */ public function postOrderstatus() { $key = \Input::get('key'); //$user = \Apiauth::user($key); $user = \Device::where('key', '=', $key)->first(); if (!$user) { $actor = 'no id : no name'; \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed')); return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => 'Device Unregistered')); } $json = \Input::all(); $batch = \Input::get('batch'); $result = array(); foreach ($json as $j) { //$j['mtimestamp'] = new \MongoDate(); if (is_array($j)) { $olog = new \Orderstatuslog(); foreach ($j as $k => $v) { $olog->{$k} = $v; } $olog->mtimestamp = new \MongoDate(time()); $r = $olog->save(); $shipment = \Shipment::where('delivery_id', '=', $olog->deliveryId)->first(); if ($shipment) { $ts = new \MongoDate(); $pre = clone $shipment; if ($appname == \Config::get('jex.pickup_app')) { $shipment->pickup_status = $olog->pickupStatus; if (isset($user->node_id)) { $shipment->position = $user->node_id; } } elseif ($appname == \Config::get('jex.hub_app')) { $shipment->warehouse_status = $olog->warehouseStatus; if (isset($user->node_id)) { $shipment->position = $user->node_id; } } else { $shipment->status = $olog->status; $shipment->courier_status = $olog->courierStatus; if ($olog->status == 'pending') { $shipment->pending_count = $shipment->pending_count + 1; } elseif ($olog->status == 'delivered') { $shipment->deliverytime = date('Y-m-d H:i:s', time()); } if ($olog->status == 'pending') { //$shipment->pending_count = $olog->pendingCount; } elseif ($olog->status == 'delivered') { //$shipment->deliverytime = date('Y-m-d H:i:s',time()); if (isset($shipment->delivered_time)) { } else { $shipment->delivered_time = date('Y-m-d H:i:s', time()); $shipment->delivered_time_ts = new \MongoDate(); } $shipment->position = 'CUSTOMER'; } } /* $shipment->status = $olog->status; $shipment->courier_status = $olog->courierStatus; if($olog->status == 'pending'){ //$shipment->pending_count = $olog->pendingCount; }elseif($olog->status == 'delivered'){ //$shipment->deliverytime = date('Y-m-d H:i:s',time()); $shipment->delivered_time = date('Y-m-d H:i:s',time()); }*/ $shipment->save(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'api_shipment_change_status'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $shipment->toArray(); $hdata['actor'] = $user->identifier; $hdata['actor_id'] = $user->key; \History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'api_shipment_change_status'; $sdata['reason'] = 'api_update'; $sdata['objectType'] = 'shipment'; $sdata['object'] = $shipment->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = $user->identifier; $sdata['actor_id'] = $user->key; \Shipmentlog::insert($sdata); } if ($r) { $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => 'log inserted'); } else { $result[] = array('status' => 'NOK', 'timestamp' => time(), 'message' => 'insertion failed'); } } /* if( \Orderstatuslog::insert($j) ){ $result[] = array('status'=>'OK', 'timestamp'=>time(), 'message'=>'log inserted' ); }else{ $result[] = array('status'=>'NOK', 'timestamp'=>time(), 'message'=>'insertion failed' ); } */ } //print_r($result); //die(); $actor = $user->identifier . ' : ' . $user->devname; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync scan log')); return Response::json($result); }
/** * 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')); }
public function postResetuploaded() { $in = Input::get(); $results = Shipment::whereIn('_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); //print_r($results->toArray()); //if($results){ $res = false; //}else{ $ts = new MongoDate(); foreach ($results as $sh) { $pre = clone $sh; $sh->uploaded = 0; $sh->last_action_ts = $ts; $sh->last_action = 'Reset Uploaded Flag'; $sh->last_reason = $in['reason']; $sh->save(); //print_r(Auth::user()); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'cancel_data'; $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'] = 'cancel_data'; $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:RESCHED')); } else { return Response::json(array('result' => 'ERR:RESCHEDFAILED')); } }
/** * 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 ) ) */ }
public function postAssigndate() { $in = Input::get(); $results = Shipment::whereIn('delivery_id', $in['ids'])->get(); date_default_timezone_set('Asia/Jakarta'); if (is_null($in['trip']) || $in['trip'] == '') { $trip = 1; } else { $trip = $in['trip']; } $assignment_date = $in['date']; $ts = new MongoDate(); //print_r($results->toArray()); $reason = isset($in['reason']) ? $in['reason'] : 'initial'; //if($results){ $res = false; //}else{ foreach ($results as $r) { $pre = clone $r; /* if(is_null($in['date']) || $in['date'] == ''){ }else{ //$newdate = strtotime($in['date']); //$r->pick_up_date = new MongoDate($newdate) ; } */ $r->buyerdeliveryslot = $trip; $r->status = Config::get('jayon.trans_status_admin_dated'); $r->assigntime = date('Y-m-d H:i:s', time()); $r->assignment_date = $assignment_date; /* if($r->logistic_type == 'internal'){ if($r->cod == 0 || $r->cod == ''){ $r->awb = $r->delivery_id; $r->bucket = Config::get('jayon.bucket_dispatcher'); $r->status = Config::get('jayon.trans_status_admin_dated'); } }else{ if($r->awb != ''){ $r->bucket = Config::get('jayon.bucket_tracker'); $r->status = Config::get('jayon.trans_status_admin_dated'); } } */ $r->save(); $hdata = array(); $hdata['historyTimestamp'] = $ts; $hdata['historyAction'] = 'assign_date'; $hdata['historySequence'] = 1; $hdata['historyObjectType'] = 'shipment'; $hdata['historyObject'] = $r->toArray(); $hdata['actor'] = Auth::user()->fullname; $hdata['actor_id'] = isset(Auth::user()->_id) ? Auth::user()->_id : Auth::user()->id; History::insert($hdata); $sdata = array(); $sdata['timestamp'] = $ts; $sdata['action'] = 'assign_date'; $sdata['reason'] = $reason; $sdata['objectType'] = 'shipment'; $sdata['object'] = $r->toArray(); $sdata['preObject'] = $pre->toArray(); $sdata['actor'] = Auth::user()->fullname; $sdata['actor_id'] = isset(Auth::user()->_id) ? Auth::user()->_id : Auth::user()->id; Shipmentlog::insert($sdata); } $res = true; //} if ($res) { return Response::json(array('result' => 'OK')); } else { return Response::json(array('result' => 'ERR:MOVEFAILED')); } }
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(); } }
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() { $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')); // }