<?php
/**商品
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author lss <lss@sina.cn>
 */
namespace Mobile\Controller;
class IntegralController extends BaseController {
    public function _initialize(){
        parent::_initialize();
        //微信分享相关配置
        $wx = new \Common\Vendor\Jssdk();
        $signPackage = $wx->getSignPackage();
        $this->assign('signPackage',$signPackage);
    }
    public function index() {
        $this->assign('nowtime',NOW_TIME);
        $this->judge();
        $data=D('Mobile/Takeout')->get_cate_list();
        $this->assign($data);
        $shop_id = get_wxsmall_shop_id();
        $this->assign('shop_id',$shop_id);
        $catid = I('catid');
        if($catid){
            $this->assign('catid',$catid);
        }else{
            $this->assign('catid',0);
        }
        $title = "积分商品";
        $description = '积分商品' . '_' . C('WEB_SITE_TITLE');
        $share_url=U('Mobile/Integral/index',array('eid'=>MID));
        $this->assign('title',$title);
        $this->assign('description',$description);
        $this->assign('share_url',$share_url);
        $this->assign('page_title','积分商品列表');
        $this->display();
    }
    public function get_goods_list() {
        $postdata = I('param.');
        $return = array('status'=>0,'data'=>'');
        $shop_id = get_wxsmall_shop_id();
        $this->assign('shop_id',$shop_id);
        $data=D('Common/GoodsIntegral')->get_integral_list($postdata);
        if($postdata['keyword']){
            $this->assign('keyword',$postdata['keyword']);
        }
        if($data['g_status']){
            $goods_list = $data['goods_list']['list'];
            if($goods_list){
                $this->assign('goods_data',$goods_list);
                $this->assign('page',$data['page']);
                $this->assign('sum_page',$data['goods_list']['totalPages']);
                $return['status'] = 1;
                $return['page'] = $data['page'];
            }
        }else{
            $goods_list = array();
            $this->assign('page',1);
            $this->assign('goods_data',$goods_list);
        }

        $fetch = 'goods_list';

        $list_html=$this->fetch($fetch);
        $return['data'] = $list_html;
        $this->ajaxReturn($return);
    }
    /**
     * 商品详情页
     */
    public function goods_cont() {
        $this->judge();
        $goods_id=I('id');
        goods_footprint(MID,$goods_id);
        $shop_id=get_wxsmall_shop_id();
        if($shop_id){
            $map=array();
            $map['id']=$shop_id;
            $shop_name=M("Shops")->where($map)->getField('name');
            $this->assign('shop_name',$shop_name);
        }
        $data=D("GoodsIntegral")->getmobile_goodscontent($goods_id,$shop_id);
        $title=$data['goods_info']['goods_name'];
        $description = '积分商品分享';
        $map=array();
        $map['goods_id']=$data['goods_info']['goods_id'];
        $content=M("GoodsContent")->where($map)->field('content,seodescription')->find();
        if($content['seodescription']){
            $description=strip_tags(h($content['seodescription']));
        }elseif($content['content']){
            $description=strip_tags(h($content['content']));
        }
        $goods_img = $data['goods_imgs'][0]['goods_img'];
        $share_url=U('Mobile/Integral/goods_cont',array('id'=>$goods_id,'eid'=>MID));

        $this->assign('title',$title);
        $this->assign('description',$description);
        $this->assign('goods_img',$goods_img);
        $this->assign('share_url',$share_url);
        $url=U('Article/article_cont',array('id'=>$data['goods_info']['goods_id'],'type'=>'goods'));
        $this->assign($data);
        $this->assign('url',$url);
        $this->assign('shop_id',$shop_id);
        $this->display();
    }

    /**
     * 积分商品加入购物车
     */
    public function add_integra(){
        $goods_id=I('goods_id');
        $attr=I('goods_attr');
        $number=I('number');
        $name=I('name');
        $integra=I('integra');
        $source=I("source");
        $result=D("Common/Cart")->add_integra_cart($goods_id,$number,$attr,$name,$integra,$source);
        $this->ajaxReturn($result);
    }
}