コード例 #1
0
ファイル: CardAction.class.php プロジェクト: kevicki/pig
    public function consume(){
        $from       = $_GET['from']?trim($_GET['from']):'default';
        $cardid     = $this->_get('cardid','intval');
        $coupon_id  = $this->_get('coupon_id','intval');
        if($from == 'weixin'){//微信卡券
            $encrypt_code   = $this->_get('encrypt_code','trim');
            $openid         = $this->_get('openid','trim');

            $coupons    = new  WechatCoupons($this->wxuser);
            $unCode     = $coupons->getUnCode($encrypt_code);
            if($unCode['errcode'] == 0){
                $cancel_code    = $unCode['code'];
            }else{
                $this->error('无效的code');
            }
            if($this->wecha_id != $openid){
                $this->error('无效的卡券');
            }
            $where  = array('token'=>$this->token,'cancel_code'=>$cancel_code,'wecha_id'=>$openid);
            
            $info   = M('Member_card_coupon_record')->where($where)->find();
            
            if($info['coupon_attr']){
                $info   = array_merge($info,unserialize($info['coupon_attr']));
            }
        
        }else if($from == 'local_weixin'){
            $itemid     = $this->_get('itemid','intval');
            $where = array('token'=>$this->token,'id'=>$itemid,'wecha_id'=>$this->wecha_id);
            
            $info   = M('Member_card_coupon_record')->where($where)->find();
            
            if($info['coupon_attr']){
                $info   = array_merge($info,unserialize($info['coupon_attr']));
            }
        }else if($from == 'local'){
            $itemid     = $this->_get('itemid','intval');
            $where = array('token'=>$this->token,'id'=>$itemid,'wecha_id'=>$this->wecha_id);
            $info   = M('Member_card_coupon_record')->where($where)->find();
            
            if($info['coupon_attr']){
                $info   = array_merge($info,unserialize($info['coupon_attr']));
            }
            
        }else{
            $from   = 'default';
        }

        if($info['company_id'] != 0){
            $company    = M('Company')->where(array('token'=>$this->token,'id'=>$info['company_id']))->select();
        }else{
            $company    = M('Company')->where(array('token'=>$this->token))->order('isbranch asc,id desc')->select();
        }

        $config = M('Alipay_config')->where(array('token'=>$this->token))->find();
        $cardid = $this->_get('cardid','intval');
    
        
        $thisCard=M('Member_card_set')->where(array('token'=>$this->token,'id'=>$cardid))->find();
            
        $card       = M('Member_card_create')->field('number')->where(array('token'=>$this->token,'wecha_id'=>$this->wecha_id))->find();


        $this->assign('card',$card);
        $this->assign('from',$from);
        $this->assign('coupon_info',$info);
        $this->assign('company',$company);
        $this->assign('thisCard',$thisCard);
        $this->display();       


    }
コード例 #2
0
ファイル: CardAction.class.php プロジェクト: liuguogen/weixin
 public function consume()
 {
     $from = $_GET["from"] ? trim($_GET["from"]) : "default";
     $cardid = $this->_get("cardid", "intval");
     $coupon_id = $this->_get("coupon_id", "intval");
     if ($from == "weixin") {
         $encrypt_code = $this->_get("encrypt_code", "trim");
         $openid = $this->_get("openid", "trim");
         $coupons = new WechatCoupons($this->wxuser);
         $unCode = $coupons->getUnCode($encrypt_code);
         if ($unCode["errcode"] == 0) {
             $cancel_code = $unCode["code"];
         } else {
             $this->error("无效的code");
         }
         if ($this->wecha_id != $openid) {
             $this->error("无效的卡券");
         }
         $where = array("token" => $this->token, "cancel_code" => $cancel_code, "wecha_id" => $openid);
         $info = M("Member_card_coupon_record")->where($where)->find();
         if ($info["coupon_attr"]) {
             $info = array_merge($info, unserialize($info["coupon_attr"]));
         }
     } else {
         if ($from == "local_weixin") {
             $itemid = $this->_get("itemid", "intval");
             $where = array("token" => $this->token, "id" => $itemid, "wecha_id" => $this->wecha_id);
             $info = M("Member_card_coupon_record")->where($where)->find();
             if ($info["coupon_attr"]) {
                 $info = array_merge($info, unserialize($info["coupon_attr"]));
             }
         } else {
             if ($from == "local") {
                 $itemid = $this->_get("itemid", "intval");
                 $where = array("token" => $this->token, "id" => $itemid, "wecha_id" => $this->wecha_id);
                 $info = M("Member_card_coupon_record")->where($where)->find();
                 if ($info["coupon_attr"]) {
                     $info = array_merge($info, unserialize($info["coupon_attr"]));
                 }
             } else {
                 $from = "default";
             }
         }
     }
     if ($info["company_id"] != 0) {
         $company = M("Company")->where(array("token" => $this->token, "id" => $info["company_id"]))->select();
     } else {
         $company = M("Company")->where(array("token" => $this->token))->order("isbranch asc,id desc")->select();
     }
     $config = M("Alipay_config")->where(array("token" => $this->token))->find();
     $cardid = $this->_get("cardid", "intval");
     $thisCard = M("Member_card_set")->where(array("token" => $this->token, "id" => $cardid))->find();
     $card = M("Member_card_create")->field("number")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
     $this->assign("card", $card);
     $this->assign("from", $from);
     $this->assign("coupon_info", $info);
     $this->assign("company", $company);
     $this->assign("thisCard", $thisCard);
     $this->display();
 }