Ejemplo n.º 1
0
 function cart2()
 {
     $id = IFilter::act(IReq::get('id'), 'int');
     $type = IFilter::act(IReq::get('type'));
     //goods,product
     $promo = IFilter::act(IReq::get('promo'));
     $active_id = IFilter::act(IReq::get('active_id'), 'int');
     $buy_num = IReq::get('num') ? IFilter::act(IReq::get('num'), 'int') : 1;
     $tourist = IReq::get('tourist');
     //游客方式购物
     //必须为登录用户
     if ($tourist === null && $this->user['user_id'] == null) {
         if ($id == 0 || $type == '') {
             $this->redirect('/simple/login?tourist&callback=/simple/cart2');
         } else {
             $url = '/simple/login?tourist&callback=/simple/cart2/id/' . $id . '/type/' . $type . '/num/' . $buy_num;
             $url .= $promo ? '/promo/' . $promo : '';
             $url .= $active_id ? '/active_id/' . $active_id : '';
             $this->redirect($url);
         }
     }
     //游客的user_id默认为0
     $user_id = $this->user['user_id'] == null ? 0 : $this->user['user_id'];
     //计算商品
     $countSumObj = new CountSum($user_id);
     //判断是特定活动还是购物车
     if ($id && $type) {
         $result = $countSumObj->direct_count($id, $type, $buy_num, $promo, $active_id);
         $this->gid = $id;
         $this->type = $type;
         $this->num = $buy_num;
         $this->promo = $promo;
         $this->active_id = $active_id;
     } else {
         //计算购物车中的商品价格
         $result = $countSumObj->cart_count();
     }
     //检查商品合法性或促销活动等有错误
     if (is_string($result)) {
         IError::show(403, $result);
         exit;
     }
     //是否需要多选地址
     $this->need_choose_addr_num = 1;
     if (count($result['goodsList']) == 1 && $result['count'] > 1) {
         $this->need_choose_addr_num = $result['count'];
     }
     //检测是否属于入驻商家商品
     if ($this->gid) {
         $bool = $this->is_seller($this->gid);
         if ($bool) {
             //获取商家版支付方式
             $this->paymentList = Api::run('getSellerPaymentList');
         } else {
             $this->paymentList = Api::run('getPaymentList');
         }
     } else {
         $this->paymentList = Api::run('getPaymentList');
     }
     //获取收货地址
     $addressObj = new IModel('address');
     $addressList = $addressObj->query('user_id = ' . $user_id);
     //更新$addressList数据
     foreach ($addressList as $key => $val) {
         $temp = area::name($val['province'], $val['city'], $val['area']);
         if (isset($temp[$val['province']]) && isset($temp[$val['city']]) && isset($temp[$val['area']])) {
             $addressList[$key]['province_val'] = $temp[$val['province']];
             $addressList[$key]['city_val'] = $temp[$val['city']];
             $addressList[$key]['area_val'] = $temp[$val['area']];
             if ($val['default'] == 1) {
                 $this->defaultAddressId = $val['id'];
             }
         }
     }
     //获取用户的道具红包和用户的习惯方式
     $this->prop = array();
     $memberObj = new IModel('member');
     $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,custom');
     if (isset($memberRow['prop']) && ($propId = trim($memberRow['prop'], ','))) {
         $porpObj = new IModel('prop');
         $this->prop = $porpObj->query('id in (' . $propId . ') and NOW() between start_time and end_time and type = 0 and is_close = 0 and is_userd = 0 and is_send = 1', 'id,name,value,card_name');
     }
     if (isset($memberRow['custom']) && $memberRow['custom']) {
         $this->custom = unserialize($memberRow['custom']);
     } else {
         $this->custom = array('payment' => '', 'delivery' => '', 'takeself' => '');
     }
     //返回值
     $this->final_sum = $result['final_sum'];
     $this->promotion = $result['promotion'];
     $this->proReduce = $result['proReduce'];
     $this->sum = $result['sum'];
     $this->goodsList = $result['goodsList'];
     $this->count = $result['count'];
     $this->reduce = $result['reduce'];
     $this->weight = $result['weight'];
     $this->freeFreight = $result['freeFreight'];
     //收货地址列表
     $this->addressList = $addressList;
     //获取商品税金
     $this->goodsTax = $countSumObj->getGoodsTax($this->sum);
     //渲染页面
     $this->redirect('cart2');
 }
