Пример #1
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @return array or bool
  */
 public function goodsCount($buyInfo)
 {
     $this->sum = 0;
     //原始总额(优惠前)
     $this->final_sum = 0;
     //应付总额(优惠后)
     $this->weight = 0;
     //总重量
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总数量
     $this->promotion = array();
     //促销活动规则文本
     $this->proReduce = 0;
     //促销活动规则优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->isFreeFreight = false;
     //是否免运费
     $user_id = $this->user_id;
     $group_id = $this->group_id;
     $goodsList = array();
     $productList = array();
     /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
      *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
      *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
      *(3)优惠价等于商品(货品)原价;
      */
     //获取商品或货品数据
     /*Goods 拼装商品优惠价的数据*/
     if (isset($buyInfo['goods']['id']) && $buyInfo['goods']['id']) {
         //购物车中的商品数据
         $goodsIdStr = join(',', $buyInfo['goods']['id']);
         $goodsObj = new IModel('goods as go');
         $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id as goods_id,go.img,go.sell_price,go.point,go.weight,go.store_nums,go.exp,go.goods_no,0 as product_id');
         //开始优惠情况判断
         foreach ($goodsList as $key => $val) {
             //检查库存
             if ($buyInfo['goods']['data'][$val['goods_id']]['count'] <= 0 || $buyInfo['goods']['data'][$val['goods_id']]['count'] > $val['store_nums']) {
                 return "商品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
             }
             $groupPrice = $this->getGroupPrice($val['goods_id'], 'goods');
             $goodsList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
             $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['goods_id']]['count'];
             $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
             $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
             $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $goodsList[$key]['count'];
             $this->point += $val['point'] * $goodsList[$key]['count'];
             $this->exp += $val['exp'] * $goodsList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $goodsList[$key]['count'];
         }
     }
     /*Product 拼装商品优惠价的数据*/
     if (isset($buyInfo['product']['id']) && $buyInfo['product']['id']) {
         //购物车中的货品数据
         $productIdStr = join(',', $buyInfo['product']['id']);
         $productObj = new IQuery('products as pro,goods as go');
         $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
         $productObj->fields = 'pro.sell_price,pro.weight,pro.id as product_id,pro.spec_array,pro.goods_id,pro.store_nums,pro.products_no as goods_no,go.name,go.point,go.exp,go.img';
         $productList = $productObj->find();
         //开始优惠情况判断
         foreach ($productList as $key => $val) {
             //检查库存
             if ($buyInfo['product']['data'][$val['product_id']]['count'] <= 0 || $buyInfo['product']['data'][$val['product_id']]['count'] > $val['store_nums']) {
                 return "货品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
             }
             $groupPrice = $this->getGroupPrice($val['product_id'], 'product');
             $productList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
             $productList[$key]['count'] = $buyInfo['product']['data'][$val['product_id']]['count'];
             $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
             $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
             $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $productList[$key]['count'];
             $this->point += $val['point'] * $productList[$key]['count'];
             $this->exp += $val['exp'] * $productList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $productList[$key]['count'];
         }
     }
     $final_sum = $this->sum - $this->reduce;
     //总金额满足的促销规则
     if ($user_id) {
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($group_id);
         $this->isFreeFreight = $proObj->isFreeFreight();
         $this->promotion = $proObj->getInfo();
         $this->proReduce = $final_sum - $proObj->getSum();
     } else {
         $this->promotion = array();
         $this->proReduce = 0;
     }
     $this->final_sum = $final_sum - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => array_merge($goodsList, $productList), 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'freeFreight' => $this->isFreeFreight, 'point' => $this->point, 'exp' => $this->exp);
 }
Пример #2
0
 function promotionRuleAjax()
 {
     $promotion = array();
     $proReduce = 0;
     //总金额满足的促销规则
     if ($this->user['user_id']) {
         $final_sum = intval(IReq::get('final_sum'));
         //获取 user_group
         $groupObj = new IModel('member as m,user_group as g');
         $groupRow = $groupObj->getObj('m.user_id = ' . $this->user['user_id'] . ' and m.group_id = g.id', 'g.*');
         $groupRow['id'] = empty($groupRow) ? 0 : $groupRow['id'];
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($groupRow['id']);
         $promotion = $proObj->getInfo();
         $proReduce = $final_sum - $proObj->getSum();
     }
     $result = array('promotion' => $promotion, 'proReduce' => $proReduce);
     echo JSON::encode($result);
 }
