Пример #1
0
 /**
  * add_relation 
  * @return type
  */
 public static function add_relation()
 {
     try {
         if (!self::validation_add_relation()) {
             return self::error();
         }
         # lat&lng -> geohash
         $geohash = Util_Geohash::encode(Input::post('lat'), Input::post('lng'));
         # transaction
         DB::start_transaction();
         # shop_id指定
         if (is_null(Input::post('shop_id'))) {
             # new shop
             $shop_id = Model_Shop::add(Input::post('shop_name'));
         } else {
             $data = Model_Shop::get_by_pk("shop", Input::post('shop_id'));
             if (!$data) {
                 throw new Exception('shop_id ' . Input::post('shop_id') . " is not exsits.");
             }
             $shop_id = $data['shop_id'];
         }
         # new shop geo add
         if (is_null(Input::post('shop_id'))) {
             if (!self::add($shop_id, Input::post('lat'), Input::post('lng'), $geohash)) {
                 throw new Exception("insert geo fail.");
             }
         }
         # fileupload & setting
         self::$file_name = self::file_upload($shop_id);
         self::$file_path = self::UPLOAD_DIR . Input::post('shop_id') . DS . self::$file_name;
         if (!self::$file_name) {
             throw new Exception('file upload fail.');
         }
         # image resize
         # todo
         # image add
         if (!Model_Image::add($shop_id, Input::post('user_id'), self::$file_name)) {
             throw new Exception("insert image fail.");
         }
         # commit
         DB::commit_transaction();
         # success
         $data = ['status' => CREATED];
     } catch (Exception $ex) {
         # 画像ファイルが存在すれば削除
         if (is_file(self::$file_path)) {
             unlink(self::$file_path);
         }
         # rollback
         DB::rollback_transaction();
         $data = ['status' => DATABASE_ERROR, 'message' => '[database error]insert table fail.'];
         Log::error($ex);
     }
     return $data;
 }
Пример #2
0
 /**
  * 指定された緯度経度の近辺のショップリストを返します
  */
 public function get_neighborhood()
 {
     $this->response(Model_Geo::neighborhood());
 }
Пример #3
0
 public function getUcWiseMosAction()
 {
     $year = $this->_request->getParam('year', '');
     $month = $this->_request->getParam('month', '');
     $product = $this->_request->getParam('product', '');
     $tehsilId = $this->_request->getParam('tehsilId', '');
     $param = $this->_request->getParam('param', '');
     $type = $this->_request->getParam('type', '');
     $geoModel = new Model_Geo();
     if ($param == 'mos') {
         $return = $geoModel->getUcWiseMos($year, $month, $product, $tehsilId);
     } else {
         $return = $geoModel->getUcWiseConsumption($year, $month, $product, $tehsilId, $type);
     }
     echo Zend_Json::encode($return);
 }