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'));
     }
 }
示例#2
0
 /**
  * Tracks command and request history using a history container.
  *
  * This is useful for testing.
  *
  * @param History $history History container to store entries.
  *
  * @return callable
  */
 public static function history(History $history)
 {
     return function (callable $handler) use($history) {
         return function (CommandInterface $command, RequestInterface $request = null) use($handler, $history) {
             $ticket = $history->start($command, $request);
             return $handler($command, $request)->then(function ($result) use($history, $ticket) {
                 $history->finish($ticket, $result);
                 return $result;
             }, function ($reason) use($history, $ticket) {
                 $history->finish($ticket, $reason);
                 return Promise\rejection_for($reason);
             });
         };
     };
 }
 /**
  * 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);
 }