Ejemplo n.º 2
0
 function cart2()
 {
     $id = IFilter::act(IReq::get('id'), 'int');
     $type = IFilter::act(IReq::get('type'));
     $promo = IFilter::act(IReq::get('promo'));
     $active_id = IFilter::act(IReq::get('active_id'), 'int');
     $buy_num = IReq::get('num') ? IFilter::act(IReq::get('num'), 'int') : 1;
     $tourist = IReq::get('tourist');
     //游客方式购物
     //活动购买方式
     if ($promo == 'groupon' && $active_id != '') {
         $hashId = $this->user['user_id'] ? $this->user['user_id'] : ICookie::get("regiment_{$active_id}");
         //此团购还存在已经报名但是未付款的情况
         if (regiment::hasJoined($active_id, $hashId) == true) {
             IError::show(403, '您已经参加过此次团购,请先完成支付');
             exit;
         }
         //团购已经达到限定的人数
         if (regiment::isFull($active_id) == true) {
             IError::show(403, '此团购的参加人数已满');
             exit;
         }
     }
     //必须为登录用户
     if ($tourist === null && $this->user['user_id'] == null) {
         if ($id == 0 || $type == '') {
             $this->redirect('/simple/login?tourist&callback=/simple/cart2');
         } else {
             $url = '/simple/login?tourist&callback=/simple/cart2/id/' . $id . '/type/' . $type . '/num/' . $buy_num;
             $url .= $promo ? '/promo/' . $promo : '';
             $url .= $active_id ? '/active_id/' . $active_id : '';
             $this->redirect($url);
         }
     }
     //游客的user_id默认为0
     $user_id = $this->user['user_id'] == null ? 0 : $this->user['user_id'];
     //获取收货地址
     $addressObj = new IModel('address');
     $addressList = $addressObj->query('user_id = ' . $user_id);
     $areaArray = array();
     foreach ($addressList as $val) {
         $areaArray[$val['province']] = $val['province'];
         $areaArray[$val['city']] = $val['city'];
         $areaArray[$val['area']] = $val['area'];
     }
     if ($areaArray) {
         //拼接area_id对应的名字
         $areaIdStr = join(',', $areaArray);
         $areaObj = new IModel('areas');
         $areaList = $areaObj->query('area_id in (' . $areaIdStr . ')', 'area_name,area_id');
         foreach ($areaList as $val) {
             $areaArray[$val['area_id']] = $val['area_name'];
         }
         //更新$addressList数据
         foreach ($addressList as $key => $val) {
             $addressList[$key]['province_val'] = $areaArray[$val['province']];
             $addressList[$key]['city_val'] = $areaArray[$val['city']];
             $addressList[$key]['area_val'] = $areaArray[$val['area']];
             if ($val['default'] == 1) {
                 $this->defaultAddressId = $val['id'];
             }
         }
     }
     //获取用户的道具红包和用户的习惯方式
     $this->prop = array();
     $memberObj = new IModel('member');
     $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,custom');
     if (isset($memberRow['prop']) && ($propId = trim($memberRow['prop'], ','))) {
         $porpObj = new IModel('prop');
         $this->prop = $porpObj->query('id in (' . $propId . ') and NOW() between start_time and end_time and type = 0 and is_close = 0 and is_userd = 0 and is_send = 1', 'id,name,value,card_name');
     }
     if (isset($memberRow['custom']) && $memberRow['custom'] != '') {
         $this->custom = unserialize($memberRow['custom']);
     } else {
         $this->custom = array('payment' => '', 'delivery' => '');
     }
     //计算商品
     $countSumObj = new CountSum();
     //判断是特定活动还是购物车
     if ($id != 0 && $type != '') {
         $result = $countSumObj->direct_count($id, $type, $buy_num, $promo, $active_id);
         $this->gid = $id;
         $this->type = $type;
         $this->num = $buy_num;
         $this->promo = $promo;
         $this->active_id = $active_id;
     } else {
         //计算购物车中的商品价格
         $result = $countSumObj->cart_count();
     }
     if ($result['count'] == 0) {
         $this->redirect('/simple/cart');
         exit;
     }
     //返回值
     $this->final_sum = $result['final_sum'];
     $this->promotion = $result['promotion'];
     $this->proReduce = $result['proReduce'];
     $this->sum = $result['sum'];
     $this->goodsList = $result['goodsList'];
     $this->productList = $result['productList'];
     $this->count = $result['count'];
     $this->reduce = $result['reduce'];
     $this->weight = $result['weight'];
     $this->freeFreight = $result['freeFreight'];
     //收货地址列表
     $this->addressList = $addressList;
     //获取商品税金
     $this->goodsTax = $countSumObj->getGoodsTax($this->sum);
     //渲染页面
     $this->redirect('cart2');
 }