コード例 #1
0
 public function actionGetGroceryRate()
 {
     $inquiry = new InquiryForm('api-rate-grocery');
     $req = Yii::app()->request;
     $inquiryMap = new CMap();
     $inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
     $inquiryMap->add('service_code', $req->getQuery('service_code'));
     $inquiry->setAttributes($inquiryMap->toArray());
     if (!$inquiry->validate()) {
         echo CJSON::encode($this->statusError($inquiry->getErrors()));
         Yii::app()->end();
     }
     $service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
     if (!$service_code instanceof ProductService) {
         echo CJSON::encode($this->statusError('No Service Available'));
         Yii::app()->end();
     } else {
         if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
             echo CJSON::encode($this->statusError('This service is not available'));
             Yii::app()->end();
         }
     }
     $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
     if ($routing instanceof IntraCityRouting) {
         $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
         if (!$area) {
             echo CJSON::encode($this->statusError('No Available Service'));
             Yii::app()->end();
         }
         $rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
         $rate = array();
         foreach ($rates as $key) {
             if ($key['service_code'] == $inquiry->service_code) {
                 $rate = $key;
             }
         }
         $product = 'City Courier';
         echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
         Yii::app()->end();
     } else {
         $result = array('status' => 'success', 'result' => $data);
     }
     echo CJSON::encode($result);
     Yii::app()->end();
 }