本文整理汇总了PHP中Shipment::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Shipment::validate方法的具体用法?PHP Shipment::validate怎么用?PHP Shipment::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shipment
的用法示例。
在下文中一共展示了Shipment::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']);
//.........这里部分代码省略.........
示例2: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Customer'])) {
$model->attributes = $_POST['Customer'];
$model->save();
$this->redirect("#info");
// $this->redirect(array('view','id'=>$model->bilkey));
}
if (isset($_GET['Shipment'])) {
$shipment_model->attributes = $_GET['Shipment'];
}
$service_details = Customer::model()->getCustomerServiceDetails($id);
$shipment_details = Customer::model()->getShipmentsByCustomerBilkey($id);
$customer = Customer::model()->findByPk($id);
$commande = Commande::model()->findAllByAttributes(array('bilkey' => $id));
$shipment_model = new Shipment('search');
$shipment_model->unsetAttributes();
// clear any default values
$shipment_model->bilkey = $id;
// DEBUGGING
// print "New total: " + $total_balance . '<br />';
// print "Old total: " + $customer->bilbalance;
// die;
// TODO: We really should link the billing activity with the comkey...
if (isset($_POST['Shipment'])) {
// Check if it's an update
if (isset($_POST['update'])) {
$shipment = Shipment::model()->findByPk($_POST['update']);
$shipment->attributes = $_POST['Shipment'];
// We have to cast these manually. For some reason this fails on the production server...
$shipment->shipdebit = floatval($shipment->shipdebit);
$shipment->shipcredit = floatval($shipment->shipcredit);
// If the user leaves these fields blank, let's assume
// they meant to input a 0.
if (empty($shipment->shipdebit) || $shipment->shipdebit == null) {
$shipment->shipdebit = 0;
}
if (empty($shipment->shipcredit) || $shipment->shipcredit == null) {
$shipment->shipcredit = 0;
}
// TODO: We should prolly check this
$shipment->save();
} else {
$shipment = new Shipment();
$shipment->attributes = $_POST['Shipment'];
// We have to cast these manually. For some reason this fails on the production server...
$shipment->shipdebit = floatval($shipment->shipdebit);
$shipment->shipcredit = floatval($shipment->shipcredit);
// If the user leaves these fields blank, let's assume
// they meant to input a 0.
if (empty($shipment->shipdebit) || $shipment->shipdebit == null) {
$shipment->shipdebit = 0;
}
if (empty($shipment->shipcredit) || $shipment->shipcredit == null) {
$shipment->shipcredit = 0;
}
if ($shipment->validate()) {
$shipment->comkey = $commande[0]->comkey;
$shipment->bilkey = $customer->bilkey;
$shipment->save();
}
}
// $this->redirect("customer/update/id/" + $customer->bilkey);
$this->redirect("#billing");
}
$conn = Yii::app()->db;
// $total_balance = 0;
// Update individual account balances
foreach ($commande as $c) {
$command = $conn->createCommand("SELECT SUM(shipcredit) - SUM(shipdebit) as balance FROM shipment WHERE comkey='" . $c->comkey . "' GROUP BY comkey");
$results = $command->queryRow();
$balance = $results['balance'];
// $total_balance += $balance;
$c->dest_bilbalance = $balance;
$c->save();
}
// Fix for Support Request #430
$command = $conn->createCommand("SELECT SUM(shipcredit) - SUM(shipdebit) as balance FROM shipment WHERE bilkey='" . $customer->bilkey . "'");
$results = $command->queryRow();
$total_balance = $results['balance'];
// Update overall account balance
$customer->bilbalance = $total_balance;
$customer->save();
$this->render('//shared/user-info', array('admin' => 1, 'commande' => $commande, 'customer' => $customer, 'customer_model' => $customer, 'service_details' => $service_details, 'shipment_details' => $shipment_details, 'shipment_model' => $shipment_model));
}
示例3: bulkOrder
//.........这里部分代码省略.........
$shipment->setAttribute('receiver_city', trim($column[12]));
$shipment->setAttribute('receiver_country', trim($column[13]));
$shipment->setAttribute('receiver_postal', trim($column[14]));
$shipment->setAttribute('receiver_phone', trim($column[11]));
//shipment_detail
$shipment->setAttribute('type', 'document');
$shipment->setAttribute('payer', 'shipper');
$shipment->setAttribute('payby', 'account');
$shipment->setAttribute('pieces', trim($column[15]));
$shipment->setAttribute('package_weight', trim($column[16]));
$shipment->setAttribute('package_value', trim($column[17]));
$shipment->setAttribute('service_type', trim($column[18]));
$shipment->setAttribute('service_id', trim($column[19]));
$shipment->setAttribute('service_code', trim($column[20]));
$shipment->setAttribute('destination_code', trim($column[0]));
$customer_rate = CustomerDiscount::getCustomerDiscountRate($shipment->service_id, $shipment->customer_id);
if (!!$customer_rate) {
if ($customer_rate['discount'] == null) {
$customer_rate['discount'] = 0;
}
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) {
$price = 0;
$price_vendor = 0;
$valid_area = false;
} else {
$price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']);
$price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']);
}
}
break;
case 'Domestic':
$area = Area::getZoneID($shipment->receiver_postal);
if (!$area) {
$price = 0;
$price_vendor = 0;
$valid_area = false;
} else {
$price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']);
$price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']);
}
break;
case 'International':
$zone = FALSE;
if ($shipment->service_code == 'IEX') {
$country = $shipment->receiver_country;
} else {
if ($shipment->service_code == 'IMX') {
$country = $shipment->shipper_country;
}
}
$zone = ZoneInternational::getZoneCountryData($country);
if (!!$zone) {
$price = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['discount']);
$price_vendor = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['vendor_discount']);
} else {
$price = 0;
$price_vendor = 0;
$valid_area = false;
}
break;
case '':
continue;
}
$shipment->shipping_charges = $price;
$shipment->vendor_charge = $price_vendor;
$shipment->awb = '90' . rand(10000000, 99999999);
while (!$shipment->validate(array('awb'))) {
$shipment->awb = '90' . rand(10000000, 99999999);
}
if ($shipment->save()) {
$additional_costs = ShipmentAdditionalCharge::initSurcharges($shipment);
$shipment->charges = $shipment->shipping_charges + $additional_costs;
$shipment->save();
array_push($success, $counter);
} else {
CVarDumper::dump($shipment->attributes, 10, true);
CVarDumper::dump($shipment->getErrors(), 10, true);
array_push($failed, array('counter' => $counter, 'message' => $shipment->getErrors()));
}
} else {
array_push($failed, array('counter' => $counter, 'message' => array('this service is not available')));
}
} else {
array_push($failed, array('counter' => $counter, 'message' => array('wrong delimiter format')));
}
}
return array('success' => $success, 'failed' => $failed);
}
示例4: actionGetAwbNumber
public function actionGetAwbNumber()
{
$shipment = new Shipment();
$result = array('status' => 'error', 'data' => '');
$shipment->awb = '90' . rand(10000000, 99999999);
while (!$shipment->validate(array('awb'))) {
$shipment->awb = '90' . rand(10000000, 99999999);
}
echo CJSON::encode($result = array('status' => 'success', 'data' => $shipment->awb));
Yii::app()->end();
}