Beispiel #1
0
 /**
  * 
  * 删除Coupon, 也从shop的coupons 移除
  * @param integer $id
  *
  */
 function delete($id)
 {
     $result = $this->model->delete($id);
     //		var_dump($result);
     if ($result < 0) {
         var_dump($result);
     } else {
         echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
         echo "<script>alert('删除成功')</script>";
         $this->session->set_flashdata('msg', '删除成功');
         redirect('admin/coupons/index', 'refresh');
     }
 }
Beispiel #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, '搜索商户失败');
 }
Beispiel #3
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, '搜索商户失败');
 }