当前位置: 首页>>代码示例>>PHP>>正文


PHP Cart::cartFormat方法代码示例

本文整理汇总了PHP中Cart::cartFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::cartFormat方法的具体用法?PHP Cart::cartFormat怎么用?PHP Cart::cartFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cart的用法示例。


在下文中一共展示了Cart::cartFormat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: countOrderFee

 /**
  * 计算订单信息,其中部分计算都是以商品原总价格计算的$goodsSum
  * @param $goodsResult array CountSum结果集
  * @param $province_id int 省份ID
  * @param $delievery_id int 配送方式ID
  * @param $payment_id int 支付ID
  * @param $is_invoice int 是否要发票
  * @param $discount float 订单的加价或者减价
  * @param $promo string 促销活动
  * @param $active_id int 促销活动ID
  * @return $result 最终的返回数组
  */
 public function countOrderFee($goodsResult, $province_id, $delivery_id, $payment_id, $is_invoice, $discount = 0, $promo = '', $active_id = '')
 {
     //根据商家进行商品分组
     $sellerGoods = array();
     foreach ($goodsResult['goodsList'] as $key => $val) {
         if (!isset($sellerGoods[$val['seller_id']])) {
             $sellerGoods[$val['seller_id']] = array();
         }
         $sellerGoods[$val['seller_id']][] = $val;
     }
     $cartObj = new Cart();
     foreach ($sellerGoods as $seller_id => $item) {
         $num = array();
         $productID = array();
         $goodsID = array();
         $goodsArray = array();
         $productArray = array();
         foreach ($item as $key => $val) {
             $goodsID[] = $val['goods_id'];
             $productID[] = $val['product_id'];
             $num[] = $val['count'];
             if ($val['product_id'] > 0) {
                 $productArray[$val['product_id']] = $val['count'];
             } else {
                 $goodsArray[$val['goods_id']] = $val['count'];
             }
         }
         $sellerData = $this->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray)), $promo, $active_id);
         if (is_string($sellerData)) {
             return $sellerData;
         }
         $deliveryList = Delivery::getDelivery($province_id, $delivery_id, $goodsID, $productID, $num);
         if (is_string($deliveryList)) {
             return $deliveryList;
         }
         $extendArray = array('deliveryOrigPrice' => $deliveryList['org_price'], 'deliveryPrice' => $deliveryList['price'], 'insuredPrice' => $deliveryList['protect_price'], 'taxPrice' => $is_invoice == true ? $sellerData['tax'] : 0, 'paymentPrice' => $payment_id != 0 ? self::getGoodsPaymentPrice($payment_id, $sellerData['final_sum']) : 0, 'goodsResult' => $sellerData, 'orderAmountPrice' => 0);
         $orderAmountPrice = array_sum(array($sellerData['final_sum'], $deliveryList['price'], $deliveryList['protect_price'], $extendArray['taxPrice'], $extendArray['paymentPrice'], $discount));
         $extendArray['orderAmountPrice'] = $orderAmountPrice <= 0 ? 0 : round($orderAmountPrice, 2);
         $sellerGoods[$val['seller_id']] = array_merge($sellerData, $extendArray);
     }
     return $sellerGoods;
 }
开发者ID:xzdesk,项目名称:iwebshop.com,代码行数:54,代码来源:countsum.php

示例2: promotionRuleAjax

 function promotionRuleAjax()
 {
     $goodsId = IFilter::act(IReq::get("goodsId"), 'int');
     $productId = IFilter::act(IReq::get("productId"), 'int');
     $num = IFilter::act(IReq::get("num"), 'int');
     $goodsArray = array();
     $productArray = array();
     foreach ($goodsId as $key => $goods_id) {
         $pid = $productId[$key];
         $nVal = $num[$key];
         if ($pid > 0) {
             $productArray[$pid] = $nVal;
         } else {
             $goodsArray[$goods_id] = $nVal;
         }
     }
     $countSumObj = new CountSum();
     $cartObj = new Cart();
     $countSumResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray)));
     echo JSON::encode($countSumResult);
 }
开发者ID:xzdesk,项目名称:iwebshop.com,代码行数:21,代码来源:simple.php

