<?php
/** wap
 * 礼品卡
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaol liushanshan
 */
namespace App\Controller;
use Think\Controller;
class GiftCardController extends BaseController {
    public function _initialize(){
        parent::_initialize ();
    }
    //搜索礼品卡
    public function gift_card_info(){
        $return=array('status'=>1,'msg'=>'');
        $postdata=I('param.');
		
		$auth_code = 'main-giftcards_buy';
        $ret=D("Pad/ShopsRoleAuth")->check_auth_code($auth_code,$postdata);
        if($ret['status']!=1) {$this->ajaxReturn($ret);}
		
		if(empty($postdata['sn'])){
			$return['status']=3;$return['msg']='参数错误1！';
		}else{
			$result=D('Pad/GiftCard')->search_gift_sn($postdata['sn']);
			if($result['status']==0){
				$return['status']=3;
				if(empty($result['msg']))$result['msg']='没有查到相应的礼品卡';
				else $return['msg']=$result['msg'];
				$this->ajaxReturn($return);
			}else{
				$return['data']=$result['data'];
			}
		}
        $this->ajaxReturn($return);
    }
    //卡销售记录
    public function get_sale_list(){
    	$return=array('status'=>1,'msg'=>'');
        $postdata=I('param.');
		
		$auth_code = 'main-giftcards_buy';
        $ret=D("Pad/ShopsRoleAuth")->check_auth_code($auth_code,$postdata);
        if($ret['status']!=1) {$this->ajaxReturn($ret);}
        $result=D('Pad/GiftCard')->get_sale_list($postdata);
        if($result['status']==0){
            $return['msg']=$result['msg'];
            $this->ajaxReturn($return);
        }
        if($result['status']==2)$this->ajaxReturn($result);
        if($result['status']==1){
        	foreach ($result['list'] as $key => $value) {
        		$result['list'][$key]['add_time']=time_format($value['addtime']);
        	}
        	$return['data']['list']=$result['list'];
        }
        $this->ajaxReturn($return);
    }
    //卡销售详情
    public function get_order_info(){
    	$return=array('status'=>1,'msg'=>'');
        $postdata=I('param.');
        $result=D('Pad/GiftCard')->get_sale_cont($postdata);
        if($result['status']==1){
            $shop_id=I('shop_id');if($shop_id)$is_hide_phone=idtoname($shop_id,'Shops','is_hide_phone');
            $i=0;
            if($result['list']){
                foreach ($result['list'] as $key => $value) {
                    if($value['daogou']){$result['list'][$key]['daogou_name']=idtoname(intval($value['daogou']),'ShopsAccount','name');}else{$result['list'][$key]['daogou_name']='无';}
                    if($value['buy_uid']){
                        $username=show_user_name(intval($value['buy_uid']));                        
                        if($shop_id && $username && $is_hide_phone==1){$username=str_cutmobile($username);}                        
                        $result['list'][$key]['buy_name']=$username;
                    }else{$result['list'][$key]['buy_name']='无';}
                    $i++;
                }
            }
            $result['infos']['all_num']=$i;
            $result['infos']['paytime']=time_format($result['infos']['pay_time']);
        	$return['data']['infos']=$result['infos'];
        	$return['data']['sale_list']=$result['list'];
        }else{
        	$return['status']==2;
        	$return['msg']=$result['msg'];
        }
        $this->ajaxReturn($return);
    }
	
}
