当前位置: 首页>>代码示例>>PHP>>正文


PHP Shipment::setScenario方法代码示例

本文整理汇总了PHP中Shipment::setScenario方法的典型用法代码示例。如果您正苦于以下问题:PHP Shipment::setScenario方法的具体用法?PHP Shipment::setScenario怎么用?PHP Shipment::setScenario使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shipment的用法示例。


在下文中一共展示了Shipment::setScenario方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setJneStatusOrder

 /**
  * Set shipment status to completed
  * 
  * @param Shipment $shipment
  * @param string $recepient_name
  */
 private function setJneStatusOrder(Shipment $shipment, $status, $recepient_name = '')
 {
     $event = new ShipmentEvent();
     $shipment->setScenario('event');
     $event->created = time();
     $event->event_time = $event->created;
     $event->shipment_id = $shipment->id;
     $event->user_id = User::USER_SYSTEM;
     switch (strtoupper($status)) {
         case 'DELIVERED':
             $event->status = ShipmentStatus::POD;
             $shipment->shipping_status = ShipmentStatus::POD;
             $shipment->event_time = $event->event_time;
             $shipment->recipient_name = $recepient_name;
             break;
         case 'MANIFESTED':
             $event->status = ShipmentStatus::MDE;
             $shipment->shipping_status = ShipmentStatus::MDE;
             $shipment->event_time = $event->event_time;
             break;
         case 'RECEIVED ON DESTINATION':
             $event->status = ShipmentStatus::ARR;
             $shipment->shipping_status = ShipmentStatus::ARR;
             $shipment->event_time = $event->event_time;
             break;
         case 'ON PROCESS':
             $event->status = ShipmentStatus::OTW;
             $shipment->shipping_status = ShipmentStatus::OTW;
             $shipment->event_time = $event->event_time;
             break;
     }
     try {
         $trans = Yii::app()->db->beginTransaction();
         if ($event->save()) {
             if ($shipment->save()) {
                 $trans->commit();
                 $this->printf('Shipment set to %s', $status);
                 return true;
             } else {
                 print_r($shipment->getErrors());
                 throw new CException();
             }
         } else {
             print_r($event->getErrors());
             throw new CException();
         }
     } catch (CException $e) {
         $trans->rollback();
         throw $e;
     }
 }
开发者ID:aantonw,项目名称:dcourier.system,代码行数:57,代码来源:CheckJneStatusCommand.php