示例3: order_update

 /**
  * @brief 保存修改订单
  */
 public function order_update()
 {
     //获取必要数据
     $order_id = IFilter::act(IReq::get('id'), 'int');
     //生成order数据
     $dataArray['invoice_title'] = IFilter::act(IReq::get('invoice_title'));
     $dataArray['invoice'] = IFilter::act(IReq::get('invoice'), 'int');
     $dataArray['pay_type'] = IFilter::act(IReq::get('pay_type'), 'int');
     $dataArray['accept_name'] = IFilter::act(IReq::get('accept_name'));
     $dataArray['postcode'] = IFilter::act(IReq::get('postcode'));
     $dataArray['telphone'] = IFilter::act(IReq::get('telphone'));
     $dataArray['province'] = IFilter::act(IReq::get('province'), 'int');
     $dataArray['city'] = IFilter::act(IReq::get('city'), 'int');
     $dataArray['area'] = IFilter::act(IReq::get('area'), 'int');
     $dataArray['address'] = IFilter::act(IReq::get('address'));
     $dataArray['mobile'] = IFilter::act(IReq::get('mobile'));
     $dataArray['discount'] = $order_id ? IFilter::act(IReq::get('discount'), 'float') : 0;
     $dataArray['postscript'] = IFilter::act(IReq::get('postscript'));
     $dataArray['distribution'] = IFilter::act(IReq::get('distribution'), 'int');
     $dataArray['accept_time'] = IFilter::act(IReq::get('accept_time'));
     $dataArray['takeself'] = IFilter::act(IReq::get('takeself'));
     //设置订单持有者
     $username = IFilter::act(IReq::get('username'));
     $userDB = new IModel('user');
     $userRow = $userDB->getObj('username = "' . $username . '"');
     $dataArray['user_id'] = isset($userRow['id']) ? $userRow['id'] : 0;
     //拼接要购买的商品或货品数据,组装成固有的数据结构便于计算价格
     $goodsId = IFilter::act(IReq::get('goods_id'));
     $productId = IFilter::act(IReq::get('product_id'));
     $num = IFilter::act(IReq::get('goods_nums'));
     $goodsArray = array();
     $productArray = array();
     foreach ($goodsId as $key => $goods_id) {
         $pid = $productId[$key];
         $nVal = $num[$key];
         if ($pid > 0) {
             $productArray[$pid] = $nVal;
         } else {
             $goodsArray[$goods_id] = $nVal;
         }
     }
     //开始算账
     $countSumObj = new CountSum($dataArray['user_id']);
     $cartObj = new Cart();
     $goodsResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray)));
     $orderData = $countSumObj->countOrderFee($goodsResult, $dataArray['province'], $dataArray['distribution'], $dataArray['pay_type'], $dataArray['invoice'], $dataArray['discount']);
     if (is_string($orderData)) {
         IError::show(403, $orderData);
         exit;
     }
     //根据商品所属商家不同批量生成订单
     foreach ($orderData as $seller_id => $goodsResult) {
         //获取原价的运费
         $dataArray['payable_freight'] = $goodsResult['deliveryOrigPrice'];
         $dataArray['payable_amount'] = $goodsResult['sum'];
         $dataArray['real_amount'] = $goodsResult['final_sum'];
         $dataArray['real_freight'] = $goodsResult['deliveryPrice'];
         $dataArray['insured'] = $goodsResult['insuredPrice'];
         $dataArray['pay_fee'] = $goodsResult['paymentPrice'];
         $dataArray['taxes'] = $goodsResult['taxPrice'];
         $dataArray['promotions'] = $goodsResult['proReduce'] + $goodsResult['reduce'];
         $dataArray['order_amount'] = $goodsResult['orderAmountPrice'];
         $dataArray['exp'] = $goodsResult['exp'];
         $dataArray['point'] = $goodsResult['point'];
         //商家ID
         $dataArray['seller_id'] = $seller_id;
         //生成订单
         $orderDB = new IModel('order');
         //修改操作
         if ($order_id) {
             //获取订单信息
             $orderRow = $orderDB->getObj('id = ' . $order_id);
             //修改订单不能加入其他商家产品
             if (count($orderData) != 1 || $orderRow['seller_id'] != $seller_id) {
                 IError::show(403, "此订单中不能混入其他商家的商品");
                 exit;
             }
             $orderDB->setData($dataArray);
             $orderDB->update('id = ' . $order_id);
             //记录日志信息
             $logObj = new log('db');
             $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "修改了订单信息", '订单号:' . $orderRow['order_no']));
         } else {
             $dataArray['create_time'] = date('Y-m-d H:i:s');
             $dataArray['order_no'] = Order_Class::createOrderNum();
             $orderDB->setData($dataArray);
             $order_id = $orderDB->add();
             //记录日志信息
             $logObj = new log('db');
             $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "添加了订单信息", '订单号:' . $dataArray['order_no']));
         }
         //同步order_goods表
         $orderInstance = new Order_Class();
         $orderInstance->insertOrderGoods($order_id, $goodsResult['goodsResult']);
     }
     $this->redirect('order_list');
 }
开发者ID:xzdesk,项目名称:iwebshop.com,代码行数:100,代码来源:order.php