Пример #3
0
 /**
  * @brief 获得订单的实际金额和商品的实际价格
  */
 public function getAmount()
 {
     //获得ajax中post传来的数据
     $uid = IFilter::act(IReq::get('uid'));
     $price = IFilter::act(IReq::get('price'));
     $gid = IFilter::act(IReq::get('gid'));
     $number = IFilter::act(IReq::get('number'));
     $pid = IFilter::act(IReq::get('pid'));
     //将price和gid转换为数组
     $price_arr = array();
     $gid_arr = array();
     $num_arr = array();
     $pid_arr = array();
     $price_arr = explode(',', $price);
     $gid_arr = explode(',', $gid);
     $num_arr = explode(',', $number);
     $pid_arr = explode(',', $pid);
     //获得order_class的对象
     $ord_class = new Order_Class();
     //实际价格
     $real_price = '';
     //执行折扣前的总金额
     $real_amount = 0;
     //循环获得商品的实际价格和实际总金额
     foreach ($price_arr as $key => $value) {
         $real = $ord_class->get_real_price($uid, $gid_arr[$key], $pid_arr[$key], $price_arr[$key]);
         $real_price .= $real . ',';
         $real_amount = $real_amount + $real * $num_arr[$key];
     }
     $real_price = substr($real_price, 0, -1);
     //获得group_id
     $tb_member = new IModel('member');
     $member_info = $tb_member->query('user_id=' . $uid);
     //获得规则函数的对象
     $rule = new ProRule($real_amount);
     $rule->setUserGroup($member_info[0]['group_id']);
     //获得规则折扣后的实际总金额
     $real_amount = $rule->getSum();
     //判断是否免运费,true免,false不免
     $isBolg = $rule->isFreeFreight();
     $relieve = '0';
     if ($isBolg) {
         $relieve = '1';
     }
     //返回页面数据实际商品价格和实际总金额
     echo $relieve . ';' . $real_price . ';' . $real_amount;
 }
