Exemple #1
0
 function editShopbranch($id)
 {
     if ($this->input->post('title')) {
         //			var_dump($_POST);
         $keys = array('title', 'openTime', 'phone', 'address');
         foreach ($keys as $key) {
             $data[$key] = $this->input->post($key);
         }
         $data['district'] = avosPointer('District', $this->input->post('districtId'));
         $data['subDistrict'] = avosPointer('District', $this->input->post('subDistrictId'));
         $latitude = doubleval($this->input->post('latitude'));
         $longitude = doubleval($this->input->post('longitude'));
         $data['location'] = avosGeoPoint($latitude, $longitude);
         $result = $this->model->update($id, $data);
         if ($result < 0) {
             echo $result;
         } else {
             $this->session->set_flashdata('msg', '创建成功');
             redirect('admin/shops/index', 'refresh');
         }
         return;
     }
     $headDistricts = $this->district_m->get_all_headDistrict();
     $subDistricts = array();
     foreach ($headDistricts as $district) {
         $subDistricts = array_merge($subDistricts, $district['subDistricts']);
     }
     $data['title'] = '子商户';
     $data['main'] = 'admin_shops_editshopbranch';
     $data['model'] = $this->model->get($id);
     $data['headDistricts'] = $headDistricts;
     $data['subDistricts'] = $subDistricts;
     $this->load->view($this->config->item('admin_template'), $data);
 }
Exemple #2
0
 /**
  * 返回快券: dictionary: location -> array of coupons 
  * 先搜子商户
  * 返回的快券是有重复的,(因为不同的子商户会有同样的主商户,因此会返回重复的快券,需要客户端处理)
  * @param districtId
  * @param subDistrictId
  * @param couponTypeId
  * @param subTypeId
  * @param districtKeyword
  * @param couponTypeKeyword
  * @param latitude
  * @param longitude
  * @param skip
  * @param limit
  */
 public function searchCoupons_get()
 {
     $districtId = $this->get('districtId');
     $subDistrictId = $this->get('subDistrictId');
     $couponTypeId = $this->get('couponTypeId');
     $subTypeId = $this->get('subTypeId');
     $latitude = doubleval($this->get('latitude'));
     $longitude = doubleval($this->get('longitude'));
     $districtKeyword = $this->get('districtKeyword');
     $couponTypeKeyword = $this->get('couponTypeKeyword');
     $skip = $this->get('skip');
     $limit = $this->get('limit');
     if (empty($skip)) {
         $skip = 0;
     }
     if (empty($limit)) {
         $limit = 50;
     }
     $where['parent'] = array('$exists' => true);
     if (!empty($districtId)) {
         $where['district'] = avosPointer('District', $districtId);
     } else {
         if (!empty($subDistrictId)) {
             $where['subDistrict'] = avosPointer('District', $subDistrictId);
         }
     }
     if (!empty($couponTypeId)) {
         $where['couponType'] = avosPointer('CouponType', $couponTypeId);
     } else {
         if (!empty($subTypeId)) {
             $where['subType'] = avosPointer('CouponType', $subTypeId);
         }
     }
     if (!empty($latitude)) {
         $where['location'] = array('$nearSphere' => avosGeoPoint($latitude, $longitude));
     }
     if (!empty($couponTypeKeyword)) {
         $where['couponType'] = array('$inQuery' => array('where' => array('title' => array('$regex' => $couponTypeKeyword)), 'className' => 'CouponType'));
     } else {
         if (!empty($districtKeyword)) {
             $where['district'] = array('$inQuery' => array('where' => array('title' => array('$regex' => $districtKeyword)), 'className' => 'District'));
         }
     }
     $where = json_encode($where);
     $coupons = $this->coupon_m->search($where, $skip, $limit);
     return $this->output_results($coupons, '搜索商户失败');
 }
