コード例 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     date_default_timezone_set('Asia/Jakarta');
     $key = Input::get('key');
     $order_id = Input::get('orderid');
     $ff_id = Input::get('ffid');
     $is_dev = Input::get('dev');
     if (is_null($is_dev) || $is_dev == '') {
         $is_dev = 0;
     }
     if (is_null($key) || $key == '' || $key != $this->g21_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'));
     }
     $date_from = Input::get('from');
     $date_to = Input::get('to');
     if (is_null($date_from) || $date_from == '') {
         $date_from = new \MongoDate(strtotime(date('Y-m-d', time()) . ' 00:00:00'));
     } else {
         $date_from = new \MongoDate(strtotime($date_from . ' 00:00:00'));
     }
     if (is_null($date_to) || $date_to == '') {
         $date_to = new \MongoDate(strtotime(date('Y-m-d', time()) . ' 23:59:59'));
     } else {
         $date_to = new \MongoDate(strtotime($date_to . ' 23:59:59'));
     }
     //$logistic = \Logistic::where('api_key','=',$key)->first();
     $logistic = \Logistic::where('consignee_olshop_cust', '=', $this->g21_id)->first();
     $logistic_id = $logistic->consignee_olshop_cust;
     $orders = \Shipment::where('awb', '!=', '')->where('logistic_type', '=', 'external')->where('consignee_olshop_cust', '=', $logistic_id)->where(function ($q) {
         $q->where('status', '=', \Config::get('jayon.trans_status_admin_dated'))->orWhere('status', '=', \Config::get('jayon.trans_status_confirmed'));
     })->where(function ($qd) use($date_from, $date_to) {
         $qd->whereBetween('pick_up_date', array($date_from, $date_to));
     })->where(function ($q) {
         $q->where('uploaded', '!=', 1)->orWhere('uploaded', 'exists', false);
     })->get();
     $orderres = clone $orders;
     $orders = $orders->toArray();
     $orderlist = array();
     for ($n = 0; $n < count($orders); $n++) {
         $o = $orders[$n];
         $entry = array();
         $entry['awb'] = $o['awb'];
         $entry['remark'] = '-';
         if (isset($o['consignee_olshop_addr'])) {
             $con_address = str_replace(array("\r", "\n"), ' ', $o['consignee_olshop_addr']);
         } else {
             $con_address = '';
         }
         $consignee = array('cn_name' => $o['consignee_olshop_name'], 'address' => $con_address, 'district' => $o['district'], 'city' => $o['consignee_olshop_city'], 'province' => $o['consignee_olshop_region'], 'country' => $o['consignee_olshop_region'], 'phone' => $o['consignee_olshop_phone']);
         $insurance = 'NO';
         if (isset($o['consignee_olshop_inst_amt'])) {
             if ($o['consignee_olshop_inst_amt'] == '' || is_null($o['consignee_olshop_inst_amt'])) {
                 $insurance = 'NO';
             } else {
                 $insurance = 'YES';
             }
         }
         //if($o['pick_up_date'] instanceOf MongoDate){
         $pickupdate = date('Y-m-d', $o['pick_up_date']->sec);
         //}else{
         //    $pickupdate = $o['pick_up_date'];
         //}
         $o['cod'] = isset($o['cod']) ? $o['cod'] : 0;
         $order = array('orderid' => $o['no_sales_order'] . '-' . $o['fulfillment_code'], 'actweight' => $o['w_v'], 'pieces' => $o['number_of_package'], 'items' => array('itemname' => $o['consignee_olshop_desc']), 'goodsval' => $o['cod'], 'insurance' => $insurance, 'cod' => $o['cod'] == 0 ? '0' : '1', 'pickupdate' => $pickupdate, 'service' => $o['consignee_olshop_service']);
         $shipper = array('merchant' => 'Bilna.com', 'merchant_address' => 'Kawasan Pergudangan PT. WIDYA SAKTI KUSUMA Jl. Raya Bekasi KM 28 ( Jl. Wahab Affan ) Pondok Ungu, Medan Satria, Bekasi 17132', 'merchant_district' => 'Medan Satria', 'merchant_city' => 'Bekasi', 'merchant_province' => 'Jawa Barat', 'merchant_country' => 'Indonesia', 'merchant_phone' => '02129022132', 'merchant_contact' => 'Bilna CS');
         $entry['consignee'] = $consignee;
         $entry['order'] = $order;
         $entry['shipper'] = $shipper;
         $orderlist[] = $entry;
     }
     if ($is_dev != 1) {
         foreach ($orderres as $ord) {
             $ord->uploaded = 1;
             $ord->save();
         }
     }
     $reslog = $orderlist;
     $reslog['timestamp'] = new \MongoDate();
     $reslog['consignee_logistic_id'] = $logistic->logistic_code;
     $reslog['consignee_olshop_cust'] = $logistic->consignee_olshop_cust;
     \Threepluploadlog::insert($reslog);
     $actor = $key;
     \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'G21 PULL DATA'));
     return $orderlist;
     //
 }
コード例 #2
0
 /**
  * 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'));
 }