Пример #4
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @promo string 活动类型 团购,抢购
  * @active_id int 活动ID
  * @return array or bool
  */
 public function goodsCount($buyInfo, $promo = '', $active_id = '')
 {
     $this->sum = 0;
     //原始总额(优惠前)
     $this->final_sum = 0;
     //应付总额(优惠后)
     $this->weight = 0;
     //总重量
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总数量
     $this->promotion = array();
     //促销活动规则文本
     $this->proReduce = 0;
     //促销活动规则优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->freeFreight = array();
     //商家免运费
     $this->tax = 0;
     //商品税金
     $this->seller = array();
     //商家商品总额统计, 商家ID => 商品金额
     $user_id = $this->user_id;
     $group_id = $this->group_id;
     $goodsList = array();
     $productList = array();
     //活动购买情况
     if ($promo && $active_id) {
         $ac_type = isset($buyInfo['goods']) ? "goods" : "product";
         $ac_id = current($buyInfo[$ac_type]['id']);
         $ac_buy_num = $buyInfo[$ac_type]['data'][$ac_id]['count'];
         //开启促销活动
         $activeObject = new Active($promo, $active_id, $user_id, $ac_id, $ac_type, $ac_buy_num);
         $activeResult = $activeObject->checkValid();
         if ($activeResult === true) {
             $typeRow = $activeObject->originalGoodsInfo;
             $disPrice = $activeObject->activePrice;
             //设置优惠价格,如果不存在则优惠价等于商品原价
             $typeRow['reduce'] = $typeRow['sell_price'] - $disPrice;
             $typeRow['count'] = $ac_buy_num;
             $current_sum_all = $typeRow['sell_price'] * $ac_buy_num;
             $current_reduce_all = $typeRow['reduce'] * $ac_buy_num;
             $typeRow['sum'] = $current_sum_all - $current_reduce_all;
             if (!isset($this->seller[$typeRow['seller_id']])) {
                 $this->seller[$typeRow['seller_id']] = 0;
             }
             $this->seller[$typeRow['seller_id']] += $typeRow['sum'];
             //全局统计
             $this->weight += $typeRow['weight'] * $ac_buy_num;
             $this->point += $typeRow['point'] * $ac_buy_num;
             $this->exp += $typeRow['exp'] * $ac_buy_num;
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $ac_buy_num;
             $this->tax += self::getGoodsTax($typeRow['sum'], $typeRow['seller_id']);
             $typeRow == "goods" ? $goodsList[] = $typeRow : ($productList[] = $typeRow);
         } else {
             //报错信息
             return $activeResult;
         }
     } else {
         /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
          *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
          *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
          *(3)优惠价等于商品(货品)原价;
          */
         //获取商品或货品数据
         /*Goods 拼装商品优惠价的数据*/
         if (isset($buyInfo['goods']['id']) && $buyInfo['goods']['id']) {
             //购物车中的商品数据
             $goodsIdStr = join(',', $buyInfo['goods']['id']);
             $goodsObj = new IModel('goods as go');
             $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id as goods_id,go.img,go.sell_price,go.point,go.weight,go.store_nums,go.exp,go.goods_no,0 as product_id,go.seller_id');
             //开始优惠情况判断
             foreach ($goodsList as $key => $val) {
                 //检查库存
                 if ($buyInfo['goods']['data'][$val['goods_id']]['count'] <= 0 || $buyInfo['goods']['data'][$val['goods_id']]['count'] > $val['store_nums']) {
                     return "商品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
                 }
                 $groupPrice = $this->getGroupPrice($val['goods_id'], 'goods');
                 $goodsList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
                 $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['goods_id']]['count'];
                 $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
                 $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
                 $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
                 if (!isset($this->seller[$val['seller_id']])) {
                     $this->seller[$val['seller_id']] = 0;
                 }
                 $this->seller[$val['seller_id']] += $goodsList[$key]['sum'];
                 //全局统计
                 $this->weight += $val['weight'] * $goodsList[$key]['count'];
                 $this->point += $val['point'] * $goodsList[$key]['count'];
                 $this->exp += $val['exp'] * $goodsList[$key]['count'];
                 $this->sum += $current_sum_all;
                 $this->reduce += $current_reduce_all;
                 $this->count += $goodsList[$key]['count'];
                 $this->tax += self::getGoodsTax($goodsList[$key]['sum'], $val['seller_id']);
             }
         }
         /*Product 拼装商品优惠价的数据*/
         if (isset($buyInfo['product']['id']) && $buyInfo['product']['id']) {
             //购物车中的货品数据
             $productIdStr = join(',', $buyInfo['product']['id']);
             $productObj = new IQuery('products as pro,goods as go');
             $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
             $productObj->fields = 'pro.sell_price,pro.weight,pro.id as product_id,pro.spec_array,pro.goods_id,pro.store_nums,pro.products_no as goods_no,go.name,go.point,go.exp,go.img,go.seller_id';
             $productList = $productObj->find();
             //开始优惠情况判断
             foreach ($productList as $key => $val) {
                 //检查库存
                 if ($buyInfo['product']['data'][$val['product_id']]['count'] <= 0 || $buyInfo['product']['data'][$val['product_id']]['count'] > $val['store_nums']) {
                     return "货品:" . $val['name'] . "购买数量超出库存,请重新调整购买数量";
                 }
                 $groupPrice = $this->getGroupPrice($val['product_id'], 'product');
                 $productList[$key]['reduce'] = $groupPrice === null ? 0 : $val['sell_price'] - $groupPrice;
                 $productList[$key]['count'] = $buyInfo['product']['data'][$val['product_id']]['count'];
                 $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
                 $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
                 $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
                 if (!isset($this->seller[$val['seller_id']])) {
                     $this->seller[$val['seller_id']] = 0;
                 }
                 $this->seller[$val['seller_id']] += $productList[$key]['sum'];
                 //全局统计
                 $this->weight += $val['weight'] * $productList[$key]['count'];
                 $this->point += $val['point'] * $productList[$key]['count'];
                 $this->exp += $val['exp'] * $productList[$key]['count'];
                 $this->sum += $current_sum_all;
                 $this->reduce += $current_reduce_all;
                 $this->count += $productList[$key]['count'];
                 $this->tax += self::getGoodsTax($productList[$key]['sum'], $val['seller_id']);
             }
         }
         //总金额满足的促销规则
         if ($user_id) {
             //计算每个商家促销规则
             foreach ($this->seller as $seller_id => $sum) {
                 $proObj = new ProRule($sum, $seller_id);
                 $proObj->setUserGroup($group_id);
                 if ($proObj->isFreeFreight() == true) {
                     $this->freeFreight[] = $seller_id;
                 }
                 $this->promotion = array_merge($proObj->getInfo(), $this->promotion);
                 $this->proReduce += $sum - $proObj->getSum();
             }
         }
     }
     $this->final_sum = $this->sum - $this->reduce - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => array_merge($goodsList, $productList), 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'point' => $this->point, 'exp' => $this->exp, 'tax' => $this->tax, 'freeFreight' => $this->freeFreight, 'seller' => $this->seller);
 }
