<?php
/**
 * @author xiaogg QQ:756663992
 * @copyright 2017
 */
namespace Admin\Controller;
class DrawController extends BaseController {
	public function index(){
    	$map=array();	
    	$map['is_type'] = 1;
		$info=$this->lists('Bonu',$map);
    	$this->assign('info', $info);
    	$this->display();
	}
	public function add(){
    	$this->display('edit');
	}
	//发放代金券
	public function coupon_send(){
        $where = array();
        $where['status'] = 1;
        $where['is_type'] = 1;
        $this->suppliers = M('Suppliers')->where($where)->field('id,name')->select();
        $this->assign('suppliers',$this->suppliers);
		$this->getcateTree();
		$this->display();
	}
	//编辑代金券
	public function coupon_edit(){
        $where = array();
        $where['status'] = 1;
        $where['is_type'] = 1;
        $this->suppliers = M('Suppliers')->where($where)->field('id,name')->select();
        $this->assign('suppliers',$this->suppliers);
		$id  = I('get.id');$info='';
		$info=M('Bonu')->field(true)->find($id);
		$goods_ids=array_filter(explode(',',rtrim($info['goods_ids'],',')));
		// var_dump($goods_ids)
		foreach($goods_ids as $k=>$v){
			$goods_list.="<option value='".$v."'>".idtoname($v,'Goods','goods_name','id',false)."</option>";
		}
		$this->assign('select_link_goods',$goods_list);
		$this->getcateTree();
		$this->assign('edit',$info);
		$this -> assign('id',  $id);
		$this->display();
	}
	//代金券发放处理
	public function send_bonu(){
		$url = U('Admin/Bonu/index');
		$postdata=I('post.');
		if(empty($postdata['type_name']) || empty($postdata['type_money']) || empty($postdata['min_goods_amount'])){
			$this->error('必填项不要为空',U('Admin/Bonu/bonu_send'));
		}
		if($postdata['use_start_date'] && $postdata['use_end_date']){
			$use_start_date = strtotime($postdata['use_start_date']);
			$use_end_date = strtotime($postdata['use_end_date']);
			$arr['use_start_date'] = $use_start_date;
			$arr['use_end_date'] = $use_end_date;
		}
		$arr['type_name'] = $postdata['type_name'];
		$arr['type_money'] = $postdata['type_money'];
		$arr['min_goods_amount'] = $postdata['min_goods_amount'];
		if($postdata['suppliers_id']==0){
			$arr['catid'] = $postdata['type']==3?$postdata['catid']:0;
		}else{
			$arr['cat_id'] = $postdata['type']==3?$postdata['cat_id']:0;
		}
		
		$arr['brand_id'] = $postdata['type']==2?$postdata['brand_id']:0;	
		$arr['suppliers_id']=$postdata['suppliers_id'];
		$arr['addtime'] = NOW_TIME;
		$arr['status']=0;
		$sql_f = M('Bonu')->add($arr);
		if($sql_f){
			$this->success('添加成功！',$url);
	 	}else{
			$this->error('添加失败！',$url);
	 	}
	}
	//删除代金券
	public function delete_bonu(){
		$id  = I('id');	
		if(isset($id) && is_array($id)){
			$ids = implode(',',$id);
			$map_b = array();
			$map_b['id'] = array('in',$ids);
			$deletes=M('Bonu')->where($map_b)->delete();
		}else{
			$id = intval($id);
			$deletes=M('Bonu')->where('id='.$id)->delete();
		}
		$url=U('Admin/Bonu/index');
		if($deletes){
			$this->success('删除成功！',$url);
	 	} else {
			$this->error('删除失败！',$url);
	 	}		
	}
	//用户领取的代金券列表
	public function bonus_list(){
		$map['status']=array('neq',0);
		if(I('user')){
			$user=I('user');
			if(is_numeric($user)){
			$where_u['id|username']=   array(intval($user),array('like','%'.$user.'%'),'_multi'=>true);
			}else if($user){
			$where_u['username']    =   array('like', '%'.(string)$user.'%');
        	}
			$user_list=M('Member')->where($where_u)->field('id')->select();
			if($user_list){
				foreach($user_list as $k=>$v){
					$u_list[]=$v['id'];
				}
				$where['user_id']=array(array('in',$u_list));
			}
		}
		if(I('use')==1){
			$where['used_time']=array(array('neq',''));
		}elseif(I('use')==2){
			$where['used_time']=array(array('eq',''));
		}		
		$where['is_type']=1;
		$info=$this->lists('MemberBonus',$where);
		foreach($info as $k=>$v){
			if($v['order_id']){
				$order=M('OrderInfo')->where('id='.$v['order_id'])->field('order_sn')->find();
				$user_info[$k]['order_sn']=$order['order_sn'];
			}else{
				$user_info[$k]['order_sn']=0;
			}
		}	
		$this->assign('info',$info);
		$this->display();
	}
	/* 得到节点树 */
	private function getcateTree($pid = '',$assign='',$brandid='') {
		$GoodsCategory = getcache('GoodsCategory');	
	   $Tree = new \Common\Vendor\Tree();
       $select_categorys='';
       $treemini=$Tree->treemini($GoodsCategory);
       $select_categorys.= $Tree->treeminioption($treemini,$pid);
	   if($assign)return $select_categorys;
       else $this->assign('select_categorys',$select_categorys);
	   //品牌
	   $brand=M('Brand')->where('status=1')->field('id,brand_name')->select();
	   foreach($brand as $k=>$v){
		   if($brandid == $v['id']){
			   $brand_op.="<option selected='selected' value='".$v['id']."'>".$v['brand_name']."</option>";
			}else{
				$brand_op.="<option value='".$v['id']."'>".$v['brand_name']."</option>";
			}
	 	}
		$this->assign('select_brand',$brand_op); 
	}
    //创建新卡券
	public function insert(){
		$postdata=I('post.');
		$num=C('WIN_BONUS_NUM');
		$use_start_date = strtotime($postdata['use_start_date']);
		$use_end_date = strtotime($postdata['use_end_date']);
		if($postdata['supplier_id']){
			$arr['suppliers_id'] = $postdata['supplier_id'];
		}else{
			$this->error('请选择供货商');
		}
		$arr['type_name'] = $postdata['type_name'];
		$arr['type_money'] = $postdata['type_money'];
		$arr['min_goods_amount'] = $postdata['min_goods_amount'];
		$arr['send_type'] = 4;
		$arr['use_start_date'] = $use_start_date;
		$arr['use_end_date'] = $use_end_date;
		$arr['addtime'] = NOW_TIME;
		$arr['goods_ids']=$postdata['goods_ids'];
		$arr['is_type']=1;	
		//print_r($arr);exit;
		$goods = M('bonu')->add($arr);
		if($goods!==false){
			$url = U(CONTROLLER_NAME.'/index');
			$this->success('添加成功！',$url);
		} else {
			$this->error('添加失败！',$url);
		}
	}
	//查看
	 public function view(){
	    $id = I('id');
		$model = D('Bonu');
		$info = $model->field(true)->find($id);
		$this->assign('reg_name',$reg);
		$this->assign($info);
		$this->assign('rank_info',$rank_info);    
		$this->getcateTree($info['cat_id']);
		$this->display();
  }
	//删除微信代金券
	public function delete(){
		$id  = I('get.id');
		$url = U('Admin/Bonu/wx_bonu');
		$deletes = M('Bonu')->where('id='.$id)->order('id desc')->delete();
		if($deletes){
			$this->success('删除成功！',$url);
	 	} else {
			$this->error('删除失败！',$url);
	 	}		
	}
	//删除线下代金券
	public function delete_down(){
		$para  = I('get.');
		$id=$para['bonus_id'];
		$deletes=M('MemberBonus')->where('bonus_id='.$id)->delete();
		$url=U('Admin/Bonu/down_index');
		if($deletes){
			$this->success('删除成功！',$url);
	 	} else {
			$this->error('删除失败！',$url);
	 	}		
	}
	//删除用户代金券
	public function delete_user(){
		$para  = I('bonus_id');
		if(isset($para) && is_array($para)){
			$ids = implode(',',$para);
			$map_b = array();
			$map_b['bonus_id'] = array('in',$ids);
			$deletes=M('MemberBonus')->where($map_b)->delete();
		}else{
			$id = intval($para);
			$deletes=M('MemberBonus')->where('bonus_id='.$id)->delete();
		}
		$url=U('Admin/Bonu/bonus_list');
		if($deletes){
			$this->success('删除成功！',$url);
	 	} else {
			$this->error('删除失败！',$url);
	 	}		
	}
	//编辑微信代金券
	public function edit(){
		// $id=I('get.id');
		// $edit = M('Bonu');
		// $edits = $edit->where('id='.$id)->field(true)->find();
		// //print_r($edits);exit;
		// $num=C('WIN_BONUS_NUM');
		// $this->assign('num', $num);
		// $this->assign('id', $id);	
  //       $this->assign('edit', $edits);
		// $this->getcateTree($edits['cat_id']);
        $this->display();		
	}
	//添加微信代金券
	public function _before_add(){
		$this->getcateTree();	
	}
	//用户发放处理
	 public function send_user(){
		 $url = U('Admin/Bonu/index_user');
		$postdata=I('post.');
		$use_start_date = strtotime($postdata['use_start_date']);
		$use_end_date = strtotime($postdata['use_end_date']);
		$arr['type_name'] = $postdata['type_name'];
		$arr['type_money'] = $postdata['type_money'];
		$arr['min_goods_amount'] = $postdata['min_goods_amount'];
		$arr['cat_id'] = $postdata['cat_id'];
		$arr['use_start_date'] = $use_start_date;
		$arr['use_end_date'] = $use_end_date;
		$arr['cat_id'] = $postdata['cat_id'];
		$arr['brand_id'] = $postdata['brand_id'];	
		$goods = M('Bonu')->where('id=1')->save($arr);
		 if($postdata['ra_bonus']){
		 //$send_type = I('get.send_type');
		 	$rank_user = M('member')->where('rank_id='.$postdata['ra_bonus'])->field('id')->select();
			foreach($rank_user as $value){
				$arra['bonus_type_id'] = 1;
				$arra['user_id'] = $value['id'];
				$arra['send_time'] = NOW_TIME;
				$arra['money'] = $postdata['type_money'];
				$arra['min_goods_money'] = $postdata['min_goods_amount'];
				$arra['start_time'] = $use_start_date;
				$arra['end_time'] = $use_end_date;
				$arra['cat_id'] =$postdata['type']==3?$postdata['cat_id']:0;
				$arra['brand_id'] = $postdata['type']==2?$postdata['brand_id']:0;
				$arra['bonu_name']=$postdata['type_name'];
				$sql_f = M('MemberBonus')->add($arra);		
			}
		 } else {
			 $user_array = $postdata['rank_select_right'];
			 if(!$user_array)$this->error('请选择会员！',$url);
				 foreach($user_array as $key=>$val){
						$arra['bonus_type_id'] = 1;
						$arra['user_id'] = $val;
						$arra['send_time'] = NOW_TIME;
						$arra['money'] = $postdata['type_money'];
						$arra['min_goods_money'] = $postdata['min_goods_amount'];
						$arra['start_time'] = $use_start_date;
						$arra['end_time'] = $use_end_date;	
						$arra['cat_id'] = $postdata['type']==3?$postdata['cat_id']:0;
						$arra['brand_id'] = $postdata['type']==2?$postdata['brand_id']:0;
						$arra['bonu_name']=$postdata['type_name'];
						$sql_f = M('member_bonus')->add($arra);	 
				}
		}
		if($sql_f){
			$this->success('发放成功！',$url);
	 	} else {
			$this->error('发放失败！',$url);
	 	}
	}
	//线下发放处理
	public function send_oline(){
		$postdata = I('post.');
		$use_start_date = strtotime($postdata['use_start_date']);
		$use_end_date = strtotime($postdata['use_end_date']);
		$arr['type_name'] = $postdata['type_name'];
		$arr['type_money'] = $postdata['type_money'];
		$arr['min_goods_amount'] = $postdata['min_goods_amount'];
		$arr['use_start_date'] = $use_start_date;
		$arr['use_end_date'] = $use_end_date;
		$arr['cat_id'] = $postdata['cat_id'];
		$arr['brand_id'] = $postdata['brand_id'];		
		//print_r($arr);exit;
		$goods = M('Bonu')->where('id=4')->save($arr);
		$bonus_sum = !empty($_POST['bonus_sum'])     ? $_POST['bonus_sum']     : 1;
		if(!$bonus_sum)$this->error('请添加数量！',$url);
		//随机生成代金券序列号
		$info = M('member_bonus');
		$infos = $info->field(max('bonus_sn'))->find();
		$num = $infos[0];
		$num = $num ? floor($num / 10000) : 100000;	
		//print_r($time);echo NOW_TIME;exit;
		for ($i = 0, $j = 0; $i < $bonus_sum; $i++){
			$bonus_sn = ($num + $i) . str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT);
			$arr['bonus_type_id'] = 4;
			$arr['bonus_sn']=$bonus_sn;
			$arr['send_time']=NOW_TIME;
			$arr['money'] = $postdata['type_money'];
			$arr['min_goods_money'] = $postdata['min_goods_amount'];
			$arr['cat_id'] = $postdata['cat_id'];
			$arr['brand_id'] = $postdata['brand_id'];
			$arr['start_time'] = $use_start_date;
			$arr['end_time'] = $use_end_date;
			$arr['bonu_name'] = $postdata['type_name'];	
			//print_r($arr);exit;
			$sql = $info->add($arr);
		}
		if($sql!==false){
			$url = U('Admin/Bonu/down_index');
			$this->success('发放成功！',$url);
		} else {
			$this->error('发放失败！',$url);
		} 
	}
	//用户代金券
	public function index_user(){
		$big_menu = array('发放用户代金券' => U('user_send'));
        $this->assign('big_menu', $big_menu);
		if(I('order')){
			$where['order_id']=I('order');
		}
		if(I('user')){
			$user=I('user');
			if(is_numeric($user)){
			$where_u['id|username']=   array(intval($user),array('like','%'.$user.'%'),'_multi'=>true);
			}else if($user){
			$where_u['username']    =   array('like', '%'.(string)$user.'%');
        	}
			$user_list=M('Member')->where($where_u)->field('id')->select();
			if($user_list){
				foreach($user_list as $k=>$v){
					$u_list[]=$v['id'];
				}
				$where['user_id']=array(array('in',$u_list));
			}
		}
		if(I('use')==1){
			$where['used_time']=array(array('neq',''));
		}elseif(I('use')==2){
			$where['used_time']=array(array('eq',''));
		}		
		$where['bonus_type_id']=1;
		$info=$this->lists('MemberBonus',$where);
		foreach($info as $k=>$v){
			if($v['order_id']){
				$order=M('OrderInfo')->where('id='.$v['order_id'])->field('order_sn')->find();
				$user_info[$k]['order_sn']=$order['order_sn'];
			}else{
				$user_info[$k]['order_sn']=0;
			}
		}	
		$this->assign('info',$info);
		$this->assign('type_id',$id);
		$this->display();
	}
	//代金券到期提醒页面
	public function push_bonu(){
		$map['user_id']=array('GT','0');
		$map['used_time']=0;
		//$map['is_tixing']=0;
		if(I('name')){
			$bo=trim(I('name'));
			if(is_numeric($bo)){
				//$where_u['id|type_name']=array(intval($bo),array('like','%'.$bo.'%'),'_multi'=>true);
				$where_b['id']=$bo;
			}else{
				$where_b['type_name']=array('like', '%'.(string)$bo.'%');
        	}
			$bo_list=M('Bonu')->where($where_b)->field('id')->select();
			if($bo_list){
				foreach($bo_list as $k=>$v){
					$b_list[]=$v['id'];
				}
				$map['bonus_type_id']=array('in',$b_list);
			}
		}
		if(I('member')){
			$user=trim(I('member'));
			if(is_numeric($user)){
				$where_u['id|username']=array((int)$user,array('like','%'.$user.'%'),'_multi'=>true);
				//$where_u['id']=$user;
			}else{
				$where_u['username']=array('like', '%'.(string)$user.'%');
        	}
			$user_list=M('Member')->where($where_u)->field('id')->select();
			if($user_list){
				foreach($user_list as $k=>$v){
					$u_list[]=$v['id'];
				}
				$map['user_id']=array('in',$u_list);
			}
		}
		if(I('is_tixing')==1){$map['is_tixing']=1;}elseif(I('is_tixing')==2){$map['is_tixing']=0;}
		$date =strtotime("+1week");
		$whereand[]['end_time']=array('ELT',$date);
        $whereand[]['end_time']=array('EGT',NOW_TIME);
		$whereand['_logic'] = 'and';
		$map['_complex'] = $whereand;
		// dump($map);
		$list=$this->lists('MemberBonus',$map);
		$this->assign('list',$list);
		$this->display();
	}
	//代金券到期提醒
	public function tixing(){
		$only=I('get.id');
		if($only){
			$push_info=M('MemberBonus')->alias('mb')->where('mb.bonus_id='.$only)->field('mb.*,m.mobile,m.username')->JOIN('LEFT JOIN __MEMBER__ m ON m.id=mb.user_id')->find();
			if($push_info['mobile']){
				$data=array();
				$data['to']=$push_info['mobile'];
				$sms=sendbytheme($data,'BONU_PUSH');
			}else{
				$this->error('该用户没有绑定手机号！',U('Admin/Bonu/push_bonu'));
			}
			if($sms){
				$tixing['is_tixing']=1;
				$is_tixing=M('MemberBonus')->where('bonus_id='.$only)->save($tixing);
				$this->success('提醒成功！',U('Admin/Bonu/push_bonu'));
			}else{
				$this->error('提醒失败！',U('Admin/Bonu/push_bonu'));
			}
		}
		$info=I('post.');
		if($info){
			$i=0;
			foreach($info['id'] as $k=>$v){
				$push_info=M('MemberBonus')->alias('mb')->where('mb.bonus_id='.$v)->field('mb.*,m.mobile,m.username')->JOIN('LEFT JOIN __MEMBER__ m ON m.id=mb.user_id')->find();
				if($push_info['mobile']){
					$data=array();
					$data['to']=$push_info['mobile'];
					$sms=sendbytheme($data,'BONU_PUSH');
				}else{
					$this->error($push_info['username']."用户没有绑定手机号！",U('Admin/Bonu/push_bonu'));
				}
				if($sms){
					$tixing['is_tixing']=1;
					$is_tixing[$i]=M('MemberBonus')->where('bonus_id='.$v)->save($tixing);
				}
				$i++;
			}
			if($is_tixing){
				$this->success('提醒成功！',U('Admin/Bonu/push_bonu'));
			}else{
				$this->error('提醒失败！',U('Admin/Bonu/push_bonu'));
			}
		}
	}
	//发放用户代金券的页面
	public function user_send(){
		$rank = M('member_rank')->where('status=1')->field('id,name')->select();
		foreach($rank as $value){
			$ranks .="<option value='".$value['id']."'>".$value['name']."</option>";
		}
		$this->assign('rank_list',$ranks);
		$bonu=M('Bonu')->where('id=1')->find();
		$this->assign('edit',$bonu);
		$this->getcateTree($bonu['cat_id']);
		$this->display();
	}
	//线下代金券
	public function down_index(){
		$big_menu = array('生成线下代金券' => U('down_send'));
        $this->assign('big_menu', $big_menu);
		if(I('order')){
			$where['order_id']=I('order');
		}
		if(I('user')){
			$user=I('user');
			if(is_numeric($user)){
			$where_u['id|username']=   array(intval($user),array('like','%'.$user.'%'),'_multi'=>true);
			}else if($user){
			$where_u['username']    =   array('like', '%'.(string)$user.'%');
        	}
			$user_list=M('Member')->where($where_u)->field('id')->select();
			if($user_list){
				foreach($user_list as $k=>$v){
					$u_list[]=$v['id'];
				}
				$where['user_id']=array(array('in',$u_list));
			}
		}
		if(I('use')==1){
			$where['used_time']=array(array('neq',''));
		}elseif(I('use')==2){
			$where['used_time']=array(array('eq',''));
		}		
		$where['bonus_type_id']=4;
		$info=$this->lists('MemberBonus',$where);
		foreach($info as $k=>$v){
			if($v['order_id']){
				$order=M('OrderInfo')->where('id='.$v['order_id'])->field('order_sn')->find();
				$user_info[$k]['order_sn']=$order['order_sn'];
			}else{
				$user_info[$k]['order_sn']=0;
			}
		}
			
		$this->assign('info',$info);
		$this->assign('type_id',$id);
		$this->display();
	}
	//生成线下代金券的页面
	public function down_send(){
		$bonu=M('Bonu')->where('id=4')->find();
		$this->getcateTree($bonu['cat_id']);
		$this->assign('edit',$bonu);
		$this->display();
	}
	//微信代金券
	public function wx_bonu(){
		$big_menu = array('添加微信代金券' => U('add'),'活动设置'=>geturl('set_act'));
        $this->assign('big_menu', $big_menu);
		$name = M('Bonu');
		$info = $name->where('send_type=4')->field(true)->order('id desc')->select();
		$this->assign('list',$info);	
		$this->display();
	}
	//查看微信代金券
	public function wx_bonu_view(){
		$id=I('get.id');
		$name = M('MemberBonus');
		$info = $name->where("bonus_type_id=".$id)->field(true)->select();
		$this->assign('info',$info);	
		$this->display();
	}
	//修改代金券信息
	public function update(){
		$postdata=I('post.');
		$use_start_date = strtotime($postdata['use_start_date']);
		$use_end_date = strtotime($postdata['use_end_date']);
		$arr['type_name'] = $postdata['type_name'];
		$arr['type_money'] = $postdata['type_money'];
		$arr['min_goods_amount'] = $postdata['min_goods_amount'];
		$arr['send_type'] = 4;
		$arr['use_start_date'] = $use_start_date;
		$arr['use_end_date'] = $use_end_date;	
		$arr['addtime'] = NOW_TIME;
		$arr['goods_ids']=$postdata['goods_ids'];
		$arr['is_type']=1;
		$goods = M('bonu')->where('id='.$postdata['id'])->save($arr);
		if($goods!==false){
			$url = U(CONTROLLER_NAME.'/index');
			$this->success('编辑成功！',$url);
		} else {
			$this->error('编辑失败！',$url);
		}
	}
	//会员搜索
	public function searchusers(){
		$c = I('get.');
		if(!empty($c['keyword'])){
			$user=$c['keyword'];
			if(is_numeric($user)){
				$map['id|mobile']=   array(intval($user),array('like','%'.$user.'%'),'_multi'=>true);
			}else if($user){
				$map['username']    =   array('like', '%'.(string)$user.'%');
        	}
		}	
		$list =  M('member')->where($map)->field('id,username')->select();
		foreach($list as $value){
			$result.="<option value='".$value['id']."'>".$value['username']."</option>";
		}
		echo $result;exit;
	}
	//加入会员
	public function jia_right(){
		$c = I('get.');
		$user_arr = explode(',',$c['left']);		
		array_pop($user_arr);
		//echo (print_r($user_arr));exit;
		//print_r($user_arr);
		$counts = count($user_arr);
		//echo ($counts);exit;
		for($i=0;$i<$counts;$i++){			
			$user = M('member')->where('id='.$user_arr[$i])->field('id,username')->find();			
			$result.="<option value='".$user['id']."' selected='selected'>".$user['username']."</option>";
		}
		echo $result;exit;
	}	
	//注册代金券
	public function register_bonu(){
		if(IS_POST){
			$postdata = I('post.');
			$arr['type_name'] = $postdata['type_name'];
			$arr['type_money'] = $postdata['type_money'];
			$arr['min_goods_amount'] = $postdata['min_goods_amount'];
			$arr['use_start_date'] = 0;
			$arr['use_end_date'] = $postdata['use_end_date'];
			$rez=M('Bonu')->where('send_type=5')->find();
			if ($rez) {
				$goods = M('Bonu')->where('send_type=5')->save($arr);
			}else{
				$arr['send_type']=5;
				$goods = M('Bonu')->add($arr);
			}
			
			if ($goods!==false) {
				$this->success('操作成功');
			}else{
				$this->error('操作失败');
			}
		}else{
			$bonu=M('Bonu')->where('send_type=5')->find();
			$this->assign('edit',$bonu);
			$this->display();
		}
		
	}
	//活动设置
	public function set_act(){
		if (IS_POST) {
			$postdata=I('post.');
			$map['name']='WX_BOUNS_BG';
			$map['status']=1;
			$data['value']='pc_bg:'.$postdata['pc_bg'].',m_bg:'.$postdata['m_bg'].',name:'.$postdata['name'];
			$rez=M('Config')->where($map)->save($data);
			if ($rez!==false) {
				$this->success('设置成功');
			}else{
				$this->error('设置失败');
			}
		}else{
			$act_set=C('WX_BOUNS_BG');
			$this->assign('list',strtoarray($act_set));
			$this->display();
		}
		
	}
	//关联商品搜索 
	public function searchgoods(){
		$c = I('get.');
		// if(!empty($c['catid'])){
  //           $cat_sons = get_children($c['catid'],1);$catstr=implode(',',$cat_sons);
  //           $extension_goods_id=get_extension_goods($c['catid'],1);$extensionstr=implode(',',$extension_goods_id);
  //           if(!empty($cat_sons) && !empty($catstr))$where['catid']  = array('in',$cat_sons);
  //           if(!empty($extension_goods_id) && !empty($extensionstr))$where['id']  = array('in',$extension_goods_id);
  //           if(!empty($where)){$where['_logic'] = 'or';$map['_complex'] = $where;}
  //       }
		// if(!empty($c['brand_id']))$map['brand_id'] = $c['brand_id'];
		$return['status'] = 0;
		if(empty($c['supplier_id'])){
			$return['data'] = "请按供货商搜索";
			$this->ajaxReturn($return);
		}else{
			$map['supplier_id'] = $c['supplier_id'];
		}
		if(!empty($c['keyword']))$map['goods_name'] = array('like','%'.$c['keyword'].'%');
		$map['shangjia'] = 0;
		$map['status'] = 1;
		$map['shang_status'] = 1;
		$goods = M('Goods');
		$list=$goods->where($map)->field('id,goods_name')->select();
		$result='';
		foreach($list as $v){
          $result.="<option value='".$v['id']."'>".$v['goods_name']."</option>";
		}
		$return['status'] = 1;
		$return['data'] = $result;
		$this->ajaxReturn($return);
	}
}
?>