示例4: getDelivery

 /**
  * @brief 配送方式计算管理模块
  * @param $province    int 省份的ID
  * @param $delivery_id int 配送方式ID
  * @param $goods_id    array 商品ID
  * @param $product_id  array 货品ID
  * @param $num         array 商品数量
  * @return array(
  *	if_delivery => 0:支持配送;1:不支持配送;
  *	price => 运费;
  *	protect_price => 保价;
  *	seller_id => array(price => 运费,protect_price => 保价,org_price => 原始运费)
  *	)
  */
 public static function getDelivery($province, $delivery_id, $goods_id, $product_id = 0, $num = 1)
 {
     //获取默认的配送方式信息
     $delivery = new IModel('delivery');
     $deliveryDefaultRow = $delivery->getObj('is_delete = 0 and status = 1 and id = ' . $delivery_id);
     if (!$deliveryDefaultRow) {
         return "配送方式不存在";
     }
     //最终返回结果
     $result = array('name' => $deliveryDefaultRow['name'], 'description' => $deliveryDefaultRow['description'], 'if_delivery' => 0, 'org_price' => 0, 'price' => 0, 'protect_price' => 0);
     //读取全部商品,array('goodsSum' => 商品总价,'weight' => 商品总重量)
     $sellerGoods = array();
     $goods_id = is_array($goods_id) ? $goods_id : array($goods_id);
     $product_id = is_array($product_id) ? $product_id : array($product_id);
     $num = is_array($num) ? $num : array($num);
     $goodsArray = array();
     $productArray = array();
     foreach ($goods_id as $key => $gid) {
         $pid = $product_id[$key];
         $gnum = $num[$key];
         if ($pid > 0) {
             $productArray[$pid] = $gnum;
             $goodsRow = Api::run("getProductInfo", array('#id#', $pid));
             if (!$goodsRow) {
                 throw new IException("计算商品运费货品ID【" . $pid . "】信息不存在");
             }
         } else {
             $goodsArray[$gid] = $gnum;
             $goodsRow = Api::run("getGoodsInfo", array('#id#', $gid));
             if (!$goodsRow) {
                 throw new IException("计算商品运费商品ID【" . $gid . "】信息不存在");
             }
         }
         if (!isset($sellerGoods[$goodsRow['seller_id']])) {
             $sellerGoods[$goodsRow['seller_id']] = array('goodsSum' => 0, 'weight' => 0);
         }
         $sellerGoods[$goodsRow['seller_id']]['weight'] += $goodsRow['weight'] * $gnum;
         $sellerGoods[$goodsRow['seller_id']]['goodsSum'] += $goodsRow['sell_price'] * $gnum;
     }
     //获取促销规则是否免运费
     $countSumObj = new CountSum(self::$user_id);
     $cartObj = new Cart();
     $countSumResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray)));
     //根据商家不同计算运费
     $deliveryExtendDB = new IModel('delivery_extend');
     foreach ($sellerGoods as $seller_id => $data) {
         $weight = $data['weight'];
         //计算运费
         $goodsSum = $data['goodsSum'];
         //计算保价
         //使用商家配置的物流运费
         $deliverySellerRow = $deliveryExtendDB->getObj('delivery_id = ' . $delivery_id . ' and seller_id = ' . $seller_id);
         $deliveryRow = $deliverySellerRow ? $deliverySellerRow : $deliveryDefaultRow;
         //设置首重和次重
         self::$firstWeight = $deliveryRow['first_weight'];
         self::$secondWeight = $deliveryRow['second_weight'];
         $deliveryRow['if_delivery'] = '0';
         //当配送方式是统一配置的时候,不进行区分地区价格
         if ($deliveryRow['price_type'] == 0) {
             $deliveryRow['price'] = self::getFeeByWeight($weight, $deliveryRow['first_price'], $deliveryRow['second_price']);
         } else {
             $matchKey = '';
             $flag = false;
             //每项都是以';'隔开的省份ID
             $area_groupid = unserialize($deliveryRow['area_groupid']);
             foreach ($area_groupid as $key => $item) {
                 //匹配到了特殊的省份运费价格
                 if (strpos($item, ';' . $province . ';') !== false) {
                     $matchKey = $key;
                     $flag = true;
                     break;
                 }
             }
             //匹配到了特殊的省份运费价格
             if ($flag) {
                 //获取当前省份特殊的运费价格
                 $firstprice = unserialize($deliveryRow['firstprice']);
                 $secondprice = unserialize($deliveryRow['secondprice']);
                 $deliveryRow['price'] = self::getFeeByWeight($weight, $firstprice[$matchKey], $secondprice[$matchKey]);
             } else {
                 //判断是否设置默认费用了
                 if ($deliveryRow['open_default'] == 1) {
                     $deliveryRow['price'] = self::getFeeByWeight($weight, $deliveryRow['first_price'], $deliveryRow['second_price']);
                 } else {
                     $deliveryRow['price'] = '0';
                     $deliveryRow['if_delivery'] = '1';
//.........这里部分代码省略.........
开发者ID:herrify,项目名称:iwebshop,代码行数:101,代码来源:delivery.php


注:本文中的Cart::cartFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。