Пример #5
0
 /**
  * @brief 计算商品价格
  * @param Array $buyInfo ,购物车格式
  * @return array or bool
  */
 private function goodsCount($buyInfo)
 {
     $this->weight = 0;
     //总重量
     $this->sum = 0;
     //原始总额
     $this->reduce = 0;
     //减少总额
     $this->count = 0;
     //总量
     $this->final_sum = 0;
     //应付总额
     $this->proReduce = 0;
     //促销活动优惠额
     $this->point = 0;
     //增加积分
     $this->exp = 0;
     //增加经验
     $this->isFreeFreight = false;
     //是否免运费
     $user_id = ISafe::get('user_id');
     $group_id = 0;
     $goodsList = array();
     $productList = array();
     //获取用户组ID及组的折扣率
     if ($user_id != null) {
         $groupObj = new IModel('member as m , user_group as g');
         $groupRow = $groupObj->getObj('m.user_id = ' . $user_id . ' and m.group_id = g.id', 'g.*');
         if (!empty($groupRow)) {
             $group_id = $groupRow['id'];
             $group_discount = $groupRow['discount'] / 100;
             $groupPriceObj = new IModel('group_price');
         }
     }
     /*开始计算goods和product的优惠信息 , 会根据条件分析出执行以下哪一种情况:
      *(1)查看此商品(货品)是否已经根据不同会员组设定了优惠价格;
      *(2)当前用户是否属于某个用户组中的成员,并且此用户组享受折扣率;
      *(3)优惠价等于商品(货品)原价;
      */
     //获取商品或货品数据
     /*Goods 拼装商品优惠价的数据*/
     if (isset($buyInfo['goods']['id']) && !empty($buyInfo['goods']['id'])) {
         //购物车中的商品数据
         $goodsIdStr = join(',', $buyInfo['goods']['id']);
         $goodsObj = new IModel('goods as go');
         $goodsList = $goodsObj->query('go.id in (' . $goodsIdStr . ')', 'go.name,go.id,go.list_img,go.sell_price,go.point,go.weight,go.store_nums,go.exp');
         if ($group_id) {
             //获取 "优惠情况(1)" 中的商品优惠价格
             $discountGoodsResult = array();
             $discountGoodsList = $groupPriceObj->query('products_id = 0 and goods_id in(' . $goodsIdStr . ') and group_id = ' . $group_id);
             foreach ($discountGoodsList as $val) {
                 $discountGoodsResult[$val['goods_id']] = $val;
             }
         }
         //开始优惠情况判断
         foreach ($goodsList as $key => $val) {
             //优惠情况(1)
             if (isset($discountGoodsResult[$val['id']]['price'])) {
                 $goodsList[$key]['reduce'] = $val['sell_price'] - $discountGoodsResult[$val['id']]['price'];
             } else {
                 if (isset($group_discount) && $group_discount != 0) {
                     $goodsList[$key]['reduce'] = $val['sell_price'] - $val['sell_price'] * $group_discount;
                 } else {
                     $goodsList[$key]['reduce'] = 0;
                 }
             }
             $goodsList[$key]['count'] = $buyInfo['goods']['data'][$val['id']]['count'];
             $current_sum_all = $goodsList[$key]['sell_price'] * $goodsList[$key]['count'];
             $current_reduce_all = $goodsList[$key]['reduce'] * $goodsList[$key]['count'];
             $goodsList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $goodsList[$key]['count'];
             $this->point += $val['point'] * $goodsList[$key]['count'];
             $this->exp += $val['exp'] * $goodsList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $goodsList[$key]['count'];
         }
     }
     /*Product 拼装商品优惠价的数据*/
     if (isset($buyInfo['product']['id']) && !empty($buyInfo['product']['id'])) {
         //购物车中的货品数据
         $productIdStr = join(',', $buyInfo['product']['id']);
         $productObj = new IQuery('products as pro,goods as go');
         $productObj->where = 'pro.id in (' . $productIdStr . ') and go.id = pro.goods_id';
         $productObj->fields = 'pro.sell_price,pro.weight,pro.id,pro.spec_array,pro.goods_id,pro.store_nums,go.name,go.point,go.exp,go.list_img';
         $productList = $productObj->find();
         if ($group_id) {
             //获取 "优惠情况(1)" 中的商品优惠价格
             $discountProductResult = array();
             $discountProductList = $groupPriceObj->query('products_id in (' . $productIdStr . ') and group_id = ' . $group_id);
             foreach ($discountProductList as $val) {
                 $discountProductResult[$val['goods_id']] = $val;
             }
         }
         //开始优惠情况判断
         foreach ($productList as $key => $val) {
             //优惠情况(1)
             if (isset($discountProductResult[$val['id']]['price'])) {
                 $productList[$key]['reduce'] = $val['sell_price'] - $discountProductResult[$val['id']]['price'];
             } else {
                 if (isset($group_discount) && $group_discount != 0) {
                     $productList[$key]['reduce'] = $val['sell_price'] - $val['sell_price'] * $group_discount;
                 } else {
                     $productList[$key]['reduce'] = 0;
                 }
             }
             $productList[$key]['count'] = $buyInfo['product']['data'][$val['id']]['count'];
             $current_sum_all = $productList[$key]['sell_price'] * $productList[$key]['count'];
             $current_reduce_all = $productList[$key]['reduce'] * $productList[$key]['count'];
             $productList[$key]['sum'] = $current_sum_all - $current_reduce_all;
             //全局统计
             $this->weight += $val['weight'] * $productList[$key]['count'];
             $this->point += $val['point'] * $productList[$key]['count'];
             $this->exp += $val['exp'] * $productList[$key]['count'];
             $this->sum += $current_sum_all;
             $this->reduce += $current_reduce_all;
             $this->count += $productList[$key]['count'];
         }
     }
     $final_sum = $this->sum - $this->reduce;
     //总金额满足的促销规则
     if ($user_id) {
         $proObj = new ProRule($final_sum);
         $proObj->setUserGroup($group_id);
         $this->isFreeFreight = $proObj->isFreeFreight();
         $this->promotion = $proObj->getInfo();
         $this->proReduce = $final_sum - $proObj->getSum();
     } else {
         $this->promotion = array();
         $this->proReduce = 0;
     }
     $this->final_sum = $final_sum - $this->proReduce;
     return array('final_sum' => $this->final_sum, 'promotion' => $this->promotion, 'proReduce' => $this->proReduce, 'sum' => $this->sum, 'goodsList' => $goodsList, 'productList' => $productList, 'count' => $this->count, 'reduce' => $this->reduce, 'weight' => $this->weight, 'freeFreight' => $this->isFreeFreight, 'point' => $this->point, 'exp' => $this->exp);
 }