Exemple #3
0
 /**
  * 
  * 返回最近的店铺
  * @param
  */
 public function nearestShop_get()
 {
     $districtId = $this->get('districti=Id');
     $couponTypeId = $this->get('couponTypeId');
     $latitude = $this->get('latitude');
     $longitude = $this->get('longitude');
     $where = array('location' => array('$nearSphere' => avosGeoPoint($latitude, $longitude)));
     if (!empty($districtId)) {
         $where[] = array('district' => avosPointer('District', $districtId));
     }
     if (!empty($couponTypeId)) {
         $where[] = array('couponType' => avosPointer('CouponType', $couponTypeId));
     }
     $url = HOST . '/classes/Shop?where=' . json_encode($where);
     //   		echo $url;
     $json = $this->kq->get($url);
     $error = checkResponseError($json);
     if (!empty($error)) {
         return $error;
     }
     $results = resultsWithJson($json);
     $shopParentIds = array();
     ///获得ShopIds
     foreach ($results as $result) {
         /// 获得shopIds,去除parentId是一样的,
         $parentId = trim($result['parent']['objectId']);
         if (!in_array($parentId, $shopParentIds)) {
             $shopIds[] = trim($result['objectId']);
             $shopParentIds[] = $parentId;
         }
     }
     if (!isLocalhost()) {
         $this->output->cache(CacheTime);
     }
     return $this->outputArray($shopIds);
 }
Exemple #4
0
 /**
  * 返回快券: dictionary: location -> array of coupons 
  * 先搜子商户
  * 返回的快券是有重复的,(因为不同的子商户会有同样的主商户,因此会返回重复的快券,需要客户端处理)
  * @param districtId
  * @param subDistrictId
  * @param couponTypeId
  * @param subTypeId
  * @param districtKeyword
  * @param couponTypeKeyword
  * @param latitude
  * @param longitude
  * @param skip
  * @param limit
  */
 public function searchCoupons_get()
 {
     $districtId = $this->get('districtId');
     $subDistrictId = $this->get('subDistrictId');
     $couponTypeId = $this->get('couponTypeId');
     $subTypeId = $this->get('subTypeId');
     $latitude = doubleval($this->get('latitude'));
     $longitude = doubleval($this->get('longitude'));
     $districtKeyword = $this->get('districtKeyword');
     $couponTypeKeyword = $this->get('couponTypeKeyword');
     $skip = $this->get('skip');
     $limit = $this->get('limit');
     if (empty($skip)) {
         $skip = 0;
     }
     if (empty($limit)) {
         $limit = 50;
     }
     $where['parent'] = array('$exists' => true);
     if (!empty($districtId)) {
         $where['district'] = avosPointer('District', $districtId);
     } else {
         if (!empty($subDistrictId)) {
             $where['subDistrict'] = avosPointer('District', $subDistrictId);
         }
     }
     if (!empty($couponTypeId)) {
         $where['couponType'] = avosPointer('CouponType', $couponTypeId);
     } else {
         if (!empty($subTypeId)) {
             $where['subType'] = avosPointer('CouponType', $subTypeId);
         }
     }
     if (!empty($latitude)) {
         $where['location'] = array('$nearSphere' => avosGeoPoint($latitude, $longitude));
     }
     if (!empty($couponTypeKeyword)) {
         $where['couponType'] = array('$inQuery' => array('where' => array('title' => array('$regex' => $couponTypeKeyword)), 'className' => 'CouponType'));
     } else {
         if (!empty($districtKeyword)) {
             $where['district'] = array('$inQuery' => array('where' => array('title' => array('$regex' => $districtKeyword)), 'className' => 'District'));
         }
     }
     //		where={"post":{"$inQuery":{"where":{"image":{"$exists":true}},"className":"Post"}}}
     //   		$where['title'] = array('$regex'=>'咖喱');
     $where = json_encode($where);
     //   		$url = HOST."/classes/Shop?skip=$skip&limit=$limit&where=$where&keys=parent,location&include=parent,parent.coupons";
     //
     ////   		echobr($url);
     //
     //   		$json = $this->avoslibrary->get($url);
     //
     //   		$results = json_decode($json,true);
     //
     ////   		var_dump($results);
     //
     //		if (empty($results['error']))
     //			$results = $results['results'];
     //		else
     //			return $this->output_results(-1,'搜索快券错误');
     //
     //
     //		///遍历所有的shopbranch,把主商户的coupons加入coupons数组中
     //		foreach ($results as $shopBranch) {
     //
     ////			var_dump($shopBranch);
     //
     //			if (!empty($shopBranch['parent']['coupons'])){
     //
     //				/// 给coupon加上位置信息
     //				foreach ($shopBranch['parent']['coupons'] as $coupon) {
     //					$coupon['location'] = $shopBranch['location'];
     //					$coupons[]=$coupon;
     //
     //				}
     //			}
     //
     //
     //		}
     $coupons = $this->coupon_m->search($where, $skip, $limit);
     return $this->output_results($coupons, '搜索商户失败');
 }