示例2: actionRequestOrder

 public function actionRequestOrder()
 {
     if (!isset($_POST['Shipment'])) {
         echo CJSON::encode($this->statusError('Must be in POST method'));
         Yii::app()->end();
     }
     $shipment = new Shipment('api-requestpickup');
     $shipment->attributes = $_POST['Shipment'];
     $shipment->created = time();
     $routing_code = IntraCityRouting::model()->findByAttributes(array('postcode' => $shipment->shipper_postal));
     if ($routing_code instanceof IntraCityRouting) {
         $shipment->origin_code = $routing_code->code;
     }
     $price = 0;
     $price_vendor = 0;
     $trans = Yii::app()->db->beginTransaction();
     try {
         if ($this->token instanceof Token) {
             $customer = Customer::model()->findByPk($this->token->customer_id);
             if (!$customer instanceof Customer) {
                 throw new ServiceControllerException('You have to login first');
             }
             if (!!$customer->accountnr) {
                 $shipment->awb = '70' . rand(10000000, 99999999);
                 while (!$shipment->validate()) {
                     $shipment->awb = '70' . rand(10000000, 99999999);
                 }
             }
             $shipment->customer_id = $this->token->customer_id;
         } else {
             $email = '';
             $shipment->setScenario('cekemail');
             if ($shipment->validate()) {
                 if ($shipment->payer == 'shipper' && $shipment->shipper_email) {
                     $email = Contact::model()->findByAttributes(array('email' => $shipment->shipper_email));
                 } elseif ($shipment->payer == 'consignee' && $shipment->receiver_email) {
                     $email = Contact::model()->findByAttributes(array('email' => $shipment->receiver_email));
                 }
             } else {
                 throw new ServiceControllerException($shipment->getErrors());
             }
             $shipment->setScenario('api-requestpickup');
             if (!$email instanceof Contact) {
                 $customer = new Customer();
                 if ($shipment->payer == 'shipper') {
                     $customer->name = $shipment->shipper_name;
                 } elseif ($shipment->payer == 'consignee') {
                     $customer->name = $shipment->receiver_name;
                 }
                 $customer->type = 'personal';
                 $customer->accountnr = 'WEB' . time();
                 if ($customer->save()) {
                     $contact = new Contact();
                     $contact->parent_id = $customer->id;
                     $contact->parent_model = 'Customer';
                     if ($shipment->payer == 'shipper') {
                         $contact->full_name = $shipment->shipper_name;
                         $contact->address = $shipment->shipper_address;
                         $contact->country = $shipment->shipper_country;
                         $contact->city = $shipment->shipper_city;
                         $contact->postal = $shipment->shipper_postal;
                         $contact->email = $shipment->shipper_email;
                     } elseif ($shipment->payer == 'consignee') {
                         $contact->full_name = $shipment->receiver_name;
                         $contact->address = $shipment->receiver_address;
                         $contact->country = $shipment->receiver_country;
                         $contact->city = $shipment->receiver_city;
                         $contact->postal = $shipment->receiver_postal;
                         $contact->email = $shipment->receiver_email;
                     }
                     if ($contact->save()) {
                         $shipment->customer_id = $customer->id;
                     } else {
                         throw new ServiceControllerException($contact->getErrors());
                     }
                 } else {
                     throw new ServiceControllerException($customer->getErrors());
                 }
             } else {
                 throw new ServiceControllerException('Your email is currently registered as a member, please login to create order');
             }
         }
         if ($shipment->validate()) {
             $customer_rate = CustomerDiscount::getCustomerDiscountRate($shipment->service_id, $shipment->customer_id);
             switch ($shipment->service_type) {
                 case 'City Courier':
                     $rate = RateCity::model()->findByAttributes(array('service_id' => $shipment->service_id));
                     if ($rate instanceof RateCity) {
                         if ($customer_rate['harga_invoice'] != 0) {
                             $price = $customer_rate['harga_invoice'] * RateCity::increment($shipment->package_weight, $rate->weight_inc);
                         } else {
                             $price = ($rate->price - $rate->price * ($customer_rate['discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc);
                         }
                         $price_vendor = ($rate->price - $rate->price * ($customer_rate['vendor_discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc);
                     } else {
                         $area = Area::getZoneID($shipment->receiver_postal);
                         if (!$area) {
                             throw new ServiceControllerException('No services available');
                         }
                         $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']);
//.........这里部分代码省略.........
开发者ID:aantonw,项目名称:dcourier.system,代码行数:101,代码来源:ServiceController.php

示例3: actionCreateInquiry

 public function actionCreateInquiry($cid)
 {
     $shipment = new Shipment();
     $inquiry = new InquiryForm();
     Yii::app()->user->setState('Shipment-items', '');
     Yii::app()->user->setState('Shipment-add_costs', '');
     Yii::app()->user->setState('Shipment', '');
     $items[] = new ShipmentItem();
     $costs[] = new ShipmentAdditionalCharge();
     $customer = Customer::model()->findByPk($cid);
     $contact = Contact::model()->find('parent_model=:pm and parent_id=:pid', array(':pm' => 'Customer', ':pid' => $customer->id));
     $good_types = GoodType::model()->findAll();
     $shipment->type = 'document';
     $inquiry->pickup_date = date('m/d/Y', time());
     if (isset($_POST['InquiryForm']) && isset($_POST['Shipment'])) {
         $shipment->setScenario('insert');
         $inquiry->setAttributes($_POST['InquiryForm']);
         if ($inquiry->validate()) {
             $shipment->setAttributes($inquiry->attributes);
         }
         $shipment->setAttributes($_POST['Shipment']);
         /*
          * shipment items
          */
         if ($shipment->validate()) {
             $shipment_items = $_POST['ShipmentItem'];
             $items = array();
             $weight_to_count = array();
             foreach ($shipment_items as $item) {
                 $shipment_item = new ShipmentItem();
                 $shipment_item->setScenario('inquiry');
                 $shipment_item->attributes = $item;
                 if ($shipment_item->validate()) {
                     $items[] = $shipment_item;
                     Yii::app()->user->setState('Shipment-items', $items);
                     array_push($weight_to_count, $shipment_item->getWeightToCount());
                 }
             }
             $shipment->package_weight = array_sum($weight_to_count);
             /*
              * shipment additional costs
              */
             $shipment_costs = $_POST['ShipmentAdditionalCharge'];
             $costs = array();
             $arr_costs = array();
             foreach ($shipment_costs as $cost) {
                 $shipment_costs = new ShipmentAdditionalCharge();
                 $shipment_costs->setScenario('inquiry');
                 $shipment_costs->attributes = $cost;
                 if ($shipment_costs->validate()) {
                     $costs[] = $shipment_costs;
                     Yii::app()->user->setState('Shipment-add_costs', $costs);
                     array_push($arr_costs, $shipment_costs->cost);
                 }
             }
             $total_add_cost = array_sum($arr_costs);
             $shipment->charges = $shipment->shipping_charges + $total_add_cost + $shipment->cod;
             Yii::app()->user->setState('Shipment', $shipment);
             $this->redirect(array('view'));
         }
     }
     $shipment->pickup_address = $contact->address;
     $shipment->payer = 'shipper';
     $shipment->pay_by = 'account';
     $inquiry->shipper_city = 'Jakarta';
     $inquiry->shipper_country = 'Indonesia';
     $data_render = array('inquiry' => $inquiry, 'customer' => $customer, 'good_types' => $good_types, 'items' => $items, 'costs' => $costs, 'contact' => $contact, 'shipment' => $shipment);
     $this->render('createInquiry', $data_render);
 }
开发者ID:aantonw,项目名称:dcourier.system,代码行数:69,代码来源:ShipmentController.php


注:本文中的Shipment::setScenario方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。